Skip to content

fix(bin): let verified harness ancestry outrank retained markers (#3) - #3578

Merged
kunchenguid merged 5 commits into
kunchenguid:mainfrom
NewAiCoder:up/fm-harness-ancestry
Sep 13, 2026
Merged

kunchenguid merged 5 commits into
kunchenguid:mainfrom
NewAiCoder:up/fm-harness-ancestry

Conversation

@NewAiCoder

@NewAiCoder NewAiCoder commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3517

What Changed

bin/fm-harness.sh treated a verified environment marker (CLAUDECODE, CURSOR_AGENT, etc.) as unconditionally authoritative when detecting which harness owns the current session. A Codex session started from an environment that had retained CLAUDECODE=1 was detected as claude, so session start emitted Claude's Stop-owned supervision protocol to a Codex primary and blocked every turn end for missing Claude recovery. codex, opencode, kimi, and muse publish no identity marker at all, so any retained CLAUDECODE renamed them - this was a precedence boundary defect, not a single-harness bug.

Markers and process ancestry are now separate evidence layers arbitrated by detect_own:

  • no ancestry match, or no marker: the single available layer answers, unchanged;
  • same harness family: the marker's finer verdict stands (e.g. a launch-selected pi-signed is not flattened to pi);
  • different harness with a structural (command-name) ancestor: ancestry wins, since only ancestry proves who owns the process tree;
  • different harness with only a bare-interpreter script-path match: the marker wins, since a harness-shaped path in some node process's arguments is weaker evidence than a harness publishing its own identity.

The correction is symmetric (a retained CURSOR_AGENT no longer renames a nested claude worker either), and extends to two related walks that shared the same underlying defect:

  • The ancestry walk originally stopped as soon as the next pid was 1, assuming pid 1 is always init. Inside a PID namespace that assumption inverts - the harness itself can be pid 1 - so the walk never examined the one process that proves ownership. Fixed by examining the top of the process chain instead of assuming init; a host's real pid 1 matches no harness name, so this costs one extra ps call with no false-positive risk.
  • The same pid-1 assumption existed independently in bin/fm-session-lock-lib.sh's and bin/fm-sessionstart-nudge.sh's own ancestry walks (session-lock recognition and the re-read nudge), fixed the same way.
  • The installed-harness drift guard probed only the pane process, which is args-strength under an interpreter shim (the native binary carrying comm-strength is its child); a release that stopped spawning that child would have silently regressed to the original bug while the guard kept passing. fm-harness.sh gains an ancestry-subtree mode that asks the walk from the pane process and every descendant, requiring comm-strength evidence somewhere in that set.

tests/fm-harness-precedence.test.sh is the portable regression: built from real renamed processes with no harness installed, every case drives the two evidence layers apart and asserts each alone as well as the combination, and pins Codex's real two-process install topology since the fix depends on the native binary being what a tool subprocess meets first. docs/verification/runtime-backends.md records real evidence from a Codex session under codex sandbox holding a retained Claude marker (codex-cli 0.152.0 before/after), including the PID-namespace case the first fix round's evidence didn't yet cover.

Risk Assessment

✅ Low: the change narrows an over-broad "marker always wins" rule to a principled precedence layering, backed by a portable regression suite built from real process shapes (not mocked harness output) plus a live-verified before/after record. Documentation (.agents/skills/harness-adapters/, the codex/opencode/kimi/cursor/muse references, docs/verification/runtime-backends.md) is updated to match the corrected contract.

Testing

bash tests/fm-harness-precedence.test.sh and the other touched suites (tests/fm-cursor-harness.test.sh, tests/fm-kimi-harness.test.sh, tests/fm-secondmate-harness.test.sh, tests/fm-session-lock-ancestry.test.sh, tests/fm-sessionstart-nudge.test.sh, tests/fm-guard-stale-banner.test.sh, tests/fm-turnend-guard.test.sh, tests/fm-watcher-lock.test.sh, tests/fm-x-mode.test.sh) pass in full.

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ Intent recorded for the run.

✅ **Rebase** - passed

✅ Rebased onto current upstream main. The branch was rebuilt from this PR's own commits only, dropping an add-then-remove commit pair that would otherwise have reverted an upstream change. Conflicts in bin/fm-harness.sh and bin/fm-test-run.sh were resolved by keeping both sides, including carrying the upstream agy ancestry match into the new process-verdict walk.

✅ **Review** - passed

✅ One finding fixed in round 1: the agy harness test still asserted the old marker-wins behavior and was vacuous under the new precedence. Fixed to expect agy from a real ancestry stub, with agy added to the precedence suite and its adapter reference. The re-review found no further issues.

✅ **Test** - passed

✅ No issues found. The precedence suite, the agy test, and the sibling harness suites touched in the diff pass.

✅ **Document** - passed

✅ One stale marker description in the kimi adapter reference was corrected; no unresolved documentation items.

✅ **Lint** - passed

✅ No issues found.

  • fm-lint.sh: ShellCheck 0.11.0 (pinned), local changed-file mode.
  • fm-lint-workflows.sh: actionlint 1.7.12 (pinned), 3 workflow files valid.
ℹ️ **Push** - by the PR author

The pipeline's push step stopped before pushing because its bot identity cannot edit a pull request opened by the personal account. The PR author then pushed the exact pipeline-validated head 4771aed8bc0d2987dbd119238c154b4ccd615dab and wrote this attestation from the run's actually completed steps above (run 01M2CECTYE6T2AD376XWNEXNF0). The push step is therefore not listed as a completed pipeline step.

@greptile-apps

greptile-apps Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (3): Last reviewed commit: "fix(bin): let verified harness ancestry ..." | Re-trigger Greptile