Expand description
Cooperative cancel and FINALIZE ledger. One-shot lifecycle: INIT → EXECUTE → FINALIZE → EXIT.
§Workload
Coordination (not compute fan-out): one CancellationToken per process
invocation. Residual scavenge may use map_cpu when candidate paths are
large (see crate::residual). FINALIZE is ordered: Browser.close → residual
kill → flush. No multi-writer shared state.
§Graceful shutdown model (rules_rust_encerramento_graceful_shutdown)
This binary is a one-shot CLI, not a daemon. Shutdown is therefore minimal + critical for pipelines, not a full multi-subsystem coordinator:
- Detect — OS signals (
SIGINT/SIGTERM, Windows Ctrl-C/Break) viacrate::browser::shutdown_signalwired insidecrate::browser::block_on_browser_timeout. - Signal — cooperative [
CancellationToken] cancel (exit 130). - Await / finalize — primary
OneShotSession::shutdown(Browser.close + wait ≤5s + kill); residual ledger kill with SIGTERM → grace → SIGKILL; dual stream flush; processExitCode.
§Deadlines
| Phase | Bound |
|---|---|
| Work / navigation | CLI --timeout / XDG / step-timeout |
| Browser.close wait | 5s (finalize_browser) |
| Residual child grace (SIGTERM→SIGKILL) | [FINALIZE_CHILD_GRACE] |
| Second OS signal | Forces residual Lifecycle::finalize immediately |
§Not applicable (product law)
Daemon patterns: TaskTracker fleets, readiness probes, SIGHUP hot-reload,
sd_notify, PID files, OpenTelemetry flush, TUI terminal restore.
§Safety
On Unix, finalize may send SIGTERM then (after grace) SIGKILL to a
recorded Chrome PID as last resort when primary Browser.close reap did not
clear the ledger. Profile dirs and Chrome Singleton side-channels are wiped
only when recorded in this ledger (never a host-wide chrome wipe).
Structs§
- Lifecycle
- Runtime token for cooperative cancel and FINALIZE.
- Resource
Ledger - Ledger of resources owned by this invocation (browser, profile, temp dirs).
Constants§
- FINALIZE_
CHILD_ GRACE - Max wait after residual
SIGTERMbefore escalating toSIGKILL(Unix).
Functions§
- current_
cancel - Return the cancel token for the active invocation, or a fresh inert token.
- current_
lifecycle - Return a clone of the active
Lifecycle, if one was registered. - kill_
unix_ graceful Unix - Send SIGTERM, wait up to
gracewhile the pid exists, then SIGKILL if needed. - mark_
profile_ dir - Record a temporary Chrome profile directory on the ledger for FINALIZE wipe.
- mark_
side_ channel - Record a side-channel path (SingletonLock, etc.) owned by this launch.