Skip to content

fix(bin): stop a closed task's browser sessions at teardown and list orphan browser helpers - #53

Merged
speechybubble merged 6 commits into
mainfrom
fm/teardown-stop-browser-sessions
Oct 27, 2026
Merged

speechybubble merged 6 commits into
mainfrom
fm/teardown-stop-browser-sessions

Conversation

@speechybubble

@speechybubble speechybubble commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

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 stop was a no-op for an orphan. The outcome wanted: a finished task never leaves a browser helper running.

What Changed

  • bin/fm-teardown.sh now 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 new bin/fm-browser-sessions-lib.sh finds each bridge by reading FM_TASK_ID and FM_HOME from its /proc/<pid>/environ. When the session's pid file names that exact bridge, it calls chrome-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 /proc the step is skipped.
  • New bin/fm-browser-sessions.sh command: 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's state/<id>.meta still exists.
  • bin/fm-fleet-snapshot.sh adds a browser_helpers field taken from list --json. If the listing fails, the field reads supported:null and the snapshot still succeeds. bin/fm-fleet-view.sh adds 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 in tests/fm-browser-sessions.test.sh and tests/fm-teardown.test.sh that use fake-bridge fixtures.

Risk Assessment

⚠️ Medium: The change is well scoped: ownership comes from each bridge's environment, start times are re-checked before every signal, and the stop is gated behind teardown's refusals. On this machine's live bridges, the env fields and the parent-pid tree walk match the real layout. One gap remains: the sweep runs before the worker's pane is closed, so a bridge started in that window can still outlive the task.

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.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Captain tears down a finished ship task whose worker opened a browser: the real bridge and headless Chrome tree end, and teardown prints the session it stopped ✅ pass live 06-round2-live-teardown-late-bridge.txt: 'stopped browser session own-sess for task-x1 ... 15 process(es)'; own-sess is gone from the AFTER list
Worker starts a new bridge after the first sweep but before its window closes: the second sweep stops it, and no FM_TASK_ID process survives ✅ pass live 06-round2-live-teardown-late-bridge.txt: late-sess stopped after the mid-flight start; the /proc scan found no survivors. The b3 teardown case fails without the second sweep and passes with it.
Adversarial: bridges of another home with the same task id, bridges with no FM_TASK_ID, and the operator's real fleet bridges are not touched by teardown ✅ pass live 06-round2-live-teardown-late-bridge.txt: the AFTER list still shows foreign-sess (other_home), plain-sess (unattributed) and the operator bridges 1420105, 1522727 and 3695090
Operator lists browser helpers with task, scope, age and memory, and stops a closed task's orphans with bin/fm-browser-sessions.sh stop (now executable) ✅ pass live 06-round2-live-teardown-late-bridge.txt: list output before and after; FM_HOME=&lt;other-home&gt; bin/fm-browser-sessions.sh stop task-x1 stopped foreign-sess, exit 0
Adversarial: a bridge that ignores TERM is killed with KILL; a refused teardown leaves the task's browser running ⏸️ untested no The prior payload did not show a live result for this scenario. It was only run through the repository's tests (tests/fm-browser-sessions.test.sh 'a bridge tree that ignores TERM is killed' and the te…
Evidence: 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)

