Skip to content

fix(afk): make Pi escalation and return catch-up reliable - #587

Merged
kunchenguid merged 4 commits into
mainfrom
fm/fm-afk-catchup-blocker-f7
Jul 15, 2026
Merged

kunchenguid merged 4 commits into
mainfrom
fm/fm-afk-catchup-blocker-f7

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Investigate and fix the exact 2026-07-14 Pi-on-Herdr away-mode two-owner supervision gap. Reproduce why a genuinely idle Pi pane was left uninjected for 4555 seconds, make wedge prevention primary by recognizing only a provably safe Pi composer, preserve refusal for busy, pending-input, unreadable, incomplete, non-Pi, over-tall, and ambiguous states, and retain the existing observable alarm as defense in depth. Preserve composer safety, submit verification, durable transport-safe markers, dedupe, target resolution, and permissions. Enforce deterministic unmarked-return catch-up before ordinary captain work, assign open blocked keys to Firstmate and decisions to the captain, prevent away-mode re-entry until remediation or explicit durable reclassification, and keep Bearings read-mostly with structured blocker projection. Add causal unit, tmux and Herdr parity, restart, re-entry, dedupe, no-forced-submit, catch-up precedence, remediation ownership, and real Pi/Herdr end-to-end regressions plus privacy-safe incident documentation. Validate and open a PR, but do not merge it.

What Changed

  • Recognize genuinely idle Pi composers on Herdr using native agent identity and bounded separator structure, while failing closed for unsafe or ambiguous states.
  • Add a durable away-mode return gate that drains catch-up evidence and blocks ordinary work or re-entry until actionable blockers are resolved or explicitly reclassified.
  • Replace terminal-unsafe control-byte markers with U+2063 and add unit, tmux, Herdr parity, restart, dedupe, and real Pi/Herdr end-to-end regressions.

Risk Assessment

✅ Low: The follow-up fixes both prior findings, and the cumulative change preserves fail-closed lifecycle, composer refusal, marker, dedupe, and blocker-ownership invariants without additional material issues found.

Testing

The full configured baseline passed, focused Herdr and return-gate regressions passed, and real Pi 0.80.7 on Herdr 0.7.3 demonstrated safe pending-draft refusal, one observable alarm, one terminal-safe marked injection, catch-up before Bearings, remediation, dedupe, and clean away-mode re-entry end to end.

Evidence: Real Pi/Herdr away-return E2E transcript

Real Pi 0.80.7 / Herdr 0.7.3 transcript demonstrating pending-draft refusal, one marked injection, catch-up gating, remediation, and clean re-entry.

