# Table reference

> Columns, types and meanings of the sys_* tables you can query in an environment.

Source: https://cairnflow.dev/docs/query/tables

The tables below are available to every environment through `POST /query` and the console's
**Query** page. Each query only sees the data of the environment it runs in. Columns may be added
over time; existing columns are not renamed or removed.

Types: `text`, `int` (signed integer), `uint` (unsigned integer), `float`, `bool`, `timestamp`
(returned as an ISO-8601 string). Columns ending in `_ms` hold milliseconds, as Unix time when
they are points in time.

**Required key** means the table can only be read with an equality filter on those columns, for
example `WHERE id = '…'`.

Other `sys_*` tables describe the cell itself (nodes, ranges, rules, keys, trash) and need operator
access; they are not listed here.

## Invocations

### `sys_invocation`

One row per invocation, newest first (`created_at DESC, id ASC`).

| Column | Type | Meaning |
|---|---|---|
| `id` | text | Invocation ID (48 hex characters) |
| `tenant` | text | Environment the invocation belongs to |
| `service` | text | Service |
| `handler` | text | Handler |
| `key` | text | Object or workflow key (empty for a plain service) |
| `kind` | text | How it was started: `call`, `send`, `workflow`, … |
| `class` | text | `active`, `paused`, `completed` or `failed` |
| `status` | text | Detailed status: `running`, `suspended`, … |
| `root` | bool | `true` if it was not started by another invocation |
| `created_at` | timestamp | When it was created |
| `transitioned_at` | timestamp | When it entered its current class (`active`: creation time) |
| `ended_at` | timestamp | When it ended |
| `duration_ms` | int | `ended_at − created_at` |
| `scope` | text | Scope it runs in |
| `parent_id` | text | The invocation that called or sent it |
| `root_id` | text | Root of its call tree (`NULL` on a root). `WHERE root_id = …` returns a whole tree |
| `schedule` | text | The schedule that started it |
| `idempotency_key` | text | Idempotency key it was started with |
| `limit_key` | text | Limit key it was started with |
| `tags` | text | Tags set when it was started, as JSON |
| `deployment` | text | Deployment it was created on |
| `pinned_deployment` | text | Deployment it is attached to now (differs after a migrate); unfinished invocations only |
| `restarted_from` | text | The invocation it was restarted from |
| `range` | uint | Key range holding it |
| `failure_code` | int | Failure code of a `failed` or `paused` invocation (572 cancelled, 575 out of attempts, 576 quarantined, 577 stuck in infrastructure) |
| `failure_message` | text | Message that goes with `failure_code` |
| `attempt` | int | Attempts counted for the pending retry |
| `retry_at` | timestamp | When the pending retry is due |
| `last_failure_code` | int | Code of the most recent failed attempt |
| `last_failure_message` | text | Message of the most recent failed attempt (cut at 1 KiB) |
| `last_failure_at` | timestamp | When the most recent failed attempt ended |
| `purge_at` | timestamp | When an ended invocation will be removed (retention) |
| `journal_len` | int | Number of journal entries |
| `hash_chain_len` | int | Entries covered by the tamper-evident hash chain, when enabled |

Columns such as `status`, `failure_code`, `attempt`, `purge_at` and `journal_len` cost an extra
read per row when you select them; filter first, then select.

### `sys_invocation_counts`

Invocation counts per group, kept in memory and exact as of the last commit. Reads nothing from
storage, so it is the cheap way to count.

| Column | Type | Meaning |
|---|---|---|
| `tenant` | text | Environment |
| `service` | text | Service |
| `handler` | text | Handler |
| `class` | text | `active`, `paused`, `completed` or `failed` |
| `root` | bool | Root invocations only |
| `count` | uint | Number of invocations |

## Inside one invocation

### `sys_journal`

The journal of one invocation, in order. **Required key:** `id`.

