Skip to content

fix(bin): read a Claude worker below a shell foreground as alive on Rex - #7728

Merged
kunchenguid merged 1 commit into
kunchenguid:mainfrom
leo1oel:fm/fm-rex-liveness
Oct 25, 2026
Merged

kunchenguid merged 1 commit into
kunchenguid:mainfrom
leo1oel:fm/fm-rex-liveness

Conversation

@leo1oel

@leo1oel leo1oel commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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:

fish 68540            <- Rex foreground (pgid = tpgid = 68540)
  bash ~/.cac/bin/claude
    ~/.cac/versions/2.1.310/claude

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 relaunch could not confirm the running agent, and the watcher raised stale wakes.

 fm_backend_rex_agent_state
   harness in foreground or ancestors -> alive
+  shell foreground
+    harness among its live descendants (shared classifier) -> alive
+    process table unreadable -> ambiguous
   shell foreground -> dead
 fm_backend_rex_live_pids          # OSC 7501 owner trust
   foreground + ancestors
+  + harness pids below a shell foreground

Owner trust follows the same rule, so a fish-launched worker's own working/blocked records still count.
docs/rex-backend.md states the updated rule, and docs/verification/runtime-backends.md records the captured fish/shim process shape.

Evidence

  • Before: the new tests/fm-backend-rex.test.sh case, which uses a real shell -> wrapper -> claude process 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 staying dead with its records ignored, and a harness foreground staying alive.
  • Before: on a live Rex server, a fish foreground over a real Claude Code 2.1.310 read dead, and fm-send refused with "agent has exited".
    After: the same pane reads alive and fm-send is no longer refused, and it reads dead again 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 ps table reads per state or trust check.
A harness-named process left running below an idle shell would now read alive instead of dead.
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.

⚠️ **Review** - 4 issues (1 warning, 3 infos)
  • ⚠️ bin/backends/rex.sh:795 - Beyond what the intent needs: the intent asks for a live worker on Rex to read as alive, 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 to fm_backend_rex_live_pids (rex.sh:791-797). That widens the OSC 7501 owner-trust rule, which fm_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 own working/blocked records 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 the dead agent 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 leave fm_backend_rex_live_pids as 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_pids runs 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_pids then re-classifies a foreground that fm_backend_rex_agent_state already classified as shell. With the fish-wrapper setup, every agent_state, busy_state/native_state and per-edge owner_trusted read (rex.sh:1240) now does two full ps -axo snapshots 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_identity still 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 a fish foreground 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 in fm_backend_rex_descendant_harness_pids is a near copy of the walk inlined in fm_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.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
