Skip to main content

Module background_work

Module background_work 

Source
Expand description

What agents left running in the background, and what a quit does about it (docs/specs/SPEC_UPGRADE_FOR_USERS_AND_AGENTS_2026_10_15.md §6.2).

Everything an agent starts runs in its pane’s process tracker (a Windows job object, a Linux cgroup), which nothing can leave, Start-Process included; a quit closes the panes and the trackers with them, so it stops a dev server or a whole task dev AgentMux an agent started. That stays so (letting processes escape a pane was rejected on purpose: SPEC_BACKGROUND_TASK_TEARDOWN_SURVIVAL_2026_08_20.md §0). What changes is that it no longer happens without a word:

  • Before: running lists it, by agent (describe): the version panel shows the list while an upgrade waits to restart, the launcher’s dialog (updates/stopping.txt, write_for_launcher) and an agent asking for the upgrade are told.
  • At the quit (at_quit, from the quit’s session save): it is recorded, and on Windows another AgentMux among it is told the session is ending (WM_QUERYENDSESSION), so it saves all its windows as at an OS shutdown before its tracker stops it. Its windows aren’t closed: a close deletes the window’s workspace, and stopped as it is, its windows all come back on its next start. Elsewhere it is stopped with its pane as before, which keeps its windows the same way.
  • After: each agent that resumes is told what of its own was stopped (on_registered), once, with its next turn, so it can start it again.

Structs§

Work
One process tree an agent left running.

Constants§

RECORD_FILE
The record of what the last quit stopped, in the channel folder (beside upgrade_notice’s): a version’s own data folder is new after an upgrade.

Functions§

at_quit
A quit is about to close every pane (SaveSessionSnapshot with for_quit): record what agents left running, for their note after the next start, and on Windows tell another AgentMux among it that the session is ending, so it saves its windows before its tracker stops it.
describe
One line for the user: “Agent-1: an AgentMux instance (task dev), running 9 h”.
init
At srv start: what the last quit stopped, if it was recent.
launcher_file
Where the launcher reads the list for its dialog: beside the staged update (updates/ in this version’s data folder).
note_text
The note for items, all of one agent’s, stopped by the quit at at_ms.
on_registered
An agent registered in block_id: if the last quit stopped something of its own, tell it once. Called under the handler lock, so the agent is looked up, and told, from a task of its own.
running
What every running agent left running now, by agent.
trees
The process trees among members (what an agent started: the tracker’s list_block), one Work per tree: a root is a member whose parent isn’t one.
write_for_launcher
Write lines for the launcher’s dialog (an empty list removes the file).