| Column | Type | Meaning |
|---|---|---|
| `id` | text | Invocation ID |
| `index` | int | Entry index |
| `ty` | text | Message type code, such as `0x0402` |
| `name` | text | Message type name (`Sleep`, `Call`, …) |
| `payload` | text | Raw payload in hex, cut at 64 KiB |
| `payload_len` | int | Payload size in bytes |
| `entry_lite` | text | Decoded header, as JSON: `kind`, `name`, target (`service`, `handler`, `key`), `invocationId`, `wakeUpAtMs`, `promise`, `stateKey`, `signal`, `failure`, `awaits`/`completes`, `completed` (`false` means still waiting for its result), `hasBody` |
| `body` | text | Decoded user body, as JSON `{encoding, size, truncated, text or base64}`, cut at 64 KiB; `NULL` when the entry has no body |

### `sys_timer`

Pending sleeps of one invocation. **Required key:** `id`.

| Column | Type | Meaning |
|---|---|---|
| `id` | text | Invocation ID |
| `completion_id` | int | The completion the timer will fulfil |
| `due_at_ms` | int | When it fires |

### `sys_attachment`

Who else is waiting for this invocation's result (attach by ID or by workflow, duplicate calls).
**Required key:** `id`.

| Column | Type | Meaning |
|---|---|---|
| `id` | text | The invocation being waited for |
| `caller_id` | text | The invocation waiting |
| `completion_id` | int | The waiter's completion that will receive the result |

### `sys_log`

`ctx.log` lines of one invocation, by offset. Durable records only. **Required key:** `id`.

| Column | Type | Meaning |
|---|---|---|
| `id` | text | Invocation ID |
| `offset` | int | Record offset |
| `step` | int | Step |
| `attempt` | int | Attempt |
| `kind` | text | `data`, `gap` (records dropped over the cap) or `superseded` |
| `body` | text | The record (UTF-8, otherwise hex) |

### `sys_span`

Trace spans of one invocation, one row per span. Build the tree with `parent_id`. Durable records
only. **Required key:** `id`.

| Column | Type | Meaning |
|---|---|---|
| `id` | text | Invocation ID |
| `span_id` | text | Span ID |
| `parent_id` | text | Parent span |
| `name` | text | Span name (`llm <model>`, `tool <name>`, your own) |
| `start_ts` | text | Start time (JSON) |
| `end_ts` | text | End time (JSON) |
| `status` | text | Status at the end |
| `unfinished` | bool | Started but never ended |
| `start_lost` | bool | Ended, but its start record was lost |
| `attrs` | text | Attributes, as JSON |
| `input_tokens` | int | Input tokens reported at the end |
| `output_tokens` | int | Output tokens reported at the end |
| `step` | int | Step |
| `attempt` | int | Attempt |

### `sys_stream`

Durable streams of one invocation (`ctx.stream(name, { durable: true })`, the log and the trace),
one row per stream. Temporary streams are not stored and do not appear. **Required key:** `id`.

| Column | Type | Meaning |
|---|---|---|
| `id` | text | Invocation ID |
| `name` | text | Stream name |
| `chunks` | int | Stored chunks |
| `records` | int | Records |
| `total_bytes` | int | Payload bytes received |
| `dropped` | int | Records dropped over the cap |
| `last_offset` | int | Offset of the last record |

### `sys_stream_record`

Records of one durable stream. **Required key:** `id` and `name`.

| Column | Type | Meaning |
|---|---|---|
| `id` | text | Invocation ID |
| `name` | text | Stream name |
| `offset` | int | Offset |
| `step` | int | Step |
| `attempt` | int | Attempt |
| `kind` | text | `data`, `gap` or `superseded` |
| `body` | text | The record (UTF-8, otherwise hex), cut at 64 KiB |

### `sys_artifact`

Artifacts of one invocation. The bytes are at `GET /invocations/{id}/artifacts/{sha}`.
**Required key:** `id`.

| Column | Type | Meaning |
|---|---|---|
| `id` | text | Invocation ID |
| `sha256` | text | Content hash, hex |
| `size` | int | Size in bytes |
| `content_type` | text | Content type |
| `epoch` | int | Write epoch |

### `sys_outbox`

