Skip to content

fix: discover safe herdr AFK supervisor targets - #337

Closed
NumberedThought wants to merge 5 commits into
kunchenguid:mainfrom
NumberedThought:fix/herdr-afk-supervisor-discovery
Closed

NumberedThought wants to merge 5 commits into
kunchenguid:mainfrom
NumberedThought:fix/herdr-afk-supervisor-discovery

Conversation

@NumberedThought

Copy link
Copy Markdown

Intent

Fix away-mode supervision so the AFK sub-supervisor can adapt to a herdr primary pane when this API/tool shell lacks HERDR_ENV and HERDR_PANE_ID. Preserve explicit FM_SUPERVISOR_BACKEND and FM_SUPERVISOR_TARGET override precedence, keep direct herdr env target composition and tmux behavior intact, discover a safe firstmate-home Codex pane from herdr agent list when no env markers survived, reject crewmate project/treehouse worktree panes, and fail loudly rather than silently falling back to tmux firstmate:0 in an active herdr fleet with no safe primary. Add focused tests for explicit overrides, direct herdr env, herdr agent-list discovery, crewmate rejection, and the no-safe-primary failure path, and update only the AFK skill contract text that owns this behavior.

What Changed

  • Adjusted AFK supervisor target selection so herdr fleets can discover a safe firstmate-home primary pane from herdr agent metadata when shell env markers are missing, while refusing crewmate/project worktree panes.
  • Preserved explicit supervisor backend and target overrides, including explicit tmux fallback behavior, and kept direct herdr environment target composition intact.
  • Expanded daemon and session-start tests around herdr discovery, rejection/failure paths, override precedence, and the missing-tool fixture; refreshed the AFK/herdr documentation contract.

Risk Assessment

✅ Low: Captain, the change is narrowly scoped, preserves the explicit tmux override after the follow-up fix, and adds focused coverage for the new herdr discovery/refusal behavior.

Testing

The configured full baseline had already passed; I then exercised the focused daemon and session-start regression suites plus a CLI-level daemon startup transcript showing the intended herdr AFK supervisor discovery, rejection, and override behavior. No UI evidence was applicable because this change is shell daemon behavior, not a rendered surface.

