Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(reaper): the kill log names both clocks, and the passive-view trade-off is recorded
Claude Coded77b565d1957
diff --git a/src/core/session-budget.test.ts b/src/core/session-budget.test.tsindex 5b7f8c370..cb3a94669 100644--- a/src/core/session-budget.test.ts+++ b/src/core/session-budget.test.ts@@ -422,6 +422,21 @@ describe('createSessionReaper (service)', () => {])})+ it('the kill log names BOTH clocks, with the silence leading', async () => {+ // The attach clock's only production consumer is this log line. It rides along BECAUSE it+ // disagrees with the silence: an operator cross-checking `tmux ls` sees `session_activity`+ // minutes old and would read the reap as a bug unless the line itself explains the discrepancy.+ // The numbers are pinned, not just the words — 100.0h of silence against a 0.0h-old attach is+ // exactly the two-clock disagreement the whole change rests on.+ const lines: string[] = []+ const w = fakeWorld({ 'node-terminal': [row('nt-x', 0, OLD)] })+ const reaper = createSessionReaper({ ...base, log: (m) => lines.push(m), tmuxBin: () => 'tmux', exec: w.exec })+ expect(await reaper.sweep()).toBe(1)+ expect(lines).toEqual([+ '[session-budget] reaped detached session nt-x — no pane output for 100.0h; last attach 0.0h ago (socket node-terminal)'+ ])+ })+it('re-verifies at kill time: a session attached between plan and kill is spared', async () => {let first = trueconst w = fakeWorld({})diff --git a/src/core/session-budget.ts b/src/core/session-budget.tsindex d29aec923..33724cd5f 100644--- a/src/core/session-budget.ts+++ b/src/core/session-budget.ts@@ -57,8 +57,9 @@ export interface SessionInfo {*/clients: number/**- * `#{session_activity}`. **Kept for the log line and NOTHING else — it is not an idleness- * signal, and this module must never gate a kill on it again.**+ * `#{session_activity}`. **Kept for exactly two consumers — the kill log's second clock (so an+ * operator cross-checking `tmux ls` sees why tmux disagrees) and the test suite's two-clock pin —+ * it is not an idleness signal, and this module must never gate a kill on it again.**** MEASURED on this host, 2026-08-15, on a private throwaway socket (a real socket was never* swept): tmux bumps `session_activity` to `now` every time a CLIENT ATTACHES, with no pane@@ -292,6 +293,13 @@ export function hostUnderMemoryPressure(mem: MemInfo | null, cfg: SessionBudgetC* than about half an hour, so no grace window could ever elapse and this function returned an* empty plan on a host that was 84% into its swap.*+ * A deliberate trade-off rides on that clock: PASSIVELY VIEWING a session no longer protects it.+ * Attaching and reading a pane without pressing a key moves neither `window_activity` (measured —+ * attach does not bump it) nor, therefore, `outputSec`, so a long-silent session someone glanced at+ * an hour ago is still eligible. Accepted because the exposure is narrow — an ATTACHED session is+ * never eligible at all, a single keystroke's echo restamps the clock, and the grace window still+ * applies — and because the alternative is the attach clock this module just stopped trusting.+ ** Eligible = named `nt-*` AND detached AND silent past the grace window. Then:* - memory below the watermark → up to `batchMax` (a failed memory read — `mem === null` — is* NOT pressure: absence of evidence never triggers the primary path);@@ -531,7 +539,8 @@ export function createSessionReaper(opts: SessionReaperOpts): SessionReaper {const now = nowSec()const plan = new Set(planReap(all, readMem(), now, cfg, sweepOpts?.pressure !== undefined))if (plan.size === 0) return 0- const silentH = new Map(all.map((s) => [s.name, ((now - s.outputSec) / 3600).toFixed(1)]))+ const h = (sec: number): string => ((now - sec) / 3600).toFixed(1)+ const clocks = new Map(all.map((s) => [s.name, `no pane output for ${h(s.outputSec)}h; last attach ${h(s.activitySec)}h ago`]))let killed = 0for (const [socket, listed] of bySocket) {@@ -547,11 +556,12 @@ export function createSessionReaper(opts: SessionReaperOpts): SessionReaper {// `=` forces an exact target match — never tmux's prefix matching.await exec(bin, ['-L', socket, 'kill-session', '-t', `=${name}`])killed++- // The silence is what justified the kill, so it is what the log has to name — an operator- // reading "idle" against tmux's own `session_activity` would be reading the clock this- // change exists to stop trusting.+ // The silence is what justified the kill, so it leads — and the attach clock rides along+ // BECAUSE it disagrees: an operator cross-checking `tmux ls` sees `session_activity`+ // minutes old and would otherwise read this reap as a bug. Naming both clocks puts the+ // discrepancy, and the reason for it, in the line they will actually be looking at.log(- `[session-budget] reaped detached session ${name} — no pane output for ${silentH.get(name) ?? '?'}h (socket ${socket})`+ `[session-budget] reaped detached session ${name} — ${clocks.get(name) ?? 'clocks unknown'} (socket ${socket})`)} catch {// A vanished-in-between session or a kill failure changes nothing; next sweep re-plans.