Repository navigation
fix(bin): keep supervision armed for registered custom checks - #3860
kunchenguid merged 4 commits into
Conversation
A custom check bound by bin/fm-check-register.sh only ever runs inside the watcher's check sweep, but fm_supervision_status counted in-flight tasks, the relay poll shim, and process-event sources as supervision need, and not registered checks. Tearing down the last task therefore stopped every home-level check silently until the next spawn. Count a state/<id>.check.sh that carries its state/<id>.check-trust binding as supervision need. The relay shim keeps its own trust path and task PR polls carry no such binding and are torn down with their task, so neither arms a home by accident. Presence of the binding is the whole test: the sweep validates the bytes at execution time and wakes firstmate when it rejects one, which is the outcome an idle home needs. Closes #3856
…and doc invariant
Confidence Score: 5/5The PR appears safe to merge, with the shared supervision predicate and its consumers consistently handling registered custom checks. Registered checks now keep supervision active, the watcher and away daemon already continue polling them, and no concrete blocking failure remains in the changed paths. Reviews (1): Last reviewed commit: "no-mistakes(document): point Grok re-arm..." | Re-trigger Greptile |
|
Speaking as Kun's firstmate: Triage on HEAD Contract-class: restore. Registration + check sweep already promised a trust-bound Diff reviewed: Attestation: MATCH for tip CI/NM this pass: first-time fork workflows approved after security skim — CI VISION.md (each rule)
Security: no. Trust-binding already gates execution; presence-not-hash is intentional so rejection wakes rather than silence. Merge-eligible N until CI/NM green. Waiting-ci. Auto-merge candidate once green (restore + MATCH + safe review). No captain flag this pass. |
|
Speaking as Kun's firstmate: this is merged. Thank you @gyute — really appreciate you taking the time on this. |
* fix(bin): wait out transient primary-checkout reads in the spawn worktree poll (#3834)
* fix(spawn): keep the worktree poll from adopting the repository primary
After `treehouse get` is sent, the worktree-discovery poll reads the pane's
foreground-process cwd. While treehouse is still fetching and checking a slot
out, the foreground process is treehouse itself and it reports the repository's
PRIMARY checkout as its cwd for several seconds. The poll accepted any path
that merely differed from the spawning project, so from a linked spawning home
- whose project is itself a worktree of that repository - it adopted the
primary, and the isolation guard then refused a launch whose slot treehouse
went on to create normally.
Screen every candidate with the isolation guard's own conditions, extracted as
spawn_worktree_isolated, so a read the guard would reject stays a transient the
poll keeps waiting through. The two-consecutive-reads rule and the guard as
final backstop are unchanged; a pane that never reaches an isolated worktree
still fails at the existing 60s deadline, now naming the last path it reported.
The already-settled timing assertion counted whole-spawn wall time against a
5s budget and failed on unmodified HEAD on slower machines; it now counts pane
reads, which is what "one confirming read, not an extra cycle" actually means.
* fix(spawn): say which path the worktree wait rejected, and why
Screening every discovery-poll candidate means a host that never reaches an
isolated worktree spends the whole 60s window before refusing. That wait is
deliberate - separating a transient from a terminal misconfiguration needs
machinery this path does not want - so the refusal explains itself instead:
the isolation check records why a candidate failed, and the deadline names the
last path seen together with that reason. Message and diagnostics only; the
poll's control flow is unchanged.
Two suites asserted the guard's wording on paths the poll now rejects rather
than adopts, so their refusal arrives from the deadline instead: realign
fm-tangle-guard's non-git and subdirectory-of-primary cases (each now also
asserting the stated reason, and the second the metadata absence it was
missing) and the herdr projection e2e's forced non-worktree cwd.
* no-mistakes(review): stub poll sleep in tangle-guard spawn isolation test
* no-mistakes(document): document spawn poll isolation screen in fm-spawn header
* test(spawn): make the non-git isolation case non-git anywhere
The refusal-reason assertion for a path outside any repository assumed TMPDIR
is not inside a git repository. Where it is, git walks up from the temporary
directory, finds that repository, and the spawn reports the subdirectory cause
instead - so the case passed or failed on a property of the host rather than on
the behaviour under test.
Build the path under a directory the test then names in GIT_CEILING_DIRECTORIES,
which git documents as not chdir-ing up into a listed directory while looking
for a repository. Git never excludes the directory being searched, so the
ceiling is the parent of the path handed to the spawn.
The assertions pin which cause fired rather than the sentence that explains it,
leaving the operator wording free to improve.
* no-mistakes(document): point spawn poll comment at the isolation screen's comparison
* no-mistakes(ci): Fixed the "Behavior portable serial 2" failure in tests/fm-tangle-guard.test.sh ("non-worktree spawn did not say why the path was rejected (missing: 'not inside a git worktree')"). Root cause, in this PR's code: bin/fm-spawn.sh's spawn_worktree_isolated resolved the git toplevel with `wt_top_real=$(cd "$SPAWN_WT_TOP" ...)`. For a path in no repository, `git rev-parse --show-toplevel` yields empty, and `cd ""` is a SUCCESSFUL no-op on bash before 5.3 (CI's ubuntu-latest ships bash 5.2). The empty toplevel therefore resolved to fm-spawn's own cwd — the CI checkout — so the poll reported "it is a subdirectory of worktree root '/home/runner/work/firstmate/firstmate'" instead of the correct "it is not inside a git worktree". Dev machines with bash 5.3 fail `cd ""`, which is why the suite passed locally and only failed on CI; it is a genuine shell-portability defect in the reason vocabulary this change added, not a test-environment artifact. Fix (smallest root-cause change, 1 line + comment, bin/fm-spawn.sh:2168-2173): guard the empty value so it never reaches `cd` — if [ -n "$SPAWN_WT_TOP" ] && ! wt_top_real=$(cd "$SPAWN_WT_TOP" 2>/dev/null && pwd -P); then No change to the poll's timing or deadline behavior (respecting the recorded refusal-latency and spawn-wt-reason-vocabulary decisions), no new tests, no other files touched. Verification: - Reproduced the exact CI failure locally by putting bash 3.2 (same `cd ""` semantics as CI's 5.2) first on PATH: fails before the fix with the identical message shape, passes after. - tests/fm-tangle-guard.test.sh passes under both bash 3.2 and bash 5.3. - tests/fm-spawn-worktree-settle.test.sh and tests/fm-spawn-pool-base-freshen.test.sh pass; shellcheck -x bin/fm-spawn.sh clean. - bin/fm-test-run.sh --changed: 46 suites completed, every FM_TEST_END exit=0, 1076 passing assertions, 0 "not ok" (including fm-tangle-guard, fm-control-relaunch, fm-lint). The run ended on my own 900s wall-clock cap (rc=124), not on any test failure
* fix: support stock macOS Bash 3.2 paths (#3732)
Co-authored-by: Talon Stark <[email protected]>
* fix(bin): read orphaned green ci monitor and daemon-down failed record as not failed (#3846)
* fix(bin): read an orphaned green ci monitor as held-for-merge, not failed
A no-mistakes run held for a captain merge decision keeps its ci step
polling until merged or closed; when the shared daemon restarts under
that poll, the run is recorded failed although every substantive step
completed and GitHub reports the PR green. A monitor whose only
remaining job is to observe a human decision must not convert the
absence of that decision into a failure verdict.
fm-crew-state.sh now reclassifies a terminal failed run as done
(held-for-merge), surfacing the run's PR URL, when the steps table
shows every step completed except exactly ci failed and the ci log's
last recognized marker reads checks green. A genuinely red check, an
unreadable ci log, or a second failed step keeps the failure.
* no-mistakes(review): Read daemon-down coarse failed ledger as unknown, not failed
* no-mistakes(document): docs: align AGENTS.md failed-verdict guidance with crew-state reclassification
* fix(spawn): verify preserved backlog state after interrupted spawn delivery (#3852)
* fix(bin): read preserved spawn state back before the interrupted exit claims it
The
Intent
External contribution PR to kunchenguid/firstmate that closes upstream Issue #3856 ("Registered custom checks stop polling when the home has no in-flight task").
Goal: a custom check registered with bin/fm-check-register.sh is a home-level slow poll that only ever runs inside the watcher's check sweep, but fm_supervision_status in bin/fm-supervision-lib.sh counted only three things as supervision need - in-flight tasks (state/*.meta), the Relay poll shim (state/x-watch.check.sh), and process-event sources. So the moment the last task was torn down, the Claude Stop auto-arm exited and every registered check went silent until the next spawn. In the reporter's home that silently swallowed three captain answers polled from the GitHub API. Add a fourth condition: a registered custom check makes FM_SUP_NEEDED=true.
Accepted design decisions, made deliberately and confirmed with firstmate:
Constraints the user set:
What Changed
fm_supervision_statusinbin/fm-supervision-lib.shnow counts astate/<id>.check.shthat has thestate/<id>.check-trustbinding written bybin/fm-check-register.shas a fourth supervision-need condition, exported asFM_SUP_CHECKS; thex-watchrelay shim is skipped by name, and presence of the binding (not a byte-hash match) is the whole test, so the Claude Stop auto-arm, turn-end guard, andbin/fm-guard.shkeep a watcher alive for a home whose only work is a registered custom check.bin/fm-guard.shandbin/fm-turnend-guard.shgained an explicit "N registered custom check(s)" branch in their stale-watcher banner and need description, replacing the fall-through to "X-mode relay polling", and their comments now point atfm-supervision-lib.shas the single owner of the condition set instead of enumerating it.docs/architecture.md,docs/turnend-guard.md,docs/configuration.md,docs/supervision-protocols/grok.md) are corrected in place to list registered custom checks as a supervision need, including that arming the watched-tool update check now keeps a watcher after the last task is torn down; tests intests/fm-turnend-guard.test.shandtests/fm-claude-stop-autoarm.test.shadd predicate cases (registered check, drifted bytes, unregistered check, task PR poll, relay shim), a turn-end guard banner case, and an end-to-end auto-arm case, all registering through the realbin/fm-check-register.sh.Risk Assessment
✅ Low: The change adds one well-bounded OR condition to the single supervision-need owner, threads the new count into two banner ladders and one description, and corrects docs in place; every traced input (registered check, unbound check, task PR poll, relay shim, drifted bytes) yields the intended count, the watcher and away-mode daemon hold no competing need logic, teardown and unregister remove the binding with the check, and all added tests drive the real registration script and the real hook without any source-byte assertions.
Testing
Completed 1 recorded test check.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
tests/fm-turnend-guard.test.sh:150- The intent states that 'a torn-down task leaves nothing behind' is 'asserted by a test', but this case never runs bin/fm-teardown.sh: it hand-creates task1.meta, task1.check.sh, and task1.pr-poll, then deletes them with rm -f and asserts the (now empty) state dir needs no supervision. The second half is trivially true for any empty directory and would still pass if remove_pr_poll_artifacts in fm-teardown.sh stopped removing <id>.check-trust. The first half (a PR poll with no .check-trust is not counted) is a genuine executable-interface assertion and is fine. Either rename the case to what it actually proves ('a PR poll without a trust binding is not counted') or drive the removal through the real teardown path; the latter would pull in fm-teardown.sh's worktree/tmux preconditions, which is why this is flagged for the author rather than fixed here.🔧 Fix: narrow PR poll predicate test to what it proves
1 info still open:
bin/fm-turnend-guard.sh:217- The two fix-round commits (e86eafe 'no-mistakes(review): name registered checks in turn-end block banner and doc invariant' and dd753d7 'no-mistakes(review): narrow PR poll predicate test to what it proves') do not follow the intent's stated contribution rule that commit subjects use 'fix(bin): ...' with a why/what body ending in 'Closes Registered custom checks stop polling when the home has no in-flight task #3856'. Their content is correct and carries none of the forbidden attribution trailers (no Co-Authored-By, Claude-Session, or 'Generated with'), and the original commit 6d6760a satisfies the rule fully. If the push step forwards all three commits as-is, the PR to kunchenguid/firstmate will carry two commits outside the convention the user set. The remedy is a squash of the two fixer commits into 6d6760a (or a reword) before push, which is a history rewrite the user should authorize rather than something to fix in source.bin/fm-test-run.sh --changed --exclude-family real-herdr-gated✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
On "a matching valid
.check-trustbinding"The triage on #3856 asks for a check to be counted only when it carries "a matching valid
.check-trustbinding the watcher would execute".This patch counts the binding's presence and deliberately does not re-verify the byte hash inside the predicate.
The check sweep in
bin/fm-watch.shalready validates those bytes at execution time throughfm_custom_check_snapshot_prepare, and a check that fails that validation is not dropped silently: the sweep reports it ascheck: rejected unauthenticated state checks, which is a wake the operator needs to see.Hash-gating the predicate would invert that, because a registered check whose bytes drifted would stop arming the home and the rejection would then never be reported - the same silence this issue is about.
It would also pull
bin/fm-check-lib.shandbin/fm-pr-lib.shplus a SHA-256 of every check file onto hook-hot paths, since the Claude Stop auto-arm and the turn-end guard evaluate this predicate at every turn boundary, for no added safety.The triage's other two constraints hold unchanged: an unregistered or untrusted check is still rejected by the sweep exactly as before, and a task PR poll carries no
.check-trustbinding and is removed with its task bybin/fm-teardown.sh, so neither can keep a home armed.tests/fm-turnend-guard.test.shpins this decision with a case asserting that a registered check whose bytes drifted still needs supervision.Verification
bin/fm-lint.shpasses with the pinned shellcheck 0.11.0 and actionlint 1.7.12, andbin/fm-doc-audience-check.shpasses.The six added cases all pass: a registered check needs supervision with no task in flight, a drifted registered check still needs supervision, a
check.shwith no registration binding does not, a task PR poll without a trust binding is not counted, the relay shim is not counted as a custom check, and an idle home with a registered check still arms the Stop auto-arm cycle.The turn-end guard also blocks a check-only blind turn with
1 registered custom check(s)instead of misreporting it as relay polling.Every test runs over
FM_STATE_OVERRIDEtemp directories through the existingtests/lib.shhelpers, so no live firstmate home is read or written.On the full changed-file selection (
bin/fm-test-run.sh --changed) this branch reports 15 failures out of 107 scripts, against 17 out of 107 for the unmodified base on the same machine, so the branch fails fewer scripts than its own baseline.Those failures split into three causes, none of them in code this change touches: suites that fail identically on base
a913539extracted withgit archive, suites that fail on a missingnodein the sandbox (No version is set for command node), and load-related timing on a machine running the suite with bounded concurrency.Two environments observed two different pre-existing turn-end failures - locally the Pi injection case, and in the pipeline sandbox the fresh-beacon-no-live-lock case (
hook must block when a fresh beacon has no live watcher lock) - and both reproduce on basea913539, so each is named as observed rather than as one fixed case.