Repository navigation
fix(bin): read a Claude worker below a shell foreground as alive on Rex - #7728
Conversation
Rex's process view reports a block's foreground process and its ancestors only. A login shell that starts the harness through a wrapper in its own process group (a fish function, a bash shim) stays the reported foreground, so a live worker read as dead: steering was refused, relaunch could not confirm the running agent, and the watcher raised stale wakes. Before calling a shell foreground dead, walk its live descendants through the shared agent classifier, and trust OSC 7501 records from a harness found there under the same rule.
|
Speaking as Kun's firstmate: thank you @leo1oel for the clear process-tree capture, and for before/after evidence on a real Rex server. I read head
Contract-class (my own read): restore. The Rex adapter already promises recovery-grade liveness for a live worker. Here a running Claude worker read CI: this is a first-time fork run. I reviewed the diff and approved CI Status: waiting on CI, not on you. If it comes back green and the head hasn't changed, this is on track to merge. |
|
Speaking as Kun's firstmate: this is merged. Thank you @leo1oel — really appreciate you taking the time on this. |
Summary
On Rex, a Claude worker started from a fish login shell through a fish function and the cac bash shim runs inside fish's own process group.
Rex therefore reports fish as the foreground process, with ancestors treehouse, fish, and login, and the harness sits only among the foreground's descendants:
The adapter checked only the foreground and its ancestors, so a live worker read
dead.As a result, steering doorbells were refused with "agent has exited",
fm-control relaunchcould not confirm the running agent, and the watcher raised stale wakes.Owner trust follows the same rule, so a fish-launched worker's own
working/blockedrecords still count.docs/rex-backend.mdstates the updated rule, anddocs/verification/runtime-backends.mdrecords the captured fish/shim process shape.Evidence
tests/fm-backend-rex.test.shcase, which uses a real shell -> wrapper ->claudeprocess tree under the captured fish payload, fails on the base adapter:not ok - a harness running below the shell foreground, through a wrapper, is alive (expected 'alive', got 'dead')(output).After: the Rex unit suite passes, including a bare shell staying
dead, a non-harness child stayingdeadwith its records ignored, and a harness foreground stayingalive.dead, andfm-sendrefused with "agent has exited".After: the same pane reads
aliveandfm-sendis no longer refused, and it readsdeadagain once Claude exits (agent-state transcript, fm-send transcript, real-Rex smoke).Merge Danger
Door: two-way
Revert restores the previous classification; no state or data format changes.
Blast Radius: Rex-only
Only Rex blocks with a shell foreground take the new path, at the cost of two local
pstable reads per state or trust check.A harness-named process left running below an idle shell would now read
aliveinstead ofdead.That errs toward never launching a duplicate agent onto a live worktree.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/backends/rex.sh:795- Beyond what the intent needs: the intent asks for a live worker on Rex to read asalive, and the agent_state change at rex.sh:780-786 does that on its own. The change also adds harness pids below a shell foreground tofm_backend_rex_live_pids(rex.sh:791-797). That widens the OSC 7501 owner-trust rule, whichfm_backend_rex_owner_trusted(rex.sh:805),fm_backend_rex_trusted_record(rex.sh:818) and the event-stream filter (rex.sh:1240) all use. So a harness's ownworking/blockedrecords now count as busy and transition evidence. That is a change to busy and transition behavior, and the intent's symptoms (doorbells refused as 'agent has exited', relaunch failing to confirm, stale wakes) all come from thedeadagent state. The widening is consistent: it trusts exactly what the process view now calls alive. Still, the author should confirm they want the trust rule widened in this PR. If not, the smallest remedy is to leavefm_backend_rex_live_pidsas foreground plus ancestors and drop the matching docs sentence (docs/rex-backend.md:85) and the busy assertions in the test.bin/backends/rex.sh:688-fm_backend_rex_descendant_harness_pidsruns the forking shared classifier on every descendant of the shell foreground (Claude's MCP servers, tool subprocesses, and so on) and keeps going after it finds a harness.fm_backend_rex_shell_harness_pidsthen re-classifies a foreground thatfm_backend_rex_agent_statealready classified asshell. With the fish-wrapper setup, every agent_state, busy_state/native_state and per-edge owner_trusted read (rex.sh:1240) now does two fullps -axosnapshots plus several forks per descendant. That cost is bounded, but agent_state only needs one match. Stopping at the first match for the alive check, and passing the already-known foreground pid in directly, would cut the cost.bin/backends/rex.sh:869- A related path the change leaves alone, which is fine for this intent.fm_backend_rex_composer_identitystill takes identity (pi, polytoken, command-code) from the foreground process only. A Pi, polytoken or Command Code worker started through the same fish-function or shell-shim wrapper would show afishforeground and lose its composer identity. Claude does not use this path, so the stated intent is met. This note is only for a possible follow-up.bin/backends/rex.sh:691- The awk descendant closure infm_backend_rex_descendant_harness_pidsis a near copy of the walk inlined infm_backend_herdr_pane_process_state_sample(bin/backends/herdr.sh:2209-2236). Both sit on the shared classifier in bin/fm-agent-process-lib.sh, which says it exists so the backends agree on liveness. A shared descendant-harness helper there would keep the two walks from drifting. This is optional; nothing currently breaks because of the copy.✅ **Test** - passed
✅ No issues found.
aliveon Rexalivedeadagain (no stale alive)alivedead, and a non-shell non-harness foreground still reads ambiguoustests/fm-backend-rex.test.sh(unit-base.txt), which runs against stubs, not the live product, so it did not establish a live result. The li…tests/rex-test-safety.shprivate Rex server (own socket, state dir and empty config; rex 0.0.1792787366-g623b2d) driven byrex-live-driver.sh: fish login shell in a block, fish function wrapper plus cac bash shim, realclaude2.1.310;fm_backend_agent_state rexandfm_backend_rex_live_pidsread with the target adapter and with the base-commit adapter (f6b54afbin/backends/rex.shin a temp copy ofbin/) against the same live blockLive S1a: fish job control on, so the shim leads its own process group and Rex reportsbashas the foreground over Claude: targetalive, basedeadLive S1:status job-control none, matching the reported pgid = tpgid = fish shape; Rex reportsfishas the foreground and Claude is visible only throughps: targetalive, basedead; live_pids includes the Claude pidLive S2: kill the Claude pid, and the pane readsdeadagain on the targetLive S3 (adversarial): fish function →bash -c 'sleep 300'below the fish foreground readsdead, notaliverex-live-fm-send-driver.sh: real Claude past the folder-trust prompt with an unsubmitted draft in its composer, task recorded in a disposablebin/fm-lab-home.sh createhome; ranbin/fm-send.sh w1 'please rebase onto main'from the basebin/copy and from the target worktreebash tests/fm-backend-rex.test.shon the target commit (passes) and the same suite against the base adapter (the new testtest_agent_state_sees_a_harness_below_a_shell_foregroundfails with expected 'alive', got 'dead')bash tests/fm-backend-rex-smoke.test.shagainst a private real Rex server on the target commit (all pass: dead at a bare shell, ambiguous under another program, OSC 7501 busy, kill, relaunch reclaim, isolation)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.