Agent ArchitectureRuntime and effect recoveryPrincipal
How should an agent track an asynchronous tool job after receiving HTTP 202 Accepted?
By Amit Kumar3 min readWorked answer includedReviewed 26 Sept 2026
The question
Interview question
An export provider returns 202 Accepted and a job ID, then fails later. The agent may stop waiting before a callback arrives, callbacks can repeat, and a poll can race with a callback. Design durable state and terminal-outcome verification, gate dependent steps, and handle cancellation, lost submission responses and provider retention limits.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
The HTTP response tells us the provider accepted a request for processing. It does not say the export succeeded. RFC 9110 is explicit that a 202 request may or may not eventually be acted upon. The agent's tool result should therefore say accepted, with the provider job ID and an operation ID owned by our runtime. It should not collapse accepted into completed merely because the initial API call returned a 2xx status.
I would create a durable operation record before submission: tenant, user, exact action and arguments, approval and policy version, idempotency key if the provider supports one, attempt ID, and deadline. Submission transitions it to accepted only when the provider response is known. The dependent step waits on a verified terminal outcome. Polling and callbacks are two ways to observe the same provider job. Normalize both into a single state machine and make each observation idempotent by provider job ID, event ID or revision where supplied, and operation identity.
A callback might arrive twice or after the wait deadline. Both deliveries should attach to the same operation. An identical terminal event is a no-op. A contradictory terminal event is not silently overwritten by “last callback wins.” Check the provider's status resource or event ordering contract, record both observations, and reconcile. An expired wait is not proof that the provider job stopped. Keep the operation as unresolved, report that to the user, and continue to monitor or query it according to retention and product deadlines.
Persist each provider observation before releasing dependent work. A callback and a poll may both report success, so the terminal transition and the decision to schedule the next step need coordination. Use a conditional operation update and a durable downstream-work record, or an equivalent transactional mechanism, so two observers do not launch the dependency twice. Scheduling that dependency safely still does not make its external effect exactly once.
An early callback can arrive before the submission response stores the provider job ID. Supply a client correlation identity where the API supports it, or durably retain unmatched authenticated events until they can be associated with the prepared operation. Dropping that callback because no in-memory waiter exists creates a permanent false timeout. Never match it to a convenient current job merely because its customer name is similar.
Cancellation adds a sharper edge. If the user cancels after 202, send the provider's cancel request if it exists and record whether cancellation was accepted or confirmed. The export may finish anyway. Do not mark cancelled solely because the local waiter stopped. If the late callback says succeeded, record the effect, stop dependent actions that were cancelled, and tell the user what happened. A follow-up cleanup action may be possible, but it has its own outcome and authorization.
If the provider has no status API, we can still wait for a signed callback within a bounded period, but after that the operation is unknown unless another authoritative reconciliation channel exists. Retrying submission with a new key risks a second export. If the provider documents idempotent resubmission using the same key, we can use that specific contract within its window. Otherwise escalate rather than invent a completed result. Temporal's asynchronous Activity documentation illustrates that a worker function can return while the activity execution remains incomplete. Our external provider still decides the actual effect.
I would test response lost before the job ID is stored, callback before the waiter starts, duplicate callbacks, poll racing a callback, wait timeout, cancel racing completion, and provider retention expiry. The answer the user sees must reflect the strongest verified state we have, even if that state is uncomfortable: accepted, still running, failed, succeeded, or unresolved.
Related questions
Keep practising agent architecture
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux