The run object
Every run field the browser receives, the permission that unlocks it, and what is never sent.
The browser never gets the full stored run. It gets a short list of safe fields. Your grant decides which of those fields arrive.
In React
useRun returns the run as run. It is undefined until the first snapshot arrives.
const { run } = useRun<typeof writeAnswer>(runId)
run?.status // 'running'
run?.meta?.progress // 3
run?.output // { parts: 10 }, once the run succeeds| Field | What it holds | Needs |
|---|---|---|
id | The run ID | Status |
environment | The environment that owns the run | Status |
taskId | The task ID, such as 'answer.write' | Status |
status | The current status | Status |
attempts | How many attempts have started | Status |
eventSequence | A counter that goes up with each status or metadata change | Status |
version | The code version that started the run, when known | Status |
meta | Metadata saved with context.updateMeta() | Status and Meta |
output | The final output, typed from the task | Status and Output |
failure | Why the run failed: name, code, message, and retryable | Status and Output |
useRun needs Status. Without it, run stays undefined.
output is the value your task returned, before any output schema transforms. Streamed parts are separate. useRun does not receive stream data at all. To show stream text, use useRunStream.
Status values
| Status | Meaning | Finished? |
|---|---|---|
scheduled | Waiting for its start time | No |
queued | Ready, waiting for a worker | No |
running | An attempt is running | No |
retrying | An attempt failed. A retry is waiting. | No |
released | Paused by a wait, such as a sleep or signal | No |
cancellation_requested | Cancel was asked for. The attempt is stopping. | No |
succeeded | Finished with an output | Yes |
failed | Finished with a failure | Yes |
cancelled | Stopped by a cancel | Yes |
expired | Did not start before its deadline | Yes |
Compare status with plain strings, such as run.status === 'succeeded'. TypeScript checks them, so a typo is an error. A failed run is still normal data. The reader does not report it as an error. Check run.status and run.failure instead.
Metadata
Each context.updateMeta() call sends a patch. The client merges it into run.meta:
- A patch replaces the top-level keys it names. Other keys stay.
- A nested object or array replaces the old value at that key. It does not merge.
nullis a value. It does not delete the key.
Metadata from a task is typed as JSON. Check a value's type before you use it, or declare its type:
const progress = run?.meta?.progress
return <progress value={typeof progress === 'number' ? progress : 0} max={10} />Never sent
These fields stay on the server, even when you grant every permission:
- the task payload (its input);
- tags, queue, priority, and keys;
- failure stack traces and failure metadata;
- wait tokens, leases, and trace data.
Keep secrets out of metadata and output anyway. A reader with Meta or Output sees everything in them.
In the plain client
client.subscribe() yields events instead of one merged object. A new reader gets a snapshot first, unless the run already finished. See follow a run for the order.
Event type | Fields |
|---|---|
snapshot | run: the fields above, plus createdAt, updatedAt, startedAt, and finishedAt as Date objects. Attempts are in run.counters.attempts. |
status | status, attempts, eventSequence, version, and, with Output, output and failure |
meta | eventSequence, and patch: the top-level keys that changed |
stream | record: one stream record. See read a stream. |
Every event also has cursor and occurredAt. See the JavaScript client for a full example.