ADS-0004: Long-Running Operations
Canonical flat Operation schema, status lifecycle invariants, structured nextAction contract, and HTTP polling and cancellation conventions for asynchronous Photon public HTTP APIs.
- Status: Approved
- Updated: 2026-11-25
Consistent asynchronous contracts let callers, generated SDKs, dashboards, CLIs, and AI agents start, poll, resume, and cancel long-running workflows with one shared state machine instead of per-endpoint conventions. This standard is part of Photon API Design Standards and uses the keywords MUST, MUST NOT, SHOULD, and MAY as described in RFC 2119.
Scope and Asynchronous Patterns
Not every 202 Accepted endpoint requires a separate Operation resource. Photon public HTTP APIs distinguish three asynchronous patterns:
- Long-Running Operations: Multi-step provisioning, billing mutations, external provider handshakes, or batch workflows whose asynchronous execution is tracked independently of a single domain entity. These endpoints MUST return
202 Acceptedwith aLocationheader pointing toGET <scope>/operations/{operationId}, an advisoryRetry-Afterheader when non-terminal, and a canonical flatOperationJSON body. - Lifecycle-Bearing Resources: Domain resources whose own canonical representation carries a durable lifecycle state (for example a resource awaiting provisioning, verification, or review). Creating or mutating such a resource MAY return
202 Acceptedwith aLocationheader pointing to the resource itself rather than introducing a separateOperationresource. - Fire-and-Forget Requests: Ephemeral or queued signals that have no pollable status resource (for example typing indicators or best-effort queued notifications). These endpoints MAY return
202 Acceptedwithout aLocationheader.
The normative rules below apply to Long-Running Operations.
Normative Rules
1. Canonical flat Operation schema
Every Operation resource MUST be a flat top-level JSON object consistent with ADS-0002, modeled as a discriminated union keyed on status.
- Responses MUST NOT wrap the operation under a single-key envelope such as
{ "operation": { ... } }or under a genericdata,result, orpayloadenvelope. - Every
statusbranch MUST declare and require all eight universal fields below using their exact names:
| Field | Type | Requirement |
|---|---|---|
id | string | Primary operation identifier per ADS-0001 (for example pho_op_01h455vb4pex5vsknk084sn02v). MUST NOT be named operationId. The corresponding URL path parameter MUST be {operationId}. |
type | string | Service-defined enum naming the action in <resource>.<action> format (for example plan.change, domain.verify, connection.authorize, or line.provision). MUST NOT be named kind. |
status | string | Lifecycle discriminator. MUST NOT be named state. Values MUST be a subset of the canonical six-state vocabulary below. |
createdAt | string (date-time) | RFC 3339 UTC timestamp recording when the operation was created. MUST NOT be named submittedAt. |
updatedAt | string (date-time) | RFC 3339 UTC timestamp recording the most recent update to the operation. |
completedAt | string | null (date-time) | null on every non-terminal status; non-null RFC 3339 UTC timestamp on every terminal status. MUST NOT be named resolvedAt or endedAt. |
response | <TResponse> | null | On succeeded, holds the typed operation outcome (matching what a synchronous equivalent would return, or explicit null for empty-outcome operations such as asynchronous deletions). On all other statuses, MUST be null. MUST NOT be named result. |
error | ProblemDetails | null | On failed, MUST be a non-null RFC 9457 Problem Details object containing at minimum type, title, status, and code (plus optional detail, remediation, and typed domain extensions such as retryable) matching synchronous HTTP error objects. On all other statuses, MUST be null. MUST NOT be named failure. |
Canonical status vocabulary
status MUST use values strictly from this six-state vocabulary:
- Non-terminal:
pending,running,requires_action(optional capability). - Terminal:
succeeded,failed,cancelled(optional capability).
Services MAY declare a strict subset (for example omitting running, requires_action, or cancelled when unsupported), and MUST NOT invent synonyms such as queued, in_progress, processing, done, completed, or canceled.
Terminal statuses (succeeded, failed, cancelled) are immutable. Once an operation reaches a terminal status, it MUST NOT transition back to a non-terminal status or to another terminal status.
Standardized optional capability fields
Services include optional capability fields only when applicable, and MUST use these reserved names when doing so:
| Field | Type | When to include |
|---|---|---|
startedAt | string | null (date-time) | When queue wait time before execution is meaningful to callers. |
cancellable | boolean | When the service exposes POST <scope>/operations/{operationId}/cancel. |
metadata | object | When exposing structured progress or domain context (for example current step or target resource references named with ADS-0001 <resource>Id keys). |
nextAction | object | null | Required on services that support requires_action; omitted on services that never enter requires_action. |
2. Status-specific invariants
An Operation schema MUST enforce these invariants per status branch:
status | Terminal | completedAt | response | error | nextAction |
|---|---|---|---|---|---|
pending | No | null | null | null | null (or omitted) |
running | No | null | null | null | null (or omitted) |
requires_action | No | null | null | null | Non-null object (required) |
succeeded | Yes | date-time | <TResponse> or null | null | null (or omitted) |
failed | Yes | date-time | null | ProblemDetails | null (or omitted) |
cancelled | Yes | date-time | null | null | null (or omitted) |
- Non-terminal statuses that share identical invariants (such as
pendingandrunning) MAY share a branch. - Branches MUST NOT combine statuses with incompatible invariants (for example combining
pendingandsucceeded,succeededandfailed, orrequires_actionwith any other status in a single un-discriminated object).
3. Layered nextAction schema and requires_action invariant
The relationship between status: "requires_action" and nextAction is a strict biconditional:
- When
statusisrequires_action,nextActionMUST be a required, non-null structured object. If an operation is waiting on an internal job or upstream provider without requiring caller action, it MUST remain inpendingorrunning, neverrequires_action. - On every other status (
pending,running,succeeded,failed,cancelled),nextActionMUST benull(or omitted entirely by services that never enterrequires_action).
Every nextAction object follows a layered contract:
- Required base fields:
type(string, required):snake_casestring literal or enum discriminator identifying the caller action (for exampleredirect,confirm_payment, orverify_dns). MUST NOT be namedkindoraction.expiresAt(string | null, optional,format: date-time): Reserved expiration timestamp for the action when time-bounded. MUST NOT be nameddeadlineorvalidUntil.
- Predefined cross-service variant (
redirect):- Services that send the user to an external or hosted URL SHOULD use the standard
redirectvariant:{ "type": "redirect", "url": "<uri>", "expiresAt": "<date-time> | null" }, whereurlis a required string withformat: uriandexpiresAtis optional. Usingredirectlets CLIs, SDKs, dashboards, and agents handle browser handoffs generically.
- Services that send the user to an external or hosted URL SHOULD use the standard
- Domain-specific variants:
- Services MAY extend
nextActionviaoneOfusing the same base shape andADS-0001<resource>Idforeign keys (for exampleconfirm_paymentreferencinginvoiceId, orverify_dnscarrying structured DNSrecords).
- Services MAY extend
- Structured and credential-safe:
nextActionMUST carry structured machine-readable fields and MUST NOT include a free-textmessagefield (static instructions belong in OpenAPI descriptions).- Because
GET <scope>/operations/{operationId}responses are repeatable reads,nextActionMUST NOT expose high-sensitivity credentials such asclientSecret,accessToken,refreshToken,password,apiKey, orsecret.
4. HTTP wire protocol and route conventions
Triggering endpoint
- Starting a long-running operation MUST return
202 Acceptedwith:- A
Locationresponse header pointing to the canonical poll URL (GET <scope>/operations/{operationId}). - An advisory
Retry-Afterresponse header (delay in seconds) when the operation is non-terminal. - The flat
Operationobject in the response body.
- A
- An idempotent replay of a request whose operation has already reached a terminal status MAY return
200 OKwith that terminalOperation.
Polling endpoint (GET <scope>/operations/{operationId})
- The polling endpoint MUST return HTTP
200 OKwith the flatOperationbody (including whenstatusisfailedorcancelled), unless a supported conditional request returns304 Not Modified. - HTTP
4xxand5xxstatuses on the polling endpoint are reserved for failures of the poll request itself (such as404 Not Foundfor an unknown operation or403 Forbidden), never for execution failure of the underlying operation. - Polling responses SHOULD include
Retry-Afterwhile non-terminal and MAY support conditional requests viaETagand304 Not Modified.
Optional list and cancel endpoints
- List:
GET <scope>/operationsMUST return a top-level JSON object collection (for example{ "operations": [ ... ], "nextPageToken": "..." }). - Cancel:
POST <scope>/operations/{operationId}/cancelMUST return200 OKwith the updated flatOperation(or409 Conflictwhen the operation is not cancellable). Cancellation MUST usePOST <scope>/operations/{operationId}/canceland MUST NOT useDELETE.
Scope symmetry
- An operation initiated under a project route MUST be polled under
/v1/projects/{projectId}/.../operations/{operationId}. - An operation initiated under an organization route MUST be polled under
/v1/organizations/{organizationId}/.../operations/{operationId}. - An API MUST NOT return an operation identifier without exposing a matching pollable route under the same scope.
Examples
Triggering an operation (202 Accepted)
Good — POST /v1/projects/{projectId}/plan-changes returns 202 Accepted with Location, Retry-After, and a flat pending Operation:
HTTP/1.1 202 Accepted
Content-Type: application/json
Location: https://api.photon.codes/v1/projects/prj_01h455vb4pex5vsknk084sn02q/operations/pho_op_01h455vb4pex5vsknk084sn02v
Retry-After: 2{
"id": "pho_op_01h455vb4pex5vsknk084sn02v",
"type": "plan.change",
"status": "pending",
"createdAt": "2026-11-25T10:00:00Z",
"updatedAt": "2026-11-25T10:00:00Z",
"completedAt": null,
"response": null,
"error": null,
"cancellable": true,
"nextAction": null
}Polling requires_action variants (200 OK)
Good — predefined cross-service redirect variant (connection.authorize):
{
"id": "pho_op_01h455vb4pex5vsknk084sn02w",
"type": "connection.authorize",
"status": "requires_action",
"createdAt": "2026-11-25T10:01:00Z",
"updatedAt": "2026-11-25T10:01:02Z",
"completedAt": null,
"response": null,
"error": null,
"cancellable": true,
"nextAction": {
"type": "redirect",
"url": "https://auth.example.com/authorize?state=example_state",
"expiresAt": "2026-11-25T10:16:00Z"
}
}Good — domain-specific confirm_payment variant (plan.change) referencing invoiceId per ADS-0001:
{
"id": "pho_op_01h455vb4pex5vsknk084sn02v",
"type": "plan.change",
"status": "requires_action",
"createdAt": "2026-11-25T10:00:00Z",
"updatedAt": "2026-11-25T10:00:05Z",
"completedAt": null,
"response": null,
"error": null,
"cancellable": true,
"nextAction": {
"type": "confirm_payment",
"invoiceId": "pho_inv_01h455vb4pex5vsknk084sn02x",
"expiresAt": "2026-11-25T11:00:00Z"
}
}Terminal outcomes (200 OK)
Good — succeeded with typed response (plan.change):
{
"id": "pho_op_01h455vb4pex5vsknk084sn02v",
"type": "plan.change",
"status": "succeeded",
"createdAt": "2026-11-25T10:00:00Z",
"updatedAt": "2026-11-25T10:00:12Z",
"completedAt": "2026-11-25T10:00:12Z",
"response": {
"id": "sub_01h455vb4pex5vsknk084sn02y",
"projectId": "prj_01h455vb4pex5vsknk084sn02q",
"plan": "scale"
},
"error": null,
"cancellable": false,
"nextAction": null
}Good — failed with RFC 9457 Problem Details in error (returned with HTTP 200 OK from GET .../operations/{operationId}):
{
"id": "pho_op_01h455vb4pex5vsknk084sn02z",
"type": "line.provision",
"status": "failed",
"createdAt": "2026-11-25T10:05:00Z",
"updatedAt": "2026-11-25T10:05:18Z",
"completedAt": "2026-11-25T10:05:18Z",
"response": null,
"error": {
"type": "https://docs.photon.codes/errors/provider-capacity-exhausted",
"title": "Provider capacity exhausted",
"status": 503,
"code": "provider_capacity_exhausted",
"detail": "No phone numbers are currently available in the requested area code.",
"retryable": true
},
"cancellable": false,
"nextAction": null
}Non-conformant patterns
Bad — wrapped under { "operation": ... }, non-canonical field names (operationId, kind, state, submittedAt, resolvedAt, result, failure), and non-canonical status "in_progress":
{
"operation": {
"operationId": "pho_op_01h455vb4pex5vsknk084sn02v",
"kind": "plan.change",
"state": "in_progress",
"submittedAt": "2026-11-25T10:00:00Z",
"updatedAt": "2026-11-25T10:00:02Z",
"resolvedAt": null,
"result": null,
"failure": null
}
}Bad — leaking a high-sensitivity credential (clientSecret) and free-text message inside nextAction, or using DELETE to cancel:
{
"id": "pho_op_01h455vb4pex5vsknk084sn02v",
"type": "plan.change",
"status": "requires_action",
"createdAt": "2026-11-25T10:00:00Z",
"updatedAt": "2026-11-25T10:00:05Z",
"completedAt": null,
"response": null,
"error": null,
"nextAction": {
"type": "confirmPayment",
"clientSecret": "example_secret_value",
"message": "Complete payment in your browser."
}
}paths:
/v1/projects/{projectId}/operations/{operationId}:
delete:
summary: Uses DELETE instead of POST .../operations/{operationId}/cancelNon-operation 202 Accepted endpoints (unaffected)
Good — lifecycle-bearing resource returning 202 Accepted with Location pointing to the domain resource itself (POST /v1/projects/{projectId}/domains):
{
"id": "dom_01h455vb4pex5vsknk084sn030",
"projectId": "prj_01h455vb4pex5vsknk084sn02q",
"hostname": "mail.example.com",
"status": "pending_verification",
"createdAt": "2026-11-25T10:10:00Z"
}Good — fire-and-forget 202 Accepted with no Location header (POST /v1/projects/{projectId}/typing):
{
"accepted": true
}Changelog
- 2026-11-25: Approved and published as
ADS-0004.
Feedback
Found a Photon API that does not follow this standard, or have a suggestion to improve it? Open an issue in photon-hq/api-design-standards (we do not accept external pull requests).