A live Claude worker started from a fish login shell through a fish function wrapper and the cac bash shim (pgid = tpgid = fish, Rex foreground = fish) reads alive on Rex ✅ pass live rex-live-transcript.txt S1: Rex process view foreground fish 34754, ps shows bash 39666 and claude 39770 in pgid 34754; agent_state target=alive, base=dead; live_pids includes 39770
Variant: with fish job control on, the shim is the Rex foreground over a live Claude and reads alive ✅ pass live rex-live-transcript.txt S1a: foreground bash 36932 with claude 37003 below; target=alive, base=dead
Steering a live Rex worker with fm-send is no longer refused as 'agent has exited' ✅ pass live rex-live-fm-send-transcript.txt: base fm-send printed 'doorbell not typed because the agent ... has exited'; target fm-send treated the worker as live (ring deferred only for the visible pending draft…
After the harness exits, the fish prompt reads dead again (no stale alive) ✅ pass live rex-live-transcript.txt S2: after killing claude, target agent_state=dead, live_pids back to [fish, login]
Adversarial: a non-harness process tree (fish function → bash → sleep) below a fish foreground does not read alive ✅ pass live rex-live-transcript.txt S3: target agent_state=dead, live_pids excludes bash/sleep
A bare fish/shell prompt still reads dead, and a non-shell non-harness foreground still reads ambiguous ✅ pass live rex-live-transcript.txt S0 (bare fish dead); rex-smoke-target.txt 'agent_state reads dead at a shell, ambiguous under another program'
The regression test reproduces the bug: it fails on the base adapter and passes on the fix ⏸️ untested no The prior payload got this result only from the unit suite tests/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.sh private Rex server (own socket, state dir and empty config; rex 0.0.1792787366-g623b2d) driven by rex-live-driver.sh: fish login shell in a block, fish function wrapper plus cac bash shim, real claude 2.1.310; fm_backend_agent_state rex and fm_backend_rex_live_pids read with the target adapter and with the base-commit adapter (f6b54af bin/backends/rex.sh in a temp copy of bin/) against the same live block
  • Live S1a: fish job control on, so the shim leads its own process group and Rex reports bash as the foreground over Claude: target alive, base dead
  • Live S1: status job-control none, matching the reported pgid = tpgid = fish shape; Rex reports fish as the foreground and Claude is visible only through ps: target alive, base dead; live_pids includes the Claude pid
  • Live S2: kill the Claude pid, and the pane reads dead again on the target
  • Live S3 (adversarial): fish function → bash -c &#39;sleep 300&#39; below the fish foreground reads dead, not alive
  • rex-live-fm-send-driver.sh: real Claude past the folder-trust prompt with an unsubmitted draft in its composer, task recorded in a disposable bin/fm-lab-home.sh create home; ran bin/fm-send.sh w1 &#39;please rebase onto main&#39; from the base bin/ copy and from the target worktree
  • bash tests/fm-backend-rex.test.sh on the target commit (passes) and the same suite against the base adapter (the new test test_agent_state_sees_a_harness_below_a_shell_foreground fails with expected 'alive', got 'dead')
  • bash tests/fm-backend-rex-smoke.test.sh against 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.

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.
@kunchenguid

Copy link
Copy Markdown
Owner

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 9ced0961 against main d96bff00:

  • fm_backend_rex_agent_state still reads alive when a harness is in the foreground or its ancestors, and ambiguous for a foreground that isn't a shell. The change only applies to a shell foreground. There it walks the local process table for the shell's descendants and runs each one through the shared fm_agent_process_classify. Any verified harness reads alive. None reads dead, as before. An unreadable table reads ambiguous, so it never turns into a false dead.
  • fm_backend_rex_live_pids and the OSC 7501 owner-trust rule add only those harness-classified pids below a shell foreground. A non-harness child still doesn't count, and the new test checks that its records are ignored.
  • It's Rex-only, with no state or format change. The diff touches no workflows, secrets or network calls.

Contract-class (my own read): restore. The Rex adapter already promises recovery-grade liveness for a live worker. Here a running Claude worker read dead, so fm-send refused it and the watcher raised false stales. This fixes the classification on that existing default path. It adds no new surface. VISION.md, rule by rule: One captain, one interface: aligns (no false stale wakes or refused doorbells). Authority: aligns (no change). Scripts own the mechanics: aligns (exact process-table classification through the shared classifier). Restart is a non-event: aligns (the live-worker read no longer flips to dead, and fm-control relaunch can confirm the running agent). Delegation with a spine: aligns (unit cases for a bare shell, a non-harness child and a harness foreground, plus 6/7 live). Vendor: aligns. It stays inside the Rex adapter and reads Rex's structured process view, not a rendered surface. Scope: aligns.

CI: this is a first-time fork run. I reviewed the diff and approved CI 40102937259 and Require no-mistakes 40114078515. The no-mistakes attestation is bound to 9ced0961, and live validation is go (6 of 7).

Status: waiting on CI, not on you. If it comes back green and the head hasn't changed, this is on track to merge.

@kunchenguid
kunchenguid merged commit abb8194 into kunchenguid:main Oct 25, 2026
39 of 40 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @leo1oel — really appreciate you taking the time on this.

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