Skip to content

fix(herdr): corroborate absent agent registration with process evidence - #7227

Closed
Shazellb wants to merge 8 commits into
kunchenguid:mainfrom
Shazellb:fm/firstmate-herdr-unregistered-claude-live
Closed

Shazellb wants to merge 8 commits into
kunchenguid:mainfrom
Shazellb:fm/firstmate-herdr-unregistered-claude-live

Conversation

@Shazellb

@Shazellb Shazellb commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fix probe. The secondmate liveness probe reads live Claude secondmates (caseops, sentinel) as dead, so the watcher auto-relaunched them three times in about two minutes and then parked. The scout found that Herdr agent registration absence was being treated as proof of agent absence even when the pane process classifier identified a live Claude process. Fix the probe so process evidence corroborates an absent registration: keep process-proven live Claude panes alive, preserve recovery of process-proven shell-only panes, and fail closed when process evidence is inconclusive.

What Changed

  • bin/backends/herdr.sh: a missing Herdr agent registration (agent_not_found) no longer counts as proof the agent is absent. The probe now checks pane process-info. A pane with a live Claude process stays alive. A pane proven shell-only is still read as no-agent, so recovery is preserved. Inconclusive process evidence reads as unknown, which fails closed. This stops live Claude secondmates from being auto-relaunched.
  • Tests: tests/fm-backend-herdr.test.sh gains coverage for these cases. The fake herdr in fm-agy-harness, fm-control-relaunch, fm-crew-state, fm-herdr-session-cleanup and fm-secondmate-sync now models "unregistered pane" with a shell-only process view, since an absent registration alone no longer reads as no-agent.
  • Docs: docs/herdr-backend.md and docs/verification/runtime-backends.md describe the process-corroborated unregistered-pane verdict.

Risk Assessment

✅ Low: The only production change is a small, fail-closed tweak in herdr.sh: an agent_not_found result now maps to live when the process view finds an agent, no-agent only when it proves shell-only, and unknown otherwise. The test edits only adjust fakes to match.

Testing

I ran the herdr backend suite and drove a real Herdr lab session through bin/fm-herdr-lab.sh. An unregistered pane running a Claude-named process read live, and an unregistered shell-only pane read no-agent, so both intent halves hold. The fail-closed case for unreadable process evidence was not driven live, because my failing-herdr shim never took effect; it is covered only by the existing unit test. I did not run a real Claude CLI. The lab was torn down and the worktree is clean.

  • Live validation: ✅ go - 2 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Unregistered pane running a live Claude process reads live instead of no-agent ✅ pass live Lab session probe output: fm_backend_herdr_pane_agent_state returned live while agent get returned agent_not_found
Unregistered shell-only pane still reads no-agent, so recovery is preserved ✅ pass live Lab session probe output: fm_backend_herdr_pane_agent_state returned no-agent on two separate shell-only panes
Unreadable or inconclusive process evidence fails closed to unknown ⏸️ untested no Live attempt used a PATH shim herdr that fails pane process-info, but the shim directory name used a shell PID that changed between commands, so it never took effect and the probe still read no-agen…

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 2 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Unregistered pane running real Claude is classified live ✅ pass live lab output: process=agent state=live
Unregistered shell-only pane stays no-agent (recovery preserved) ✅ pass live lab output: process=shell state=no-agent
Inconclusive process evidence fails closed to unknown ⏸️ untested no The prior payload did not establish a live result. It was covered only by a unit test that stubs the process state, and an inconclusive process state was not forced in the live lab.
  • bash tests/fm-backend-herdr.test.sh (no failures; includes the new unregistered-pane test)
  • Live Herdr lab via bin/fm-herdr-lab.sh: shell-only pane, then real claude run in the pane, classified with fm_backend_herdr_pane_agent_state
  • Missing pane w9:p9 classified as dead

✅ No issues found.

  • Live validation: ✅ go - 2 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Unregistered pane running a live Claude process reads live instead of no-agent ✅ pass live Lab session probe output: fm_backend_herdr_pane_agent_state returned live while agent get returned agent_not_found
