Skip to content

fix: relaunch missing second mates at session start - #950

Merged
kunchenguid merged 10 commits into
mainfrom
fm/fm-session-start-missing-secondmate-respawn-r1
Jul 24, 2026
Merged

kunchenguid merged 10 commits into
mainfrom
fm/fm-session-start-missing-secondmate-respawn-r1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Fix the session-start guarantee so every registered second mate whose recorded terminal session is authoritatively absent is relaunched automatically. Preserve duplicate prevention for every existing but ambiguous Pi process and every transiently unreadable target, and do not broaden inconclusive liveness into relaunch permission. Keep diagnostics concrete for missing, ambiguous, unreadable, already-live, and failed-relaunch outcomes with one authoritative state contract. Preserve proven bare-shell recovery and Herdr husk behavior, review all supported backend and worker-runtime combinations, add real session-start boundary regressions for absent tmux/Pi, ambiguous existing Pi, unreadability, bare shell, and Herdr where applicable, and run repository lint plus affected tests. The implementation also corrects the test scheduler's Bash job-table probe after the affected broader suite exposed a reproducible process-substitution race.

What Changed

  • Introduce a shared recovery state contract that distinguishes live, dead, missing, ambiguous, unreadable, and unverified second-mate endpoints, relaunching only authoritatively dead or missing sessions with concrete diagnostics.
  • Harden tmux target validation while preserving ambiguous Pi processes and unreadable targets, plus existing bare-shell and Herdr husk recovery behavior.
  • Add end-to-end session-start recovery regressions, align backend documentation, and fix the parallel test runner’s Bash job-table probe.

Risk Assessment

✅ Low: The narrowed tmux/Pi recovery now rejects malformed targets before probing, preserves ambiguous and unreadable states, retains Herdr husk recovery, and keeps Zellij conservatively unverified without introducing a substantiated remaining source risk.

Testing

Inspected the target diff, ran the focused session-start, liveness-classifier, real-tmux, and Bash parallel-scheduler regressions, then captured direct session-start operations and resulting fleet state; everything passed and the worktree remained clean. Per the Local Test rules, repository lint and the complete suite were not run.

Evidence: End-to-end session-start behavior transcript
CASE missing-recorded-session (tmux mode=missing)
diagnostic: (none - successful recovery is non-actionable)
backend operations: new-window -dP -F #{window_id} -t firstmate: -n fm-fmtest-sm-Mvzs5u -c /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-session-start-tests.Mvzs5u/evidence-missing-recorded-session/secondmate-fmtest-sm-Mvzs5u
fleet digest: endpoint: alive (backend=tmux window=firstmate:fm-fmtest-sm-Mvzs5u)
new-window count after second session start: 1

CASE ambiguous-existing-pi (tmux mode=ambiguous)
diagnostic: SECONDMATE_LIVENESS: secondmate fmtest-sm-Mvzs5u: skipped: existing endpoint has ambiguous agent process (backend=tmux)
backend operations: (none)
fleet digest: endpoint: alive (backend=tmux window=firstmate:fm-fmtest-sm-Mvzs5u)

CASE transient-unreadability (tmux mode=unreadable)
diagnostic: SECONDMATE_LIVENESS: secondmate fmtest-sm-Mvzs5u: skipped: endpoint probe unreadable (backend=tmux)
backend operations: (none)
fleet digest: endpoint: dead (backend=tmux window=firstmate:fm-fmtest-sm-Mvzs5u)

CASE bare-shell-recovery (tmux mode=shell)
diagnostic: (none - successful recovery is non-actionable)
backend operations: kill-window -t firstmate:fm-fmtest-sm-Mvzs5u
new-window -dP -F #{window_id} -t firstmate: -n fm-fmtest-sm-Mvzs5u -c /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-session-start-tests.Mvzs5u/evidence-bare-shell-recovery/secondmate-fmtest-sm-Mvzs5u
fleet digest: endpoint: alive (backend=tmux window=firstmate:fm-fmtest-sm-Mvzs5u)

