Skip to content

The event stream and the ledgers — internals

Operator-facing coverage lives in Telemetry and the ledgers; this page is the writer/reader contract.

Owning the event stream — shuttle hook event

shuttle derives per-session waiting state, the sent-files trail, session succession and family-board records from its OWN agent hook-event stream. shuttle hook event (internal/shuttlecli/hook_event.go) appends one JSON line per hook event to $SHUTTLE_EVENTS_FILE, else events.jsonl under the data directory. Shuttle.EventStream is the daemon's one reader; outside the daemon, only an idle subscription's watcher (internal/messaging/idle.go) tails it. shuttle.EventsFile (internal/shuttle/datadir.go) is the Go resolver every writer and that watcher use, held to Shuttle.EventStream.default_events_file/0 by the shared fixture below.

The data directory is $SHUTTLE_DATA_DIR, else ~/.shuttle; the variable is trimmed and a leading ~ or ~/ expands to the home directory, for every file shuttle keeps there (event stream, ledgers, mailboxes, the class-default socket, daemon state). Go resolves it in shuttle.DataDir (internal/shuttle/datadir.go), Elixir in Shuttle.data_dir/0, and daemon/test/fixtures/data_dir/cases.json holds both to the same answers.

One reader, four projections. Shuttle.EventStream decodes each line once and feeds four pure projections held in memory: sent files (Shuttle.SentFiles), turn state (Shuttle.WaitingTracker), session succession (Shuttle.SessionBinding), and family-board records (Shuttle.Board). It seeds from events.jsonl.1 then the live file in init/1, before the Poller starts, and afterwards reads only appended bytes. Its projections are the only way into the stream's contents inside the daemon: a reader asks the stream, which catches up before answering, and a stream that is down fails the read rather than having it re-read both files. A rename rotation, recognized by the live path's inode moving, continues every projection: the tail of the old file is drained, then the new one is read from its start. The family board retains up to 14 days, bounded by the records in the two event files: rotation drops records held only in the overwritten .1 file. An in-place shrink or an unaccountable replacement rebuilds the file projections from both files, replaying accepted turn events onto remembered session facts rather than replacing a session with an incomplete reconstruction. Permission, terminal state, and outstanding work survive until a transition supplies evidence clearing them. Each session retains event identities and ingestion sequence numbers within the 48-hour window, pruned at the existing periodic prune seam rather than scanned on every hook. If replay contains the session's last known transition, unseen events after it form a suffix and fold in file order, even at equal or backward timestamps. An earlier known transition is not enough to anchor a suffix when the actual known tail is missing. Without that last-transition anchor, only unseen events with strictly newer activity timestamps fold onto the remembered facts; ambiguous equal-time events leave them unchanged. Identities use the writer's event id, or a hash of the complete decoded event for legacy lines without an id. Identical no-id events are inherently indistinguishable, so replay cannot establish that a second identical legacy line is a new occurrence. The byte mechanics live in Shuttle.FileTail.

The writer is the binary; the plugin registers it. claude-plugin/hooks/event.sh is a one-line shim (exec shuttle hook event), registered in claude-plugin/hooks/hooks.json for SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Stop, SubagentStop, Notification, and SessionEnd. .codex-plugin points at the same file, so Codex sessions feed the stream too. Install with felt setup claude / felt setup codex; scripts/bootstrap.sh step 5 does both and then probes the writer. No jq, perl, or hostname — the whole line is built in Go, which is what makes it work on a bare remote login node.

Writing is gated on ~/.shuttle already existing — the daemon's state directory is the opt-in, and the hook never creates it, so an install without daemon state grows no stream. SHUTTLE_EVENTS_FILE overrides the gate and creates its parent; SHUTTLE_EVENTS=off disables recording. The live file rotates to .jsonl.1 past SHUTTLE_EVENTS_MAX_BYTES (64 MiB) — once, under a flock of the .lock sidecar, however many hooks see it full at the same moment — and a toolInput over 8 KiB is trimmed to its file paths plus truncated: true — otherwise every Write parks a whole file body in the stream.

Terminal program status

shuttle hook event bridges OSC 7501 status to the outer terminal only when TMUX is set and the harness is Claude or Pi. Direct terminals are left to the harness's native reporter. Set SHUTTLE_PROGRAM_STATUS=off or 0 in the agent environment to disable the bridge independently of event and message recording. Each report uses the harness app id (claude-code or pi) and the fiber slug as its title when available.

Hook event Status
SessionStart idle
UserPromptSubmit working
PreToolUse AskUserQuestion blocked, kind question
PreToolUse ExitPlanMode blocked, kind permission
Other PreToolUse or PostToolUse working, with the tool name
Notification permission_prompt blocked, kind permission
Notification elicitation_dialog blocked, kind question
Notification idle_prompt no report
Other Notification blocked, with no kind
Stop with background tasks working, with the count
Stop without background tasks done
SubagentStop no report
SessionEnd clear

Worker scripts enable allow-passthrough per pane; tmux before 3.3 silently ignores it. For interactive or claimed panes, tmux set -g allow-passthrough on opts the server in; this permits wrapped terminal escape sequences from programs in those panes. Passthrough reaches the outer terminal only while the pane is visible in an attached client, and no state is replayed on attach. The outer terminal owns the record as tmux; working and blocked records drop when the client exits, while done survives. Switching sessions within a client can leave a stale record.

Clearing sent files

shuttle sent-files clear <fiber> [--path <file>] appends a sent_files_cleared event through the same locked, rotating writer as shuttle send-file. The line carries the fiber's canonical uid, an epoch-millisecond timestamp, and the writer's event identity and origin. The optional path is a nonempty absolute string matching an exact sent-file fullPath; omitting it clears the whole fiber. The writer and API reject invalid supplied paths and preserve valid paths verbatim, without expansion, normalization, or an existence check. The reader ignores malformed path-clear events rather than treating them as whole-fiber clears. It needs no harness session: clearing is an operator action, not turn activity.

Shuttle.SentFiles retains clears alongside sends in the in-memory projection. At read time, both for_uid and all_since apply cutoffs keyed by {uid, path} alongside whole-UID cutoffs. Each path is hidden if its send timestamp is at or before either cutoff, leaving uncleared siblings in a multi-path send visible. The cutoff is independent of line order and uses the current session-ledger attribution, including claims recorded after a send or clear. A send after the cutoff appears normally; a send without an integer timestamp cannot be compared and remains visible in for_uid only. Clears replay from the rotated .1 file as well as the live stream and age out with the same retention as sends. No artifact bytes or fiber body embeds are changed.

The CLI is the only writer of clears; a fiber assigned to another host is cleared on that host. The CLI's ordinary fiber-addressed clear refuses a remote owner and names the host where it must run. The Desk and Channels replace their receipt lists from full 30-day composite snapshots, so an absent cleared send disappears instead of surviving in an incremental client merge. A failed post-clear refresh is reported and retried on the next poll; a remote feed awaiting refresh is marked refresh_required until its next successful fetch.

Session identity and worker binding

Turn state is keyed by the harness's sessionId, never by tmuxSession. Events with an empty or unknown session id contribute no turn state. Interactive and nested sessions can have their own records, but only the session explicitly bound to a running worker contributes that worker's phase. A pane name remains transport context for terminals, sent files, and activity; sharing a pane is not evidence of session ownership.

The worker's shuttle.runtime.session_uuid is the binding anchor. Claude launches with a daemon-generated UUID supplied through --session-id, and resume and claim paths supply their known session id. Fresh Codex and Pi launches use the dispatcher's transcript capture to learn their UUID; until capture succeeds, the worker has no hook-derived phase. Re-adoption restarts capture from the durable dispatch boundary and owning project directory, matching the store-relative fiber id the launch prompt names. Resume-to-fresh fallback signals live under the host data directory, keyed by the worker handle and dispatch boundary. Re-adoption restores their monitor or observes an already-started fallback; an observed fallback invalidates the in-memory predecessor even when clearing the durable UUID fails. Successful capture records explicit fallback completion only after the acquired UUID is persisted. Session succession alone cannot complete a pending fallback; later restarts keep the acquired identity only when acquisition completed. Capture attempts time out after two minutes and retry after 30 seconds while the worker remains unattributed. The owner snapshot and board expose identity_pending (Identifying session) or identity_failed (Session attribution failed), never Working, for that live worker. A timeout also carries identity_error; the failure remains visible during retries until acquisition succeeds. An existing-worker claim with an explicit UUID repairs missing identity without moving dispatched_at or replacing an already-known UUID. There is no first-hook or first-session-in-the-pane fallback. The runtime timestamp falls back to the worker's liveness timestamp when no session state is available. Codex workers report lifecycle through their terminal harness hooks.

Hook lines can also carry receiverPid and receiverBirth: the harness process's PID and birth token, obtained from the process running the hook rather than from an inherited worker environment variable. Pi supplies its own process id; Claude and Codex hooks resolve their nearest non-shell ancestor. The process key includes the harness and birth token, so nested harnesses and reused PIDs are distinct. Linux birth tokens include the kernel boot identity. If receiver identity cannot be read, the event still records and direct session-id joins still work.

Shuttle.SessionBinding follows a session-id change only through an explicit session_start in the same receiver process. An ordinary tool, stop, notification, or session end cannot change the binding. An explicit resume in a new receiver process transfers the session's lineage and retires the predecessor receiver. So does the first newer hook from a receiver never seen before. A retired predecessor stays a known key while its evidence is retained, so an unseen receiver cannot be its straggler. Hooks from a retired receiver cannot mutate the resumed session's turn state. The Poller persists a verified successor to shuttle.runtime.session_uuid without changing dispatched_at, and records the session-to-fiber pairing in the session ledger. Capture callbacks are serialized through the Poller and tied to the launch that requested them, so a delayed capture cannot overwrite a later worker's identity. Bindings and turn state are retained for 48 hours of activity and are replayed from the hook stream at daemon boot.

Turn state and outstanding work

Every hook line carries type, sessionId, tmuxSession, timestamp, and the harness/origin ids. Two more are written only where the harness volunteers them, and both exist so WaitingTracker can tell "this session is blocked on a human" from "this session is watching its own shells":

  • notificationKind — Claude Code's notification_type passed straight through. idle_prompt is the ~60s "nobody has typed" timer; permission_prompt and the elicitation_* kinds mean the agent really is blocked on a person. When absent, including on Codex notifications, a notification sets attention.
  • backgroundTasks — how much work a Stop or SubagentStop reports still running. The harness sends its whole background-task registry, already filtered to running and pending entries, and every kind counts: an MCP monitor or an in-process teammate IS something the session is waiting on, and the hour bound below is what keeps a long-lived one from silencing a lane. Omitted when zero. The payload is decoded tolerantly — an unexpected shape counts zero rather than failing the line, because the writer's error path drops the whole event and a stream with no stops reads as a fleet that never finishes a turn.