Unregistered shell-only pane still reads no-agent, so recovery is preserved ✅ pass live Lab session probe output: fm_backend_herdr_pane_agent_state returned no-agent on two separate shell-only panes
Unreadable or inconclusive process evidence fails closed to unknown ⏸️ untested no Live attempt used a PATH shim herdr that fails pane process-info, but the shim directory name used a shell PID that changed between commands, so it never took effect and the probe still read no-agen…
  • bash tests/fm-backend-herdr.test.sh (0 failures, includes the unregistered-pane process-evidence test)
  • bin/fm-herdr-lab.sh provision and run, driving fm_backend_herdr_pane_agent_state on an unregistered shell-only pane, giving no-agent
  • The same call on an unregistered pane running a process with argv0 claude, giving live
  • bin/fm-herdr-lab.sh teardown of the lab session
✅ **Document** - passed

✅ No issues found.

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @Shazellb — treating a missing Herdr registration as "gone" was clearly wrong when the pane still has a live Claude process, and failing closed on inconclusive process evidence is the right side to err on.

I reviewed tip 89624c1b vs main: three files only (bin/backends/herdr.sh, docs, tests). No workflow, secret, or network surface. Attestation MATCH. Live: 2 of 3 scenarios driven against a real Herdr lab (live Claude + shell-only); the inconclusive/unknown case is unit-covered only, which is fine for a fail-closed branch.

Contract-class: restore. The unconfigured Herdr liveness probe already promised not to relaunch a live secondmate; this makes the agent_not_found branch match that promise using process evidence the product already had.

VISION.md: one-interface / authority / scripts / restart / spine / vendor / scope: align (corrective probe; quarantine stays on the named Herdr adapter; no new default-on surface).

Status: waiting-ci. Main is red right now on unrelated Pi 1.2 type drift — no merges this wake. If this PR's CI fails only on those same main-red shards, that is not on you. When main is green and this is green → auto-merge (restore). Nothing else needed from you unless CI is red for a reason other than that main drift.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @Shazellb for the two follow-up commits. I looked at 40e80567 and f8dc6fe6. They only change test fakes: five suites now give an unregistered pane a shell-only process view. The probe itself is unchanged. The no-mistakes attestation matches f8dc6fe6.

CI on f8dc6fe6 (run 38427288085):

  • Parallel 1 fails only on tests/fm-pi-primary-types.test.sh. That's main's Pi 1.2 type drift, so it isn't on you.
  • Serial 2 hit the 30-minute cancel. That's a known infra issue and isn't on you either.
  • Three suites fail here but pass on main's last full run (38316792015). The first two look tied to the new rule:
    • tests/fm-remote-secondmate-lifecycle-e2e.test.sh (serial 5): "the agent-free remote pane did not classify dead".
    • tests/fm-session-start.test.sh (serial 4): "successful Herdr husk recovery should stay non-actionable". The output shows SECONDMATE_LIVENESS: ... skipped: endpoint probe unreadable (backend=herdr). This is a different assertion from the "home summary ledger" failure your no-mistakes run saw before the PR.
    • tests/fm-remote-reply.test.sh (serial 4): "the NUL-bearing line was not captured". This one may be unrelated or flaky, so a local run would tell.

The remote-lifecycle failure deserves a real look, not just a fake. The shell-only proof reads the local process table. For a remote Herdr pane, the probe may never be able to prove shell-only, so a genuinely agent-free remote pane would never read dead. If that fail-closed result is intended, the test and docs/herdr-backend.md should say so. If it isn't, the remote path needs its own proof.

Contract-class: restore (unchanged). VISION.md: all rules still align. This is a corrective probe on the named Herdr adapter with no new default-on surface.

Status: waiting on you for those suites. Once CI is green apart from main's drift and main itself is green, this goes to auto-merge.