CASE confirmed-herdr-husk
diagnostic: (none - successful recovery is non-actionable)
backend operations: pane close p-old --session default;tab create --workspace ws1 --cwd /private/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/fm-session-start-tests.Mvzs5u/evidence-herdr-husk/secondmate-fmtest-herdr-Mvzs5u --label fm-fmtest-herdr-Mvzs5u --no-focus --session default;pane run p-new export GOTMPDIR=/tmp/fm-fmtest-herdr-Mvzs5u/gotmp --session default;
fleet digest: endpoint: alive (backend=herdr window=default:p-new)
recorded replacement: herdr_pane_id=p-new
Evidence: Focused automated test transcript
FM_TEST_BEGIN 2026-07-24T02:09:37Z tests/fm-session-start.test.sh family=session-bootstrap expected_gate_skip=none
ok - context digest distinguishes ABSENT, empty-but-present, and populated files
ok - a lock refusal prints a loud read-only banner, skips every mutating step, and still completes the digest
ok - digest sections are ordered diagnostics-first, bulk-context-last
ok - session start: configured and auto-detected Herdr homes never require tmux
ok - session start: an absent recorded tmux window relaunches its Pi secondmate exactly once
ok - session start: an existing ambiguous Pi process prevents duplicate recovery
ok - session start: transient tmux unreadability never licenses a relaunch
ok - session start: the proven bare-shell recovery path remains intact
ok - session start: a confirmed Herdr husk is closed and relaunched
ok - status tail is bounded to the configured line count, with the full log path always printed
ok - orphan status logs are printed once with bounded tails
ok - tmux endpoint liveness is reported per task: alive for a live window, dead for a gone one
ok - herdr endpoint liveness is reported per task: alive for a live pane, dead for a gone one
ok - fm-session-start.sh composes the real fm-lock.sh, fm-bootstrap.sh, and fm-wake-drain.sh output verbatim
ok - compatible tasks-axi backlog rendering is compact, bounded, and preserves recovery metadata
ok - manual backlog rendering prints only title lines with hold and blocker metadata
ok - unavailable or incompatible tasks-axi falls back to compact manual backlog rendering
ok - an empty fleet reports (none) for in-flight tasks and an absent AFK flag
ok - session start emits X-mode cadence guidance in the harness supervision block
ok - next step delegates watcher ownership to the AFK daemon
ok - session start emits exactly one detected harness block and reports Pi extension load state
ok - session start rejects stale Pi loaded markers
ok - session start accepts current Pi markers written before lock acquisition
ok - session start rejects Pi sessions missing the turn-end guard marker
ok - session start rejects Pi loaded markers from previous sessions
FM_TEST_END 2026-07-24T02:10:19Z tests/fm-session-start.test.sh exit=0 duration_ms=41620 gate_skip=false
FM_TEST_BEGIN 2026-07-24T02:10:19Z tests/fm-secondmate-liveness.test.sh family=secondmate expected_gate_skip=none
ok - fm_backend_tmux_agent_state: separates live, dead, missing, ambiguous, and unreadable
ok - fm_backend_tmux_agent_state: rejects malformed targets before probing tmux
ok - fm_backend_herdr_agent_state: preserves missing/no-agent/live/unknown husk behavior
ok - fm_backend_agent_state: routes tmux/Herdr and keeps Zellij unverified
ok - sweep: a confirmed-dead secondmate endpoint is killed and respawned
ok - sweep: an already-live secondmate is untouched and distinguishable in verbose diagnostics
ok - sweep: an authoritatively missing Pi secondmate window is relaunched
ok - sweep: an existing ambiguous Pi process prevents duplicate recovery
ok - sweep: transient target unreadability never licenses recovery
ok - sweep: failed relaunch diagnostics distinguish a confidently missing endpoint
ok - sweep: an unverified harness blocks recovery with a concrete diagnostic
ok - sweep: idempotent by construction - a live secondmate is never re-touched on a later run
ok - sweep: skipped entirely under FM_BOOTSTRAP_DETECT_ONLY=1, exactly like the other mutating sweeps
ok - sweep: a silent no-op with no kind=secondmate meta present (a secondmate home's own natural scoping)
# all fm-secondmate-liveness tests passed
FM_TEST_END 2026-07-24T02:10:37Z tests/fm-secondmate-liveness.test.sh exit=0 duration_ms=17884 gate_skip=false
FM_TEST_BEGIN 2026-07-24T02:10:37Z tests/fm-backend-tmux-smoke.test.sh family=backend-dispatch expected_gate_skip=none
@1
ok - real tmux: fm_backend_tmux_create_task creates a window and refuses a duplicate
ok - real tmux: fm_backend_tmux_send_text_line sends literal text and submits with Enter
ok - real tmux: fm_backend_tmux_send_literal + fm_backend_tmux_send_key Enter submit as two separate steps
ok - real tmux: fm_backend_tmux_capture's -S -N bound trims old history for a small window and reaches it for a large one
ok - real tmux: fm_backend_tmux_resolve_bare_selector (list-live) finds the created window by name
ok - real tmux: fm_backend_tmux_resolve_bare_selector fails for a window that does not exist
ok - real tmux: kill removes the window and the readable session inventory authoritatively classifies it missing
FM_TEST_END 2026-07-24T02:10:38Z tests/fm-backend-tmux-smoke.test.sh exit=0 duration_ms=1110 gate_skip=false
FM_TEST_BEGIN 2026-07-24T02:10:38Z tests/fm-test-run.test.sh family=pure-contract-unit expected_gate_skip=none
ok - exact suite coverage: --all lists every tests/*.test.sh once
ok - family selection returns a proper subset of the suite
ok - single-script selection lists exactly that path
ok - changed-file selection stays conservative (never silent full suite)
ok - changed selection covers dependents and fails closed for unmapped source
ok - empty changed selection emits deterministic text and JSON summaries
ok - timing markers and JSON artifact are valid
ok - aggregate exit reflects any script failure
ok - gate-skip accounting is honest and non-failing
ok - fail-on-gate-skip converts herdr-not-found into a hard failure
ok - exclude-family drops the named primary family after selection
ok - CI and CONTRIBUTING call the one-owner runner; no full-suite local Test
ok - portable shard union, disjointness, and coverage guard hold
ok - --jobs refuses non-proven / stateful selections
ok - jobs scheduler runs proven scripts; failure propagates; non-proven refused
ok - aggregate-json merges lane timing artifacts
FM_TEST_END 2026-07-24T02:10:47Z tests/fm-test-run.test.sh exit=0 duration_ms=9059 gate_skip=false
FM_TEST_SUMMARY total=4 failed=0 skipped_gate=0 duration_ms=69815
FM_TEST_SUMMARY_FAMILY family=backend-dispatch count=1 duration_ms=1110 failed=0
FM_TEST_SUMMARY_FAMILY family=pure-contract-unit count=1 duration_ms=9059 failed=0
FM_TEST_SUMMARY_FAMILY family=secondmate count=1 duration_ms=17884 failed=0
FM_TEST_SUMMARY_FAMILY family=session-bootstrap count=1 duration_ms=41620 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-session-start.test.sh duration_ms=41620
FM_TEST_SLOWEST rank=2 script=tests/fm-secondmate-liveness.test.sh duration_ms=17884
FM_TEST_SLOWEST rank=3 script=tests/fm-test-run.test.sh duration_ms=9059
FM_TEST_SLOWEST rank=4 script=tests/fm-backend-tmux-smoke.test.sh duration_ms=1110

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 4 issues found → auto-fixed (6) ✅
  • 🚨 bin/backends/tmux.sh:152 - Required criterion: "every registered second mate whose recorded terminal session is authoritatively absent is relaunched automatically." When the recorded tmux session itself is absent, list-windows fails and this hunk classifies it as unreadable, so bootstrap skips recovery. Distinguish authoritative session absence from other inventory failures at this adapter boundary while preserving fail-closed handling for genuinely unreadable responses.
  • 🚨 bin/fm-backend.sh:721 - Required criterion: "every registered second mate whose recorded terminal session is authoritatively absent is relaunched automatically." Zellij supports --secondmate, but the wildcard always returns unverified, including when the recorded session or pane is conclusively absent, so those second mates remain stopped. Add a conservative Zellij classifier that authorizes recovery only after authoritative absence is established.
  • 🚨 tests/fm-session-start.test.sh - Required criterion: "add real session-start boundary regressions for ... Herdr where applicable." The change adds tmux session-start recovery cases and only unit-level Herdr state mapping; no test drives session start through bootstrap and the real respawn boundary for a missing or husk Herdr second mate. Add that boundary regression so the required Herdr path is source-verifiably covered.
  • 🚨 tests/fm-session-start.test.sh:689 - These new tests create and recursively delete the fixed path /tmp/fm-sm. That path is also the production task-temp location for any live task named sm, so running the suite can destroy unrelated active task data. Use a collision-resistant test task ID and register its exact temp directory with the test cleanup mechanism instead of deleting a generic global path.

🔧 Fix: Isolate session-start recovery test cleanup
3 errors still open:

  • 🚨 bin/backends/tmux.sh:152 - Required criterion: "every registered second mate whose recorded terminal session is authoritatively absent is relaunched automatically." If the recorded tmux session itself is absent, list-windows fails and this branch returns unreadable, so bootstrap still skips recovery. Distinguish a confirmed missing session from other inventory failures at this adapter boundary.
  • 🚨 bin/fm-backend.sh:721 - Required criterion: "every registered second mate whose recorded terminal session is authoritatively absent is relaunched automatically." Zellij supports second-mate launches, but this wildcard returns unverified even when its recorded session or pane is conclusively absent. Add a conservative Zellij classifier that authorizes recovery only for authoritative absence.
  • 🚨 tests/fm-session-start.test.sh - Required criterion: "add real session-start boundary regressions for ... Herdr where applicable." The suite still has only unit-level Herdr state mapping and generic session-start diagnostics/liveness checks. No regression drives a missing or husk Herdr second mate through session start, bootstrap, and respawn.

🔧 Fix: Complete backend-safe secondmate session recovery
1 error still open:

  • 🚨 bin/backends/zellij.sh:408 - Required criteria: "every registered second mate whose recorded terminal session is authoritatively absent is relaunched automatically" and concrete diagnostics for "ambiguous" outcomes. This early return trusts a numeric pane ID anywhere in the session without checking its recorded tab or task label. After a session recreation, another tab can reuse that pane ID while the second mate's recorded tab is absent, causing unverified and permanently skipping recovery. Even when the pane is genuinely the recorded one, an existing terminal whose process cannot be attributed matches the shared ambiguous definition, not unverified. Verify tab/label ownership before returning, then classify a matching existing pane as ambiguous and continue structural absence checks for stale ID reuse.

🔧 Fix: Resolve Zellij task ownership before recovery
1 error still open:

  • 🚨 bin/backends/zellij.sh:449 - Required criterion: "every registered second mate whose recorded terminal session is authoritatively absent is relaunched automatically." When the task label resolves uniquely to a different tab ID, this branch returns ambiguous before checking whether that tab contains any terminal pane. A relocated empty Zellij ghost is therefore skipped indefinitely even though the readable pane inventory proves the task terminal is absent. Check terminal presence on the resolved task tab first, and ensure cleanup closes that resolved label-owned tab before relaunch.

🔧 Fix: Recover relocated Zellij ghost tabs safely
2 errors still open:

  • 🚨 bin/backends/zellij.sh:614 - Required criterion: "Preserve duplicate prevention for ... every transiently unreadable target, and do not broaden inconclusive liveness into relaunch permission." If this new list-tabs read fails or returns malformed data after the earlier dead classification, kill silently resolves no tab and still returns success; bootstrap then relaunches, while create_task also treats an unreadable tab inventory as containing no duplicate. Require a verified close or a fresh missing state before spawning so transient unreadability cannot leave duplicate task tabs or processes.
  • 🚨 bin/backends/zellij.sh:433 - Required criteria include preserving unreadable outcomes and authorizing relaunch only for authoritative absence. The classifier validates only that inventories are arrays; a valid JSON array containing incomplete or schema-incompatible tab objects is interpreted as missing, while malformed pane objects are ignored and can yield dead. Validate the required tab and pane fields before absence checks, returning unreadable when the inventory shape cannot prove absence.

🔧 Fix: Restore conservative Zellij recovery boundary
1 error still open:

  • 🚨 bin/backends/tmux.sh:152 - Required criterion: "do not broaden inconclusive liveness into relaunch permission." This condition merely skips inventory validation when the recorded target has an empty session/window or no colon; tmux then interprets targets such as sess: as the session's current window. If that unrelated pane is a shell, it is classified dead, killed, and replaced. Reject malformed tmux targets as unreadable before issuing any tmux command.

🔧 Fix: Reject malformed tmux recovery targets
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bin/fm-test-run.sh tests/fm-session-start.test.sh tests/fm-secondmate-liveness.test.sh tests/fm-backend-tmux-smoke.test.sh tests/fm-test-run.test.sh
  • Manual evidence run of real bin/fm-session-start.sh through the repository fixtures for missing tmux/Pi, ambiguous Pi, unreadable tmux, bare-shell recovery, and Herdr husk recovery
  • git status --short after testing to confirm the worktree remained clean
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid
kunchenguid merged commit f017572 into main Jul 24, 2026
10 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-session-start-missing-secondmate-respawn-r1 branch July 24, 2026 03:26
LoneExile pushed a commit to LoneExile/firstmate that referenced this pull request Jul 24, 2026
* fix(session-start): relaunch missing second mates

* fix(test): detect completed parallel workers

* no-mistakes(review): Isolate session-start recovery test cleanup

* no-mistakes(review): Complete backend-safe secondmate session recovery

* no-mistakes(review): Resolve Zellij task ownership before recovery

* no-mistakes(review): Recover relocated Zellij ghost tabs safely

* no-mistakes(review): Restore conservative Zellij recovery boundary

* no-mistakes(review): Reject malformed tmux recovery targets

* no-mistakes(document): Align secondmate recovery documentation

* no-mistakes: apply CI fixes

(cherry picked from commit f017572)
omp-adapt: verified-harness=omp in session-start tests; fake tmux list-windows emits meta windows for kunchenguid#950 inventory check
LoneExile added a commit to LoneExile/firstmate that referenced this pull request Jul 24, 2026
… watcher missing->dead)

Two gaps flagged in the kunchenguid#950 self-review, now covered:

- fm-session-start: test_session_start_leaves_live_herdr_secondmate_untouched
  proves the session-start sweep leaves a LIVE herdr secondmate untouched
  (no pane close, no relaunch) - the herdr-default sweep-level alive->untouched
  coverage the dropped tmux positive-alive test could not express. Non-vacuous:
  neutering the live-agent fake path makes the sweep respawn -> assertions fail.

- fm-watch-triage: test_captain_held_bounded_recheck_via_missing_endpoint proves
  the watcher consumes kunchenguid#950's new missing->dead semantics: an authoritatively
  MISSING tmux endpoint (window omitted from a readable list-windows inventory)
  reads dead via fm_backend_agent_alive and drives the bounded paused recheck.
  Non-vacuous: neutering the shim's missing->dead mapping to unknown makes the
  bounded recheck vanish (bare stale wake instead) -> assertion fails.

Both files bash -n + fm-lint clean (rc=0).
ItsFlow referenced this pull request in ItsFlow/firstmate Jul 26, 2026
* fix: block primary-session delegation outside the fleet (#854)

* feat: fence primary-session delegation outside the fleet

A firstmate primary that delegates through Claude Code's built-in
delegation tools creates work with no state/<id>.meta. Because
fm-supervision-lib.sh counts *.meta and fm-turnend-guard.sh exits
silently at zero, such work does not merely go unsupervised: it makes
the whole guard stack structurally inert, and it dies with the primary
session. On 2026-07-22 that cost two workers mid-flight and left
supervision down for 73 minutes unnoticed.

Layer 1, the primary fix: a permissions.deny list in
.claude/settings.json removes the 18 delegation, scheduling, worktree,
and task-tracking tools from the model's schema, so they are never
offered. This is removal rather than interception, so there is no call
to intercept and no fail-open path. The list is flat and in one file so
its width stays reviewable; the captain owns that width.

Layer 2, bin/fm-subagent-pretool-check.sh: a deny list is fail-open
against tools that do not exist yet, and permissions.allow is a
pre-approval list rather than an availability list, so there is no
fail-closed allowlist to use instead. This backstop classifies the tool
NAME by shape rather than against a fixed list, so a delegation tool
that ships before the deny list is updated is still refused. It excludes
mcp__* names and observe-or-stop operations, scopes itself to a genuine
primary home via the shared fm_primary_scope_matches predicate so a
crewmate's task worktree is unaffected, and offers one deliberate
FM_ALLOW_SUBAGENT=1 escape hatch that must be set at launch.

Verified live against Claude Code 2.1.217, including a deny-key A/B with
a nonsense-name control, layer 2 denying an un-denied Workflow call, the
same call allowed in a linked worktree, and the escape hatch. Corrects a
prior finding: both Task and Agent work as deny keys, so both are
pinned. Codex 0.144.1 verified to expose no delegation tool; grok,
opencode, and pi are inspected and documented as not wired because those
binaries are absent from this host and the repo requires live validation
before trusting a harness hook. Evidence in docs/subagent-guard.md.

* no-mistakes(review): Ship scoped Claude delegation guard

* no-mistakes(test): Ship Claude delegation deny list

* no-mistakes(document): Clarify PreToolUse guard ownership

* no-mistakes(lint): Keep Claude deny list local

* fix: install tasks-axi in portable CI shards (#866)

Reproduction: portable-parallel-2 completed successfully without tasks-axi while fm-decision-hold-lifecycle emitted a gate skip in 30 ms. The pre-shard lane installed tasks-axi and exercised the test fully. Installing tasks-axi is the smallest counterfactual and makes the representative shard execute the test with gate_skip=false in about 20 seconds. Both parallel jobs receive symmetric setup, while the exact 91-test inventory and coverage guard remain unchanged.

* feat(bin): make dispatch profiles quota aware (#867)

* feat: make dispatch profiles quota aware

* no-mistakes(review): Fix quota window and Grok product scoping

* no-mistakes(document): Document implicit quota-aware dispatch accurately

* Add built-in ahoy recap skill (#873)

* fix: preserve trustworthy Bearings data in partial snapshots (#875)

* fix: preserve mixed Bearings projections

* no-mistakes(review): Enforce strict invalidity precedence for partial snapshots

* no-mistakes(review): Enforce ownership for unknown child metadata

* no-mistakes(document): Document partial structured Bearings projections

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* feat(pi): add session-local calm mode (#884)

* Add session-local Pi calm mode

* no-mistakes(review): Preserve Pi HTML exports during calm mode

* no-mistakes(review): Preserve calm exports across submit bindings and share

* no-mistakes(document): Document calm-mode feasibility across supported harnesses

* fix(pi): prevent redundant watcher re-arms (#885)

* fix(pi): limit watcher arm tool to recovery

* no-mistakes(review): Strengthen Pi live re-arm regression coverage

* no-mistakes(document): Document Pi first-cycle and recovery-only watcher arming

* fix(pi): clean up Calm transcript rendering (#895)

* fix(pi): clean up Calm transcript rendering

* no-mistakes(review): Captain, preserve Calm exports and classify Pi launch briefs

* no-mistakes(review): Captain, eliminate Calm gaps and verify exported conversations

* no-mistakes(review): Restore Calm rows received while active

* no-mistakes(review): Preserve diagnostics during Calm restoration

* no-mistakes(document): Clarify Calm transcript behavior and injection paths

* fix: execute every PR body compliance event (#898)

* fix: execute every PR body compliance event

* no-mistakes(document): Document independent PR compliance events

* fix: exclude operational injections from ahoy boundaries (#899)

* fix: distinguish operational input in ahoy

* no-mistakes(review): Handle legacy Ahoy operational boundaries

* no-mistakes(review): Narrow legacy Ahoy boundaries with live regressions

* no-mistakes(document): Document Ahoy operational marker ownership

* no-mistakes(lint): Suppress intentional literal fixture lint warnings

* fix: canonically classify operational inputs across harnesses (#909)

* fix: type canonical operational inputs

* no-mistakes(document): Correct canonical operational-input documentation ownership

* fix: avoid generic secondmate start acknowledgements (#926)

* fix: avoid generic secondmate acknowledgements

* no-mistakes(document): Document sparse secondmate acknowledgement behavior

* no-mistakes: apply CI fixes

* fix(pi): make calm mode persistent and gapless (#927)

* fix(pi): preserve calm presentation across sessions

* no-mistakes(review): Fix Calm home fallback persistence

* no-mistakes(document): Clarify Calm gapless and export contracts

* no-mistakes: apply CI fixes

* fix(watch): retire merged PR polls after durable notification (#932)

* fix: retire merged PR polls after notification

* no-mistakes(review): Decouple PR retirement recovery from template updates

* no-mistakes(review): Recover pending PR retirements before poll migration

* no-mistakes(document): Document merged PR poll retirement contracts

* fix: refine scout intake and parallel dispatch (#934)

* Clarify intake evidence and overlap handling

* no-mistakes(review): Align scout guard with intake classification

* no-mistakes(document): Clarify scout documentation and intake ownership

* fix(pi): prevent duplicate assistant replies in Calm (#936)

* fix(pi): preserve operational follow-up semantics in Calm

* no-mistakes(document): Correct Calm operational-row visibility documentation

* perf(bin): shrink the ShellCheck source graph (#939)

* perf(lint): shrink shell source graph

* no-mistakes(review): Ensure lint workers terminate fully on cancellation

* no-mistakes(document): Repair stale lint documentation ownership

* fix(pi): remove Calm hidden-block gaps (#942)

* fix(pi): remove Calm hidden-block gaps

* no-mistakes(review): Validate Calm geometry against current viewport

* no-mistakes(review): Synchronize Calm geometry checks with reload completion

* fix: enforce contract boundaries for ask-user findings (#945)

* fix: escalate ask-user contract expansion

* no-mistakes(document): Point project management to authority owner

* docs: prefer direct operational paths (#946)

* fix(pi): hide operational user rows in Calm mode (#948)

* fix(pi): hide Calm operational user rows

* no-mistakes(review): Narrow Calm operational input suppression

* no-mistakes(review): Avoid Calm replay classifier subprocesses

* no-mistakes(document): docs: point Pi verification to Calm owner

* fix: relaunch missing second mates at session start (#950)

* fix(session-start): relaunch missing second mates

* fix(test): detect completed parallel workers

* no-mistakes(review): Isolate session-start recovery test cleanup

* no-mistakes(review): Complete backend-safe secondmate session recovery

* no-mistakes(review): Resolve Zellij task ownership before recovery

* no-mistakes(review): Recover relocated Zellij ghost tabs safely

* no-mistakes(review): Restore conservative Zellij recovery boundary

* no-mistakes(review): Reject malformed tmux recovery targets

* no-mistakes(document): Align secondmate recovery documentation

* no-mistakes: apply CI fixes

* fix(herdr): reclaim resumed task projections after restart (#967)

* fix(herdr): reclaim resumed task projections safely

* no-mistakes(review): Enforce safe Herdr reclaim close boundaries

* no-mistakes(document): docs: clarify Herdr restart projection contract

* Teach Ahoy to surface open decisions (#968)

* Require shipshape routine acknowledgement (#969)

* docs: separate current guidance from verification evidence (#994)

* docs: separate current guides from verification

* no-mistakes(review): Restore Herdr 0.7.5 restart-reclaim verification evidence

* fix: preserve Claude watcher continuity across Stop hooks (#997)

* feat(claude): Stop-owned tokenless watcher continuity via asyncRewake auto-arm

Claude primaries (main home and marked secondmate homes) no longer depend
on the model remembering to re-arm the watcher after each wake. A tracked
Stop asyncRewake hook (bin/fm-claude-stop-autoarm.sh, timeout 28800s)
fires on every turn end, claims one home-scoped single-flight owner,
foregrounds bin/fm-watch-arm.sh inside the hook-owned process tree, and
translates an actionable close or typed watcher failure into exactly one
exit-2 rewake. The hook scopes to genuine primary checkouts, requires the
session lock to be held by its own harness ancestor, stays inert while
AFK owns triage or the home is idle, and hands AFK transitions mid-cycle
to the daemon without rewaking.

The synchronous turn-end guard gains a --claude cooperative mode: it
ignores stop_hook_active (true on every post-continuation stop, which is
what re-opened the 2026-07-21 blind window), waits briefly for a watcher
health proof, a live auto-arm owner claim, or a fresh rewake epoch, and
re-blocks only when the auto-arm genuinely failed to establish - bounded
to 3 consecutive blocks per session, safely below Claude Code's 8-block
override, then a degraded allow with a visible systemMessage. Codex
keeps the previous one-block loop guard byte-identically, and Pi,
OpenCode, and Grok adapters are untouched.

Continuity PreToolUse gate and durable wake queue are preserved; the
gate's recovery guidance now names the Stop-owned re-arm and reserves
manual background arms for auto-arm failure. Claude supervision protocol,
harness-adapters facts, architecture, configuration, and continuity docs
updated; docs/turnend-guard.md records the 2026-07-24 Claude 2.1.218
contract revalidation (tokenless multi-cycle rewake, no-dedup, timeout
process-group kill, 8-block cap, interactive non-stall) and the 2.1.219
product live E2Es.

Regression matrix: hermetic tests cover scope, identity, AFK, need,
single-flight, translation, guard cooperation, budget, and registration;
the new live E2E proves two full tokenless auto-arm rewake cycles with
zero model arm commands; Pi and OpenCode Option B live E2Es pass
unchanged.

* no-mistakes(review): Fix Claude X-mode auto-arm continuity backstop

* no-mistakes(review): Remove unsupported Claude contract-lab verification claims

* no-mistakes(document): Update Claude auto-arm continuity documentation

* fix(herdr): clean stale projections at session start (#996)

* Clean stale Herdr projections at session start

* no-mistakes(document): Document stale Herdr session-start projection cleanup

* no-mistakes(review): Enforce locked exact Herdr projection cleanup

* no-mistakes(review): Fail closed on unverified session lock ownership

* no-mistakes(review): Serialize session lock acquisition atomically

* no-mistakes(document): Align session-start and Herdr cleanup documentation

* no-mistakes(document): Generalize lock-refusal diagnostics

* no-mistakes(lint): Avoid reserved keyword in concurrency test

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* feat(inbox): add the captain's decision and review board generator

bin/fm-inbox-view.sh writes one self-contained HTML board from live fleet
state, so every open captain decision, review-ready pull request and stopped
task is answerable from a single surface instead of arriving one chat
interrupt at a time.

It is a read-only projection in the same shape as fm-fleet-view.sh: it shells
out to fm-fleet-snapshot.sh --json and `tasks-axi show --full`, and writes
nothing but the board file. A test proves state/ and data/ stay byte-identical
across a generation.

Three selection defects the existing aggregated surface has are fixed here.
Decisions are selected on the captain hold alone, because the snapshot's own
captain_actionable flag also requires kind == "captain" and therefore hides
every thread gated with `tasks-axi hold --kind captain`, which is where the
oldest waiting decisions live.
Decision text is read through tasks-axi, because the snapshot's metadata
capture stops at the first comma and silently drops the options from any hold
reason that lists them.
A recorded pull request renders as unverified unless --verify-prs live-checks
it, because locally recorded metadata cannot know a pull request was closed
and a closed one must never read as ready to merge.

Decision cards lead with plain English. An optional captain-private cards file
supplies the plain question, what the captain is actually choosing, where it
came from, firstmate's recommendation, a link to research a product or
service, and a collapsed technical section. An item that is firstmate's own
assumption rather than a choice the captain made is flagged as one. A decision
with no card still renders and says so rather than looking complete.

Answers use the Lavish input contract: native radios plus a free-text note,
with exactly one queued prompt per question on submit. This change delivers
the surface only; regenerating on a cadence, relaying answers back, and any
escalation-routing change remain separate captain decisions.

* feat(inbox): free-form answers, discuss path, reliable delivery, overflow fix

Fold in the captain's hard requirements from live use of the board.

Free-form answers are now first-class. A card's predefined options are
optional quick-picks with a clear-selection reset; the answer submits with
just free text and no option selected. Previously the submit required picking
an offered option, so a genuine free-form answer could not be sent at all.

Each card gains a discuss path that sends a question back (DISCUSS <id>: ...)
instead of an answer (DECISION <id>: ...), so a decision can be clarified
rather than forced.

Delivery is made reliable end to end. bin/fm-inbox-serve.sh is one operator
command that regenerates the board, arms the answer relay, serves it on the
Tailscale address, and verifies the link. bin/fm-inbox-arm.sh writes and
registers state/inbox.check.sh, a bounded lavish poll bound by
fm-check-register, so firstmate's supervision cycle relays answers on its
normal check cadence without anyone remembering to poll. The relay fails
closed: when the board is not served the poll errors fast and it stays silent.
Submitting also sends immediately with a visible confirmation, closing the
window where an answer looked silently eaten.

Long titles and ids now wrap instead of overflowing horizontally, which
Lavish's own layout audit flags as an error. No-project items get readable
area names derived from their origin or id instead of a generic badge.

Behavior is covered by tests/fm-inbox-view.test.sh (generator, read-only,
free-form, discuss, immediate send, area names, wrapping) and
tests/fm-inbox-arm.test.sh (the relay is a valid registered fail-closed
check, silent while unserved, rejected after tampering). docs/inbox-board.md
records the design and verification evidence.

* no-mistakes(review): Fix inbox relay safety and PR verification

* no-mistakes(review): Gate inbox relay before polling

* no-mistakes(document): Align inbox board docs

* no-mistakes: apply CI fixes

---------

Co-authored-by: Kun Chen <[email protected]>
rega10 added a commit to rega10/firstmate that referenced this pull request Jul 27, 2026