Work Record Object

A Work Record tracks one run of a Station. Each time a station runs, a new work record captures the run's state and output.

Object Structure

{
  "id": "wr_abc123def",
  "station": "st_def456",
  "status": "completed",
  "output": { "done_count": 2, "failed_count": 1 },
  "config_snapshot": {},
  "config_overrides": null,
  "started_at": "2024-01-15T10:30:00Z",
  "completed_at": "2024-01-15T10:30:45Z",
  "performed_by": "api_key_name",
  "error": null,
  "created_at": "2024-01-15T10:30:00Z"
}

Fields

FieldTypeRequiredDescription
idstringAuto12-character unique identifier
stationstringYesID of the station being executed
statusstringAutoExecution status
outputobjectAutoWhat the station's handler returned
config_snapshotobjectAutoThe station's config with the run's overrides, frozen when the run was queued
config_overridesobjectNoPer-run overrides sent to Run Station
started_atstringAutoWhen execution started
completed_atstringAutoWhen execution finished
performed_bystringAutoWho triggered the execution
errorstringAutoWhat went wrong, if failed
created_atstringAutoISO 8601 timestamp

Status Values

StatusDescription
pendingWork record created; queued, waiting for a factory session at the line's location to claim it
runningClaimed by a factory session
completedThe handler returned; its result is in output
failedThe handler failed and wasn't retried, or failed after its retries (see error)
cancelledCancelled by a person or through the API
timed_outRunning for more than 4 hours, or pending for more than 30 minutes

Status Transitions

pending → running → completed
   │         ├─→ failed
   │         └─→ timed_out / cancelled
   └─→ timed_out / cancelled

A handler that throws is reported with POST /api/factory/failed. A retryable failure queues the run again, up to 3 retries; after the last, the work record is failed. A retry runs the handler again from the start, so a station must be safe to rerun. A workpiece that fails inside a run doesn't fail the run: the handler completes and reports each workpiece's outcome.

How a run is queued

The work record is the run's queue entry; there is no separate queue. When a run starts, the Orchestrator freezes the station's config (with the run's config_overrides) as config_snapshot and the line's location on the work record, and queues it. Editing the station or the line doesn't change a run already queued.

A factory session at that location claims the oldest queued run with GET /api/factory/poll, runs the station's handler, and reports the handler's result, which is stored as output. A retried run stays running, goes back in the queue and keeps its place there.

The queue fields (location, queued_at, claimed_at, retry_count, factory_session) live on the work record but aren't returned by the API.

Error Structure

When a work record fails, error holds the message the factory session reported:

{
  "status": "failed",
  "error": "HTTP request failed with status 500"
}

Triggering Execution

Run a station to create a work record and queue it:

curl -X POST "https://orchestrator.assemblyline.sh/api/v1/stations/st_def456/run" \
  -H "api-key: al_xxxxxxxxxxxx" \
  -H "api-secret: xxxxxxxxxxxxxxxx"

The orchestrator will:

  1. Create the work record with status pending
  2. Freeze the config and location on it and queue it
  3. Hand it to a factory session at the line's location, which runs the station's handler
  4. Update status to completed or failed

Create Work Record records a run without queuing it.

Polling for Completion

After creating a work record, poll to check completion:

curl -X GET "https://orchestrator.assemblyline.sh/api/v1/work-records/wr_abc123" \
  -H "api-key: al_xxxxxxxxxxxx" \
  -H "api-secret: xxxxxxxxxxxxxxxx"

Check the status field until it's completed or failed.

See Also