The supplier's file says the enamel mug is gone. The app reads that, decides the mug should be a
draft, and writes status: DRAFT to the store. The store accepts it. Then the merchant's automation
runs, sees a product with twelve units on hand and a draft status, and puts it back to ACTIVE. The
store fires products/update for its own change, the app receives it, still believes the mug should
be a draft, and writes again.
Forty rounds later the store's rate limit stops it. The mug is still on sale.
No single step in that loop is broken: the app reads the supplier file accurately, the automation enforces its stock rule, and the webhook reports a real change that the app itself requested.
Key takeaways
- A write that the store answers with a webhook is a write that comes back to you as input.
- The app and the store's automation both own
status, and no state satisfies both rules, so every write undoes the last one. - Forty writes to one product means the rate limit stopped the loop, while the underlying conflict remains.
- Quieting the handler makes the log readable and leaves the product in the wrong state: check A is the one that notices.
- The lab has no concurrency on purpose, so the one-lane-per-product advice you would reach for is not exercised here.
What it measures now
Every line below comes from make demo and make check, run on the starter as it ships:
| check | what it says |
|---|---|
make demo |
writes=120 throttled=3 final=ACTIVE, forty writes per product |
A. supplier says unavailable, product ends DRAFT |
MUG-01 status=ACTIVE after 40 writes |
| B. that change costs at most 2 writes | 40 writes to sync one product |
| C. no product is ever throttled | 2 product(s) throttled across 4 scenarios: MUG-01, TEE-01 |
| D. renaming a product produces 0 writes | 39 app write(s) after 1 title edit |
| E. a burst of five changes ends on the fifth | first decision after the burst: ACTIVE; fifth update says DRAFT, first said ACTIVE |
F. supplier restores it, product ends ACTIVE |
out: ACTIVE/12, back: ACTIVE/12 |
| G. no write whose payload already equals the live value | 40 redundant of 160 writes |
make check: 0 of 7 green.
In row D, a single title edit triggers thirty-nine writes because the handler recalculates everything on every product event without checking whether anything changed. That noisy bug is easy to spot first, and it floods the log enough to hide the other failures.
Two rules, one field
supplier file -> app decides status -> store.write(status="DRAFT")
|
the store's automation: | inventory > 0 and DRAFT
status = "ACTIVE" <------+
|
products/update ---------+---> the app, again
The app's rule is "no supplier stock means draft". The store's rule is "stock on hand means it cannot be a draft". Both rules are defensible, yet together they have no state that satisfies both, so the two systems keep undoing each other's writes one round trip at a time.
Treat store/store.py as the test harness rather than code to edit. It fires products/update after
every accepted write, including a write that changed nothing, which is what a real store does and what
turns a redundant write into a loop instead of a no-op. It throttles a product after forty writes so the
loop becomes a log you can read instead of a process that hangs. And it delivers the webhook
synchronously, inside write(), before returning: a real store does it over the network in the same
window between your write and your next line of code. The lab collapses the network so the failure is
reproducible instead of flaky.
Your mission
Make make check green. The seven checks cover three conditions:
- One supplier change for one product ends in
DRAFT, costs at most two writes, and never hits the rate limit in any scenario. - Unrelated edits produce zero writes: renaming a product triggers nothing, and no write sends a payload that already matches the live value.
- The newest supplier answer wins: five updates arriving before the worker runs end on the fifth, and
restoring the product returns it to
ACTIVEwith its previous stock so drafting does not permanently wipe out the stock count.
You may change anything in app/. Do not change store/, data/, or scripts/check.py.
What this lab does not do
There is no concurrency here: one thread, one queue, and no locks. The usual production fix of keeping
one lane per product so two workers cannot interleave writes is not exercised or rewarded by
make check, because this lab focuses on field ownership.
The lab also does not call a real store, so there is no network and no credentials. The write counts are exact and reproducible for the harness, while a real store enforces per-minute quotas per app and a loop often triggers hours after deploy on an unmonitored product.
Finally, redundant writes here cost log lines and eventually a throttle error rather than billing against a shared merchant API quota.
The answer
The answer article is here, and the fix lives on the
solusi branch: git diff main solusi -- 0007.echo-loop/. Read HINTS.md
first; it has three levels, one per bug, and the first is enough for most people.
Stopping the handler from reacting to its own writes only quiets the log; it still leaves the mug active on the storefront.