Evidence: Focused daemon test transcript
$ bash tests/fm-daemon.test.sh
ok - supervise daemon state root is scoped by FM_HOME
ok - routine signal self-handles
ok - captain-relevant status verbs escalate
ok - check + unknown escalate; heartbeat self-handles
ok - transient stale self-handles and records a persistence marker
ok - stale + terminal status escalates immediately
ok - persistent stale escalates after threshold and clears its marker
ok - resumed (busy) stale clears its marker without escalating
ok - persistent herdr stale resolves the target from metadata and escalates
ok - herdr idle busy-footer stale clears through capture corroboration
ok - resumed herdr stale clears through backend-aware busy state
ok - persistent Orca stale resolves the terminal from metadata
ok - multiple escalations flush as a single batched digest
ok - batch flush measures max-delay from the first append, not the last
ok - catch-all scan escalates a missed terminal once, not twice
ok - handle_wake routes routine->self and captain->escalate
ok - INJECT_SKIP forces self-handle, bypassing captain-relevant classification
ok - is_wake_reason distinguishes watcher wake reasons from singleton-status stdout
ok - terminal-stale escalate removes its marker so housekeeping does not re-escalate
ok - captain signal escalate marks seen so the catch-all scan does not re-fire
ok - _collapse_newlines replaces newlines with literal separator
ok - afk flag absent: daemon does not inject, buffer preserved
ok - busy-guard defers injection when supervisor pane is busy
ok - marker detection: marker -> stay afk, no marker -> exit afk
ok - /afk invocation is exempt from afk exit (no self-cancel)
ok - should_exit_afk returns false when afk is not active
ok - strip_injection_marker removes the sentinel marker cleanly
ok - pane_input_pending detects partial input on the cursor line
ok - pane_input_pending: blank cursor line is not pending
ok - pane_input_pending: bare prompts are not pending (idle)
ok - pane_input_pending honors FM_COMPOSER_IDLE_RE after border stripping
ok - classify_signal dedupes against the catch-all scan seen marker
ok - classify_stale dedupes against the signal path seen marker
ok - pane_input_pending: an idle bordered composer is NOT pending (afk-invx-i5)
ok - pane_input_pending: text inside a bordered composer is still pending
ok - submit-ACK confirms a submit when the composer returns to a bordered-empty box
ok - submit-ACK reports pending on a persistently swallowed Enter (type-once)
ok - max-defer on an empty stuck pane types once, alarms, and preserves the buffer
ok - max-defer flushes and clears the buffer on an empty bordered pane
ok - max-defer on a pending composer alarms without typing
ok - normal flush clears a stale wedge marker
ok - below MAX_DEFER: no inject, no alarm, buffer preserved
ok - max-defer does not flush or alarm while afk is inactive
ok - fm-send exits non-zero on a confirmed swallow, zero on a clean submit
ok - fm-send exits non-zero when initial text send fails
ok - discover_supervisor_backend: override > TMUX_PANE > HERDR_ENV+HERDR_PANE_ID > tmux fallback
ok - discover_supervisor_target: override > TMUX_PANE > herdr '<session>:<pane-id>' composition > firstmate:0 fallback
ok - discover_supervisor_target: no env markers discovers the firstmate-home Codex pane from herdr agent list
ok - discover_supervisor_target: crewmate project/treehouse panes are not selected
ok - daemon startup refuses tmux firstmate:0 fallback when herdr has agents but no safe primary
ok - daemon startup preserves explicit tmux backend precedence over herdr fallback refusal
ok - pane_is_busy: herdr native busy_state='busy' short-circuits without a capture fallback
ok - pane_is_busy: herdr falls back to the shared regex-over-capture reader when native busy_state is unknown
ok - pane_is_busy: herdr corroborates native idle with the shared regex-over-capture reader
ok - pane_is_busy: omitted backend arg defaults to tmux (pre-existing callers unaffected)
ok - pane_input_pending: dispatches through fm_backend_composer_state for backend=herdr
ok - inject_msg: herdr busy-guard defers before ever attempting a submit
ok - inject_msg: herdr composer-guard defers before ever attempting a submit
ok - inject_msg: herdr pane-gone check defers before any busy/composer/submit call
ok - inject_msg: dispatches busy-guard/composer-guard/submit through the herdr backend and succeeds on a confirmed empty composer
Evidence: Session-start regression transcript
$ bash tests/fm-session-start.test.sh
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 - 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 - an empty fleet reports (none) for in-flight tasks and an absent AFK flag
ok - next step sources the X-mode cadence before arming the watcher
ok - next step delegates watcher ownership to the AFK daemon
Evidence: Manual herdr AFK supervisor evidence

Shows: safe herdr agent-list discovery resolves backend=herdr and target=default:w1:p1; crewmate-only herdr fleet exits 1 with the loud refusal; explicit tmux backend/target still starts and logs backend=tmux target=firstmate:0.

Scenario 1: no HERDR_ENV/HERDR_PANE_ID, safe firstmate-home Codex pane exists in herdr agent list
resolved_backend=herdr
resolved_target=default:w1:p1

Scenario 2: herdr has only crewmate/project/treehouse panes, so daemon startup refuses tmux fallback loudly
exit_code=1
error: herdr appears active, but no safe firstmate supervisor pane was discoverable from HERDR_PANE_ID or herdr agent list; refusing tmux fallback 'firstmate:0'. Set FM_SUPERVISOR_BACKEND=herdr and FM_SUPERVISOR_TARGET=<session>:<pane-id> explicitly.