…r-related suites locally and found four that broke because of this PR. The PR's probe change is correct and I didn't touch it. A missing agent registration now only counts as "no agent" when the process view proves the pane is shell-only, and it reads as live when the process view finds a harness. Four test fakes still modelled "unregistered pane" with no process evidence, or with a fake `claude` process. Under the new rule that reads as live or unknown, so these tests failed. All four now pass locally, and I changed only test fakes: - `tests/fm-control-relaunch.test.sh`: the fake `pane process-info` and `ps` now show a shell-only pane unless the fake agent is live. - `tests/fm-crew-state.test.sh`: the husk-pane test sets `FM_FAKE_HERDR_PROCESS=shell`. - `tests/fm-herdr-session-cleanup.test.sh`: stubbed `fm_backend_herdr_pane_process_state` to report `shell`. - `tests/fm-secondmate-sync.test.sh`: the fake herdr now answers `pane process-info` for the stale pane with a shell-only view. `fm-session-start`'s "locked session start did not publish the home summary ledger" also fails locally, but it fails identically with the pre-PR `herdr.sh`. I left it alone, and I don't know whether it is one of the failing CI shards. The CI logs gave no failing test names, so mapping fixes to the six checks is by local reproduction only. I didn't run the full CI shards or the other `agent_not_found` suites (the e2e and smoke ones)
…e more suite that broke because of this PR, but the CI logs again showed no failing test names. I mapped the failure by running the herdr-related suites locally. **What broke:** `tests/fm-agy-harness.test.sh` had a test, "an unregistered pane must read no-agent", whose fake herdr returned `agent_not_found` with no process view. Under the PR's rule that reads as `unknown`, so the test failed. The probe change itself is correct and I didn't touch it. **Invariant:** an absent registration counts as "no agent" only when `pane process-info` proves the pane is shell-only. **Fix (test fake only):** the test now gives the fake herdr a shell-only process view. It uses a live `sleep` as the pane shell, because the shell-only proof reads the real process table, the same way the stale-registration test next to it does. Both the `pane_agent_state` check and the `tab_is_husk` check in that test now get the process view, and the sleep is killed afterwards. **Result:** `fm-agy-harness` now passes. I also ran these suites, and they pass: - `fm-control-herdr-smoke` - `fm-backend-herdr` and its respawn-idem, focus-flash, prune-safety and agent-exit-shell e2e suites - `fm-herdr-pi-stale-registration-live-e2e` - `fm-afk-inject-herdr-e2e` - `fm-teardown` **Not fixed:** `fm-session-start` still fails locally with "a locked session start did not publish the home summary ledger". The previous round found it fails the same way with the pre-PR `herdr.sh`, so I left it alone. **Not run:** I haven't run the full CI shards, so I can't confirm which of the four shards this clears
@Shazellb
Shazellb force-pushed the fm/firstmate-herdr-unregistered-claude-live branch from f8dc6fe to d9971f0 Compare October 13, 2026 23:08
@Shazellb Shazellb changed the title fix(herdr): corroborate unregistered-pane liveness with process evidence fix(herdr): corroborate absent agent registration with process evidence Oct 13, 2026
…start.test.sh. I did not touch bin/backends/herdr.sh. The fix is uncommitted in the worktree. The earlier timed-out agent had already left this edit there, and I verified it. **Cause:** the fake herdr husk pane in `test_session_start_relaunches_herdr_husk_secondmate` had no `pane process-info` view. Under the PR's rule, an absent registration with no process proof reads as unknown. The liveness probe then printed `SECONDMATE_LIVENESS: ... skipped: endpoint probe unreadable (backend=herdr)` and the "non-actionable" assertion failed. **Change:** - The fake herdr now answers `pane process-info` with a shell-only view: a real shell pid and an empty foreground list. - `run_session_start_herdr_secondmate` starts a short-lived `sleep` as that shell pid, because the proof reads the real process table. - The same function sets `FM_HERDR_PS_BIN=/bin/ps` so the test's fake `ps` doesn't interfere. **Verification:** `tests/fm-session-start.test.sh` passes in full locally ("all assertions passed", including the husk test). Locally this only works with `jq` on the test's base PATH. I ran it with `FM_TEST_BASE_PATH=/usr/bin:/bin:/usr/sbin:/sbin:/home/shaz/.local/bin`, because `jq` is installed in `~/.local/bin` here. Without it, the "home summary ledger" failure from earlier rounds reappears. That was a local-environment artifact and not a PR bug. CI has `jq` in `/usr/bin`. The uncommitted edits to `tests/fm-remote-secondmate-lifecycle-e2e.test.sh` and `tests/remote-herdr-fixture.sh` were also left by the timed-out agent. I left them alone and did not run them, since this round was scoped to the one fake
…ssertion in tests/fm-remote-secondmate-lifecycle-e2e.test.sh was failing because of a leftover debug edit, not a missing process view. I did not run that assertion locally. The local run exits earlier, so a full pass is unconfirmed. `tests/remote-herdr-fixture.sh` already gives an unregistered pane a shell-only `pane process-info` view. That is `$PPID` as the shell pid with an empty foreground list. A registered pane still shows a harness. So the PR's rule already holds there: no registration plus shell-only process proof reads as dead. The failure came from the timed-out agent's debug edit. That edit had been committed into the test at ~line 1291. It captured the state output with `2>&1`, printed `DBGV[...]` to stderr, and tailed the Herdr log. Because stderr was merged in, the captured value was never exactly `dead`, so the assertion failed. I restored the original `[ "$(remote_env ... state ios)" = dead ]` check and removed the debug lines. Only `tests/fm-remote-secondmate-lifecycle-e2e.test.sh` changed. I did not touch `bin/backends/herdr.sh`. I ran the test file locally. It stops at an earlier step with "remote spawn never reached its blocked inheritance write", before the edited assertion. I have not checked whether that early failure happens on main or comes from this machine; the cause is unknown. The local run also hit `rm` permission errors in its temp-dir cleanup, which I cleared by hand. The fix itself is traced by reading the fixture and the test, not by a passing run
…ests/remote-herdr-fixture.sh the unregistered 'pane process-info' branch now reports a dedicated isolated pane-shell pid (a `sleep 600` with fds redirected, pid recorded in $STATE.shell.pid and reused while alive) with empty foreground_processes, instead of the probe's $PPID. Registered panes still show codex. In tests/fm-remote-secondmate-lifecycle-e2e.test.sh the cleanup trap kills the recorded sleep, and the 'agent-free remote pane did not classify dead' assertion now fails with the actual state, the fixture's raw pane process-info and the Herdr log tail. The local lifecycle run finished but I only saw cleanup rm permission errors, so a passing run of the edited assertion is unconfirmed; earlier local runs stopped before it at 'remote spawn never reached its blocked inheritance write'. The CI shard on the pushed head is the real check
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @Shazellb for the follow-up commits since the waiting-author stamp on f8dc6fe6. Tip is now 5b368bb0.

What I re-checked: the probe in bin/backends/herdr.sh is still the same restore — agent_not_found no longer means gone; process view proves live / shell-only no-agent / else unknown. The new commits are test/fixture only (agy-harness, session-start, remote-herdr-fixture isolated shell pid, remote-secondmate-lifecycle e2e debug revert). Attestation MATCH.

CI on 5b368bb0 (run 38498457143): the suites that were red because of this PR are green now (serial 4, serial 5, Herdr, session-start path). Parallel 1 fails only on tests/fm-pi-primary-types.test.sh — that is main's Pi 1.2 type drift, not on you. Serial 2 was still running when I looked; if it only hits the known 30-minute cancel, that is infra noise.

Contract-class: restore (unchanged). VISION.md: all rules still align.

Status: waiting-ci. When main is green and this head is clean apart from that main drift / serial-2 cancel → auto-merge. Nothing else needed from you unless CI turns red for a PR-caused reason.

@Shazellb

Copy link
Copy Markdown
Contributor Author

Closing: not needed upstream, fix stays on the fork.

@Shazellb Shazellb closed this Oct 14, 2026
@Shazellb Shazellb reopened this Oct 19, 2026
@Shazellb Shazellb closed this Oct 19, 2026
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