Skip to main content
The Specification group documents how the worker operates internally: the BlobHub data model it builds on, the state it keeps on disk versus on the wire, how it synchronizes the two, and the per-job-type object notation. You do not need any of this to connect the worker to your sessions — read the Overview for that. This group is for understanding the mechanics.

The BlobHub data model the worker builds on

The worker is a client of the existing BlobHub session API. It introduces no new backend endpoints: it reads and writes the same sessions, session objects, and thread items any client speaks, as its own user. Everything below is part of the generic data model — the worker only attaches meaning to specific metadata blocks within it.
  • Sessions — a session is the shared context the worker attaches to. One session_agent_harness section attaches to one session.
  • Session objects — a thread-typed session object has an envelope of attributes (display metadata) and metadata (the structured state). The worker uses two kinds: a single worker object that marks its attachment, and one object per unit of work. See thread session object and upload_session_object.
  • Thread items — an append-only stream of items on a thread. The agent’s output is posted as items; a human’s posts arrive as items. See post_session_thread_item, list_session_thread_items, and get_session_thread_item.
  • Session events — the session’s event stream, which the worker listens to over the WebSocket API and reads back with list_session_events to learn what happened. The relevant types are object.written, object.deleted, thread.item_posted and the session.* lifecycle types. See Session events and Listeners.
The worker reuses these generic operations directly; this specification does not re-document their request and response shapes.

What the worker reads and writes

The worker never invents new object types or commands. On each object it touches, it reads and writes only specific metadata blocks — for example the control channel and agent settings on a unit-of-work object, optionally an artifacts publish contract and a guarded-mode policy on that same object, and the attachment marker on the worker object. The exact blocks per object are documented on the per-job-type object pages, starting with the Job Session Object and the Worker Session Object.

Sync model

The worker stays current by listening. Each attached section opens one WebSocket connection to the realtime API and adds connection listeners on it: one for a whole-session section, two under a session_prefix, because a filter is a conjunction and a lifecycle event has no object alias. Every match arrives as a listener/event frame carrying the stored event. A frame is a latency path, not a guarantee, so the worker also sweeps: it lists the stream with list_session_events from its persisted cursor, once after every (re)connect, once a minute while the connection is live, and at the polling cadence while it is not. Frames make the worker fast and sweeps make it correct. Only a sweep moves the persisted cursor, and each one re-reads the 60 seconds before it, because event ids are minted before they commit and a listing can show a later id before an earlier one. The worker keeps the ids it has already handled inside that window (seen) and drops repeats, so a frame and the sweep that lists the same event handle it once. A worker that cannot reach the realtime API, or whose listener is refused, still works: the section reports polling and sweeps at the fallback cadence. An event is a hint, and the platform’s current state decides. Before acting on a lifecycle event, or on the deletion of an object, the worker reads the session or the object, so a replayed or reordered event never tears down work that still exists. Every write the worker makes carries its client tag (see Filesystem Layout), which the listeners exclude, so the worker does not wake on its own writes. When the worker needs to change an envelope, it does an optimistic read-modify-write: read the current object, mutate only the fields it owns, write back, and on a write conflict re-read and retry, resyncing from the next event. A section’s watch can be scoped to part of a session (session_prefix; see Configuration) instead of the whole thing. Discovery is then list, then watch: an attach pages every object under the prefix and classifies each alias it hasn’t seen as the worker’s own work or not, and steady state re-classifies for free from the type each object.written event already carries — no separate re-list. See Concepts for the mental model.

Local vs wire state

The worker keeps two views of each unit of work, and they are deliberately not the same:
  • The wire envelope (the session object’s metadata) is authoritative for handoff — it is how the user and the worker communicate ownership and the control-channel state.
  • The local thread.yaml on the worker host is authoritative for recovery — it records the resume pointer, the last consumed/posted item cursors, and the local failure detail, none of which appear on the wire.
The worker persists local state before any observable side effect (before posting an item, before spawning an agent), so that a crash at any point leaves the on-disk record consistent with what the rest of the system can see. The two layouts differ field-by-field; see the Job Session Object for the wire shape and the wire-to-local mapping.

Job types

A section’s job_type is the discriminator that selects which validator runs at preflight, which objects the section attaches to, and how it behaves at runtime. session_agent_harness is the one job type in v1. See Job Types for the dispatch mechanics and extensibility.

See also