Repository navigation
feat: propagate W3C trace context to spawned agents - #3
Merged
Merged
Conversation
Apply only the isolated upstream PR-995 trace-context feature delta on top of the current fork main, which already carries canonical Firstmate content from the fork-sync merge. This makes the already-validated, default-off W3C trace-context capability available on the captain's integration fork without waiting for the canonical upstream merge of PR 995. The change is the exact PR-995 feature delta (a53ffc1..2ff8ab8, the validated integration merge of PR-995 head 2fbe2fd), applied with cherry-pick -m1 so the trace-context implementation is preserved with no semantic delta; every feature-only file is byte-identical to the PR-995 head. Three genuine overlaps with the newer canonical commit kunchenguid#1303 (bound and consolidate startup memory during stow) are resolved by preserving both behaviors: the inheritable-config set in bin/fm-config-inherit-lib.sh, the config-push list in docs/configuration.md, and the inheritance comment in tests/fm-secondmate-harness.test.sh now declare both startup-memory-budget and trace-context. No canonical kunchenguid#1303 content is dropped and no unrelated upstream content is reintroduced. Focused suites pass: fm-trace-context-lib, fm-trace-context-spawn, fm-session-start, fm-documentation-audiences, fm-secondmate-harness, and bin/fm-lint.sh.
allstargg
pushed a commit
that referenced
this pull request
Sep 16, 2026
…kunchenguid#3578) * fix(bin): let verified harness ancestry outrank retained markers (#3) * fix(bin): let a structural harness ancestor outrank a retained marker bin/fm-harness.sh treated a verified environment marker as unconditionally authoritative, so a Codex session started from an environment that had retained CLAUDECODE=1 detected as claude. Session start then emitted Claude's Stop-owned supervision protocol to a Codex primary, and every turn end was blocked for missing Claude recovery. The defect is the precedence boundary, not any one harness. codex, opencode, kimi, and muse publish no identity marker at all, so with markers winning outright any retained CLAUDECODE renamed them; the Cursor-before-Claude ordering was a point patch on the same class of problem, and the launch-time marker clearing only ever covered sessions fm-spawn started. Markers and ancestry are now separate evidence layers that detect_own arbitrates: - no ancestry match, or no marker: the single available layer answers, unchanged; - same harness family: the marker's finer verdict stands, so a launch-selected pi-signed is not flattened to pi by an ancestry walk that can only see the shared launcher name; - different harness with a structural (command-name) ancestor: ancestry wins, because 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 claude worker nested under cursor either. Adds fm-harness.sh ancestry [<pid>], ancestry evidence with no marker layer, so a real harness process can be asked what the walk makes of it. tests/fm-harness-precedence.test.sh is the portable regression, built from real renamed processes with no harness installed. Every case drives the two layers apart and asserts each alone as well as the combination, so no case can pass vacuously; it also pins Codex's real two-process install topology, since the fix depends on the native binary being what a tool subprocess meets first. The opt-in drift guard gains the matching live half: each installed harness's real running process must still be identified by the ancestry walk, and it fails naming the harness and version when a release changes that name. Documentation follows the corrected contract in the script header, the harness-adapters detection section, the codex, opencode, kimi, and cursor references, and a dated verification record. * fix(tests): drop the unused argument pass-through in the shim-topology helper bin/fm-lint.sh refused the branch: run_shim declared a `[ancestry]` argument and forwarded "$@", but every call site that varies the environment or passes the ancestry subcommand invokes the shim entry point directly, so the helper is only ever called with no arguments (ShellCheck SC2120/SC2119). Behavior is unchanged: with no arguments "$@" expanded to nothing. * fix(bin): examine the top of the process chain instead of assuming init harness_ancestry stopped as soon as the next pid was 1, on the assumption that pid 1 is always init and can never be a harness. Inside a PID namespace that assumption inverts: the harness itself is pid 1, so the walk never examined the one process that proves who owns the tree, reported no ancestry at all, and handed the verdict straight back to a retained marker. A real Codex session under `codex sandbox`, holding CLAUDECODE=1 and CLAUDE_CODE_ENTRYPOINT=cli, is exactly that shape: it resolved claude and rendered Claude's Stop-owned supervision protocol even with the marker-vs-ancestry precedence boundary in place. The same probe now resolves codex and renders the Codex foreground checkpoint. A host's real pid 1 (init, systemd, launchd) matches no harness name, so examining it costs one ps call and can introduce no false positive; the walk still stops once that top process has been read, and a non-numeric or zero ppid still ends it. tests/fm-harness-precedence.test.sh pins the namespace shape with a fake ps that reports every process as bash with ppid 1 and pid 1 as the harness. The case asserts the marker still answers alone when pid 1 is host-shaped, so it cannot pass vacuously, and it fails against the previous stop condition. * docs(verification): record the real-Codex retained-marker evidence The existing record proved the precedence boundary with the portable regression and recorded each installed harness's process name behind the ancestry walk, but it had no evidence from a real Codex process actually holding a retained Claude marker, which is the failure the boundary exists for. Adds the dated before/after result from codex-cli 0.152.0 under `codex sandbox`, with the exact command and the decisive verdict and rendered protocol on each side, and records the second boundary that shape exposed: the walk must examine the top of the process chain, because inside a PID namespace the harness is pid 1. Refreshes the portable regression's observed output for the case it gained. * no-mistakes(review): blind ancestry in marker-pinned harness tests * no-mistakes(review): blind ancestry in the Pi guard-routing test * no-mistakes(review): classify precedence suite, dedupe ps stub, soften claims * no-mistakes(review): model the spawn-and-wait Codex shim topology * no-mistakes(document): correct stale muse marker-clearing detection claims * no-mistakes: apply CI fixes * fix(bin): examine the top of the chain in the lock and nudge walks too The pid-1 defect corrected in bin/fm-harness.sh survived unchanged in the two other harness-ancestry walks, on the exact topology the branch verified against a real Codex process. bin/fm-session-lock-lib.sh's fm_harness_ancestry_pids stopped as soon as the next pid was 1, so a firstmate whose harness is pid 1 of its own PID namespace could not find that harness at all and did not recognize its own session lock. bin/fm-sessionstart-nudge.sh carried the same stop plus a blanket rejection of a lock pid of 1, so the same session was told to run session start again on every turn. Both walks now compare the top process before stopping, matching the shape used in bin/fm-harness.sh. For the lock walk this is safe because fm_harness_process_matches rejects a host's real pid 1. For the nudge, `kill -0` still gates the lock pid, and on a host an unprivileged `kill -0 1` fails, so a lock file that wrongly names pid 1 leaves the hook silent rather than acting on init. Each walk gains one regression case. The lock case drives a deterministic process table whose pid 1 is the harness and asserts a host-shaped pid 1 still finds nothing, so it cannot pass vacuously. The nudge case needs a real PID namespace, because the builtin `kill -0` gate cannot be reached through a fake ps, and it first proves the same fixture nudges with no lock present; it skips explicitly where unprivileged namespaces are unavailable. * no-mistakes(review): assert comm-strength detection from subprocess vantage in drift guard * fix(bin): verify the live harness guard at the strength the guarantee needs The marker-versus-ancestry boundary this branch ships is a strength claim: detect_own hands an args-strength verdict straight back to a retained foreign marker, so a harness is only protected where the ancestry walk reaches it at comm strength. The installed-harness drift guard probed the pane process alone. Under an interpreter shim the pane process IS the shim, whose own script path is args strength, while the native binary that carries comm strength is its child. The guard therefore observed args for Codex, passed, and would have kept passing if a release stopped spawning that native child at all, while real sessions silently regressed to the original bug. fm-harness.sh gains `ancestry-subtree`, which asks the walk from the pane process and every descendant of it, the vantage a tool subprocess actually occupies. The guard now requires comm strength somewhere in that set and requires every vantage to name the same harness. This supersedes the preceding commit's in-guard leaf walk, which reached the same vantage but left the logic inside the test file, where CI could not pin it and nothing else could reuse it. A harness-dependent check needs both halves: `tests/fm-harness-precedence.test.sh` now carries a portable case proving the subtree probe reaches a strength the top-of-session probe cannot, mutation checked twice, once against the pre-change script and once by disabling descendant enumeration. The subtree walk also avoids depending on tty and process-group semantics that differ between Linux and macOS. Verified live: codex-cli 0.152.0 reports [args codex;comm codex] and Claude Code 2.1.257 reports [comm claude]. * no-mistakes(review): narrow drift guard to the upward vantage path * no-mistakes(review): judge only comm-strength vantages in drift guard * no-mistakes(document): drop duplicated rationale in detection precedence evidence * no-mistakes(review): fix pid-1 nudge case vacuity and descent no-arg expansion * no-mistakes(document): drop branch-relative phrasing in detection precedence evidence * no-mistakes(review): guard remaining empty positional expansions in fm-harness * no-mistakes(document): scope cursor marker-ordering claim to the marker layer * no-mistakes(review): Prefer comm-strength leaves in equal-depth descent ties * no-mistakes(document): Document comm-strength descent tie-break --------- * no-mistakes(review): Blind ancestry in stale gemini/rovo marker-precedence tests * no-mistakes(document): Add missing equal-depth-tie test line to precedence evidence transcript * no-mistakes(review): Fix stale/vacuous agy precedence test, add agy to precedence suite and docs * no-mistakes(document): Fix stale kimi.md marker doc missed by ancestry-precedence fix --------- Co-authored-by: NewAiCoder <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Make the already-validated upstream PR-995 native W3C trace-context capability available on the captain's integration fork (allstargg/firstmate) without waiting for the canonical upstream merge of PR 995. This is a deliberate, exact port: the trace-context implementation is preserved byte-for-byte from PR-995 head 2fbe2fd (every feature-only file is byte-identical), applied as the isolated feature delta (a53ffc1..2ff8ab8) via cherry-pick -m1 onto current fork main. Fork main already carries canonical Firstmate content from an earlier squash fork-sync, so this change is intentionally scoped to ONLY the trace-context feature: the 22 changed files are exactly PR 995's files. Three genuine overlaps with the newer canonical commit kunchenguid#1303 (bound and consolidate startup memory during stow) were resolved BY DESIGN to preserve BOTH behaviors - bin/fm-config-inherit-lib.sh, docs/configuration.md, and tests/fm-secondmate-harness.test.sh now declare both startup-memory-budget and trace-context in their shared config lists/comments; no canonical content was dropped and no old upstream content reintroduced. The capability is default-off (presence flag config/trace-context plus FM_TRACE_CONTEXT override), propagates a W3C traceparent to spawned agents, freezes its decision at locked session start, and inherits into secondmate homes. PR 995 passed 10/10 upstream checks and the focused suites (trace-context lib/spawn, session-start, documentation-audiences, secondmate-harness, lint) pass locally. The exact integrated trace-context tree is required and must not be altered; the cherry-pick merge strategy and the kunchenguid#1303 overlap resolutions were explicitly captain-approved.
What Changed
traceparentpropagation and metadata recording for spawned agents, including inherited child traces and stable relaunch context.Risk Assessment
✅ Low: The trace-context port is well-bounded and source evidence shows the required default-off behavior, locked-session decision, spawn propagation, metadata agreement, secondmate inheritance, and approved overlap resolutions remain intact.
Testing
The required startup check was clean; focused library, real spawn-path, locked-session, secondmate-inheritance, documentation, backend-carrier, and test-run fixtures all passed, with transcripts demonstrating default-off behavior, identical recorded/injected W3C carriers, safe failure handling, frozen decisions, relaunch identity, and primary-to-secondmate-to-worker propagation. This is a shell capability with no rendered UI, so visual screenshots were not applicable.
Evidence: End-to-end trace-context spawn transcript
Evidence: Secondmate inheritance transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
git diff --stat --name-only a1f63638e5c5f87b12d5ab81d1eac72d4bbedea5..5bd5bb7d60f4dd0da467ef5871e0f6d3926a1171bin/fm-session-start.shbash tests/fm-trace-context-lib.test.shbash tests/fm-trace-context-spawn.test.shbash tests/fm-session-start.test.shbash tests/fm-secondmate-harness.test.shbash tests/fm-documentation-audiences.test.shbash tests/fm-backend-cmux.test.shbash tests/fm-backend-zellij.test.shbash tests/fm-test-run.test.shInspected the three #1303 overlap surfaces withrg -n 'startup-memory-budget|trace-context' bin/fm-config-inherit-lib.sh docs/configuration.md tests/fm-secondmate-harness.test.shChecked evidence logs for failure markers and confirmedgit status --shortremained cleandocs/trace-context.md:25-docs/trace-context.mdclaims coverage across every harness but omits the fork's verifiedpi-signedharness. Addingpi-signedwould fix the authoritative trace-context guide, but would violate the explicit requirement that every feature-only PR-995 file remain byte-identical. Recommend preserving the required exact port unless the captain authorizes this one-word documentation divergence; declining leaves this sentence inaccurate forpi-signed.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.