Repository navigation
fix(bin): stop a closed task's browser sessions at teardown and list orphan browser helpers - #53
Merged
Merged
Conversation
…orphan browser helpers in the fleet view A chrome-devtools-axi bridge and its headless Chrome run detached until chrome-devtools-axi stop names them, so a task that ended without that stop left about 150 MB per session running for days. Teardown now finds every bridge whose own environment carries the task's FM_TASK_ID and this home's FM_HOME, asks chrome-devtools-axi to stop it when that session's pid file names exactly that bridge, terminates whatever remains of the tree by pid, and prints one line per session it stopped. Bridges of other tasks, other homes, or with no task id are never touched, and the step runs only after teardown's landed-work refusals have passed. bin/fm-browser-sessions.sh lists every helper with its task, home, age and memory, and stops a closed task's helpers on request; the fleet snapshot carries that listing and the fleet view shows each orphan with its cleanup.
… tests/fm-gotmp.test.sh. The failure came from this PR: bin/fm-teardown.sh now requires bin/fm-browser-sessions-lib.sh and exits early if it is missing. The test builds its own fake bin directory for the real teardown script, and it did not include that library, so teardown failed before the temp-dir cleanup the test checks. I reproduced the failure locally ("not ok - teardown exited non-zero with a valid tasktmp"). Rule that was broken: every fake bin directory that runs the real teardown must contain every library teardown requires. The test builds that fake directory in two places, and I added the missing link to both. Other tests that use teardown's libraries are unaffected: fm-teardown.test.sh and tests/fixtures.sh already include the new library, and the remaining ones use the real bin directory or call single functions. Checks: bash tests/fm-gotmp.test.sh now passes all 3 cases, and shellcheck is clean on the edited file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Not a captain request. On 2026-10-26 the machine ran out of memory for an hour: eight orphaned chrome-devtools-axi helper trees (a bridge plus a headless Chrome, about 150 MB each) from tasks finished days earlier held about 1.2 GB and all 8 GB of swap. Bash library loads failed with "Cannot allocate memory", four workers broke, one steer was lost, five of firstmate's replies lost their sound, and the turn-end guard reported supervision off once (data/backpass-20261026-2200/report.md, class N8/T11/T14/T18). Firstmate found the cause by reading each bridge's /proc//environ, which carries CHROME_DEVTOOLS_AXI_SESSION and FM_TASK_ID, and killed the trees by pid;
chrome-devtools-axi stopwas a no-op for an orphan. The outcome wanted: a finished task never leaves a browser helper running.What Changed
bin/fm-teardown.shnow stops a ship or scout task's chrome-devtools-axi browser sessions. It runs once before the worktree process reap and again after the worker's endpoint closes. The newbin/fm-browser-sessions-lib.shfinds each bridge by readingFM_TASK_IDandFM_HOMEfrom its/proc/<pid>/environ. When the session's pid file names that exact bridge, it callschrome-devtools-axi stop, then sends TERM and KILL to whatever is left of the tree. It never touches bridges from other tasks, from other homes, or with no task id. If a process survives, teardown prints a warning but still completes. On a platform without/procthe step is skipped.bin/fm-browser-sessions.shcommand:list [--json]shows every bridge with its pid, session, task, home, age, RSS and scope (live_task,orphan,other_home,unattributed).stop <task-id>cleans up after a task that closed before this change, and refuses while the task'sstate/<id>.metastill exists.bin/fm-fleet-snapshot.shadds abrowser_helpersfield taken fromlist --json. If the listing fails, the field readssupported:nulland the snapshot still succeeds.bin/fm-fleet-view.shadds a "Browser helpers" section that lists helpers not owned by a live task, with age, memory, and a cleanup command for orphans. The docs (docs/scripts.md,docs/architecture.md) and the test runner are updated, with new tests intests/fm-browser-sessions.test.shandtests/fm-teardown.test.shthat use fake-bridge fixtures.Risk Assessment
Testing
I ran the browser-sessions test file and the three browser cases from the teardown test file, and all passed. I also confirmed the late-bridge case fails when the new second sweep is removed. Then I drove the real teardown live in a throwaway lab home: a tmux worker window, real chrome-devtools-axi bridges and real headless Chrome. Teardown reported stopping own-sess and the late-sess bridge the worker started mid-teardown, and exited 0. Afterwards no process with the task's FM_TASK_ID and FM_HOME was left. The other home's bridge, the unattributed bridge and the operator's pre-existing bridges were not touched. The TERM-ignoring bridge and refused-teardown cases were only covered by repository tests with stand-in processes, so they are recorded as untested live. The full teardown test file was too long to finish inside the 10-minute background limit and was stopped, so only its browser cases were run. The change has no visual UI: the fleet listing is CLI text, captured as a transcript.
listoutput before and after;FM_HOME=<other-home> bin/fm-browser-sessions.sh stop task-x1stopped foreign-sess, exit 0Evidence: Round 2 live teardown transcript (own and late bridges stopped, others untouched)
Source: Round 2 live teardown transcript (own and late bridges stopped, others untouched)
Evidence: Live lab driver script
Source: Live lab driver script
Evidence: Teardown stderr excerpt
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-teardown.sh:3654- The browser sweep (fm_browser_stop_task) runs before teardown closes the worker's endpoint (fm_backend_kill at bin/fm-teardown.sh:3692 for orca and :3794 for other backends). Until then the worker agent is still alive and can still run chrome-devtools-axi, for example a scout torn down with --force mid-turn, or a worker answering a last steer. Any chrome-devtools-axi command auto-starts a detached bridge (setsid, as the live tree on this machine shows: the bridge leads its own session and its parent is the WSL relay, not the pane). Killing the pane therefore does not reach a bridge created after the sweep, and the finished task leaves a ~150 MB helper running. That contradicts the intended outcome: "a finished task never leaves a browser helper running". Smallest correction within the existing design: run fm_browser_stop_task "$FM_HOME" "$ID" teardown a second time, best effort, after the endpoint close succeeds (both fm_backend_kill sites and the herdr pane close). Keep the early call so a bridge started inside the worktree is still stopped as a session before Fix 2. A teardown test could start a bridge from the fake pane's close hook to cover it.bin/fm-browser-sessions.sh:62- Simplification check: beyond the required teardown stop, the change adds a detection layer. It has three parts: thelistcommand in text and --json modes (bin/fm-browser-sessions.sh:62-111), the browser_helpers field in the fleet snapshot (bin/fm-fleet-snapshot.sh:2254-2259), and the "Browser helpers" section of the fleet view (bin/fm-fleet-view.sh:59-68, 109-125). The stated outcome only requires that a finished task never leaves a helper running. Thestop <task-id>command is reasonable containment for orphans that already exist, but the listing and fleet-view surface go beyond that requirement, and so does the separate text mode oflist, which nothing in the change consumes. They are defensible: they surface leftovers when a TERM/KILL survivor warning is missed. Confirm whether to keep them. If not, remove the listing/view pieces, or keep onlylist --jsonfor the fleet view.bin/fm-browser-sessions-lib.sh:178- Simplification check: fm_browser_polite_stop is a second stop path ahead of the pid-based TERM/KILL. It parses the session pid file, overrides HOME and unsets the CHROME_DEVTOOLS_AXI_* variables, wraps the call in a 15 s timeout, and adds a 2 s wait per session. The pid-based termination alone already ends every matched tree, and the intent noteschrome-devtools-axi stopcannot reach orphans. The benefit is a graceful Chrome shutdown when the pid file still names the bridge. Even then the tests show the Chrome child still needs TERM afterwards ("terminated 1 remaining process(es)"). Confirm whether the graceful path is wanted. Removing it would shrink the lib and the fixture stub.🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
bin/fm-browser-sessions.sh:62- Simplification check: beyond the required teardown stop, the change adds a detection layer. It has three parts: thelistcommand in text and --json modes (bin/fm-browser-sessions.sh:62-111), the browser_helpers field in the fleet snapshot (bin/fm-fleet-snapshot.sh:2254-2259), and the "Browser helpers" section of the fleet view (bin/fm-fleet-view.sh:59-68, 109-125). The stated outcome only requires that a finished task never leaves a helper running. Thestop <task-id>command is reasonable containment for orphans that already exist, but the listing and fleet-view surface go beyond that requirement, and so does the separate text mode oflist, which nothing in the change consumes. They are defensible: they surface leftovers when a TERM/KILL survivor warning is missed. Confirm whether to keep them. If not, remove the listing/view pieces, or keep onlylist --jsonfor the fleet view.bin/fm-browser-sessions-lib.sh:178- Simplification check: fm_browser_polite_stop is a second stop path ahead of the pid-based TERM/KILL. It parses the session pid file, overrides HOME and unsets the CHROME_DEVTOOLS_AXI_* variables, wraps the call in a 15 s timeout, and adds a 2 s wait per session. The pid-based termination alone already ends every matched tree, and the intent noteschrome-devtools-axi stopcannot reach orphans. The benefit is a graceful Chrome shutdown when the pid file still names the bridge. Even then the tests show the Chrome child still needs TERM afterwards ("terminated 1 remaining process(es)"). Confirm whether the graceful path is wanted. Removing it would shrink the lib and the fixture stub.🔧 **Test** - 3 issues found → auto-fixed ✅
bin/fm-browser-sessions.sh:1- bin/fm-browser-sessions.sh was committed with mode 100644, so running it directly fails with Permission denied (exit 126). That breakslistandstop, the fleet snapshot's browser_helpers field (it silently falls back to supported:null, so the fleet view says 'Browser helper listing unavailable'), and the retry command that teardown's warning and the fleet view point operators to. tests/fm-browser-sessions.test.sh also fails. Fixed in the worktree with chmod +x (from 100644 to 100755, uncommitted); all live scenarios and that test pass after the fix.bin/fm-browser-sessions-lib.sh:140- The Memory column sums RSS across the whole Chrome tree. For a fresh real headless Chrome this showed about 1.35 GB per tree, because pages shared between processes are counted once per process. The real footprint was closer to the 150 MB the incident cites, so the column overstates the cost of orphans.bash tests/fm-browser-sessions.test.shbefore the fix (fails: exit 126 Permission denied) and after the chmod (all 6 cases ok)bin/fm-live-lab.sh up --harness claude --worker /tmp/fmlab.JMLrZB: real Claude primary plus a real spawned local-only ship worker, all readiness checks okStarted real chrome-devtools-axi bridges with headless Chrome, 15 processes each, using the worker's /proc environ with HOME isolated to the lab: own task, another home with the same task id, unattributed, and own task with a pid file pointing at another bridgeLab checkout at HEAD:bin/fm-browser-sessions.sh listandbin/fm-fleet-view.shreproduce the mode bugAfter the fix:bin/fm-browser-sessions.sh list,stop <live-task>(refused),bin/fm-fleet-view.shBrowser helpers sectionRealbin/fm-teardown.sh lab93fe54b7c32e-workeragainst the lab's tmux backend; process trees captured before, survivors checked after, and /proc environ scanned for the task's FM_TASK_IDAfter close: orphan, other-home and unattributed bridges started outside any worktree; fleet view lists the orphan with its cleanup command;bin/fm-browser-sessions.sh stop <task>kills only the orphan tree;list --jsoncheckedbin/fm-live-lab.sh down(lab removed, lab bridges killed, operator bridges untouched)bash tests/fm-teardown.test.sh: exit 0, 126 ok, 0 failures, including all 3 browser cases (b1, b2, b3)🔧 Fix applied.
✅ Re-checked - no issues remain.
listoutput before and after;FM_HOME=<other-home> bin/fm-browser-sessions.sh stop task-x1stopped foreign-sess, exit 0bash tests/fm-browser-sessions.test.sh(all 6 cases ok, including a bridge that ignores TERM being killed and the fleet view listing an orphan)Three browser cases fromtests/fm-teardown.test.shrun on their own: stops the task's sessions, refused teardown leaves the browser running, late bridge started during window close is stopped (all ok)Regression check: with the secondteardown_stop_browser_sessionscall removed,test_bridge_started_during_the_endpoint_close_is_stoppedfails; restored afterwards and the worktree is cleanLive lab:~/.no-mistakes/evidence/01M5Y8R7P0QZBST14F2P0Q8VA1/lab-teardown-drive.sh- lab home frombin/fm-lab-home.sh create, real tmux worker window on a private TMUX_TMPDIR, realchrome-devtools-axi openbridges with real headless Chrome, realbin/fm-teardown.sh task-x1,bin/fm-browser-sessions.sh listbefore and after, a /proc environ scan for survivors,bin/fm-browser-sessions.sh stopfor the other home; lab removed afterwardsFulltests/fm-teardown.test.shwas started but hit the 10-minute background limit and was stopped; replaced by the targeted browser cases above✅ **Document** - passed
✅ No issues found.
🔧 **Lint** - 1 issue found → auto-fixed ✅
🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Push** - passed
✅ No issues found.