The build passed. The agent was waiting for a build. If it takes the result as its cue to continue, it sends the wrong commit to review.
In this hypothetical maintenance workflow, a developer replaces commit A with commit B while continuous integration (CI) is still running. A succeeds anyway. Its webhook is valid, and the provider eventually delivers it twice. The event belongs to this workflow’s history. Whether it can advance the workflow depends on what the workflow is waiting for when the event is applied.
| Time | Event ID | Correlated build | Workflow revision | Disposition |
|---|---|---|---|---|
| 09:00 | request-a | build-41 for A | — → 1 | The agent requests a build and records the wait. |
| 09:02 | replace-with-b | build-42 for B | 1 → 2 | The user replaces A. A’s wait is superseded and B’s becomes active. |
| 09:04 | ci/evt-751 | build-41 for A | 2 | Intake verifies and saves A’s success, then crashes before acknowledging it. A worker recovers the row and records it as stale. |
| 09:05 | reconcile-42 | build-42 for B | 2 → 3 | B’s webhook is overdue. A lookup confirms B succeeded. The workflow consumes the observation, queues review, and resumes. |
| 09:06 | ci/evt-751 | build-41 for A | 3 | The provider retries A’s delivery. Intake recognizes the event ID and acknowledges the retry. |
| 09:09 | ci/evt-752 | build-42 for B | 3 | B’s webhook arrives under a fresh ID. Its wait was already satisfied by reconciliation. |
The runtime needs to answer three questions. Did we accept this event? Which request and waiting step does it describe? Can it still change the current workflow? The retry at 09:06 is settled by event identity. The first delivery at 09:04 and the late webhook at 09:09 both require durable workflow state to explain their outcomes.
Put that logic in the harness, before asking the model to continue. The harness can show the agent exactly why B is ready for review and keep the full decision trail available to operators.
What two implementations tell us about the handoff
In its October 29 engineering report, Trigger.dev describes verifying and deduplicating a webhook, then writing the delivery to a durable queue before returning HTTP 200. Postgres persistence and routing happen later. A delivery can start a task, satisfy a waiting run, or reach an agent session. Trigger.dev describes deduplication both at ingress and at task-run creation. Its waiter simulator found a race when a delivery reached a buffer just before its waiter was created. The shipped matching rule accepts deliveries that arrived after waiter creation. Trigger.dev reports roughly 385,000 simulator operations and 49,000 injected crashes after that change. Those are results for its implementation and simulator. Trigger.dev engineering report
Microsoft’s Durable Task documentation describes external events addressed to a specific orchestration instance and event name. Its October 13 update says the MSSQL storage provider consumes the external event and updates orchestrator state in one transaction. Azure Storage can deliver duplicates, so Microsoft advises carrying a unique event ID for portable deduplication. The documentation also recommends racing an external event against a durable timer when the wait needs a deadline. Microsoft Durable Task external events
Together these accounts motivate two commits in the example below. One records the accepted delivery. The other records the decision to apply it and advances the workflow. A stable provider ID answers whether a delivery is a retry. A build identity and a current wait answer whether applying its result is still valid.
Persist the delivery before returning success
The intake endpoint resolves the configured provider connection, enforces a payload limit, and verifies the signature using the provider’s required bytes and headers. It records an authenticated envelope with the connection, provider event ID, event kind, receipt time, and enough payload to recover and interpret it. The source namespace comes from configured connection identity. For the hypothetical provider, the inbox has a unique constraint on (connection_id, event_id). If a provider distinguishes logical events from delivery attempts, keep both and use the documented stable identity for deduplication. Verify authenticity on each attempt. If one event key appears with conflicting business fields, retain the original and flag the conflict for investigation. Standard Webhooks specification
Return success after the inbox commit, including on a verified retry of a previously accepted event. A crash before that commit leaves the delivery unaccepted. A crash after it can leave the sender unsure whether it was accepted, while the worker can still recover it by scanning pending rows. Any notification to a worker can be an optimization if the scan can find every pending row independently. If the durable store is unavailable, surface the failed acceptance so the sender or the operator can respond according to the integration’s delivery policy.
Provider behavior belongs in that policy. Stripe documents automatic retries and warns that events can arrive out of order. GitHub requires an explicit redelivery after a failed webhook attempt, either through its interface or through the API. The retry at 09:06 is a property of our hypothetical CI provider. The inbox protects accepted events. Reconciliation can recover a build result whose delivery never reached that point. Stripe webhook delivery behavior · GitHub failed webhook deliveries
Store the verified fields the reducer needs and set separate lifetimes for sensitive payloads and deduplication records. A compact event key, payload fingerprint, and outcome can outlive the raw body. Size that window using the provider’s retry and manual redelivery behavior and your recovery obligations. Once an inbox key expires, the current wait and its completion record still decide whether a replay can move the workflow.
Correlate the result with the exact wait
When requesting B, persist a wait for a specific tenant, provider connection, repository ID, immutable commit SHA, build request, and build attempt. Associate that request with workflow maint-17 and wait wait-b. Store the expected event kind and the workflow definition version that interprets it. Where the provider accepts a client request key, persist the wait and key before dispatch. Where the provider assigns the only usable build ID, persist the local intent first and associate the returned ID with it. A fast callback can arrive before that association commits. The inbox gives it somewhere to sit while the association is resolved.
Look up the request using the authenticated connection and provider build identity, then compare repository, commit, and attempt with the saved request. Resolve the workflow from that association. A branch name can move, a commit can have multiple builds, and the same repository can have several agents waiting. The immutable wait ID identifies the particular obligation even if unrelated metadata changes the workflow’s revision. The revision controls concurrency when the workflow applies the result.
Keep the previous wait’s outcome. It lets a worker distinguish a superseded wait, such as A’s, from an already-satisfied wait, such as B’s at 09:09. An event with an expected but unresolved mapping can remain pending until a deadline. An event with conflicting identifiers can be quarantined. The operator should be able to see whether an event was stale, already satisfied, awaiting correlation, unrelated, invalid, or applied. Log typed reasons and safe identifiers so the distinction survives a restart.
Consume the event and change workflow state in one transaction
For this example, a single database owns the inbox, wait, workflow, and outbox. Each build request resolves to one wait, and the wait can be satisfied only once. Four records carry the handoff.
| Record | Key and relevant fields |
|---|---|
| Inbox event | Unique source namespace and event ID, authenticated build identity, status, disposition, evaluated revision. |
| Build wait | Immutable wait ID, tenant and build identity, expected event kind, deadline, active or terminal state, and winning event ID when satisfied. |
| Workflow | Workflow ID, current revision, active wait ID, definition version, and next step. |
| Outbox operation | Unique operation ID, originating workflow revision, wait ID, immutable action payload, and delivery state. |
The worker loads and locks the pending inbox event and the workflow it resolves to, then evaluates the wait against the locked state. Every writer that changes the active wait, including user supersession and cancellation, uses the same workflow lock. In PostgreSQL a SELECT FOR UPDATE on the workflow row can provide this serialization if all writers follow it. A revision-guarded update is another option when a conflict causes the transaction to roll back and the worker re-evaluates from fresh state. PostgreSQL transaction isolation
in one database transaction:
event = lockPendingInboxEvent(eventKey)
if event is absent:
return
request = resolveRecordedBuild(event.authenticatedIdentity)
if request is unresolved:
deferOrQuarantine(event, reason, correlationDeadline)
return
workflow = lockWorkflow(request.workflowId)
wait = readWait(request.waitId)
outcome = evaluate(event, request, wait, workflow)
if outcome does not advance the workflow:
recordDisposition(event, outcome, workflow.revision)
return
satisfyWait(wait, event.key)
nextRevision = advanceToReview(workflow, wait, event.result)
markConsumed(event, wait.id, nextRevision)
operationId = reviewOperationId(workflow.id, wait.id)
insertOutbox(operationId, reviewPayload(request, nextRevision))The example uses success to enter review. A build failure can move to a failure-handling step using the same transaction. A progress notification can be recorded without satisfying the wait. Keep the reducer deterministic and record its inputs, including any authoritative build snapshot and the evaluation time if a deadline matters. Provider lookups, queue sends, and model calls take place outside the transaction.
If the worker dies before commit, the event is still eligible for processing. If it dies after commit, the winning event, satisfied wait, new revision, and outbox entry survive together. If a webhook and a reconciliation observation race, each has its own event key. The workflow lock and the single transition out of the wait decide the winner. The second worker sees the satisfied wait and records its disposition without queueing another review.
An external review service adds another crash window. The outbox relay can send successfully and die before updating the delivery record. Retrying with the same operation ID lets a consumer that owns its effect apply it with a unique receipt in one transaction. If the consumer calls another provider, use that provider’s idempotency contract or reconcile an uncertain result before attempting a second effect. An outbox makes the intent recoverable across crashes. Its delivery can still repeat. AWS transactional outbox guidance · Amazon Builders’ Library on idempotent APIs
The queued operation binds the immutable commit and the workflow revision that justified the next step. A user may still replace B after revision 3 commits. A consumer that can take a consequential action must check current authority and relevance at dispatch, and use target-side conditions or fencing where the required guarantee depends on the state of a separate service. A build result supplies evidence for review. Approval to publish or deploy has its own binding. ContextOS execution contract
Reconcile missing and reordered notifications
Schedule reconciliation against overdue active waits. Query the provider for the recorded build and attempt, using the original connection. Use a capped number of attempts, timeouts, and backoff within the wait’s deadline. Feed a terminal result back through the same reducer as a durable observation with its own source and stable identity. For a provider that gives each attempt one immutable terminal result, the connection and attempt can identify that observation. If a provider can revise the result, use its documented version semantics and retain the observation that supported the decision.
Arrival time alone cannot establish which status is current. A running notification that follows a verified terminal result for the same attempt cannot reopen the wait. If conflicting statuses have no trustworthy version order, query the provider’s authoritative state and record uncertainty if the lookup fails. A lookup that reports the build is still running leaves the workflow waiting within its deadline. A deadline that expires without a trustworthy terminal result yields an explicit timeout or escalation. None of those decisions needs the agent to infer build state from a conversation transcript.
Use the same workflow lock when a deadline races a result. Decide in advance which time the deadline refers to. If acceptance before the deadline entitles an event to be considered, the timeout path must account for pending accepted events. In the simpler processing-time policy used here, once the timeout transition commits, a later observation is recorded against the closed wait. The case at 09:05 is an overdue notification check performed before that deadline.
Test the records at each crash boundary
Run the workflow against a controllable CI fixture with a durable log of the submitted review operations. Inject failures around commits and acknowledgments, and verify the inbox, workflow, outbox, and consumer records independently of anything the model says.
| Fault or race | Expected evidence |
|---|---|
| Intake dies before the inbox commit | The delivery is unaccepted. A redelivery can insert it, or a provider lookup can recover the missing result through reconciliation. |
| Intake dies after the commit, before HTTP 200 | The original inbox row survives. The retry resolves to the same key and the worker can still process the row. |
| A succeeds after B’s wait is installed | A’s event is marked stale against revision 2. No action targets build-41. |
| The worker dies between writes in the apply transaction | No partial transition commits. A retry can commit one complete transition. |
| B’s webhook and a lookup both report success | Two observations remain traceable. Exactly one satisfies wait-b and creates a review operation. |
| The review service accepts the request before the relay dies | The resend uses the same operation ID. The idempotent consumer’s effect log contains one review. |
| The lookup runs out of attempts with no confirmed terminal state | The workflow records its deadline outcome and why it could not establish a build result. |
Measure acceptance latency and acceptance-to-disposition latency separately. A healthy response time can hide a growing inbox backlog. Track the oldest pending event, waits past deadline, the share resolved by reconciliation, and time from outbox creation to downstream receipt. Count superseded and duplicate deliveries separately so genuine user revisions remain visible. Audit a sample by tracing the build request through the winning event and workflow revision to the resulting operation ID. For failures, start at the first missing record in that chain.
At 09:09, the operator can explain the whole run from stored facts. A passed after its wait was superseded. B passed and was confirmed through the provider’s API. That observation satisfied B’s wait exactly once and created one review operation. The late webhook supplied another observation of the same result. By the time the agent resumes, the decision about which build matters has already been made and recorded.
