Repository navigation
fix: stop task browser bridge groups during teardown - #55
Merged
Merged
Conversation
Once cleanup is accepted, stop the chrome-devtools-axi bridge process group whose FM_TASK_ID is the torn-down task. Leave a different task, an unmarked process, and the shared CDP browsers running. A failure to stop a bridge does not undo the cleanup.
…ad override handling
…dentities before KILL
peterOC26
force-pushed
the
fm/fm-teardown-stop-browser-bridges-b1
branch
from
November 11, 2026 20:24
dc6cbb9 to
380abda
Compare
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
Teardown leaves the finished task's browser bridge running. Found 2026-11-02 17:44Z: 50 chrome-devtools-axi bridges (each with npm exec + chrome-devtools-mcp) from finished tasks were still running; swap was 8191/8191 MB and MemAvailable 3.3 GB, which stalled live test calls and the nightly run. Each bridge carries FM_TASK_ID and CHROME_DEVTOOLS_AXI_SESSION in its environment and is its own process group. Firstmate stopped the 49 whose task had no state meta (kill -TERM -- -pgid): MemAvailable went to 8.9 GB, swap to 3.7 GB. Fix: bin/fm-teardown.sh stops the bridge process group whose FM_TASK_ID is the torn-down task.
Part of the firstmate upkeep batch the captain approved (Q1931 A sweep; Q1994: "use grok and deepseek" - Grok builds).
What Changed
FM_PROC_ROOT_OVERRIDEdisables bridge cleanup.Risk Assessment
Testing
Reproduced the base-commit leak, passed five live cleanup and boundary scenarios with real bridges, and passed focused executable regressions and fault injections. Product transcripts were captured, temporary files were removed, and remaining live limitations are explicit.
Evidence: Live bridge cleanup, KILL escalation, and ownership exclusions
Source: Live bridge cleanup, KILL escalation, and ownership exclusions
Evidence: Dirty-work refusal preserves responsive bridge
Source: Dirty-work refusal preserves responsive bridge
Evidence: Proc override silently preserves bridge
Source: Proc override silently preserves bridge
Evidence: Original leak reproduced on base commit
Source: Original leak reproduced on base commit
Evidence: Executable identity-change and inspection-failure injections
Source: Executable identity-change and inspection-failure injections
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-teardown.sh:2834- Bridges are matched only on FM_TASK_ID == $ID and on the uid. The repo expects equal task ids in different homes (bin/fm-spawn.sh:7631: "the full home-identity hash isolates equal task ids across homes"), and a local secondmate home runs as the same user. Concrete sequence: the primary home and a local secondmate home each have a live taskfoo-b1with a chrome-devtools-axi bridge. Tearing downfoo-b1in the primary sends TERM and then KILL to the secondmate's live bridge group, which breaks that task's browser session. The same check repeats at bin/fm-teardown.sh:2860 (the re-verify before signaling). A source-backed way to tell the homes apart is already in the bridge's environment: every launch exports FM_TASK_INBOX=$STATE_REAL/$ID.inbox (bin/fm-spawn.sh:7728, 7776), so the bridge could also be required to have FM_TASK_INBOX equal to this home's resolved $STATE/$ID.inbox when that variable is present. The intent says to match on FM_TASK_ID alone, so adding a second key narrows the authored rule. The narrowing, not the defect, is what needs authorization.bin/fm-teardown.sh:2796- On a host without /proc (macOS is supported: Darwin branches in bin/fm-backend.sh:368, bin/fm-bootstrap.sh:1002, and LaunchAgent handling), every successful teardown now prints "warning: could not inspect chrome-devtools-axi bridges for <id> (/proc is unavailable); cleanup continues". The bridges cannot be identified there at all, so this warning shows on every teardown and nothing can be done about it. Firstmate agents read teardown stderr, so the constant warning is noise that can send them investigating. Fix: return 0 without a message when /proc is absent, as the FM_PROC_ROOT_OVERRIDE branch already does, or gate the feature on Linux.bin/fm-teardown.sh:2805- Unrequired component: when FM_PROC_ROOT_OVERRIDE names a directory that exists, the first scan builds its snapshot from that fake /proc tree. The member scans (lines ~2867, 2917, 2950) still use realps -u, and the kill calls signal real pgids. No caller uses this branch: the new tests run against the real /proc, and the existing teardown tests set the override to a missingno-procdirectory, which takes the silent early return. No intent requirement needs the fake-tree snapshot, and it mixes fake and real process sources. Recommend removing it and keeping only the silent early return used when the override is set.🔧 Fix applied.
5 issues (4 warnings, 1 info) still open:
bin/fm-teardown.sh:2834- Bridges are matched only on FM_TASK_ID == $ID and on the uid. The repo expects equal task ids in different homes (bin/fm-spawn.sh:7631: "the full home-identity hash isolates equal task ids across homes"), and a local secondmate home runs as the same user. Concrete sequence: the primary home and a local secondmate home each have a live taskfoo-b1with a chrome-devtools-axi bridge. Tearing downfoo-b1in the primary sends TERM and then KILL to the secondmate's live bridge group, which breaks that task's browser session. The same check repeats at bin/fm-teardown.sh:2860 (the re-verify before signaling). A source-backed way to tell the homes apart is already in the bridge's environment: every launch exports FM_TASK_INBOX=$STATE_REAL/$ID.inbox (bin/fm-spawn.sh:7728, 7776), so the bridge could also be required to have FM_TASK_INBOX equal to this home's resolved $STATE/$ID.inbox when that variable is present. The intent says to match on FM_TASK_ID alone, so adding a second key narrows the authored rule. The narrowing, not the defect, is what needs authorization.bin/fm-teardown.sh:2796- On a host without /proc (macOS is supported: Darwin branches in bin/fm-backend.sh:368, bin/fm-bootstrap.sh:1002, and LaunchAgent handling), every successful teardown now prints "warning: could not inspect chrome-devtools-axi bridges for <id> (/proc is unavailable); cleanup continues". The bridges cannot be identified there at all, so this warning shows on every teardown and nothing can be done about it. Firstmate agents read teardown stderr, so the constant warning is noise that can send them investigating. Fix: return 0 without a message when /proc is absent, as the FM_PROC_ROOT_OVERRIDE branch already does, or gate the feature on Linux.bin/fm-teardown.sh:2805- Unrequired component: when FM_PROC_ROOT_OVERRIDE names a directory that exists, the first scan builds its snapshot from that fake /proc tree. The member scans (lines ~2867, 2917, 2950) still use realps -u, and the kill calls signal real pgids. No caller uses this branch: the new tests run against the real /proc, and the existing teardown tests set the override to a missingno-procdirectory, which takes the silent early return. No intent requirement needs the fake-tree snapshot, and it mixes fake and real process sources. Recommend removing it and keeping only the silent early return used when the override is set.bin/fm-teardown.sh:339- The round-1 fix (commit 3a3af40) narrowed bridge ownership, but the script header still describes the old rule. The function points readers to this header ("See the script header for the ownership rules", bin/fm-teardown.sh:2783). The header still says a bridge is stopped when "FM_TASK_ID is exactly this task" and lists only "a different task id, a missing FM_TASK_ID, another user's process" as excluded. The code now also requires FM_TASK_INBOX to equal this home's resolved state dir + /<id>.inbox (bin/fm-teardown.sh:2823-2824, re-verified at 2851-2852), and it skips the whole cleanup without a message whenever FM_PROC_ROOT_OVERRIDE is set (bin/fm-teardown.sh:2790). The round-1 fix left both sibling docs behind: this header at lines 339-344, and the FM_PROC_ROOT_OVERRIDE entry at docs/configuration.md:3369, which still calls it only an alternate /proc root for identity readers. That entry should say that setting it also turns off browser-bridge cleanup at teardown. As a result, an operator reading the documented contract would expect a same-id bridge from another home, or one without FM_TASK_INBOX, to be stopped, and would not know that the override disables cleanup. Fix: add the FM_TASK_INBOX match and the override skip to the header, and add the override behavior to the configuration doc entry.bin/fm-teardown.sh:2629- Round 1 made stop_task_browser_bridges_inner return early whenever FM_PROC_ROOT_OVERRIDE is set and hard-coded proc_root=/proc. The new helpers that only this function uses still read ${FM_PROC_ROOT_OVERRIDE:-/proc}, so that override branch can no longer run: teardown_proc_pgrp:2629, teardown_proc_still_running:2646, teardown_proc_real_uid:2662, teardown_proc_env_value:2674, teardown_proc_comm:2691, teardown_pid_is_browser_bridge:2702, teardown_pid_holds_inode:2741, teardown_pid_is_shared_cdp_browser:2762. A simplification would be to use /proc directly in these helpers, matching teardown_shared_cdp_inodes. Separately, the three member scans (around 2858, 2908, 2941) ignore the pgid column thatps -o pid=,pgid=,comm=already returns. Instead they forkcat /proc/<pid>/statfor every process the user owns. Filtering on the ps pgid column first would avoid hundreds of forks per bridge group. This is not a correctness issue.🔧 Fix applied.
7 issues (5 warnings, 2 infos) still open:
bin/fm-teardown.sh:2834- Bridges are matched only on FM_TASK_ID == $ID and on the uid. The repo expects equal task ids in different homes (bin/fm-spawn.sh:7631: "the full home-identity hash isolates equal task ids across homes"), and a local secondmate home runs as the same user. Concrete sequence: the primary home and a local secondmate home each have a live taskfoo-b1with a chrome-devtools-axi bridge. Tearing downfoo-b1in the primary sends TERM and then KILL to the secondmate's live bridge group, which breaks that task's browser session. The same check repeats at bin/fm-teardown.sh:2860 (the re-verify before signaling). A source-backed way to tell the homes apart is already in the bridge's environment: every launch exports FM_TASK_INBOX=$STATE_REAL/$ID.inbox (bin/fm-spawn.sh:7728, 7776), so the bridge could also be required to have FM_TASK_INBOX equal to this home's resolved $STATE/$ID.inbox when that variable is present. The intent says to match on FM_TASK_ID alone, so adding a second key narrows the authored rule. The narrowing, not the defect, is what needs authorization.bin/fm-teardown.sh:2796- On a host without /proc (macOS is supported: Darwin branches in bin/fm-backend.sh:368, bin/fm-bootstrap.sh:1002, and LaunchAgent handling), every successful teardown now prints "warning: could not inspect chrome-devtools-axi bridges for <id> (/proc is unavailable); cleanup continues". The bridges cannot be identified there at all, so this warning shows on every teardown and nothing can be done about it. Firstmate agents read teardown stderr, so the constant warning is noise that can send them investigating. Fix: return 0 without a message when /proc is absent, as the FM_PROC_ROOT_OVERRIDE branch already does, or gate the feature on Linux.bin/fm-teardown.sh:2805- Unrequired component: when FM_PROC_ROOT_OVERRIDE names a directory that exists, the first scan builds its snapshot from that fake /proc tree. The member scans (lines ~2867, 2917, 2950) still use realps -u, and the kill calls signal real pgids. No caller uses this branch: the new tests run against the real /proc, and the existing teardown tests set the override to a missingno-procdirectory, which takes the silent early return. No intent requirement needs the fake-tree snapshot, and it mixes fake and real process sources. Recommend removing it and keeping only the silent early return used when the override is set.bin/fm-teardown.sh:339- The round-1 fix (commit 3a3af40) narrowed bridge ownership, but the script header still describes the old rule. The function points readers to this header ("See the script header for the ownership rules", bin/fm-teardown.sh:2783). The header still says a bridge is stopped when "FM_TASK_ID is exactly this task" and lists only "a different task id, a missing FM_TASK_ID, another user's process" as excluded. The code now also requires FM_TASK_INBOX to equal this home's resolved state dir + /<id>.inbox (bin/fm-teardown.sh:2823-2824, re-verified at 2851-2852), and it skips the whole cleanup without a message whenever FM_PROC_ROOT_OVERRIDE is set (bin/fm-teardown.sh:2790). The round-1 fix left both sibling docs behind: this header at lines 339-344, and the FM_PROC_ROOT_OVERRIDE entry at docs/configuration.md:3369, which still calls it only an alternate /proc root for identity readers. That entry should say that setting it also turns off browser-bridge cleanup at teardown. As a result, an operator reading the documented contract would expect a same-id bridge from another home, or one without FM_TASK_INBOX, to be stopped, and would not know that the override disables cleanup. Fix: add the FM_TASK_INBOX match and the override skip to the header, and add the override behavior to the configuration doc entry.bin/fm-teardown.sh:2629- Round 1 made stop_task_browser_bridges_inner return early whenever FM_PROC_ROOT_OVERRIDE is set and hard-coded proc_root=/proc. The new helpers that only this function uses still read ${FM_PROC_ROOT_OVERRIDE:-/proc}, so that override branch can no longer run: teardown_proc_pgrp:2629, teardown_proc_still_running:2646, teardown_proc_real_uid:2662, teardown_proc_env_value:2674, teardown_proc_comm:2691, teardown_pid_is_browser_bridge:2702, teardown_pid_holds_inode:2741, teardown_pid_is_shared_cdp_browser:2762. A simplification would be to use /proc directly in these helpers, matching teardown_shared_cdp_inodes. Separately, the three member scans (around 2858, 2908, 2941) ignore the pgid column thatps -o pid=,pgid=,comm=already returns. Instead they forkcat /proc/<pid>/statfor every process the user owns. Filtering on the ps pgid column first would avoid hundreds of forks per bridge group. This is not a correctness issue.bin/fm-teardown.sh:2856- The shared-CDP protection covers only the Chromium browser process, not its child processes. The header (bin/fm-teardown.sh:343-345) says a shared CDP browser that "shares the bridge's process group" is never signaled, and the test models that browser as a single process. A real Chromium keeps its zygote, renderer, GPU and utility children in the same process group. Those children have commchromium/chrome, a command line with--type=renderer(or zygote, gpu-process, and so on) but no--remote-debugging-port, and they do not hold the 9223/9224 listening socket. So teardown_pid_is_shared_cdp_browser (bin/fm-teardown.sh:2753-2768) returns false for them. In the TERM pass (2856-2865, signals sent at 2870-2878) and again in the KILL pass (2908-2926), they are added totargetsand receive TERM, then KILL. Concrete sequence: a shared Chromium on port 9224 runs in the bridge's group with a zygote and renderers. Teardown keeps the browser pid but kills its zygote and renderers, so every tab crashes and no new tab can open. That breaks the shared browser for other live tasks, which is exactly what the protection exists to prevent. The final 'still running' check (2945-2953) has the same gap. The protection logic is the author's own addition (the intent only asks to stop the bridge's group), and the test at tests/fm-teardown.test.sh bridge-cdp uses a single-process 'chromium', so it cannot catch this. Remedy needs a decision: either extend the protection to every descendant of a protected browser (walk the ppid chain inside the group) in all three member scans, or, if a shared browser never actually shares a bridge's group, remove the shared-CDP protection component and its test.bin/fm-teardown.sh:2915- In the KILL pass,identity=$(task_process_identity "$member")is computed but never used. Unlike the TERM pass, the identity is not added totargets(targets="$targets $member"), so it works only as an existence filter. Simplification: drop the assignment, or carry the identity and re-verify it beforekill -KILLas the TERM pass does at 2875.🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
bin/fm-teardown.sh:2796- On a host without /proc (macOS is supported: Darwin branches in bin/fm-backend.sh:368, bin/fm-bootstrap.sh:1002, and LaunchAgent handling), every successful teardown now prints "warning: could not inspect chrome-devtools-axi bridges for <id> (/proc is unavailable); cleanup continues". The bridges cannot be identified there at all, so this warning shows on every teardown and nothing can be done about it. Firstmate agents read teardown stderr, so the constant warning is noise that can send them investigating. Fix: return 0 without a message when /proc is absent, as the FM_PROC_ROOT_OVERRIDE branch already does, or gate the feature on Linux.bin/fm-teardown.sh:2915- In the KILL pass,identity=$(task_process_identity "$member")is computed but never used. Unlike the TERM pass, the identity is not added totargets(targets="$targets $member"), so it works only as an existence filter. Simplification: drop the assignment, or carry the identity and re-verify it beforekill -KILLas the TERM pass does at 2875.🔧 Fix applied.
✅ Re-checked - no issues remain.
bin/fm-teardown.sh:2784- Simplification only; behavior stays the same. stop_task_browser_bridges_inner repeats the same member-scan loop three times. Each copy runsps -uand then, per pid, checks that teardown_proc_pgrp equals the group, that the real uid matches, and that teardown_proc_still_running holds: the TERM pass at bin/fm-teardown.sh:2784, the KILL pass at :2817 and the final still-running check at :2855. The leader-lookup loop that maps a pgid back to its leader pid and identity is also duplicated, at :2807 and :2844, along with the[ -r /proc/$leader/stat ] && task_process_identity_matchesguard after each copy. The initial scan also re-reads the pgrp (pgrp=$(teardown_proc_pgrp "$pid"),[ "$pgrp" = "$pid" ]) and rechecks own_pgrp right after teardown_pid_is_browser_bridge has already confirmed that pgrp equals pid. Suggested fix: one helper (for exampleteardown_bridge_group_members <pgrp> <uid> [with-identity]) that printspid identitylines, plus a single leader-lookup helper; drop the repeated pgrp check from the initial scan. This keeps the uid filter, reads pgrp from /proc, and keeps the KILL-pass identity recheck the user asked for. Do not filter on the ps pgid column; the user ruled that out.🔧 **Test** - 1 issue found ✅
Selectedtest_teardown_stops_own_browser_bridge_groups,test_teardown_refusal_leaves_browser_bridges,test_teardown_proc_override_leaves_browser_bridges, andtest_teardown_bridge_kill_rechecks_member_identityfromtests/fm-teardown.test.sh; loading also executed its existing opencode busy-plugin check.python3 .phase-live-bridge.py: installed chrome-devtools-axi 0.1.46, isolated browser sessions, real process-group cleanup, SIGSTOP/KILL escalation, and ownership exclusions.python3 .phase-live-refusal.py: corrected lab Git setup and verified dirty-worktree refusal with a responsive real bridge.python3 .phase-live-override.py: verified set-but-empty FM_PROC_ROOT_OVERRIDE preserves a responsive real bridge.bash tests/.phase-bridge-baseline.sh: reproduced surviving bridge and child processes after successful teardown using the base executable; the target regression also failed against base as expected.bash tests/.phase-bridge-identity-evidence.sh: captured executable output and surviving process after injected member identity change.bash tests/.phase-bridge-inspection-evidence.sh: verified unavailable-uid and failed-snapshot warnings remain best effort.Checked for remaining processes naming disposable lab paths, removed transient worktree files, and confirmed cleangit status --short.✅ No issues found.
python3 ~/.no-mistakes/evidence/01M75HG71DW0AXQEVWWFWAR53K/round2-live-bridge-driver.pypython3 ~/.no-mistakes/evidence/01M75HG71DW0AXQEVWWFWAR53K/round2-live-refusal-driver.pypython3 ~/.no-mistakes/evidence/01M75HG71DW0AXQEVWWFWAR53K/round2-live-override-driver.pypython3 ~/.no-mistakes/evidence/01M75HG71DW0AXQEVWWFWAR53K/round2-live-baseline-driver.pyusing the teardown executable from base commit f3d13fbTMPDIR="$PWD/.phase-test-tmp" bash tests/.phase-teardown-selected.shselecting the four browser-bridge regression testsTMPDIR="$PWD/.phase-test-tmp" FM_PHASE_DETAIL_LOG=~/.no-mistakes/evidence/01M75HG71DW0AXQEVWWFWAR53K/round2-executable-faults.log bash tests/.phase-teardown-faults.shRemoved temporary scripts and disposable labs; verified no lab processes remained andgit status --shortwas clean.✅ **Document** - passed
✅ No issues found.
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
✅ No issues found.
Environment note
test_leaked_worktree_process_is_reapedfails in this environment because lsof is not installed.That failure is unchanged and pre-existing.
This change does not install lsof and does not change that test.