Each session holds a turn (unstarted, open, closed, or ended), a background-task count, a live-child count, a pending human request, and its real last-event timestamp. The phase is derived from those facts: a pending request is attention; an open turn is working; a closed turn with recent outstanding work is working; otherwise the session is waiting.

  • session_start clears counts and pending requests. A known conversation reopens waiting; a first opening has no turn phase until prompt or tool evidence, so the board keeps a fresh launch starting rather than calling it the human's turn. A prompt or tool event starts the turn, so a quiet resume of a known waiting session remains the human's turn.
  • user_prompt_submit opens the turn and clears background work and pending requests, preserving the Codex child count.
  • stop closes the turn, restates the background count, and clears pending requests. Claude's StopFailure also records stop, so an API-failed turn doesn't stay working.
  • Permission, elicitation, and untyped notifications set a pending request. idle_prompt closes a started turn without clearing an existing request; an unstarted session remains unstarted.
  • Tool progress clears pending requests and opens the turn, except for Codex child activity on an already-closed parent turn with live children.
  • session_end ends the turn and clears counts and pending requests. Only a new session_start can reopen the conversation.
  • interrupted closes the turn and clears counts and pending requests, unless later activity already landed. No harness hook reports an interrupt (Esc in Claude Code, an aborted Codex turn). Shuttle.InterruptWatcher reads it from the transcript of a silent open turn (a [Request interrupted by user entry, or a Codex turn_aborted event) and appends it with shuttle hook interrupted, carrying the transcript record's time and id and no receiver fields.
  • Sent files and unrecognized event types do not change turn state. A Claude subagent's SendUserFile records file_sent, preserving its paths without reporting the parent's tool activity.

The background count carries forward until a prompt, session start, session end, or another stop changes it. An idle notification knows nothing about those shells on its own. A pending permission request takes precedence even when background work is running.

Codex states no count on its Stop, but its spawned agents leave a trail on the parent's own stream: each spawn_agent or followup_task call (tool on a post_tool_use line) starts a child turn and each SubagentStop ends one, and the children's tool calls land on the parent's session too. WaitingTracker counts starts minus stops as the session's live children. A stop over live children holds: the children's tool events refresh its time without turning it back into a running turn, and the SubagentStop that brings the count to zero is when the session becomes the human's move. A prompt does not clear this count, since no later stop restates it; a session start or end does. The count is scoped to the parent's sessionId and starts only through the parent's explicit spawn or follow-up tool events. A child's events under a different session id never alter the parent merely because they share a pane. Identified child-count events are deduplicated within the 48-hour replay window. A duplicate spawn event is inert for both the child count and the foreground turn. The hook stream supplies no individual child identity or live registry; an incomplete stream can therefore leave a stale count until the session is pruned. Pi exposes turn activity through the shared event stream but no child registry here; an idle Pi worker reads idle. Child activity does not clear a pending human request on a closed parent turn. A child completion changes the outstanding count, not whether someone has answered the parent's permission prompt.

Outstanding work holds Working for as long as it is outstanding. Each harness reports a child's end with an event: Claude delivers a finished background task to the model, whose follow-up turn's stop restates the count, and Codex decrements its child count on SubagentStop. A session with work still running is still working, however long the job takes. A task that hangs holds its card in Working, where the human sees it as running work rather than a question. A worker whose process dies is the dispatcher's to observe, not the event stream's: a launched worker through its terminal, which ends with its run script, and a claimed worker through the harness process its claim recorded (Shuttle.Terminal.Receipts), since the human's terminal outlives it. A stale count from a lost event lasts at most until the 48-hour prune drops the session.

Boot and incomplete histories

The daemon reconstructs session state from the retained raw event files; it does not migrate or copy a pane-keyed phase cache. A worker with a known UUID can therefore recover its idle state immediately, including from event lines without receiver metadata. A worker without a known UUID stays unattributed until dispatch capture or an explicit claim supplies it. A session-id change without receiver evidence cannot be inferred safely from pane coincidence. The same limit applies when the retained files no longer contain the anchor-to-successor relation and the continuation marker has not been updated. Refreshing the installed harness hooks supplies receiver evidence for subsequent changes; the daemon does not rewrite old events.

internal/shuttlecli/testdata/events_golden.jsonl is the cross-language contract: written byte-for-byte by internal/shuttlecli/hook_event_test.go, parsed by the Elixir projections in daemon/test/shuttle/events_parity_test.exs. Each host's daemon follows its own host's stream.

The two ledgers

Beside the event stream sit two append-only ledgers, both read by the temporal views as join rung 0 — the structural pairing that replaces an inference.

  • ~/.shuttle/sessions.jsonl (daemon/lib/shuttle/session_ledger.ex) pairs a fiber with the harness session dispatched against it. The daemon writes it, at dispatch / claim / resume. Rows can also carry the role assignment and the selected agent and configured model at that event. These are historical snapshots: a later role or registry edit must not change them. A configured model can be a provider alias; it does not prove which concrete checkpoint served the request. Records lacking this information remain unattributed on those axes. The session provenance response preserves the snapshots on individual events as well as its current row, so a resumed session's assignment changes remain visible. Role identity is separate from both the work's fiber UID and the execution model.
  • ~/.shuttle/commits.jsonl (daemon/lib/shuttle/commit_ledger.ex) pairs a commit with the session that made it: one line per commit carrying sha, subject, repo, the --shortstat counts, and session / tmux / cwd, so no reader parses a fiber name out of a commit subject. The Pi extension writes it through shuttle hook commit; the Claude/Codex plugin registers no commit recorder. The daemon is a reader only, and an absent or stale ledger is valid. Coverage is therefore partial: commits made outside an agent session, or before the plugin was installed, are absent — and there is no fallback. Only recorded, joined commits are ever drawn, so a day with no ledger has no prose rather than a guessed one.

Both are served host-scoped (/api/v1/sessions, /api/v1/commits) with a cross-host /composite sibling. Shuttle.RemoteTemporalRegistry fetches a remote's copy when a composite asks for it, never on a timer.