Calls, replies and cancels that an invocation produced and that are not delivered yet.
**Required key:** `id` (the sender).

| Column | Type | Meaning |
|---|---|---|
| `range` | int | Key range holding the row |
| `seq` | int | Order produced |
| `id` | text | The sending invocation |
| `completion_id` | int | Completion of the sending command |
| `kind` | text | `call`, `reply`, `attach`, `peek_output`, `cancel`, `fire`, `signal` |
| `target` | text | Target invocation (`attach`, `peek_output`, `cancel`) |
| `service` | text | Target service (`call`, `fire`) |
| `handler` | text | Target handler (`call`, `fire`) |
| `key` | text | Target key (`call`, `fire`) |

## Objects and workflows

### `sys_state`

State of one virtual object or workflow. **Required key:** `service` and `key`.

| Column | Type | Meaning |
|---|---|---|
| `tenant` | text | Environment |
| `scope` | text | Scope (empty when none) |
| `service` | text | Service |
| `key` | text | Object key |
| `state_key` | text | State key (UTF-8, otherwise hex) |
| `value` | text | Value (UTF-8, otherwise hex), cut at 64 KiB; `NULL` for a value stored as segments |
| `value_len` | int | Value size in bytes (the whole value, also when stored as segments) |

### `sys_value`

Segments of the large values of one virtual object or workflow: one row per holder and segment,
so a segment shared by several holders has several rows. **Required key:** `service` and `key`.

| Column | Type | Meaning |
|---|---|---|
| `tenant` | text | Environment |
| `scope` | text | Scope (empty when none) |
| `service` | text | Service |
| `key` | text | Object key |
| `holder_kind` | text | `state` (the current value of a state key), `invocation` (a journal) or `promise` |
| `holder` | text | State key (UTF-8, otherwise hex), invocation ID or promise name |
| `sha` | text | SHA-256 of the segment, hex |
| `gen` | text | Sealing generation, 16 hex characters |
| `len` | int | Segment size in bytes |

Bytes held by the object's state: `sum(len)` over the rows with `holder_kind = 'state'`.

### `sys_promise`

**Completed** durable promises of one object or workflow. Promises still waiting are in
`sys_promise_waiter`. **Required key:** `service` and `key`.

| Column | Type | Meaning |
|---|---|---|
| `tenant` | text | Environment |
| `scope` | text | Scope |
| `service` | text | Service |
| `key` | text | Object key |
| `name` | text | Promise name |
| `ok` | bool | Completed with a value (not an error) |
| `value` | text | Value (UTF-8, otherwise hex), cut at 64 KiB |
| `failure_code` | int | Error code |
| `failure_message` | text | Error message |
| `completed_by` | text | The invocation that completed it |

### `sys_promise_waiter`

Who is waiting on a promise of an object or workflow that is **not** completed yet.
**Required key:** `service` and `key`.

| Column | Type | Meaning |
|---|---|---|
| `tenant` | text | Environment |
| `scope` | text | Scope |
| `service` | text | Service |
| `key` | text | Object key |
| `name` | text | Promise name |
| `waiter_id` | text | The waiting invocation |
| `completion_id` | int | The waiter's completion |

### `sys_object`

Objects (virtual objects, workflows) of a service: one row per key that has state or holds an
invocation. **Required key:** `service`.

| Column | Type | Meaning |
|---|---|---|
| `tenant` | text | Environment |
| `scope` | text | Scope |
| `service` | text | Service |
| `key` | text | Object key |
| `has_state` | bool | The object has state |
| `invocations` | int | Invocations it holds (counted up to 16; 16 means at least 16) |
| `range` | int | Key range holding it |

### `sys_vqueue_entry`

The queue of an object or service: who holds the lock or a slot (`running`) and who waits
(`inbox`, by `seq`). **Required key:** `service` (add `key` for one object).

| Column | Type | Meaning |
|---|---|---|
| `tenant` | text | Environment |
| `scope` | text | Scope |
| `limit_key` | text | Limit key |
| `service` | text | Service |
| `key` | text | Object key |
| `stage` | text | `inbox`, `running`, `suspended` or `paused` |
| `seq` | int | Position in the queue |
| `id` | text | Invocation ID |
| `range` | int | Key range holding the entry |

## Scheduled work

### `sys_schedule`

Server-side schedules.

| Column | Type | Meaning |
|---|---|---|
| `name` | text | Schedule name |
| `id` | text | Schedule ID |
| `service` | text | Target service |
| `handler` | text | Target handler |
| `overlap` | text | `skip` or `allow` |
| `paused` | bool | Paused |
| `next_at` | int | Next run, ms |
| `fired` | int | Runs started |
| `missed` | int | Runs missed |
| `skipped` | int | Runs skipped because the previous one was still active |
| `created_at` | int | Created, ms |
| `updated_at` | int | Last changed, ms |

### `sys_delayed`

One-way calls sent with a delay that are not due yet, by due time.

| Column | Type | Meaning |
|---|---|---|
| `caller_id` | text | The invocation that sent it |
| `completion_id` | int | Completion of the send command |
| `due_at_ms` | int | When it will be delivered |
| `tenant` | text | Environment of the sender |
| `service` | text | Target service |
| `handler` | text | Target handler |
| `key` | text | Target key |
| `range` | int | Key range holding it |

## Code

### `sys_deployment`

Registered deployments.

| Column | Type | Meaning |
|---|---|---|
| `id` | text | Deployment ID |
| `tenant` | text | Environment |
| `created_at_ms` | int | Registered, ms |
| `endpoint` | text | URI of your service |
| `wire_version` | int | Protocol version |
| `protocol_mode` | text | `BIDI_STREAM` or `REQUEST_RESPONSE` |
| `services` | text | Its services, as JSON |
| `current_for` | text | Services it is the current version of, as JSON |
| `pinned` | int | Unfinished invocations still on it (`NULL` when a range did not answer); `0` means it can be removed |

### `sys_service`

Current services.

| Column | Type | Meaning |
|---|---|---|
| `name` | text | Service name |
| `ty` | text | `service`, `virtual_object` or `workflow` |
| `deployment` | text | URI of the current deployment |
| `deployment_id` | text | ID of the current deployment |

### `sys_handler`

Handlers of every current service.

| Column | Type | Meaning |
|---|---|---|
| `service` | text | Service |
| `name` | text | Handler name |
| `ty` | text | `exclusive`, `shared` or `workflow` |
| `deployment_id` | text | ID of the current deployment |

## Usage and performance

### `sys_metering`

Usage of the current hour.

| Column | Type | Meaning |
|---|---|---|
| `tenant` | text | Environment |
| `hour` | text | Hour, `yyyy-mm-ddThh` UTC |
| `invocations` | int | Invocations |
| `steps` | int | Durable steps |
| `run_ms` | int | Run time, ms |
| `input_tokens` | int | Input tokens |
| `output_tokens` | int | Output tokens |
| `cost_micros` | int | Token cost in millionths of a US dollar, when prices are set |
| `sdk_bytes_out` | int | Bytes sent to your service, after compression |
| `sdk_bytes_in` | int | Bytes received from your service |
| `units` | int | Billing units: each durable command counts one per started 64 KiB of payload (at least 1), plus 2 per invocation |

### `sys_artifact_bytes`

Bytes of live artifacts, counted in memory with each commit. This is what the artifact storage
limit is checked against. While a range rebuilds its counters, the answer carries an `indexing`
warning.

| Column | Type | Meaning |
|---|---|---|
| `tenant` | text | Environment |
| `bytes` | uint | Bytes of live artifacts |

### `sys_handler_stats`

Per-handler summary over the recent default window, for the whole cell.

| Column | Type | Meaning |
|---|---|---|
| `node` | text | Node (absent in combined rows) |
| `tenant` | text | Environment |
| `service` | text | Service |
| `handler` | text | Handler |
| `deployment` | text | Deployment |
| `turns` | int | Turns of your service |
| `completed` | int | Completed |
| `failed` | int | Failed |
| `paused` | int | Paused |
| `failed_attempts` | int | Failed attempts |
| `suspensions` | int | Suspensions |
| `steps` | int | Durable steps |
| `run_ms` | int | Run time, ms |
| `cu` | int | Compute units |
| `p50_ms` | float | Median turn time, ms |
| `p99_ms` | float | 99th percentile turn time, ms |
| `max_ms` | float | Longest turn, ms |
| `quarantine` | text | Why the handler is quarantined, if it is |

### `sys_handler_history`

The same summary **per hour**, for the last 30 days.

| Column | Type | Meaning |
|---|---|---|
| `hour_ms` | int | Start of the hour, ms |
| `tenant` | text | Environment |
| `service` | text | Service |
| `handler` | text | Handler |
| `deployment` | text | Deployment |
| `turns` | int | Turns of your service |
| `completed` | int | Invocations completed |
| `failed` | int | Invocations failed |
| `paused` | int | Invocations paused |
| `failed_attempts` | int | Failed attempts |
| `suspensions` | int | Suspensions |
| `steps` | int | Durable steps |
| `run_ms` | int | Run time, ms |
| `cu` | int | Compute units |
| `p50_ms` | float | Median turn time, ms (upper bound of the bucket) |
| `p99_ms` | float | 99th percentile turn time, ms (upper bound of the bucket) |
| `max_ms` | float | Longest turn, ms |

### `sys_slow_run`

Recent runs that took longer than the slow threshold. Kept in each node's memory (up to 1,000
rows per node).

| Column | Type | Meaning |
|---|---|---|
| `at_ms` | int | When it was recorded, ms |
| `node` | text | Node |
| `tenant` | text | Environment |
| `service` | text | Service |
| `handler` | text | Handler |
| `deployment` | text | Deployment |
| `invocation` | text | Invocation ID |
| `outcome` | text | `completed`, `failed`, `paused`, `retry`, `suspended` or `error` |
| `total_ms` | int | Total time of the run, ms |
| `threshold_ms` | int | The slow threshold, ms |
| `turns` | int | Turns of your service |
| `steps` | int | Durable steps |
| `run_ms` | int | Time in your code, ms |
| `sdk_ms` | int | Time waiting for your service, ms |
| `durable_waits` | int | Durable waits |
| `durable_wait_ms` | int | Time in durable waits, ms |
| `engine_wait_ms` | int | Time waiting for the engine, ms |
| `permit_wait_ms` | int | Time waiting for a flow-control slot, ms |

## History

### `sys_archive`

Invocations removed (by retention or purge) on one UTC day. The archived journal and final status
are at `GET /archive/{id}`. **Required filter:** `date = 'yyyy-mm-dd'`.

| Column | Type | Meaning |
|---|---|---|
| `date` | text | UTC day |
| `id` | text | Invocation ID |
| `run` | int | Run of that ID on that day (0 is the first) |
| `bytes` | int | Size of the archive object |
| `written_at_ms` | int | When it was archived, ms |

### `sys_audit`

Actions on the environment in the last 24 hours. For longer ranges use the console's **Audit log**.

| Column | Type | Meaning |
|---|---|---|
| `ts` | int | When, ms |
| `tenant` | text | Environment |
| `kind` | text | `row`, `intent`, `done`, or `denied` and `noop` (refused requests and actions that changed nothing, grouped) |
| `action` | text | Action, such as `invocation.cancel` or `deployment.register` |
| `outcome` | text | `ok`, `noop`, `not_found`, `pending`, `error`, `denied` or `unknown` (the outcome of an intent never arrived) |
| `actor_type` | text | Kind of actor |
| `actor_id` | text | Actor ID (the key ID) |
| `actor_role` | text | Role of the key |
| `target` | text | Target, as JSON |
| `status` | int | HTTP status |
| `count` | int | Number of grouped `denied` or `noop` records |
| `ip` | text | Client IP |
| `user_agent` | text | User agent |
| `request_id` | text | Request ID |
| `name` | text | Object name |
