Skip to main content

Module agent_teardown

Module agent_teardown 

Source

Structs§

Policy
What one teardown covers (spec §5). A consumer picks a constructor; it never adds its own kill code.
TeardownReport
What a teardown did, for the consumer’s summary and the audit.

Enums§

CliStop
How the agent’s own process is stopped.

Constants§

APP_EXIT_CAP
App exit’s overall cap (spec §11 O3), the leftover-shell sweep included: every agent closes concurrently under it. The launcher waits longer than this for srv to exit on every quit (SRV_EXIT_WAIT, quiesce_srv), so it force-kills srv only if the teardown overran.
ESCAPE_SETTLE 🔒
MEMBERS_GRACE_MAX 🔒
The longest wait after SIGTERM to what an agent started; never past the teardown’s deadline.
SETTING_STOP_KEEPS_BACKGROUND
Setting: does Stop keep the agent’s run_in_background tasks (dev servers) running when the caller doesn’t say? Per user, default true, today’s behaviour (spec §11 O2).
SHELL_SWEEP_GRACE 🔒
The grace the leftover-shell sweep gives its kill tasks. [reagent #1422 P2]
VERIFY_WAIT 🔒
How long the verify step waits for the tracker’s release to take effect, before and after its one forced kill per survivor.

Statics§

CLOSES 🔒
Every teardown and window close in flight. Each runs as its own task, so a caller that stops waiting can’t cut it short: an HTTP handler whose client hung up (the host gives CloseWindow 2 s) or srv’s servers stopping on quit. app_exit waits for all of them.

Functions§

app_exit
App exit (main.rs, after the servers stop): tear down every live agent with Policy::app_exit(), concurrently, and wait for every close already in flight, all under APP_EXIT_CAP. Then stop any Shell() session left over (one whose agent is already gone, or whose teardown hit the cap). Returns how many controllers it closed.
close_cli 🔒
The per-agent close (SPEC_AGENT_PANE_CLOSE_GRACEFUL_SHUTDOWN_2026_09_18.md §4.2), then the verify step (agent teardown spec §6.2 step 8). Returns the survivors.
close_sub_blocks 🔒
Close a parent’s sub-blocks (PtyShell drawers) the way a pane closes, concurrently and under the parent’s deadline.
compose_containers_left 🔒
Running Docker Compose containers started from the agent’s working directory (docker compose up -d): they belong to the Docker daemon, not the agent’s process tree, so no tracker ends them. Reported, not stopped: a person may be using them too. Skipped when the agent works in / or the home directory, where every project would match.
detached 🔒
Run fut to completion as a tracked task, even if the caller is dropped first; app_exit waits for it. None if it panicked.
discard
Drop a block’s controller and process tracker at once, with no graceful phase: for a controller that isn’t an agent to wind down (a PtyShell drawer the user closed, a /btw throwaway, a spawn being rolled back) and as the backstop after a close that already ran the teardown (idempotent; finds nothing left).
escaped 🔒
Live processes tagged with block_id (process_tracker::scan) that aren’t already in known. Two scans ESCAPE_SETTLE apart: one the tracker’s kill is still ending shows in the first only.
release_claims_and_list_crons 🔒
Release the agent’s work claims, so the items go back to the pool now rather than when the 120 s lease expires, and list the crons that target it (kept: a cron is a deliberate schedule that resumes when the agent is reopened). SQLite reads and writes, off the async workers.
replace_now
The replace policy’s entry, for resync_controller (synchronous, below the saga layer, and already holding the old controller): stop its own CLI process only (Policy::replace).
run
run_many for one block.
run_many
Tear down every block in block_ids concurrently, under ONE deadline: ten agents take one grace period, not ten. Each runs detached.
run_one 🔒
stop
Stop (agent.stop, FleetBulkStop, a deferred Stop action): Policy::stop. stop_background is the caller’s answer to “also stop its background tasks?”; None takes the user’s setting (SETTING_STOP_KEEPS_BACKGROUND). Errors with NOT_RUNNING when the block has no controller, as agent.stop always has.
stop_background_tasks 🔒
Stop the agent’s running run_in_background tasks, each with its process tree, after re-checking each PID is still that task. Returns how many.
stop_container 🔒
Stop a container agent’s container (spec §6.7), unless another live pane runs the same agent in it. Docker’s own SIGTERM → SIGKILL grace is bounded by what’s left of the teardown’s deadline.
stop_keeps_background 🔒
stop_now
Policy::stop_cli_only’s entry, for callers with no AppState (the watchdog, the pane’s AgentStop command): controller.stop() only. Errors with NOT_RUNNING when the block has no controller.
terminate_members 🔒
Ask everything in the block’s tree to exit and wait until it has, or the grace passes. Returns at once where the tracker has no graceful signal (Windows), nothing is left, or the deadline has passed (the release’s kill follows straight away).
verify_gone 🔒
Spec §6.2 step 8: wait for every process in the snapshot to be gone. Any still running (same PID and start time) gets one forced kill of its tree; whatever is left after that is returned. Never kills a PID the OS has reused: survivors re-checks the start time right before the kill.
wait_gone 🔒
Poll until none of procs is running or VERIFY_WAIT passes; returns the ones still running.
without_sub_blocks 🔒
ids minus any that is a sub-block (PtyShell drawer) of another block in it. Store reads: call off the async workers.