Expand description
On-disk run state for background agent executions.
Each run lives under ~/.leviath/runs/<run-id>/ with:
meta.json- run metadata, updated atomically (tmp + rename)output.log- append-only combined worker stdout (legacy/fallback)stages.json- index of per-stage recordsstages/<idx>/output.log- readable agent output for that stagestages/<idx>/logs.log- operational events + tool activitystages/<idx>/context.json- context snapshot for that stage
The dashboard’s activity log is persisted separately at:
~/.leviath/dashboard.log- never cleared, appended across sessions
§Who writes, and which copy is authoritative
There are two answers to “what runs exist”, and that is deliberate. The ECS
world is the live one: it knows wait reasons and tick-fresh progress for the
runs the daemon is holding right now, and host.rs’s list() reads it.
The runs directory is the durable one: it survives a crash or a daemon that
is not running, and list_runs below reads it. Disk lags the world by at
most one persistence tick, so the two disagreeing is expected rather than a
bug, and every reconciliation of that gap goes through looks_abandoned.
The runtime’s persistence_bridge is the only thing that writes a live
run’s state. The writers in this module are #[cfg(test)] so that stays
true by compilation rather than by convention: a test can lay down a run
directory to read back, and production has no second path to the same files.
Structs§
- Context
Snapshot - Snapshot of the full context window, written to
context.jsonalongsidemeta.json. - Region
Entry Snapshot - One content entry within a region, captured at snapshot time.
- Region
Snapshot - Per-region token snapshot written by the background worker after each inference.
- RunMeta
- Metadata for a single background agent run.
- Stage
Record - Metadata record for a single stage within a run.
- Stat
Cache - A parse cache keyed by a file’s
(mtime, len): the file is re-read and re-parsed only when its stat changes.
Enums§
- Force
Cancel Outcome - The outcome of forcing a run to a terminal state on disk.
- LogStream
- Which of a stage’s two logs to read.
- RunStatus
- Current status of a background run.
- Stage
RunStatus - Status of an individual stage within a run.
- Stage
Selector - Which stage’s logs to read.
Constants§
- STALE_
AFTER_ SECS - How long a run may claim to be live on disk, while the daemon is not holding it, before anything treats it as abandoned.
Functions§
- append_
dashboard_ log - Append a timestamped line to the persistent dashboard activity log at the
default
dashboard_log_path. Silently ignores I/O errors - best-effort. - append_
dashboard_ log_ to - Append a timestamped line to the dashboard activity log at an explicit
path. Silently ignores I/O errors - the dashboard log is best-effort. - context_
history - A run’s context-window history: the full window (+ metadata) at each recorded point over time, oldest first. Empty when there’s no readable archive.
- create_
run - Create the run directory and write initial metadata.
- dashboard_
log_ path - Path to the persistent dashboard activity log (~/.leviath/dashboard.log).
- final_
output_ path - Where a run’s answer lives, beside its
meta.json. - force_
cancel - Force a run’s on-disk metadata to
Cancelled, in the runs dir resolved from the environment. Seeforce_cancel_in. - force_
cancel_ in - Force the run in
run_dirtoCancelled, stampingupdated_atwithnow. - force_
error_ in - Force the run in
run_dirtoErrorwithmessage, stampingupdated_at. - is_
terminal_ status - Whether an on-disk run status means the run has finished and should be left
alone.
Starting/Running/WaitingInputare all “still going” as far as anything reading the runs dir is concerned. - list_
runs - List all runs, sorted by started_at descending (most recent first). Silently skips any runs whose metadata cannot be read.
- list_
runs_ cached list_runsthrough aStatCache, for pollers: eachmeta.jsonis re-parsed only when its stat changes, and cache entries for deleted runs are dropped. Same ordering and skip-unreadable behavior aslist_runs.- looks_
abandoned - Whether a run that claims to be live on disk has nothing driving it: the
daemon is not holding it and it has not moved in
STALE_AFTER_SECS. - new_
run_ id - Generate a unique run ID:
<agent_name>-<timestamp>-<random>. - read_
context_ snapshot - Read the context snapshot for a run, if present.
- read_
context_ snapshot_ cached read_context_snapshotthrough aStatCache, for pollers. The snapshot is shared, not cloned: a context window is the largest thing in a run dir, and handing out copies per tick is the churn this cache removes.- read_
final_ output - Read a run’s final output, content included.
- read_
meta - Read run metadata for a given run ID.
- read_
run_ archive - Read + parse a run’s portable archive (
<run_dir>/run.lvr), returning its records, orNoneif the archive is missing or unreadable. - read_
stage_ context - Read the context snapshot for a specific stage, if present.
- read_
stages_ index - Read the stages index for a run, or return an empty vec on any error.
- read_
stages_ index_ cached read_stages_indexthrough aStatCache, for pollers.- read_
stages_ index_ from read_stages_indexfor a run directory the caller already holds.- run_dir
- Directory for a specific run.
- runs_
dir - Directory where all run state is stored.
- stage_
dir - Directory for per-stage files within a run.
- tail_
file - Read the last
max_bytesof any file on disk, returning UTF-8 text. If the file is smaller thanmax_bytesthe whole file is returned. Partial UTF-8 at the truncation boundary is handled by skipping to the first newline. Returns an empty string on any I/O error. - tail_
run_ logs - Read a run’s logs, choosing the stage and the stream.
- tail_
stage_ log - Read the last
max_bytesof the operational log for a specific stage. - tail_
stage_ output - Read the last
max_bytesof the readable output log for a specific stage. - visit_
run_ archive - Stream a run’s archive through a
visit_pointsvisitor without ever materializing the journal: one buffered pass overrun.lvr, one record and one running window in memory. ReturnsNoneif the archive is missing or its preamble is invalid; a torn tail (a live run mid-append) just ends the walk with the points already visited. - visit_
run_ records - Stream a run’s raw journal records through
visit, one at a time, without materializing the archive. Same lenient tail handling asvisit_run_archive. For consumers that inspect records rather than replayed points (journal search). - write_
meta - Atomically write run metadata (write to tmp, then rename).