fm-afk-launch: daemon launched in non-visible herdr workspace w2 (pane fm-lab-fm-afk-pi-return-e2e-49702-9761:w2:p1), supervising fm-lab-fm-afk-pi-return-e2e-49702-9761:w1:p1
ok - real Pi/Herdr pending composer refuses injection without forced submit and raises one observable fallback
ok - real idle Pi/Herdr accepts one marked escalation promptly, verifies submit, clears wedge state, and emits no duplicate alert
ok - real unmarked Pi return opens catch-up and blocks Bearings before the unresolved blocker can be deferred
fm-afk-launch: daemon launched in non-visible herdr workspace w3 (pane fm-lab-fm-afk-pi-return-e2e-49702-9761:w3:p1), supervising fm-lab-fm-afk-pi-return-e2e-49702-9761:w1:p1
fm-afk-launch: away mode stopped; daemon terminal torn down and .afk cleared
ok - resolved return catch-up allows Bearings and a clean idempotent away re-entry
evidence: herdr=herdr 0.7.3 pi=0.80.7 target=fm-lab-fm-afk-pi-return-e2e-49702-9761:w1:p1 inject-hex-prefix=e281a3 notifier-count=1
- Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (48m45s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed ✅
  • 🚨 bin/fm-afk-return.sh:154 - The required "deterministic unmarked-return catch-up before ordinary captain work" can fail open after terminal teardown fails. begin records the failure, but fm-afk-launch.sh stop still removes .afk; a subsequent check only tests .afk, ignores the surviving .afk-daemon-terminal record, and can clear the gate. Retry or reconcile recorded teardown during check, and keep the gate until it succeeds.
  • 🚨 tests/fm-afk-inject-e2e.test.sh:351 - The required dedupe regression still searches for two legacy \x1f markers even though this change switches injections to U+2063. Because grep -c 'Supervisor escalate' counts lines rather than occurrences, a line containing two concatenated U+2063 digests would pass. Update this assertion and the equivalent Herdr assertions to inspect the new marker.

🔧 Fix: Gate teardown retries and verify U+2063 dedupe
✅ Re-checked - no issues remain.

🔧 **Test** - 1 issue found → auto-fixed ✅
  • 🚨 bin/backends/herdr.sh:847 - Captain, the required fail-closed handling for incomplete Pi composers is violated. The Pi-specific override runs only when a complete separator pair is found. With an incomplete lower Pi separator beneath a stale empty bordered transcript row, the stale generic row remains authoritative and fm_backend_herdr_composer_state returns empty, making the malformed pane eligible for injection. The direct probe produced incomplete-pair-with-stale-empty-border=empty; this must remain unknown. Add explicit incomplete/ambiguous lower-separator invalidation and a causal regression covering stale generic content above the incomplete Pi composer.
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • Supplied baseline: command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • for t in tests/fm-backend-herdr.test.sh tests/fm-daemon.test.sh tests/fm-pi-watch-extension.test.sh tests/fm-afk-inject-e2e.test.sh tests/fm-afk-inject-herdr-e2e.test.sh tests/fm-afk-return.test.sh tests/fm-bearings-snapshot.test.sh; do bash "$t" || exit 1; done
  • FM_AFK_PI_HERDR_E2E=1 bash tests/fm-afk-pi-herdr-return-e2e.test.sh using Herdr 0.7.3 and Pi 0.80.7
  • Direct malformed-capture probe sourcing bin/backends/herdr.sh with a stale empty bordered row followed by an incomplete Pi separator; observed fm_backend_herdr_composer_state lab:w1:p2 return empty
  • Inspected the privacy-safe incident account in docs/herdr-backend.md and confirmed the worktree remained clean with git status --short

🔧 Fix: Fail closed on incomplete Pi composer separators
✅ Re-checked - no issues remain.

  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc" (successful pre-run baseline)
  • bash tests/fm-backend-herdr.test.sh
  • bash tests/fm-afk-return.test.sh
  • FM_AFK_PI_HERDR_E2E=1 bash tests/fm-afk-pi-herdr-return-e2e.test.sh 2>&1 | tee /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KXHN72932JAZXS22YN3MWNP4/pi-herdr-away-return-e2e.txt
  • bash tests/fm-afk-inject-e2e.test.sh
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid
kunchenguid merged commit 1811b89 into main Jul 15, 2026
5 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-afk-catchup-blocker-f7 branch July 15, 2026 03:02
sourabhshah9881 added a commit to sourabhshah9881/firstmate that referenced this pull request Jul 15, 2026
* fix: restore fleet snapshots on stock macOS Bash (kunchenguid#578)

* fix: restore stock macOS snapshot parsing

* no-mistakes(document): Clarify Linux gate and macOS CI coverage

* fix(afk): make Pi escalation and return catch-up reliable (kunchenguid#587)

* fix: close away-mode blocker supervision gap

* no-mistakes(review): Gate teardown retries and verify U+2063 dedupe

* no-mistakes(test): Fail closed on incomplete Pi composer separators

* no-mistakes(document): Document Pi composer recognition and return gating

* feat: support Pi max reasoning profiles (kunchenguid#537)

* support Pi max thinking profiles

* no-mistakes(review): Captain, allow Pi max dispatch profiles

* feat: add /observe skill for watching a running project

Adds a captain-invocable /observe skill: list which projects have a live
process, pick one, sample its log on the watcher's own check cadence, and act
on what it shows.

Design: observation rides the existing per-task check contract rather than a
foreground follow. fm-observe.sh arm writes state/observe-<project>.check.sh,
which prints ONE line iff firstmate should wake and nothing otherwise, so a
well-behaved project costs zero tokens and supervision is never blocked. An
armed session keeps the watcher relevant with an empty fleet, like X mode.
Follow-style sources (tail -f, docker logs -f) are refused at arm time, and a
cmd: source is bounded by a timeout, so a source can never hold a check open.

Findings are judged against the constraints the project's own code declares
(data/observe-<project>/constraints.md), which is what turns this from a log
tail into discrepancy detection. The skill's decision rule is explicit:
auto-dispatch a crewmate to ship a PR fix (the first-class path), escalate a
captain-owned call, or absorb noise. Firstmate never writes to the project and
never starts or stops its process; the crewmate does every write in its own
worktree behind no-mistakes.

Discovery is generic (a live process whose cwd is under projects/<name>, plus
any port it owns), not project-specific. Verified against a real fleet, which
caught two false positives now covered by tests: a login shell (argv[0] is
"-zsh") and firstmate's own toolbelt sitting in a clone both read as a running
project.

* no-mistakes(review): fix observe poll hang, cursor replay, lost crash window, cadence

* no-mistakes(review): fix check-sweep starvation, wire observation into supervision

* no-mistakes(review): fix observe cursor drops, per-check intervals, wake suppression

* no-mistakes(review): fix observe wake suppression, cmd cursor, released-session accounting

* no-mistakes(review): exempt event lines from digit suppression, fix ledger and stamp

* no-mistakes(review): unify observe line-key normalization, align payload with wake

* no-mistakes(review): collapse hex ids before digit runs in observe line keys

* no-mistakes(test): decouple herdr, shellcheck, coreutils tests from environment

* no-mistakes(test): guard opencode turn-end guard stdin against EPIPE crash

* no-mistakes(document): sync docs with observe sessions and supervised-work guards

* fix: make the check-sweep test executable so CI can run it

* no-mistakes(review): rediscover pids before stop, validate observe patterns, stamp ledger after wake

* no-mistakes(review): confirm observe stops over a grace window, commit cursor after wake

* no-mistakes(review): validate combined observe pattern, self-heal stop teardown

* no-mistakes(document): align guard, drain, and check-cadence docs with observation sessions

* no-mistakes(document): align grok turn-end guard fallback wording with supervised work

* no-mistakes(review): clip file: observe windows on whole lines, self-clean orphaned poll shims

* no-mistakes(review): harden observe discovery: interpreter argv0, arm --all, fewer forks

* no-mistakes(review): clip observe file windows on whole lines at both ends; exclude self from discovery

* no-mistakes(review): pin observe --all re-discovery to armed command subjects; atomic arm write

* no-mistakes(review): derive observe arm pids and subjects from one process snapshot

---------

Co-authored-by: Kun Chen <[email protected]>
Co-authored-by: Korallis <[email protected]>
curtis-arch added a commit to curtis-arch/firstmate that referenced this pull request Jul 15, 2026
* fix: preserve secondmate routing markers in terminal sends (kunchenguid#533)

* fix: preserve secondmate routing markers

* no-mistakes(review): Captain, preserve trailing newlines in marked secondmate sends

* no-mistakes(test): Captain, tolerate bootstrap timeout elapsed drift

* no-mistakes(document): Refresh Herdr marker documentation

* fix: align Grok effort handling with 0.2.99 (kunchenguid#527)

* fix: align grok effort docs and spawn with 0.2.99 ceiling

grok 0.2.99 accepts only low|medium|high for --reasoning-effort and
rejects both xhigh and max. Omit unsupported values on spawn, flag them
in crew-dispatch validation, and update harness-adapters.

* no-mistakes(test): Captain: refresh gotmp teardown fixture dependencies

* no-mistakes(document): Clarify Grok effort documentation ownership

* fix: derive bearings from authoritative secondmate state (kunchenguid#555)

* fix: make bearings use secondmate home state

* test: anonymize bearings fixtures

* no-mistakes(review): Bound parent activity evidence scans, captain

* no-mistakes(review): Preserve structured secondmate authority and bounds, captain

* no-mistakes(review): Preserve registry completeness and child inventory, captain

* no-mistakes(review): Reconcile parent evidence by verb and key, captain

* no-mistakes(review): Treat unkeyed parent evidence as inconclusive, captain

* no-mistakes(document): Document bearings local snapshot and PR opt-in

* no-mistakes(lint): Fix fleet snapshot ShellCheck findings

* no-mistakes: apply CI fixes

* test(orca): pin conservative liveness baseline (rider P1)

* docs(orca): record unavailable E1 observation (rider P2)

* docs(orca): refuse ambiguous semantic mapping (rider P3)

* docs(orca): record deferred liveness milestone (rider P11)

* docs(orca): record actual E1 scout refusal (rider P11)

* test(orca): tie E1 gates to runtime evidence (rider P3)

* feat(orca): add semantic agent liveness

* feat(orca): recover reminted terminal handles

* no-mistakes(review): Fix Orca liveness and durable recovery edge cases

* no-mistakes(review): Serialize metadata updates and harden Orca recovery CAS

* no-mistakes(review): Harden task metadata lifecycle against reuse races

* no-mistakes(review): Harden metadata lifecycle across task generations

* no-mistakes(review): Harden resumable teardown and Orca metadata lookup

* fix: restore fleet snapshots on stock macOS Bash (kunchenguid#578)

* fix: restore stock macOS snapshot parsing

* no-mistakes(document): Clarify Linux gate and macOS CI coverage

* fix(afk): make Pi escalation and return catch-up reliable (kunchenguid#587)

* fix: close away-mode blocker supervision gap

* no-mistakes(review): Gate teardown retries and verify U+2063 dedupe

* no-mistakes(test): Fail closed on incomplete Pi composer separators

* no-mistakes(document): Document Pi composer recognition and return gating

* feat: support Pi max reasoning profiles (kunchenguid#537)

* support Pi max thinking profiles

* no-mistakes(review): Captain, allow Pi max dispatch profiles

* chore: no-mistakes(document): Clarify yolo response ownership (kunchenguid#595)

* Clarify validation response ownership

* no-mistakes(document): Clarify yolo response ownership

* test(teardown): complete gotmp fixture dependencies

* docs(orca): clarify metadata and liveness contracts

* fix(shell): clear integration lint warnings

* feat: supervise Orca attention states

* fix: detect external Orca worktree destruction

* feat(orca): add bounded team teardown guard

* Revert "feat(orca): add bounded team teardown guard"

This reverts commit 38c21e1.

* feat(orca): team-pane primitives - CAS meta contract, fail-closed pane resolution, per-pane inventory state

* feat(orca): fm-team.sh - explicit shared-worktree team contract (add/status/close, coordinator-only edit policy)

* feat(orca): teardown enumerates and closes recorded team panes fail-closed before worktree removal

* fix(orca): secondmate refusal names the exact missing adopt-existing-directory primitive

* test(orca): team foundation fixtures from observed 1.4.141 shapes; document the team contract and refusal boundary

* fix(teardown): prevalidate forced secondmate cleanup

* test(shell): silence fixture lint false positives

* fix(spawn): make secondmate replacement fail closed

* no-mistakes(review): Harden replacement and teardown lifecycle ownership

* no-mistakes(review): Harden replacement and teardown lifecycle ownership

* fix(teardown): use arithmetic array index syntax

---------

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