Skip to main content

Module restore

Module restore 

Source
Expand description

Restart recovery: bring a freshly-spawned agent back to its persisted running state so the daemon resumes it where it stopped.

When the daemon restarts, the CLI reloads each non-terminal run’s blueprint and spawns a fresh agent, then calls restore_agent to overlay the persisted context, jump to the persisted stage + iteration, and restore token totals. The agent keeps the ReadyToInfer marker spawn_agent set, so any inference that was in flight when the daemon stopped is re-issued on the next tick - nothing is left stuck awaiting a job that died with the old process.

A tool batch that was in flight is not blindly re-issued, though: when the run journal holds a dispatched-but-unapplied batch, restore_pending_batch reconstructs its assistant turn in the window first - real journaled results for calls that completed, a verify-first INTERRUPTED_TOOL_RESULT for calls that didn’t - so the re-issued inference sees exactly what already ran and completed side effects never run twice (issue #96).

Enums§

RestorePriority
How urgently a persisted run should be brought back on restart. Ordered so a higher value restores first (see triage_restores).

Constants§

INTERRUPTED_TOOL_RESULT
The synthesized result for a call whose completion never reached the journal. It tells the model plainly that the effect may or may not have landed, so the re-issued turn verifies before re-running side-effecting work.

Functions§

classify_restore
Classify one persisted run for restart recovery from its on-disk status and whether it is parked mid fan-out (a <run_dir>/fanout.json is present).
restore_agent
Restore a just-spawned entity to the persisted state captured in snapshot (its context), stage_index + iteration (its position), and totals (its running token/tool counts). The agent stays Active + ReadyToInfer so it resumes on the next tick.
restore_pending_batch
Replay a tool batch that was dispatched but never applied before the crash (folded from the run journal as a PendingToolBatch): land the assistant turn plus one result per call in the context window, exactly as apply_tool_results would have - real journaled results for calls that finished, INTERRUPTED_TOOL_RESULT for calls that didn’t. The turn is always fully paired, so the request assembler’s orphan sanitizer keeps it, and the re-issued inference sees precisely what already ran instead of blindly re-executing the whole batch (issue #96).
triage_restores
Triage a set of persisted runs into the order they should be restored on restart: drop terminal runs, then rank the rest actionable-first (RestorePriority::Active before Blocked), breaking ties by most-recently updated. Each input is (meta, parked_on_fanout) where parked_on_fanout is whether the run has a fanout.json (see classify_restore); the returned RunMetas are ready to reload in order.