Skip to main content

Module restart_resume

Module restart_resume 

Source
Expand description

Restart resume (SPEC_ALWAYS_AVAILABLE_AGENTS_2026_10_27.md D7). An agent that is running when srv stops has a process only while srv lives. A pane in a tab is brought back by the window that shows it (controller_backstop covers the ones no window opens); an agent with no pane has no window at all, so this resumes it: the parked blocks whose agent was wanted running and was active within its idle window.

An agent that was running when srv exited is resumed whatever its recorded desired state says: a live process with desired=stopped means something started it without recording that (desired=running is written by start_agent, and an explicit stop ends the process too), so the record is the stale half. Without this a restart left such an agent stopped.

It resumes the most recently active first, one start at a time with a pause between, through start_agent: the same spawn gate, per-account warm-up slot and start limit as any other start. It stops at the cap instead of making room (start_agent_without_eviction), so a long list does not stop the agents it just resumed. Left stopped, and started by their first message or by being opened: an agent with no session to resume (it starts lazily anyway), one the user stopped, one that was idle past its window, one signed out or out of quota, and one a terminal view starts.

Structs§

Candidate 🔒
A parked agent that should come back: its definition id and its block.

Constants§

DELAY 🔒
How long after startup the resume runs: long enough for srv to be up and the first windows to ask for their panes. It does not wait for the windows to finish: a window that shows an agent first is seen by the check right before each start (still_wanted), and a window that attaches to an agent already started finds its process running.
GAP 🔒
Between two starts, so a long list does not start in one burst (start_agent has its own gates too).
RUNNING_FILE 🔒
The parked agents that were running when srv last exited, in the channel folder (record_running_at_exit).
SLOW_START 🔒
A start that takes longer than this is logged once, naming the agent. The starts run one at a time, so one that never returns holds back every agent after it, and until now left no line saying so (narko’s 0.60.9 to 0.60.10 restart wrote no closing line for eight minutes).

Statics§

EXIT_SNAPSHOT 🔒
Whether this run’s exit has already written its own list. Held while the file is written or removed, so the resume’s cleanup and an exit’s write never interleave.
PENDING 🔒
The agents the last exit left running that this start has not resumed yet: a second exit before the resume ran carries them into its own list.

Functions§

active_within 🔒
Whether an agent last active at last_active_ms is within window of now (None: no window, so any agent that ran is).
candidates_with 🔒
[candidates], and every agent in running_at_exit (definition ids) whatever its last turn: it was running when srv exited. One the idle sweep keeps running (a claimed task, a held message, the build slot) counts as recent too, so a crash, which leaves no list, does not drop it either.
clear_running 🔒
The resume has run: the list is spent.
install 🔒
Resume once, DELAY after startup.
is_the_agents_block 🔒
Whether block_id is the block start_agent runs for the agent uid, parked. Old layouts can hold several blocks for one agent and a start picks one by its own rule (a live process, then a pane over a parked block, then the lowest id): the checks for resuming have to be made on that block.
is_up 🔒
Whether the agent in block is up, as the Agents list shows it: a persistent agent has a running process, and a container agent has its controller, which holds no process between turns (each turn is a docker exec, so its status stays init or done while the agent waits for its next message). Without the second half a restart left every idle container agent off the exit list, “wanted running” and stopped, with nothing to start it (task #2283). A stop leaves the container agent’s controller registered at done too, so the controller alone says nothing: it must also be wanted running, and not stopped in this run.
last_active_ms 🔒
When the agent’s transcript was last written (ms): its last turn. None when it has none. A turn is appended to the agent’s zone in the global transcript store and, unless that took it, to the block’s own zone in this channel’s store (an older layout kept the agent’s zone there too): the newest of them. The controller names the agent’s zone by the block’s agentId meta, which for a block launched from a template is the template’s id; the bound instance’s id (uid) names the other.
latest_write_ms 🔒
The latest write time (ms) of the transcript files sources name (a store and a zone each).
read_running 🔒
The agents the last exit left running. The file stays until the resume has run (clear_running), so a crash during the wait does not lose them.
record_running_at_exit 🔒
At app exit, before the agents are closed: keep which parked agents (no pane; a window brings its own panes back) have a running process, by definition id. The next start resumes these whatever their last turn was: an agent the idle sweep keeps running (it holds a claimed task) must not be dropped by a restart for having been quiet. Replaces the last list; none removes it.
resume_after_go_ahead 🔒
The person went ahead with every pair that held parked agent uid (its block block_id) stopped at restart: it comes back as restart resume would have started it, unless something started or stopped it since.
run_once_with 🔒
[run_once] with the agents the last exit left running (candidates_with).
save_exit_snapshot 🔒
An exit’s list: written, and from now on the resume’s cleanup leaves the file alone (an exit that overlaps the delayed resume would otherwise lose the list it just saved).
spend_start_snapshot 🔒
The resume has run, so the list this start read is spent: removed unless an exit has written its own list since, which is the next start’s.
still_wanted 🔒
Whether c is still to be resumed now: stopped agents and agents a window or a message started in the meantime are not. The wait between two starts is long enough for either.
stopped_in_this_run 🔒
Whether the agent uid was stopped in this run (BLOCKING: a store read).
with_pending 🔒
running and the pending ones too, each once, in order. An agent on the list is resumed whatever its recorded desired state says, but not when it was stopped in this run, so carrying one along does no harm.
without_stopped 🔒
The pending agents (definition ids) minus the ones stopped in this run: the stop is remembered in memory only, so an exit before the resume ran would otherwise carry the agent into the next start’s list and lose the stop. BLOCKING (store reads).
write_running 🔒