== lab home: /tmp/fm-lab.KPu04G
== operator's pre-existing bridges (must be untouched):
== fleet browser listing BEFORE teardown (FM_HOME=/tmp/fm-lab.KPu04G):
PID      SCOPE         TASK                         SESSION                       AGE    RSS_MB  HOME
1420105  other_home    taste-reference-candidates   taste-r2b                     53h       157  /mnt/c/Trelume/Kun/fleet
1486275  other_home    task-x1                      foreign-sess                   0h      1400  /tmp/fm-lab.KPu04G/other-home
1486329  live_task     task-x1                      own-sess                       0h      1402  /tmp/fm-lab.KPu04G
1495784  unattributed  -                            plain-sess                     0h      1392  /tmp/fm-lab.KPu04G
1522727  other_home    captain-decisions-board      internal-page-design          13h        83  /mnt/c/Trelume/Kun/fleet
3695090  unattributed  -                            default                       11h       273  /mnt/c/Trelume/Kun/fleet
== fm-teardown.sh task-x1 (real, tmux backend on lab socket)
fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-lab.KPu04G
teardown: stopped browser session own-sess for task-x1 (bridge pid 1486329, port 9431, 15 process(es)): stopped through chrome-devtools-axi
[lab] worker starts late-sess while teardown is mid-flight
teardown: stopped browser session late-sess for task-x1 (bridge pid 1509331, port 9433, 15 process(es)): stopped through chrome-devtools-axi
/tmp/fm-lab.KPu04G/project: already current
teardown task-x1 complete (window firstmate:fm-task-x1, worktree /tmp/fm-lab.KPu04G/wt)
Backlog: task-x1 just finished (this home keeps no markdown backlog at /tmp/fm-lab.KPu04G/data/backlog.md). Update /tmp/fm-lab.KPu04G/data/backlog.md - move task-x1 to Done, keep Done to the 10 most recent, then re-scan Queued and dispatch only work whose blockers are gone and date is due.
teardown exit=0
== tmux windows after teardown:
no server running on /tmp/fm-lab.KPu04G/tmux/tmux-1000/default
== fleet browser listing AFTER teardown:
PID      SCOPE         TASK                         SESSION                       AGE    RSS_MB  HOME
1420105  other_home    taste-reference-candidates   taste-r2b                     53h       157  /mnt/c/Trelume/Kun/fleet
1486275  other_home    task-x1                      foreign-sess                   0h      1371  /tmp/fm-lab.KPu04G/other-home
1495784  unattributed  -                            plain-sess                     0h      1343  /tmp/fm-lab.KPu04G
1522727  other_home    captain-decisions-board      internal-page-design          13h        83  /mnt/c/Trelume/Kun/fleet
3695090  unattributed  -                            default                       11h       273  /mnt/c/Trelume/Kun/fleet
== any process still carrying FM_TASK_ID=task-x1 and FM_HOME=/tmp/fm-lab.KPu04G:
  (end)
== operator bridges still alive:
  1420105 (not lab)
~/.no-mistakes/evidence/01M5Y8R7P0QZBST14F2P0Q8VA1/lab-teardown-drive.sh: line 68: /proc/1522097/environ: No such file or directory
  1522097 (not lab)
  1522727 (not lab)
  3695090 (not lab)
== stop the surviving lab bridges via operator path
fm-browser-sessions: stopped browser session foreign-sess for task-x1 (bridge pid 1486275, port 9434, 15 process(es)): stopped through chrome-devtools-axi
stop other-home exit=0
  reaped leftover lab pid 1499259
== lab removed
Evidence: Live lab driver script

Source: Live lab driver script

#!/usr/bin/env bash
# Live drive: real fm-teardown.sh against a disposable lab home, real tmux worker
# window on a private lab socket, real chrome-devtools-axi bridges + headless Chrome.
set -u
WT_SRC=~/.no-mistakes/worktrees/d567722de3ac/01M5Y8R7P0QZBST14F2P0Q8VA1
cd "$WT_SRC"
LAB=$(mktemp -d "${TMPDIR:-/tmp}/fm-lab.XXXXXX")
bin/fm-lab-home.sh create "$LAB" >/dev/null
mkdir -p "$LAB/tmux" "$LAB/fakebin" "$LAB/bhome" "$LAB/data/task-x1" "$LAB/other-home"
export TMUX_TMPDIR="$LAB/tmux"; unset TMUX
REALNPM="$HOME/.npm"
echo "== lab home: $LAB"
# --- task fixture: project, origin, landed worktree branch
git init -q --bare "$LAB/origin.git"; git -C "$LAB/origin.git" symbolic-ref HEAD refs/heads/main
git clone -q "$LAB/origin.git" "$LAB/_seed" 2>/dev/null
git -C "$LAB/_seed" -c user.email=t@t -c user.name=t commit -q --allow-empty -m base
git -C "$LAB/_seed" push -q origin main; rm -rf "$LAB/_seed"
git clone -q "$LAB/origin.git" "$LAB/project"; git -C "$LAB/project" remote set-head origin main
git -C "$LAB/project" worktree add -q -b fm/task-x1 "$LAB/wt" main
git -C "$LAB/wt" -c user.email=t@t -c user.name=t commit -q --allow-empty -m "shippable work"
git -C "$LAB/wt" push -q origin fm/task-x1; git -C "$LAB/project" fetch -q origin
printf '%s\n' "window=firstmate:fm-task-x1" "endpoint_task_id=task-x1" "worktree=$LAB/wt" \
  "project=$LAB/project" "kind=ship" "mode=no-mistakes" "spawn_gen=lab-task-x1" > "$LAB/state/task-x1.meta"
touch "$LAB/state/.last-watcher-beat"
# Hermetic stubs only for external services (GitHub, no-mistakes daemon, worktree pool).
printf '#!/usr/bin/env bash\ncase "$1 $2" in "pr list") echo "count: 0 (showing first 0)"; echo "pull_requests[]: []";; "pr view") exit 1;; esac\nexit 0\n' > "$LAB/fakebin/gh-axi"
printf '#!/usr/bin/env bash\nexit 0\n' > "$LAB/fakebin/gh"
printf '#!/usr/bin/env bash\nexit 0\n' > "$LAB/fakebin/no-mistakes"
# treehouse return happens after the first browser pass and before the worker's
# window closes; the stub has the still-live worker start a NEW real bridge then.
cat > "$LAB/fakebin/treehouse" <<SH
#!/usr/bin/env bash
[ "\${1:-}" = return ] || exit 0
echo "[lab] worker starts late-sess while teardown is mid-flight" >&2
( cd "$LAB/data/task-x1" && env HOME="$LAB/bhome" npm_config_cache="$REALNPM" FM_TASK_ID=task-x1 FM_HOME="$LAB" \
  CHROME_DEVTOOLS_AXI_SESSION=late-sess CHROME_DEVTOOLS_AXI_PORT=9433 \
  timeout 120 chrome-devtools-axi open 'data:text/html,late' >/dev/null 2>&1 )
exit 0
SH
chmod +x "$LAB/fakebin/"*
# --- worker window on the lab tmux socket, env like a real worker
tmux new-session -d -s firstmate -n fm-task-x1 -c "$LAB/data/task-x1" \
  -e FM_TASK_ID=task-x1 -e FM_HOME="$LAB" -e HOME="$LAB/bhome" -e npm_config_cache="$REALNPM" \
  "CHROME_DEVTOOLS_AXI_SESSION=own-sess CHROME_DEVTOOLS_AXI_PORT=9431 chrome-devtools-axi open 'data:text/html,own' > $LAB/own-open.log 2>&1; echo worker-idle; sleep 3600"
# --- bridges that must survive: same task id but another home; no task id at all
( cd "$LAB/other-home" && env HOME="$LAB/bhome" npm_config_cache="$REALNPM" FM_TASK_ID=task-x1 FM_HOME="$LAB/other-home" \
  CHROME_DEVTOOLS_AXI_SESSION=foreign-sess CHROME_DEVTOOLS_AXI_PORT=9434 chrome-devtools-axi open 'data:text/html,foreign' >/dev/null 2>&1 )
( cd "$LAB" && env -u FM_TASK_ID HOME="$LAB/bhome" npm_config_cache="$REALNPM" FM_HOME="$LAB" \
  CHROME_DEVTOOLS_AXI_SESSION=plain-sess CHROME_DEVTOOLS_AXI_PORT=9435 chrome-devtools-axi open 'data:text/html,plain' >/dev/null 2>&1 )
for _ in $(seq 120); do grep -q . "$LAB/own-open.log" 2>/dev/null && tmux capture-pane -p -t firstmate:fm-task-x1 | grep -q worker-idle && break; sleep 1; done
echo "== operator's pre-existing bridges (must be untouched):"
PRE=$(ps -eo pid=,args= | awk '/chrome-devtools-axi-bridge/ {print $1}' | sort)
echo "== fleet browser listing BEFORE teardown (FM_HOME=$LAB):"
FM_HOME="$LAB" bin/fm-browser-sessions.sh list
echo "== fm-teardown.sh task-x1 (real, tmux backend on lab socket)"
env -u NO_MISTAKES_GATE -u FM_GATE_REFUSE_BYPASS -u FM_ROOT_OVERRIDE -u FM_STATE_OVERRIDE -u FM_DATA_OVERRIDE \
  -u FM_CONFIG_OVERRIDE -u FM_PROJECTS_OVERRIDE FM_HOME="$LAB" PATH="$LAB/fakebin:$PATH" bin/fm-teardown.sh task-x1
echo "teardown exit=$?"
sleep 1
echo "== tmux windows after teardown:"; tmux list-windows -a 2>&1
echo "== fleet browser listing AFTER teardown:"
FM_HOME="$LAB" bin/fm-browser-sessions.sh list
echo "== any process still carrying FM_TASK_ID=task-x1 and FM_HOME=$LAB:"
for f in /proc/[0-9]*/environ; do
  if grep -qaz "^FM_TASK_ID=task-x1$" "$f" 2>/dev/null && grep -qaz "^FM_HOME=$LAB$" "$f" 2>/dev/null; then p=${f#/proc/}; echo "  SURVIVOR ${p%/environ}: $(tr '\0' ' ' < /proc/${p%/environ}/cmdline | cut -c1-120)"; fi
done; echo "  (end)"
POST=$(ps -eo pid=,args= | awk '/chrome-devtools-axi-bridge/ {print $1}' | sort)
echo "== operator bridges still alive:"; for p in $(ps -eo pid=,args= | awk '/chrome-devtools-axi-bridge/ {print $1}'); do tr '\0' '\n' < /proc/$p/environ 2>/dev/null | grep -q "^HOME=$LAB/bhome$" || echo "  $p (not lab)"; done
echo "== stop the surviving lab bridges via operator path"
FM_HOME="$LAB/other-home" bin/fm-browser-sessions.sh stop task-x1; echo "stop other-home exit=$?"
for s in plain-sess foreign-sess; do HOME="$LAB/bhome" CHROME_DEVTOOLS_AXI_SESSION=$s timeout 30 chrome-devtools-axi stop >/dev/null 2>&1; done
for f in /proc/[0-9]*/environ; do grep -qaz "^HOME=$LAB/bhome$" "$f" 2>/dev/null && { p=${f#/proc/}; kill -9 ${p%/environ} 2>/dev/null; echo "  reaped leftover lab pid ${p%/environ}"; }; done
tmux kill-server 2>/dev/null
rm -rf "$LAB"; echo "== lab removed"
Evidence: Teardown stderr excerpt
teardown: stopped browser session own-sess for task-x1 (bridge pid 1486329, port 9431, 15 process(es)): stopped through chrome-devtools-axi
[lab] worker starts late-sess while teardown is mid-flight
teardown: stopped browser session late-sess for task-x1 (bridge pid 1509331, port 9433, 15 process(es)): stopped through chrome-devtools-axi
teardown task-x1 complete (window firstmate:fm-task-x1, worktree /tmp/fm-lab.KPu04G/wt)
teardown exit=0
== any process still carrying FM_TASK_ID=task-x1 and FM_HOME=<lab>:
(end)
- Outcome: 🔧 3 issues found → auto-fixed ✅ across 2 runs (57m54s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 issues (1 warning, 1 info)
  • ⚠️ 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: the list command 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. The stop &lt;task-id&gt; 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 of list, 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 only list --json for 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 notes chrome-devtools-axi stop cannot 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: the list command 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. The stop &lt;task-id&gt; 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 of list, 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 only list --json for 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 notes chrome-devtools-axi stop cannot 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 breaks list and stop, 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.
  • 🚨 live validation verdict: no-go (6 of 7 scenarios were driven live against the product); failed: Operator runs bin/fm-browser-sessions.sh and the fleet view as committed: the helpers are listed
  • Live validation: ❌ no-go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Operator runs bin/fm-browser-sessions.sh and the fleet view as committed: the helpers are listed ❌ fail live 01-before-fix-mode-644.txt: 'Permission denied' exit 126, fleet view shows 'Browser helper listing unavailable.'
Real teardown of a finished worker stops all of that task's real browser trees and prints one line per session ✅ pass live 03-real-teardown.txt and 04-after-teardown-survivors.txt: lab-own stopped through chrome-devtools-axi, lab-stale terminated; 0 of 15 alive for each; 0 processes still carry the task's FM_TASK_ID
Orphan whose pid file names another bridge (chrome-devtools-axi stop cannot reach it) is still ended ✅ pass live 03 and 05: 'chrome-devtools-axi stop skipped: its session pid file names another bridge; terminated 15 remaining process(es)'
Bridges of another home with the same task id, unattributed bridges, and the operator's real bridges are never touched ✅ pass live 05: after stop, orph-foreign 15/15, orph-unattr 15/15, and the operator bridges 1420105, 1522727, 3695090 all still alive; 04: operator bridges untouched by teardown
stop refuses while the task is live ✅ pass live 02: REFUSED ... exit=1
Fleet view lists an orphaned bridge with task, age, memory and cleanup command after the task closes ✅ pass live 05: '| lab93fe54b7c32e-worker | orphan | orph-own | 0m | 1347 MB | 281714 | bin/fm-browser-sessions.sh stop lab93fe54b7c32e-worker |'
A bridge the worker starts while its window is being closed is still stopped by teardown's second sweep ⏸️ untested no The prior payload did not establish a live result: the lab offers no hook to place a real bridge launch inside the narrow window between the first sweep and the backend kill. Only the fixture test in…
  • bash tests/fm-browser-sessions.test.sh before 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 ok
  • Started 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 bridge
  • Lab checkout at HEAD: bin/fm-browser-sessions.sh list and bin/fm-fleet-view.sh reproduce the mode bug
  • After the fix: bin/fm-browser-sessions.sh list, stop &lt;live-task&gt; (refused), bin/fm-fleet-view.sh Browser helpers section
  • Real bin/fm-teardown.sh lab93fe54b7c32e-worker against the lab's tmux backend; process trees captured before, survivors checked after, and /proc environ scanned for the task's FM_TASK_ID
  • After 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 &lt;task&gt; kills only the orphan tree; list --json checked
  • bin/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.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Captain tears down a finished ship task whose worker opened a browser: the real bridge and headless Chrome tree end, and teardown prints the session it stopped ✅ pass live 06-round2-live-teardown-late-bridge.txt: 'stopped browser session own-sess for task-x1 ... 15 process(es)'; own-sess is gone from the AFTER list
Worker starts a new bridge after the first sweep but before its window closes: the second sweep stops it, and no FM_TASK_ID process survives ✅ pass live 06-round2-live-teardown-late-bridge.txt: late-sess stopped after the mid-flight start; the /proc scan found no survivors. The b3 teardown case fails without the second sweep and passes with it.
Adversarial: bridges of another home with the same task id, bridges with no FM_TASK_ID, and the operator's real fleet bridges are not touched by teardown ✅ pass live 06-round2-live-teardown-late-bridge.txt: the AFTER list still shows foreign-sess (other_home), plain-sess (unattributed) and the operator bridges 1420105, 1522727 and 3695090
Operator lists browser helpers with task, scope, age and memory, and stops a closed task's orphans with bin/fm-browser-sessions.sh stop (now executable) ✅ pass live 06-round2-live-teardown-late-bridge.txt: list output before and after; FM_HOME=&lt;other-home&gt; bin/fm-browser-sessions.sh stop task-x1 stopped foreign-sess, exit 0
Adversarial: a bridge that ignores TERM is killed with KILL; a refused teardown leaves the task's browser running ⏸️ untested no The prior payload did not show a live result for this scenario. It was only run through the repository's tests (tests/fm-browser-sessions.test.sh 'a bridge tree that ignores TERM is killed' and the te…
  • bash 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 from tests/fm-teardown.test.sh run 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 second teardown_stop_browser_sessions call removed, test_bridge_started_during_the_endpoint_close_is_stopped fails; restored afterwards and the worktree is clean
  • Live lab: ~/.no-mistakes/evidence/01M5Y8R7P0QZBST14F2P0Q8VA1/lab-teardown-drive.sh - lab home from bin/fm-lab-home.sh create, real tmux worker window on a private TMUX_TMPDIR, real chrome-devtools-axi open bridges with real headless Chrome, real bin/fm-teardown.sh task-x1, bin/fm-browser-sessions.sh list before and after, a /proc environ scan for survivors, bin/fm-browser-sessions.sh stop for the other home; lab removed afterwards
  • Full tests/fm-teardown.test.sh was 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 ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

…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
@speechybubble
speechybubble merged commit 993041c into main Oct 27, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants