Execution, events and recovery
Use Invocation as your application's authoritative execution record, separating current state, live progress, historical events, explicit cancellation and failed-request retry.
State mapping
| Status suffix | Product behavior |
|---|---|
| ADMITTED, QUEUED | Accepted or queued, not successfully finished |
| PLANNING, PROVISIONING, RUNNING | Show progress phase and counters |
| WAITING_APPROVAL | Await an authorized decision |
| WAITING_INPUT | Await input or execution-protocol continuation |
| PAUSED | Inspect context and reason |
| COMPLETED | Execution finished; validate the business result |
| FAILED | Show error_code and actionable failure information |
| CANCELLED | Cancelled; do not automatically restart |
REST uses full string enums such as INVOCATION_STATUS_RUNNING. Current Invocation SSE snapshots use direct JSON encoding and can contain numeric enums: completed, failed and cancelled are 9, 10 and 11. The example client normalizes them at one boundary.
Live UI: snapshot and changes
curl --no-buffer --fail-with-body \
"https://api.orbitspace.dev/api/v1/invocations/$INVOCATION_ID/events" \
-H "Authorization: Bearer $ORBITSPACE_ACCESS_TOKEN" \
-H 'Accept: text/event-stream' \
-H "Last-Event-ID: $LAST_SEQUENCE"Every connection begins with invocation.snapshot, followed by invocation.changed and refreshed snapshots. change_type distinguishes status, execution, model, tool, approval and delegation activity. This is a sanitized application projection, not raw model content, chain of thought or full tool logs.
The current server advances the subscription cursor to its initial snapshot's latest sequence. An older Last-Event-ID therefore does not guarantee replay of every missed Invocation event. Apply the current snapshot to recover the UI; do not use this stream alone as a lossless business ledger.
Historical processing: JSON pages
Without the SSE Accept header, the same resource returns JSON:
curl --fail-with-body \
"https://api.orbitspace.dev/api/v1/invocations/$INVOCATION_ID/events?after_sequence=0&page_size=100" \
-H "Authorization: Bearer $ORBITSPACE_ACCESS_TOKEN" \
-H 'Accept: application/json'The response contains events, next_sequence and snapshot. Process events in order and commit your cursor with your business update. Deduplicate by event_id, and continue from next_sequence until no new records remain. For audit backfill, catch up to the subscription snapshot's position before continuing live observation.
Keep decimal sequence cursors as strings. Model rounds, timestamps and Provider sequences are not resume cursors. Do not lose precision by converting large sequence values to JavaScript Number.
REST encodes int64 fields as decimal strings; current SSE snapshots can encode them as JSON numbers. Use the SSE id string for resumption, and reload REST state before a versioned write or accounting update rather than trusting a potentially rounded numeric snapshot field.
Cancel and retry
Read current state, then submit its state_version:
curl --fail-with-body \
"https://api.orbitspace.dev/api/v1/invocations/$INVOCATION_ID:cancel" \
-H "Authorization: Bearer $ORBITSPACE_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"expected_state_version":"REPLACE_WITH_CURRENT_VERSION"}'POST /api/v1/invocations/{id}:retry uses the same body shape and accepts only FAILED Invocations. Reload after a version conflict. Do not turn cancelled or running work into another request automatically. Reconcile uncertain external side effects before retrying.
Disconnect is not cancellation
Abort SSE and pending reads when the user leaves a view. Remote execution continues until explicitly cancelled. Bound retries for reads/subscriptions; preserve submission keys for POST recovery. A production backend can consume Webhooks and then read authoritative snapshots. See Webhook ingestion.