A reviewer can approve before the workflow waits. Dropping that decision loses it, keying it by request applies it to a revised draft. Use a versioned durable inbox.
The approval that arrived too early
At Belgavi's Book Store, refunds above 2,000 rupees need a person. The help-desk agent drafts the refund, the workflow posts the draft to the review queue, and Geetha approves or rejects it. To save time, the review page shows a live preview as soon as the agent starts drafting. One afternoon Geetha opens a preview, reads it, and clicks Approve at minute 4. The workflow is still checking stock and reaches its "wait for approval" step at minute 6. The approval endpoint looks up the workflow, sees that it is not waiting, returns 409 Conflict, and forgets the click. Sixty minutes later the request escalates to a supervisor as unanswered.
Nobody made a mistake that a test would catch. The handler was written for the order the designers imagined: request, wait, decision. Human decisions do not follow that order. People open links early, click twice, approve a draft that the agent then revises, and answer after the deadline. This guide compares the ways a workflow can receive those decisions and shows which one survives each case. The interactive lab replays the same timelines.
Five ways to receive a decision
| Policy | What happens to a decision that arrives before the wait |
|---|---|
| Drop if not waiting | 409 and nothing is stored |
| Buffer in process memory | held in the worker until the wait starts |
| Durable inbox keyed by request | written to a table under the request id |
| Durable inbox keyed by request and draft version | written under the request id and the version it was about |
| Callback token issued at the wait | refused; the reviewer must submit again once the token exists |
The last two describe how the two best-known workflow engines behave, each in its own way.
Temporal records a signal in the workflow's history as soon as it is accepted. The message passing guide says that for a signal "the response is sent immediately from the server, without waiting for the Workflow to process the Signal", and that with signals "clients don't depend on the Worker being available". When an external signal is sent, "a WorkflowExecutionSignaled Event appears in the recipient's Event History". In practice the workflow code keeps the decision in workflow state from the signal handler and waits on a condition, so a signal that arrives before the wait is already in state when the wait starts. Signal-With-Start covers the case where the workflow has not even been created yet.
AWS Step Functions takes the opposite approach with the callback pattern. A task with .waitForTaskToken pauses "until it receives that task token back with a SendTaskSuccess or SendTaskFailure call", and the token exists only once the task state has started. The documentation also notes that "if a Task state using the callback task token times out, a new random token is generated". An early decision is impossible by construction: there is nothing to send it to. The cost moves to the review interface, which must not offer Approve until the token exists, or must hold the click and resend it.
The cases that separate them
The lab's eight presets, all synthetic minutes:
- Early click. Approve at minute 4, wait at minute 6. Drop loses it; the memory buffer and both inboxes apply it at minute 6 (a recorded Temporal signal behaves like the durable inbox here); the token policy refuses it, and the request proceeds only if Geetha submits again after minute 6.
- Early click, then a worker restart at minute 5. The memory buffer loses it. The durable inbox applies it at minute 7, when the restarted workflow reaches the wait.
- Draft revised after the click. Geetha approves version 1 at minute 4, the agent replaces the draft with version 2 at minute 5 (it found a second damaged book), and the wait at minute 6 is for version 2. The inbox keyed by request applies the version 1 approval to version 2. The memory buffer does the same. The versioned inbox keeps the old approval for audit, waits for a decision on version 2, and proceeds at minute 30 when Geetha approves the new draft.
- Double click. Approve and reject in the same second. With first-decision-wins the approval stands; with last-write-wins the rejection overturns it.
- After the deadline. The wait escalates at minute 10 and the approval arrives at minute 12. Every policy should record it for audit and not apply it.
The early click and the restart are about losing a decision. The revision is about applying a decision to something the reviewer never saw, which is worse: it turns an approval of a 2,000-rupee refund into an approval of a 3,400-rupee one.
The design that holds: a durable inbox keyed by what was reviewed
def receive_decision(db, req_id, draft_version, decision, reviewer):
# Idempotent: the first decision for (request, version) wins.
db.execute(
"INSERT INTO approval_inbox (req_id, draft_version, decision, reviewer, at) "
"VALUES (%s, %s, %s, %s, now()) ON CONFLICT (req_id, draft_version) DO NOTHING",
(req_id, draft_version, decision, reviewer))
notify_workflow(req_id) # wake the wait if it is already open; harmless if not
def wait_for_decision(db, req_id, draft_version, deadline):
while now() < deadline:
row = db.fetch_one(
"SELECT decision FROM approval_inbox WHERE req_id = %s AND draft_version = %s",
(req_id, draft_version))
if row:
return row.decision
sleep_until_notified_or(deadline)
return 'escalate'Three properties matter more than the storage technology:
- Durable on receipt. The decision is stored before the endpoint answers, whether or not anyone is waiting. In Temporal the event history is that store; elsewhere it is a table.
- Keyed by what the reviewer saw. The review page sends the draft version, or better a hash of the draft content, with the decision. The wait reads only the decision for the version it is waiting on.
- Checked on entry to the wait. The wait looks in the inbox before it sleeps, so an early decision is consumed immediately.
The reviewer interface should also show when a decision was recorded but not applied ("you approved version 1; the draft has changed, please review version 2"), otherwise the old approval silently disappears from the reviewer's point of view.
What stays deterministic
The agent drafts the refund and the explanation. It does not decide whether a decision applies. Matching a decision to a request and version, enforcing first-decision-wins, the deadline and the escalation are plain code with tests. The agent can be asked to summarise why a draft changed between versions, but the version comparison itself is an equality check, not a judgement.
Migrating an existing approval endpoint
- Log every 409 the endpoint returns with the request id and the reviewer. If the count is not zero, decisions are being lost today.
- Add the inbox table and write to it on every decision, while keeping the old behaviour. Compare what the inbox holds with what was applied.
- Make the wait read the inbox on entry. At this point early decisions stop escalating.
- Add the draft version to the review page and the inbox key, and make the wait ignore other versions. Show the reviewer when their decision was superseded.
- Remove the 409 path.
If you are on Step Functions, the equivalent is to keep the review page's Approve button disabled until the token is delivered, or to store early clicks in your own table and send SendTaskSuccess from a small consumer once the token arrives.
Verification
- Replay the five cases above against your real endpoint in a test environment, with the worker restart done by actually killing the process.
- Assert that no decision is applied to a version other than the one in its key. The lab's companion test checks this for the drop, versioned inbox and token policies across every preset.
- Assert that a decision after the deadline is stored and not applied, and that the escalation contains it so the supervisor can see the late answer.
- Count lost decisions in production: decisions received minus decisions applied minus decisions recorded as superseded or late. It should be zero.
When none of this is needed
If the review page is only reachable from a notification that the workflow sends after it starts waiting, and drafts are immutable once sent for review, the early-arrival and revision cases cannot happen and a simple handler is enough. That arrangement is also the simplest fix when you do not need live previews. The trouble starts the moment a person can act on something before the workflow is ready to hear about it.
The related LangGraph article on this site covers a different problem in the same family: an answer that arrives for an interrupt that has already been replaced. Here the decision is early rather than stale, but the fix rhymes: bind each answer to the exact thing it answers.
Interactive experiment
Approval arrival order: dropped, buffered and token-gated decisions. Synthetic browser-local fixtures, adjustable inputs, decision traces and JSON export.