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_agenthas 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_msis withinwindowofnow(None: no window, so any agent that ran is). - candidates_
with 🔒 - [
candidates], and every agent inrunning_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,
DELAYafter startup. - is_
the_ 🔒agents_ block - Whether
block_idis the blockstart_agentruns for the agentuid, 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
blockis 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 adocker exec, so its status staysinitordonewhile 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 atdonetoo, 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.
Nonewhen 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’sagentIdmeta, 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
sourcesname (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 blockblock_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
cis 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
uidwas stopped in this run (BLOCKING: a store read). - with_
pending 🔒 runningand thependingones 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
pendingagents (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 🔒