The three-row progression is the cleanest demo of this I've seen — markers fix re-doing finished work, the idempotency key fixes the external side effect, and only fencing stops two live workers. The subtle part worth underlining: the idempotency key only works if it's derived deterministically from the task, not generated at call time. If a retried worker mints a fresh UUID for the email, the provider sees a new request and you're back to two emails even with "idempotency" in the code. Deriving it as hash(task_id + step_name) is what makes recovery actually safe. One thing I'd add to the fencing row: the epoch/lease number has to travel all the way to the write and be checked there (compare-and-swap on the row), not just checked when the worker wakes up — otherwise the zombie worker passes the wake-up check, then stalls, then writes after the new worker already fenced it. Did your SQLite version enforce the fence at write time, or at claim time? That gap is where the "0 of 20" can quietly become "1 of 20" under real scheduling jitter.
Both points are right. The key in the demo is derived, not minted: Idempotency-Key: ${task.id}:send_email. A retried worker sends the same key, which is the only reason the keyed row reads 0. A fresh UUID per attempt would look idempotent in the code and do nothing.
The fence is enforced at write time. Every write runs inside a BEGIN IMMEDIATE transaction that first reads the task's epoch and throws if it changed, then writes. BEGIN IMMEDIATE takes SQLite's write lock before that read, so a new claim can't land between the check and the write. That makes it a compare-and-swap on the row. There's also a check just before each external call, but that one only saves work. It can't be the guarantee, because the lease can expire during the call, and that's exactly the gap the idempotency key covers. On a multi-writer database I'd write it as UPDATE ... WHERE id = ? AND epoch = ? and check the row count, rather than a separate read.
The 20/20 zombie-worker row is where most production setups get burned, because a GC pause or stalled upstream call looks identical to a dead worker from outside.
Two subtle bugs I hit in this exact durability boundary:
Replay-path errors on memoized steps. While debugging inngest/inngest-js#1904, a wrapStep middleware throwing on a memoized step during replay left the step promise unsettled instead of propagating the error, so recovery stalled right after reading the completion marker. Testing middleware failures during replay catches a class of hangs that crash-point tests miss.
Inbound webhook races between side effect and marker commit. On a venue ticketing backend I run (10,238 recorded transactions across 3,526 bookings and 7,116 POS orders with Razorpay UPI webhooks and Redis slot leases), a payment webhook can arrive before the booking worker commits its local marker. Keying both the provider call and webhook reconciliation on one deterministic booking intent ID prevented double-issued tickets.
Did your lease-fencing test also cover a provider succeeding right as the lease expires and the retry arriving after the provider's dedup window?
That's a great field report, and a sharper version of the gateway case than I could test.
The billing gap closing once transport.abort() dropped the socket instead of a graceful close draining the buffered chunks is the arm D mechanism showing up one layer further in. Mocks hide it, as you found. No, I haven't run the probe through a Python gateway. Everything went direct to DeepSeek, with only a local network proxy in the path. It would be a good next test, since the balance-meter method works whatever sits in between. The retry point deserves to be in the article too: a wrapper that treats an AbortError as a network failure turns a user's cancel into a fresh, fully billed request. Checking signal.aborted before retrying is the one-line guard.
That's a great field report, and a sharper version of the gateway case than I could test.
The billing gap closing once transport.abort() dropped the socket instead of a graceful close draining the buffered chunks is the arm D mechanism showing up one layer further in. Mocks hide it, as you found.
No, I haven't run the probe through a Python gateway. Everything went direct to DeepSeek, with only a local network proxy in the path. It would be a good next test, since the balance-meter method works whatever sits in between. The retry point deserves to be in the article too: a wrapper that treats an AbortError as a network failure turns a user's cancel into a fresh, fully billed request. Checking signal.aborted before retrying is the one-line guard.
The crash matrix makes the boundaries unusually clear. I would carry one logical task ID through the step journal, worker epoch, attempt, and external idempotency key in the trace. At after-call:send_email, a missing completion marker means “outcome unknown,” not “email failed,” and that difference matters when the provider’s key retention expires. Does the demo record a dispatch event separately from the completion marker so an operator can see that uncertainty?
A missing marker after the call means "outcome unknown", not "failed", and that's what goes to reconciliation once the key's retention has run out. In the demo the dispatch is only partly recorded. The worker logs a call-start event with its epoch before every external call, and the step journal only gets a row when the step completes. So the uncertainty is visible in the logs but not queryable in the journal. The better shape is what you describe: write a dispatched row to the journal (task ID, step, epoch, attempt, idempotency key) before the call, then mark it done with the provider's message ID afterwards. A dispatched row with no completion is then exactly the "outcome unknown" queue an operator needs.
This is the rare agent-reliability post that actually measures instead of asserts — the two tables are the whole argument. The one that sticks with me is the zombie-worker table: markers alone still double-sent in 20 of 20 runs, and the idempotency key fixed the email but not the fact that both workers finished the task. Fencing is the only thing that stopped the old worker writing, and even then the average is 4.0 calls, not 3 — the in-flight step is always paid. One gap your own 'not established' list names: a real mail provider may keep idempotency keys only for a short time. If a run retries days later and the key has expired, the second send goes through — so is the key's lifetime the real expiry you have to design around, and would you scope it to the task's retry window?
Yes, the key's lifetime is the expiry you actually design around. The experiment couldn't show it, because the mock keeps keys forever. I'd scope it the way you suggest: retries are only automatic inside the provider's retention window (Stripe documents at least 24 hours). After that, a step whose outcome is unknown stops and waits for reconciliation, using the provider's message ID if the journal has one. I've added that to the article.
And yes, the 4.0 is the honest cost. Fencing stops the old worker from writing, but the call it already had in flight has been paid for. Small steps keep that cost small.
A technologist working in automation. Here I write up what I actually learn building tools, engineering AI agents, and keeping systems running, along with the workflows and habits that stick.
The key's retention window needs to cover the whole retry window, including manual replays. If a send is still uncertain after that window, a retry can become a second email. I'd leave it for reconciliation rather than silently send again. The step journal should keep the provider's message ID when one is returned, so an operator has something concrete to look up.
Agreed on all three, and I've added them to the article. The key's lifetime has to cover every retry path, manual replays included. Past that window, an uncertain send goes to reconciliation rather than out again. And the provider's message ID belongs in the step journal next to the marker, so the reconciler has something to look up instead of guessing from timestamps.
We're a place where coders share, stay up-to-date and grow their careers.
The three-row progression is the cleanest demo of this I've seen — markers fix re-doing finished work, the idempotency key fixes the external side effect, and only fencing stops two live workers. The subtle part worth underlining: the idempotency key only works if it's derived deterministically from the task, not generated at call time. If a retried worker mints a fresh UUID for the email, the provider sees a new request and you're back to two emails even with "idempotency" in the code. Deriving it as
hash(task_id + step_name)is what makes recovery actually safe. One thing I'd add to the fencing row: the epoch/lease number has to travel all the way to the write and be checked there (compare-and-swap on the row), not just checked when the worker wakes up — otherwise the zombie worker passes the wake-up check, then stalls, then writes after the new worker already fenced it. Did your SQLite version enforce the fence at write time, or at claim time? That gap is where the "0 of 20" can quietly become "1 of 20" under real scheduling jitter.Both points are right. The key in the demo is derived, not minted: Idempotency-Key: ${task.id}:send_email. A retried worker sends the same key, which is the only reason the keyed row reads 0. A fresh UUID per attempt would look idempotent in the code and do nothing.
The fence is enforced at write time. Every write runs inside a BEGIN IMMEDIATE transaction that first reads the task's epoch and throws if it changed, then writes. BEGIN IMMEDIATE takes SQLite's write lock before that read, so a new claim can't land between the check and the write. That makes it a compare-and-swap on the row. There's also a check just before each external call, but that one only saves work. It can't be the guarantee, because the lease can expire during the call, and that's exactly the gap the idempotency key covers. On a multi-writer database I'd write it as UPDATE ... WHERE id = ? AND epoch = ? and check the row count, rather than a separate read.
The 20/20 zombie-worker row is where most production setups get burned, because a GC pause or stalled upstream call looks identical to a dead worker from outside.
Two subtle bugs I hit in this exact durability boundary:
inngest/inngest-js#1904, awrapStepmiddleware throwing on a memoized step during replay left the step promise unsettled instead of propagating the error, so recovery stalled right after reading the completion marker. Testing middleware failures during replay catches a class of hangs that crash-point tests miss.Did your lease-fencing test also cover a provider succeeding right as the lease expires and the retry arriving after the provider's dedup window?
That's a great field report, and a sharper version of the gateway case than I could test.
The billing gap closing once transport.abort() dropped the socket instead of a graceful close draining the buffered chunks is the arm D mechanism showing up one layer further in. Mocks hide it, as you found. No, I haven't run the probe through a Python gateway. Everything went direct to DeepSeek, with only a local network proxy in the path. It would be a good next test, since the balance-meter method works whatever sits in between. The retry point deserves to be in the article too: a wrapper that treats an AbortError as a network failure turns a user's cancel into a fresh, fully billed request. Checking signal.aborted before retrying is the one-line guard.
That's a great field report, and a sharper version of the gateway case than I could test.
The billing gap closing once transport.abort() dropped the socket instead of a graceful close draining the buffered chunks is the arm D mechanism showing up one layer further in. Mocks hide it, as you found.
No, I haven't run the probe through a Python gateway. Everything went direct to DeepSeek, with only a local network proxy in the path. It would be a good next test, since the balance-meter method works whatever sits in between. The retry point deserves to be in the article too: a wrapper that treats an AbortError as a network failure turns a user's cancel into a fresh, fully billed request. Checking signal.aborted before retrying is the one-line guard.
The crash matrix makes the boundaries unusually clear. I would carry one logical task ID through the step journal, worker epoch, attempt, and external idempotency key in the trace. At
after-call:send_email, a missing completion marker means “outcome unknown,” not “email failed,” and that difference matters when the provider’s key retention expires. Does the demo record a dispatch event separately from the completion marker so an operator can see that uncertainty?Agreed.
A missing marker after the call means "outcome unknown", not "failed", and that's what goes to reconciliation once the key's retention has run out. In the demo the dispatch is only partly recorded. The worker logs a call-start event with its epoch before every external call, and the step journal only gets a row when the step completes. So the uncertainty is visible in the logs but not queryable in the journal. The better shape is what you describe: write a dispatched row to the journal (task ID, step, epoch, attempt, idempotency key) before the call, then mark it done with the provider's message ID afterwards. A dispatched row with no completion is then exactly the "outcome unknown" queue an operator needs.
This is the rare agent-reliability post that actually measures instead of asserts — the two tables are the whole argument. The one that sticks with me is the zombie-worker table: markers alone still double-sent in 20 of 20 runs, and the idempotency key fixed the email but not the fact that both workers finished the task. Fencing is the only thing that stopped the old worker writing, and even then the average is 4.0 calls, not 3 — the in-flight step is always paid. One gap your own 'not established' list names: a real mail provider may keep idempotency keys only for a short time. If a run retries days later and the key has expired, the second send goes through — so is the key's lifetime the real expiry you have to design around, and would you scope it to the task's retry window?
Thanks.
Yes, the key's lifetime is the expiry you actually design around. The experiment couldn't show it, because the mock keeps keys forever. I'd scope it the way you suggest: retries are only automatic inside the provider's retention window (Stripe documents at least 24 hours). After that, a step whose outcome is unknown stops and waits for reconciliation, using the provider's message ID if the journal has one. I've added that to the article.
And yes, the 4.0 is the honest cost. Fencing stops the old worker from writing, but the call it already had in flight has been paid for. Small steps keep that cost small.
The key's retention window needs to cover the whole retry window, including manual replays. If a send is still uncertain after that window, a retry can become a second email. I'd leave it for reconciliation rather than silently send again. The step journal should keep the provider's message ID when one is returned, so an operator has something concrete to look up.
Agreed on all three, and I've added them to the article. The key's lifetime has to cover every retry path, manual replays included. Past that window, an uncertain send goes to reconciliation rather than out again. And the provider's message ID belongs in the step journal next to the marker, so the reconciler has something to look up instead of guessing from timestamps.