Resources · 107

Asynchronous API jobs: track status, resume and cancel

Separate accepted requests, started processing and final outcomes of long-running operations.

· 5 min

Private AI computing infrastructure in an empty laboratory AI-generated editorial illustration

What this guide helps achieve

  • Define states
  • Protect tracking
  • Bound status queries
  • Test concurrent cancellation
  • Handle abandoned work
  • Define repeat and expiry contracts

Quick check

  • Does 202 mean the job is finished?
  • Does cancellation erase every effect?
  • Should status queries continue indefinitely?

Step-by-step method

  1. 01

    Define states

    Describe received, queued, active, completed, failed and cancellation requested. A 202 response does not prove success; define how the client obtains the final outcome.

    Deliverable: transitions and authoritative outcome.

  2. 02

    Protect tracking

    Associate each identifier with account and request scope. Check rights for status, results and cancellation; an unguessable identifier does not replace authorisation.

    Deliverable: cross-account tests.

  3. 03

    Bound status queries

    Set polling frequency and duration, terminal state and result expiry. Preserve a reference allowing resumption after browser closure without restarting processing.

    Deliverable: tracking and resumption policy.

  4. 04

    Test concurrent cancellation

    Simulate cancellation while queued, running and publishing results. Define what can still be stopped and which effects remain; confirm an actually observed outcome.

    Deliverable: race conditions and remaining effects.

  5. 05

    Handle abandoned work

    Identify stalled jobs, repeated errors and expired results. Assign recovery, closure or review; do not present estimated progress as proof of completion.

    Deliverable: orphan-job monitoring.

  6. 06

    Define repeat and expiry contracts

    Decide whether another submission can recover the existing job. If a repeat key is used, define its account scope, lifetime, associated parameters and conflict behavior. Test acceptance with a lost response. Separate status expiry from result deletion: an unavailable result does not prove that processing never happened.

    Deliverable: repeat, expiry and incident-follow-up contract.

Choose next steps using confirmed state

Check the observed state before choosing next steps.

  1. Queued or active

    Resume tracking with the same reference.

  2. Cancellation requested

    Check outcome and effects already produced.

  3. Terminal state

    Check result, rights and retention period.

Prepare recovery without inventing success

Fictional cases to adapt to your service contract. Expected results are acceptance criteria to test, not customer outcomes.

SituationAction to prepareExpected evidence
The acceptance response is lostRecover the job through the documented repeat mechanism or check the request before creating another.Retained identifier, contract scope and job count in the test.
The client stops polling at its maximum durationRetain a tracking-interrupted state and a recovery path; do not announce business failure without evidence.Server state distinct from client timeout and recovery using the same reference.
Cancellation arrives while the result is being publishedConfirm the observed outcome and reconcile effects; requesting a stop is not erasure.Timeline, final state and proportionate list of remaining effects.
The result expires before the person returnsExplain expiry and apply the authorized recovery or new-request rule.Documented retention, denied out-of-scope access and no silent restart.

Acceptance case to reproduce

Fictional example: these inputs describe no customer or observed result.

View case inputs
{
    "job_id": "J-42",
    "timeline": [
        {
            "elapsed_seconds": 0,
            "http": 202,
            "state": "pending"
        },
        {
            "elapsed_seconds": 5,
            "http": 200,
            "state": "running"
        },
        {
            "elapsed_seconds": 6,
            "http": 200,
            "state": "cancel_requested"
        },
        {
            "elapsed_seconds": 7,
            "http": 200,
            "state": "succeeded"
        }
    ]
}

Expected decision

A 200 status read does not mean processing has finished. After requesting cancellation, conclude only from the confirmed outcome.

Cancellation requested too late

Fictional scenario: the same job J-42, seconds since submission. State names belong to this example’s contract; HTTP does not prescribe them.

TimeResponse and stateSupported conclusion
+0 sHTTP 202 · pendingAccepted for processing; no final result confirmed.
+5 sHTTP 200 · runningThe status read succeeded; the job is still running.
+6 sHTTP 200 · cancel_requestedThe stop request is recorded; cancellation remains unconfirmed.
+7 sHTTP 200 · succeededProcessing won the race. Show the observed success and check effects; do not report cancellation.

Fictional variations to test

The creation response is lost, but a job may exist.

Find the operation using the identifier specified by the contract. Avoid launching another job solely to obtain a visible response.

Polling reports success, but the result is inaccessible.

Separate completed computation from a retrievable result. Check permissions and link expiry before declaring the journey usable.

Work completes after cancellation was requested.

Read the confirmed terminal state. Record the actual result and apply the documented policy for output produced during this race.

Evidence to retain

  • Stable identifier and observed state transitions.
  • Request, cancellation and confirmation timestamps.
  • Result access tested with the intended permissions.

Microsoft — Asynchronous request-reply

Reusable worksheet

Complete with your authorised observations. These fields are a working template, not observed results.

FieldInformation to record
ReferenceAccount, operation and identifier
StateTransition, time and source
OutcomeResult, error or remaining effects
AcceptanceSame job recovered, rights checked and outcome or uncertainty explained

Worked example

Illustrative situation

Illustrative case: an export is accepted and the browser closes. A later session finds the ongoing job.

Decision and expected evidence

Reuse the identifier, verify result access rights and offer cancellation with confirmed status.

Distinguish the mechanisms

MechanismPurposeCheck or limitation
AcceptedRequest received for processingNot final success
Cancellation requestedIntention to stopConfirm actual outcome
CompletedResult availableCheck rights and retention

Management indicators

IndicatorWhat it measuresFirst action
Orphan jobsJobs without qualified progressAssign recovery or closure
ResumptionCases resumed without duplicationCorrect unnecessary restarts

Common pitfalls

  • Present acceptance as final success
  • Authorise results using only a job identifier
  • Poll without bounded frequency or duration

Frequently asked questions

Does 202 mean the job is finished?

No. Processing is not necessarily complete. The client needs access to an authoritative outcome.

Does cancellation erase every effect?

Not always. Some effects may already exist; specify them and how they are reconciled.

Should status queries continue indefinitely?

No. Define an appropriate frequency and duration, use the delay indication provided by the service and stop at a terminal outcome. A client-side timeout does not turn an active job into server-side failure.

Official references

References consulted: . The method and worksheet propose checks to adapt to your context; they do not constitute certification.