Scenario 3: explicit tmux backend/target override still wins even while herdr agents exist
log: [2026-07-08T05:50:26+0000] daemon starting (pid 1696623); target=firstmate:0; target_source=FM_SUPERVISOR_TARGET; backend=tmux; backend_source=FM_SUPERVISOR_BACKEND; afk=off; inject_skip='heartbeat'; stale_escalate=240s; batch=90s
- Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (24m0s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • 🚨 bin/fm-supervise-daemon.sh:1014 - Captain, this refusal path ignores an explicit FM_SUPERVISOR_BACKEND=tmux: in an active herdr fleet with no TMUX_PANE, startup exits before trying the intentional tmux firstmate:0 fallback, so a valid explicit backend override no longer takes precedence. Gate this hard-fail to auto-discovery cases, or otherwise skip it when the caller explicitly selected tmux.

🔧 Fix: Captain, preserve explicit tmux supervisor override
✅ Re-checked - no issues remain.

🔧 **Test** - 1 issue found → auto-fixed ✅
  • 🚨 tests failed with exit code 1
  • 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"

🔧 Fix: Captain: stabilize session-start missing-tool fixture
✅ 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"
  • Baseline already completed before this round: command -v tmux &gt;/dev/null || { echo &#34;tmux is required for e2e tests&#34; &gt;&amp;2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo &#34;== $t ==&#34;; bash &#34;$t&#34; || rc=1; done; exit &#34;$rc&#34;
  • bash tests/fm-daemon.test.sh
  • bash tests/fm-session-start.test.sh
  • Manual evidence script captured safe herdr primary discovery, crewmate-only hard-fail startup, and explicit tmux override preservation in /tmp/no-mistakes-evidence/01KX02R93B4ZQ8R38GT89DX523/herdr-afk-supervisor-e2e-transcript.txt
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@NumberedThought
NumberedThought deleted the fix/herdr-afk-supervisor-discovery branch July 8, 2026 14:43
7hoenix added a commit to 7hoenix/firstmate that referenced this pull request Jul 20, 2026
…internal clones (#5)

* feat(spawn): harden no-mistakes internal clones against unattended-credential hangs

The no-mistakes pipeline commits and pushes inside its own internal clone at
~/.no-mistakes/repos/<hash>.git, which fm-sign-lib's per-worktree override never
reaches. That clone inherits the operator's global git config, so on a machine
like the captain's it hits two unattended-hostile settings that block autonomous
validation runs:

  - Surface 3: global commit.gpgsign=true drives a GUI signer no autonomous run
    can click, hanging every pipeline commit.
  - Surface 4: a global url."[email protected]:".insteadOf=https://github.com/
    rewrites plain-HTTPS network ops to SSH (same GUI agent), and the default
    macOS credential chain (osxkeychain) hangs when the keychain is locked.

Both were recovered manually on ark PR kunchenguid#337 and dotfiles PR #4 with the same
dodge. This automates it: bin/fm-nm-clone-config.sh locates the internal clone via
the project's own no-mistakes remote (hash-independent) and scopes, repo-local to
that clone only, commit/tag.gpgsign=false plus, when SSH routing is detected, the
username-form origin URL + reverse insteadOf + gh credential helper. The operator's
global config, the no-mistakes install, and every project clone are never touched.

Timing: applied at spawn time (fm-spawn.sh, the deterministic firstmate-owned
guarantee, where fm-sign-lib already lives) and re-applied by a ship-brief line
right before /no-mistakes (the internal clone can be created mid-run, after spawn).
Both applications are idempotent. Every piece is a graceful no-op on a machine
without the problem: no no-mistakes remote, no global gpgsign, no insteadOf, or no
gh each shrink the work to nothing without error.

Tests simulate a fake global config + internal clone + project with a curated
PATH-shimmed gh, covering the full dodge, gh-absent username fallback, clean
machine, non-gated repo, no-resolvable-username, and idempotency.

* no-mistakes(test): isolate host git signing config and skip absent-shellcheck in tests

* no-mistakes(document): add fm-nm-clone-config.sh to scripts.md toolbelt catalog
@richardzip

Copy link
Copy Markdown

Notes

  • OTA-eligible. Only app TypeScript, specs and skill docs change: no native code, package, patches/, .gitignore, eas.json, build.json, asset or package.json script change, so the runtime fingerprint does not move.
  • Resend path (no new trigger needed). A rejected push stays in RxDB's upstream masterWrite loop, which retries the same rows every retryTime (5 s default, not overridden) until the handler resolves. A writes-suspended rejection is never quarantined, so the replicator is not recreated and that loop sends the edit on the first attempt after the switch lifts. asset-replicator-kill-switch-refusal.spec.tsx shows this: 7 refusals (past the cap of 5), then acceptance, with NetInfo held online and no relaunch.
  • Regression evidence. With the API's text, that spec failed on the old matcher (recovery: 'needs-decision', meaning quarantined). Restoring the old regex fails 6 tests across 4 suites.
  • Follow-up (out of scope): have the API return a typed GraphQL error code for WritesSuspended and classify on that code rather than message text. extractTypedErrorCode is already wired, and classifyPushErrorClass checks the refusal before the typed code so a ValidationError typename cannot turn it permanent.
  • No staging, production or Statsig change; multi_select_asset_fields stays off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants