Repository navigation
fix(bin): keep secondmate restarts from losing or masking a navigator - #48
Merged
Merged
Conversation
Restarting a persistent secondmate failed two ways, and the restart report hid the first. - fm-control relaunch of a secondmate now holds that mate's per-task liveness lock from before the old agent stops until the transaction settles, so the watcher tick and session-start sweep skip the mate instead of reading the shell-only gap as dead and killing its endpoint. - The liveness relaunch never kills an endpoint while a spawn of that task holds its spawn lock (a relaunch or a hand-run respawn), and re-reads the endpoint under that lock before killing it. Those skips are flagged deferred, so the watcher logs them instead of failing. - Every firstmate-launched Claude agent gets "disableAgentView": true in its --settings value (crewmate inline JSON and the secondmate settings file), turning off /background, --bg, agent view and the on-demand daemon for those agents only. - fm-control exit and relaunch refuse, before any key is sent, a Claude agent that `claude agents --json --cwd` lists as a live background session, and name the recovery (persist, claude stop, relaunch). - fm-secondmate-restart reports the restart's own error lines (first cause and last state) and skips NOTICE/WARNING/warning and fm-config-inherit advisories; a local mate whose endpoint is already missing or dead is reported at once with no persist request and no 900 s wait. Tests: the lab reproduction becomes a real private-tmux regression (a tick during an in-flight relaunch leaves the endpoint intact) plus a watcher-level regression of the incident; fm-control lock and background-session cases; restart reason and no-agent cases; and a token-free live guard for the Claude agent-view surfaces, recorded in docs/verification/runtime-backends.md.
…stly - fm-remote-secondmate-relaunch.sh holds the parent home's per-task liveness lock for the whole remote relaunch (bounded by FM_CONTROL_LIVENESS_WAIT, released on every exit), so the parent watcher's remote probe cannot read the host's agent-free gap as a dead mate and start a relaunch of its own; a check that keeps the lock refuses the relaunch before anything reaches the host. - fm-secondmate-restart reports a local mate whose endpoint reads missing as not found from this home (gone or unreachable), since a missing reading alone does not prove the endpoint was destroyed. - The restart suite's concurrency test now keeps its modeled remote relaunch in flight until the local relaunch stops its agent (bounded), instead of betting on a fixed sleep.
…d because this PR changes 15 upstream-owned files that no ADR covers. They are bin/fm-control.sh, bin/fm-remote-secondmate-relaunch.sh, bin/fm-secondmate-liveness-lib.sh, bin/fm-secondmate-restart.sh, bin/fm-test-run.sh, docs/agent-control.md, docs/verification/runtime-backends.md, and eight test files. The rule A4 enforces: every path that differs from the upstream pin must sit in a PixelOven namespace or an ADR's file list, and the workflow allowlist must match its copy in identity.md. The fix follows the pattern from ADR-0021, 0023 and 0024: - **New ADR:** added docs/adr/0025-secondmate-restart-reliability.md, which lists every inherited file this PR touches and what each may carry. That includes fm-spawn.sh, fm-watch.sh, configuration.md, remote-secondmates.md and the spawn tests, which were already on the allowlist but only for other ADRs' changes. - **Allowlist:** added the 15 paths to the A4 allowlist in .github/workflows/pixeloven-gates.yml, and made the identical edit to its copy in docs/pixeloven/identity.md. - **Registration:** added the ADR to docs/adr/README.md and docs/documentation-audiences.json, and to the ADR lists in fork-contract.md and identity.md. - **Status:** I set the ADR to Accepted, because the user intent explicitly asks for this local carry. ADR-0024 was set to Proposed in a similar case, so the operator may want to change it. - **Alternatives:** the ADR's "Alternatives considered" section is my own reasoning, not taken from the diagnosis report, so the operator should review it before merging. Local results: I ran the fork-contract step taken from the workflow, and checks A1–A4 and A6–A11 pass, including A4. A5 still fails locally, but only because macOS sed rejects the step's `1{/^$/d}` command. That was the same in earlier rounds, README.md is unchanged, and A5 passed in CI. tests/fm-documentation-audiences.test.sh and bin/fm-doc-audience-check.sh pass. bin/fm-lint-workflows.sh was not run because actionlint is not on PATH; the workflow edit only changes the allowlist pattern. The new ADR file is staged with `git add -N` so the documentation-audience check can see it
ADR-0025 is taken by the open serial 5 carry, so this carry becomes ADR-0026, titled to match the decision. The ADR index, documentation inventory, fork contract, and identity ADR lists follow, and the ADR now states that the upstream offer is drafted later, not published now.
# Conflicts: # .github/workflows/pixeloven-gates.yml # docs/adr/README.md # docs/documentation-audiences.json # docs/pixeloven/fork-contract.md # docs/pixeloven/identity.md
ductiletoaster
added a commit
that referenced
this pull request
Nov 3, 2026
…02bd60). The Full suite check only failed because the lanes below failed. Fixes: 1. **Lint 1 (SC2329).** The merge left two definitions of `finish_concurrent_recovery` in `tests/fm-backend-herdr-presentation-e2e.test.sh`, so the first one was never called. Rule broken: a function should be defined only once. I removed the old fork copy, which used `$PROJECT_DIR`. Upstream's copy, which uses `$RECOVERY_PROJECT_DIR`, is the one the test was already calling. The lint-phase decline was about the generic local lint finding; this CI lint check was selected for fixing in this round. 2. **Behavior portable serial 5** (`tests/fm-wake-queue.test.sh`, "sequence 9223372036854775806 advanced to -9223372036854775807"). The fork's `_fm_wake_sequence_floor_locked` found the highest queue sequence using awk numbers. awk rounds 9223372036854775806 up to …808, which overflows bash. Rule broken: a recovered sequence must be computed from the exact decimal text. Upstream's exact decimal-text pass, which runs right after this helper in `fm_wake_append_locked`, already raises the sequence to the queue's highest row. So I removed the fork's duplicate queue scan. I kept its fail-closed refusal of an unreadable queue and its process-event marker floor. The helper has no other callers. 3. **Behavior portable parallel 1** (`tests/fm-backend-t3code.test.sh`, "an unproved close must stop recovery"). The fork's #48 recheck in `fm_secondmate_liveness_relaunch` re-reads the endpoint before any kill. When T3 thread reads fail, it now refuses with "endpoint now reads unreadable rather than dead". Upstream's kill-proof path never runs, because it uses the same thread read. The rule still holds: nothing is spawned and the record is kept. Only the reason string changed, and no relaunch-ledger entry is written. Removing the recheck would let the kill archive a newly republished live thread, so it stays. I updated the upstream test to assert the merged behaviour: same no-spawn and record-kept checks, the deferral reason, and no ledger attempt. The "could not prove" branch is still reachable if the state changes between the recheck and the kill. `tests/fm-secondmate-liveness.test.sh` still covers its non-T3 side. 4. **gitleaks.** Two fake values in upstream test fixtures, now in our history: 7647d6b (#5409, `EFFECTIVE_SECRET='kc-effective-…-never-on-argv'`) and 3004ccb (#7518, `secret=fm-inherited-secret-7f3a`). History can't be rewritten without a force-push, so I added both fingerprints with reason comments to `docs/pixeloven/gitleaksignore`. This follows the existing #4692 entry. **Verification** - gitleaks 8.30.1 full-history scan with the ignore file: no leaks found. - `bin/fm-lint.sh` on the three edited shell files: no findings. - The updated t3code test passes when run alone with `FM_TEST_ONLY`. - The full `tests/fm-wake-queue.test.sh` exits 0, with no `not ok` lines. I did not run the whole t3code suite or the herdr e2e suite locally
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
Ship ONE operator PR with all the Recommendations in the navigator restart diagnosis report:
(a) the secondmate relaunch holds the per-task liveness lock, and the liveness relaunch never kills an endpoint while a spawn of that task is in flight;
(b) firstmate-launched Claude agents get "disableAgentView": true (no /background, --bg, agent view or on-demand daemon);
(c) fm-control refuses /exit on a background-kind Claude session with a precise reason;
(d) fm-secondmate-restart reports the real error line and does not wait 900 s on a mate whose endpoint is already gone.
Include a regression test from the lab reproduction. It is a local carry in pixeloven/operator under the maintainer role; an upstream offer is drafted later, not published now. The operator merges.
Report substance: restarting a persistent secondmate failed two ways. (1) During
fm-control.sh relaunchthe pane holds only a shell for 20-30 s; the watcher's secondmate liveness tick (bin/fm-watch.sh, bin/fm-secondmate-liveness-lib.sh) classifies it dead, kills the endpoint, then its own fm-spawn is refused by the relaunch's spawn lock ("another spawn is already creating task"), leaving no endpoint. Reproduced in a tmux lab; holding the per-task liveness lock during the relaunch prevents it. fm-secondmate-restart masked the real error by reporting the first stderr line (an unrelated NOTICE or fm-config-inherit advisory). (2) A Claude session converted to a Claude Code background session by /background treats /exit as detach (prints a recap) and keeps running outside its pane, so fm-control's 30 s exit wait ends exit=unconfirmed.Follow-up decision (operator, 2026-11-02): PR #47 merged to main (1aaf68c) and added ADR-0025 (remote-test timing deflake). Bring PR #48 up to date by MERGING origin/main into fm/op-sm-restart-fix as a new merge commit (no rebase, no force-push). The merge resolves the shared ADR index, documentation-audiences, fork-contract and identity conflicts by keeping BOTH entries (ADR-0025 from #47 and ADR-0026 from #48), and the A4 allowlist in .github/workflows/pixeloven-gates.yml (mirrored in docs/pixeloven/identity.md) as the union of both sides. Do not merge the PR.
What Changed
fm-control.sh <id> relaunchfor a secondmate, andfm-remote-secondmate-relaunch.sh, now take the mate's per-task liveness lock before the old agent stops. They wait up toFM_CONTROL_LIVENESS_WAIT(default 30 s) for the lock and refuse if a check still holds it after that. They keep it until the relaunch settles. Separately,fm_secondmate_liveness_relaunchrefuses to kill an endpoint while that task'sfm-spawnlock is held, and checks again under the lock that the endpoint still reads dead. The watcher logs these deferred skips (FM_SM_LIVE_DEFERRED) and checks again on the next tick instead of raising an error.fm-spawn.shnow gets"disableAgentView": truein its--settings, for both crewmates and secondmates. This turns off/background,--bg, agent view and the on-demand daemon.fm-control.shexitandrelaunchnow refuse a Claude agent thatclaude agents --json --cwdlists as a livebackground-kind session. The check runs before any key is sent, and the refusal names the session ID and pid and gives theclaude stoprecovery steps.fm-secondmate-restart.shreports the real failure and skips dead mates. A failed restart now reports its first and lasterror:lines and ignoresNOTICE:,WARNING:andfm-config-inherit:advisories. A local mate whose endpoint already readsmissingordeadis reported unreached straight away, without sending the persist request or waiting out its timeout. Regression tests are added for the liveness, control, relaunch, remote-relaunch, restart and wake-queue paths. A new default-on live test,fm-claude-agent-view-live-e2e.test.sh, checks the installedclaudeagainst both agent-view assumptions. The change is recorded as a local carry in ADR-0026 and added to the fork-contract A4 allowlist, the ADR index and the documentation-audiences file, next to ADR-0025 frommain.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The new merge commit only resolves the shared ADR registry and fork-contract conflicts as the user asked: it keeps both the ADR-0025 and ADR-0026 entries and makes the A4 allowlist the union of both sides, identical in the workflow and identity.md. The carried secondmate fixes already went through earlier review rounds, and re-tracing their locking, spawn-lock guard, restart reporting and disableAgentView changes found no new reachable defect.
Testing
I drove the disableAgentView guard live. A real Claude session in a disposable tmux lab, given fm-spawn's exact settings, rejected /background as an unknown command, stayed interactive and exited cleanly on /exit. All seven targeted suites that finished passed, but they ran on fixtures or a scripted lab, not against the live product, so their scenarios are marked untested. The spawn-dispatch-profile suite hit the background time limit with no failures. The worktree is clean.
Evidence: Live Claude /background refused under disableAgentView
Source: Live Claude /background refused under disableAgentView
Evidence: Live agent-view e2e guard
Source: Live agent-view e2e guard
Evidence: Secondmate liveness suite incl. real-tmux reproduction
Source: Secondmate liveness suite incl. real-tmux reproduction
Evidence: fm-control relaunch suite (liveness lock)
Source: fm-control relaunch suite (liveness lock)
Evidence: fm-control suite (background refusal)
Source: fm-control suite (background refusal)
Evidence: Secondmate restart suite
Source: Secondmate restart suite
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
bash tests/fm-claude-agent-view-live-e2e.test.sh(installed Claude Code v2.1.316): exit 0bash tests/fm-secondmate-liveness.test.sh(real private-tmux lab reproduction of the in-flight relaunch): exit 0, 24 okbash tests/fm-control-relaunch.test.sh: exit 0, 91 ok, including the liveness-lock gap and busy-lock refusal testsbash tests/fm-control.test.sh: exit 0, 47 ok, including the background-session refusalbash tests/fm-secondmate-restart.test.sh: exit 0, 25 okbash tests/fm-remote-secondmate-relaunch.test.sh: exit 0bash tests/fm-secondmate-harness.test.sh: exit 0, 56 okbash tests/fm-spawn-dispatch-profile.test.sh: stopped at the background time limit after 71 ok and no failuresLive lab: tmux on the privatefm-labsocket, a disposable mktemp lab, realclaude --settings '{"feedbackDrafts":"off","disableAgentView":true}';/backgroundreturned 'Unknown command';claude agents --jsonreported kind interactive;/exitended the session; lab removed✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.