Repository navigation
fix(bin): only resurface recovery episodes that have something to present - #2784
EternalTime wants to merge 27 commits into
Conversation
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (2): Last reviewed commit: "no-mistakes(test): count report lines po..." | Re-trigger Greptile |
…ge range, document timer
…em back in the folder that holds the project
…local-only landing
Land the captain's edits: refreshed nautical-seasoning examples, a pointer to ~/VOICE.md when writing under his identity, a new general-guidelines section for all crewmates, and a plain-language rule in section 9. Give the sentence-per-line, plain-dash, and no-agent-co-author rules a single owner in that new section, replacing the copies in the coding guidelines skill, CONTRIBUTING.md, and section 1 with cross-references.
…line, brief guidelines
…resent A watcher close publishes a downtime episode unconditionally, and resurface_after_downtime woke firstmate for any pending episode without testing whether anything actually needed resurfacing. With a torn-down fleet that produced a self-sustaining loop: each re-arm closed the previous watcher, which republished downtime, so the next successor delivered another "check: rearm-resurface" whose handling turn found an empty queue, no work under way and nothing armed. Gate the wake on the three sources docs/watcher-continuity.md says the recovery presentation contains - unacknowledged queue rows, still-open decisions, and unread informational status lines - and retire an episode proved empty so later arms cannot re-fire it. The emptiness re-check and the generation-bound acknowledgement share the queue lock fm_wake_append holds, so a wake racing that decision keeps its episode, and any failure to read a source is treated as work present. Delivering the wake still does not retire the episode. That is the durability guarantee behind release-lock-existing: the wake is delivered but not yet handled, and preserving it is what lets an interrupted handling turn re-drain the same work. The decision fold uses the whole-file scan rather than its incremental sibling, which writes a cursor the unread-status scan falls back to and would otherwise let this check blind the drain it protects. Three existing cases asserted the recovery wake on an empty fleet as proof that lock or marker evidence survived. They now hold a real open decision, so they still prove evidence retention while exercising resurfacing rather than the noise.
… to watcher family
…annot be read The open-decision pre-filter read grep's nonzero exit as proof that a status file holds no opening verb, so a read failure (exit 2) looked exactly like a file with nothing open. The recovery gate then retired the episode and stayed silent about a decision it never managed to read. Only grep's no-match (exit 1) is that proof now; any other exit, and any failure of the fold itself, propagates out of scan_open_decisions so the gate takes its documented fail-open path and still resurfaces.
|
Speaking as Kun's firstmate: Corrective intent is right: stop VISION:
Security: no. This branch is not the isolated watcher fix. HEAD is 28 ahead / 10 behind Greptile is red on the grep-error path. No Actions runs are queued on this SHA yet, so there is no fork workflow to approve and no-mistakes has not run. This is waiting on the author, not the captain: rebase onto origin/main with only the resurface commits, fix the grep fail-open, then CI can run. |
…ck suite BSD wc pads its count, so the three one-line report assertions compared a padded " 1" against "1" and failed on macOS while passing on the Linux CI runners. Strip the padding the way the probe-count assertion in the same script already does.
81a8559 to
469d703
Compare
|
Speaking as Kun's firstmate: closing this as stale. It has been waiting on a contributor update for 14+ days with no author push or comment (the last author activity was the push on 2026-08-22, about 97 days ago). Thank you @EternalTime for tracking down the empty For anyone picking it up again: the open points from my earlier review still stand. The branch bundled unrelated work (28 commits ahead of main, overlapping other PRs' files) and should carry only the resurface commits, the Contract class: cannot-tell (not re-inspected against current main; the branch is far behind and bundled). VISION: the honest-interface rule did not align at the last review (a failed grep could retire an episode that hides a decision); the others were fine. |
Intent
Stop the firstmate watcher waking firstmate with nothing to report, without breaking the resurfacing it exists to do.
Observed symptom: in the captain's main home, 'check: rearm-resurface' fired eleven times in a row over roughly fifteen minutes, and every one cost a visible turn and found nothing. Verified at each occurrence: bin/fm-wake-drain.sh returned empty, zero state/.meta so no work was under way, zero state/.check.sh so nothing was armed, and state/.last-watcher-beat was current so the watcher itself was healthy. The fleet had just been fully torn down. With no work under way and no armed checks, the correct behaviour is silence.
This is supervision machinery. Breaking real resurfacing is far worse than leaving the noise in place; that priority was explicit and drives several choices in the diff.
Required and done: the loop was reproduced end to end first, in a disposable FM_HOME, before anything was changed. The reproduction confirmed the suspected cause and refined it: an ordinary watcher close publishes a downtime episode unconditionally, and because every re-arm closes the previous watcher, a torn-down fleet re-arms straight into another empty episode, so resurface_after_downtime delivers a recovery wake whose handling drain presents zero bytes.
Two candidate defects were named up front, with a requirement to address both or give a written reason for only one.
Defect 1 (resurface fires with nothing to resurface) was confirmed and fixed: the wake is now gated on the three sources docs/watcher-continuity.md says the recovery presentation contains - unacknowledged queue rows, still-open decisions, and unread informational status lines - and an episode proved empty is retired under the queue lock fm_wake_append holds, so later arms cannot re-fire it.
Defect 2 (the marker is not cleared by the wake meant to consume it) was deliberately REFUTED rather than fixed, and this is intentional, not an oversight. Preserving the episode across delivery is the durability guarantee behind the release-lock-existing transition: the wake is delivered but not yet handled, and preserving it is what lets an interrupted handling turn re-drain the same work. Commit f9b9d43 and tests/fm-watch-arm.test.sh's interrupted-handling case pin that behaviour. Clearing the marker at delivery time would lose work on any interruption, so release-lock-existing is deliberately untouched.
Deliberate implementation choice worth knowing: recovery_has_presentable_work uses the whole-file scan_open_decisions rather than its incremental sibling scan_open_decisions_incremental. The incremental one writes a per-task cursor that the unread-status scan falls back to when no presentation manifest exists, so using it made the watcher silently blind the very drain the check protects. That was caught by the unread-note regression test and is why the seemingly more efficient incremental variant is not used here. Any failure to read one of the three sources is deliberately treated as work present, because a redundant wake costs a turn while a suppressed one costs the work.
Tests were required to be colocated in tests/ as .test.sh, extending an existing script rather than adding a runner, and the resurfacing-still-works test was required to be written first because it is the one protecting the feature. Both are in tests/fm-watch-arm.test.sh: one case proves each of the three presentation sources alone still resurfaces after a real down stretch, and one proves a fully torn-down fleet re-arms silently across consecutive cycles. The silence case was verified to fail against the unfixed watcher with the exact reported symptom, and the protective case passes against both the old and new watcher so it protects the feature rather than the fix.
Deliberate test change worth knowing: three pre-existing cases (marker publication failure, malformed marker quarantine, and reused-pid/dead-pid lock reclaim, across tests/fm-watch-arm.test.sh and tests/fm-watcher-lock.test.sh) used the empty-fleet recovery wake itself as the observable proof that lock or marker evidence had survived. Those assertions were asserting the noise being removed. They now seed a real open decision via a shared seed_open_decision helper in tests/wake-helpers.sh, so they still prove evidence retention while exercising genuine resurfacing. This is an intended change to existing assertions, not an incidental one.
Constraints: bin/*.sh must pass shellcheck and bin/fm-lint.sh must pass; both were run clean. Markdown in this repo is one full sentence per line, plain dashes, and no em dash anywhere. This is firstmate's own shared tracked material, so .agents/skills/firstmate-coding-guidelines/SKILL.md applies, including its one-owner rule: docs/watcher-continuity.md is the single owner of the recovery contract and was patched in place rather than having a second copy of the contract added elsewhere, and AGENTS.md was deliberately left unchanged to preserve its size discipline.
What Changed
bin/fm-watch.shnow gatescheck: rearm-resurfacebehind a newrecovery_has_presentable_work, which reads the three sourcesdocs/watcher-continuity.mdnames as the recovery presentation - unacknowledged queue rows, still-open decisions, and unread informational status lines - through their owners, read-only, and answers "work present" on any read failure. When all three are empty,retire_empty_recovery_episodeacknowledges that downtime generation under the same queue lockfm_wake_appendholds, so a torn-down fleet stops re-firing the episode on every re-arm;release-lock-existingis deliberately untouched so a delivered-but-unhandled wake still survives an interrupted handling turn.bin/fm-classify-lib.shaddsFM_DECISION_OPENING_VERB_REand pre-filters each.statusfile (rejecting symlinks first) beforescan_open_decisionsruns its per-line fold, keeping the fleet-wide scan off the watcher's arm critical path without changing its output;bin/fm-test-run.shmapsbin/fm-pr-check-migrate.shinto the watcher family, anddocs/watcher-continuity.mdnarrows its unconditional-resurface claim and records the retirement and reclaim paths.tests/fm-watch-arm.test.shgains cases proving each presentation source alone still resurfaces after a real down stretch, that an empty fleet re-arms silently across consecutive cycles, and that the stale-lock reclaim path behaves the same way; a sharedseed_open_decisionhelper intests/wake-helpers.shreseeds three pre-existing cases in that suite andtests/fm-watcher-lock.test.shthat had been using the removed empty wake as their proof of evidence retention.Note: the branch also carries 23 commits that exist only on the local
main(local-only project landing on secondmate routes, the/updatethecaptainloop, AGENTS.md guidelines). They are unrelated to this fix and drop out of the delta oncemainis pushed to origin.Risk Assessment
✅ Low: Round 4 changes no executable code - a comment-stripped diff of bin/fm-watch.sh and tests/fm-watch-arm.test.sh against round 3 is identical - and it resolves the last outstanding concern by making every code, test, and documentation claim match source, with the one race-only state now honestly recorded as deliberately untested rather than silently claimed as covered.
Testing
I reproduced the reported symptom first, end to end in a disposable FM_HOME driving the real arm, watcher, and drain binaries: against the pre-fix watcher, 9 of 11 consecutive re-arms over a fully torn-down fleet delivered
check: rearm-resurfaceand every one of those drains presented zero bytes, with zero state/.meta, zero state/.check.sh, and a current .last-watcher-beat at each occurrence, matching the captain's report. Running the identical script against this change produced 0 of 11 wakes and 11 silent arms, and in the same run a watcher that went down with a real open decision still emitted the recovery wake and still presented the OPEN DECISIONS block, so the resurfacing the change exists to protect is intact. On the automated side, the full fm-watch-arm and fm-watcher-lock suites pass including the three new cases and the reseeded pre-existing ones, and every consumer of the changed decision-scan pre-filter passes unchanged; the changed-test mapping was confirmed to select the watcher suites for this diff. This change has no UI surface - it is a background supervision daemon whose only end-user surface is the wake line and the drain transcript, so the CLI transcripts above are the reviewer-visible evidence rather than screenshots. No failures or flakes were observed, the worktree is clean, and the temporary pre-fix tree used for the comparison was removed.Evidence: Before/after CLI transcript summary: 9 of 11 empty wakes before, 0 of 11 after, resurfacing intact
BEFORE | re-arm 1: check: rearm-resurface drain presented 0 bytes BEFORE | re-arm 2: check: rearm-resurface drain presented 0 bytes BEFORE | re-arm 3: check: rearm-resurface drain presented 0 bytes BEFORE | re-arm 4: check: rearm-resurface drain presented 0 bytes BEFORE | re-arm 5: check: rearm-resurface drain presented 0 bytes BEFORE | re-arm 6: SILENT (watcher still live, no wake) drain presented 0 bytes BEFORE | re-arm 7: check: rearm-resurface drain presented 0 bytes BEFORE | re-arm 8: check: rearm-resurface drain presented 0 bytes BEFORE | re-arm 9: check: rearm-resurface drain presented 0 bytes BEFORE | re-arm 10: SILENT (watcher still live, no wake) drain presented 0 bytes BEFORE | re-arm 11: check: rearm-resurface drain presented 0 bytes BEFORE | RESULT: 9 of 11 re-arms woke firstmate; 2 stayed silent AFTER | re-arm 1..11: SILENT (watcher still live, no wake) drain presented 0 bytes AFTER | RESULT: 0 of 11 re-arms woke firstmate; 11 stayed silent AFTER | --- Phase 3: the same home, but one real open decision is waiting ------ AFTER | re-arm after downtime: check: rearm-resurface AFTER | $ bin/fm-wake-drain.sh AFTER | OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line): AFTER | held [key=ship-the-release] needs-decision: fixture is held for a decisionEvidence: Full pre-fix E2E transcript (watcher at 89bdcb8, symptom reproduced)
Evidence: Full post-fix E2E transcript (watcher at 4d90bda, silent plus still resurfacing)
Evidence: Reproduction script used for both runs (takes the tree under test as an argument)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
.agents/skills/afk/SKILL.md- branch carries 23 commit(s) that exist on your local main branch but were never pushed to origin/main; rebasing would bundle this unrelated work (121 file(s)) into the PR:Push main to origin, or rebase your branch onto origin/main, before gating.
🔧 **Review** - 2 issues found → auto-fixed (3) ✅
bin/fm-watch.sh:844-recovery_has_presentable_workruns the whole-file fleet-wide decision fold on the watcher's arm critical path, andbin/fm-classify-lib.shitself documents that this exact usage is what the incremental sibling exists to avoid (lines 377-391: "A fleet-wide scan using that whole-file function would pay that cost for every task on every wake, which grows unbounded as tasks run longer").status_open_decisionsforks a subshell per line for the fold, and_fm_decision_fold_lineforks ~3 more (status_line_verb,_fm_decision_key,status_line_note), so cost is roughly 4-5 forks per status line per task. Because an ordinary watcher close republishes downtime unconditionally, essentially every re-arm now reaches this fold, and it reaches it precisely in the quiet case the cheaper checks did not short-circuit. Concretely: 5 live tasks with 300-line status logs is ~1500 lines, i.e. several thousand forks blocking the watcher before it settles into its live wait; a long-running task with a few thousand status lines makes that noticeably worse. The intent explains whyscan_open_decisions_incrementalcannot be substituted (its cursor write blinds the unread-status fallback), and that reasoning is correct - but a cheap sound pre-filter avoids the tradeoff entirely: a decision can only be opened by aneeds-decisionorblockedverb, sogrep -qE '^[[:space:]]*(needs-decision|blocked)'per status file (one fork per file) can skip the fold for any file that provably has no open decision, and the full fold still runs for files that do. That keeps the read-only property and the whole-file semantics intact. Flagging rather than fixing because the scan choice is a deliberate, documented decision in this diff.bin/fm-watch.sh:885- The new gate only takes effect on thepending:downtime:*branch, so one narrow path still deliverscheck: rearm-resurfacewith nothing to present. Whenfm-watch.shreclaims a stale watcher lock itself,FM_LOCK_RECOVERED_PIDsetsWATCHER_RECOVERY_PENDING=1(line 774); if the queue is empty and no marker exists,_fm_recovery_marker_arm_checkwrites no marker and leavesFM_RECOVERY_MARKER_ACTION=none(bin/fm-wake-lib.sh:794-800), soWATCHER_RECOVERY_PENDINGstays 1.resurface_after_downtimethen skips the arm check at line 867, finds nothing presentable, snapshots an emptyFM_RECOVERY_MARKER_TOKEN, matches nocasearm, and falls through towakeat line 885. The same fall-through applies if the snapshot readspending:handling:*. This is pre-existing behaviour that the fix narrows rather than introduces, and it self-limits: the next arm'sclear_stale_recorded_watcher_lock(bin/fm-watch-arm.sh:233) publishes a real downtime marker, after which the new gate retires it silently. It also matches the change's stated bias that a redundant wake is cheaper than a suppressed one. Noting it only so the residual path is on record; no action needed for this change.🔧 Fix: pre-filter decision fold, gate every empty recovery wake
1 warning still open:
tests/fm-watch-arm.test.sh:934-start_reclaiming_watcherdoes not actually exercise the path it was added for, so the closed gap stays unpinned.bin/fm-watch.shruns"$SCRIPT_DIR/fm-pr-check-migrate.sh" --checks-safeas its very first action, before its ownfm_lock_try_acquire. On the fresh statemake_casecreates there is no.pr-check-migration-scan-v1, soscan_completefails,migration_completefails, and the[ "$ALLOW_INCOMPLETE_REPAIRS" -eq 1 ] && scan_completeshort-circuit fails too (bin/fm-pr-check-migrate.sh:259-262) - the migration therefore falls through tofm_lock_try_acquire "$WATCH_LOCK". The lock the helper planted holds a numeric dead pid, sofm_lock_mid_acquire_is_freshreturns 1 (it only guards empty/non-numeric pids) and the migration steals it, settingFM_LOCK_RECOVERED_PIDand thereforewatch_recovery_required=1(bin/fm-pr-check-migrate.sh:312). Its EXIT trap then runsfm_recovery_transition ... release-lock "$WATCH_LOCK" downtime(line 332), which PUBLISHES a downtime marker and releases the lock. By the timefm-watch.shreaches its ownfm_lock_try_acquire, the lock is free,FM_LOCK_RECOVERED_PIDis reset to empty at the top of that function (bin/fm-wake-lib.sh:730),WATCHER_RECOVERY_PENDINGstays 0, andarm_checkrecovers an ordinarypending:downtime:*episode. The test therefore re-covers the published-downtime casetest_empty_fleet_recovery_stays_silent_across_rearmsalready covers, and never reaches theFM_LOCK_RECOVERED_PID-with-no-marker case the fix at bin/fm-watch.sh:889 exists for. Both sub-cases still pass, so this is silent under-coverage rather than a failure, and docs/watcher-continuity.md:90 now asserts coverage ("which reaches recovery without any arm-side publication") that does not exist. The guard at line 963 does not catch it:lock_pid = ARM_PIDholds either way. Remedy: seed the migration short-circuit markers instart_reclaiming_watcherthe way tests/fm-watcher-lock.test.sh:18-23 does for its own dead-pid lock cases (.pr-check-migration-scan-v1and.pr-check-migration-v1, mode 0600) - ideally by promoting that helper into tests/wake-helpers.sh so the two suites share one owner - and add a positive premise guard after the lock-ownership check,[ ! -e "$state/.watcher-down" ] || fail "... so this case proves nothing", matching the idiom already used at lines 963-964 and in the round-1 cases.🔧 Fix: pin stale-lock reclaim test to the real reclaim path
2 issues (1 warning, 1 info) still open:
tests/fm-watch-arm.test.sh:940- The stale-lock reclaim case still does not discriminate the regression it was added for, and the reason is that the markerless state it targets is not reachable.fm_lock_try_acquirepublishes the downtime marker as PART of the watch-lock steal: bin/fm-wake-lib.sh:804-805 runs_fm_recovery_marker_publish "$STATE/.watcher-down" downtimeafterfm_lock_recheck_stale_ownersucceeds and beforeFM_LOCK_RECOVERED_PID=$curat line 816. I verified every gate on that path passes for the planted fixture (plain directory lock, dead numeric pid:fm_lock_recheck_stale_ownertakes itselif [ -e "$lockdir" ]branch, the pid matches,fm_pid_aliveis false, andfm_lock_mid_acquire_is_freshreturns 1 because the pid is numeric). SoFM_LOCK_RECOVERED_PIDnon-empty for$STATE/.watch.lockIMPLIES the marker exists aspending:downtime:<gen>. The guard at line 950 checks the marker before the watcher starts, which the watcher's own steal then creates. Concretely for this fixture: migration short-circuits, watcher steals the lock and mintspending:downtime:G,WATCHER_RECOVERY_PENDING=1(bin/fm-watch.sh:774),arm_checkreadspending:downtime:GsoFM_RECOVERY_MARKER_ACTION=recover, andresurface_after_downtimematches thepending:downtime:*case arm and retires. That is byte-identical behaviour under the round-1 form of the branch, so the case does NOT fail if the nothing-presentable branch is restricted back to onlypending:downtime:*- the exact discriminating property you required. This also corrects my round-1 finding 2: the 'no marker at all' path I described is not reachable through the watch-lock steal. The same misconception is embedded in the code comment at bin/fm-watch.sh:876-878, which contrasts 'a recovery pending through the watcher's own stale-lock reclaim' with 'a published downtime episode' when the reclaim IS one, and in the fixture comment at lines 934-939, whose stated goal (avoid 'turning this case back into the published-episode case') is not achieved because the watcher publishes it instead of the migration. What the round-2 generalization genuinely closes is narrower but real: after the steal leavespending:downtime:GwithWATCHER_RECOVERY_PENDING=1, a drain racing the watcher's first poll can move the token topending:handling:Goracked:handling:G, and only the generalized branch stays silent there. That state needs a concurrent drain, so no deterministic fixture reaches it without a new watcher-side test seam (the drain already hasFM_WAKE_DRAIN_TEST_DELAY_BEFORE_COMMIT; an analogous delay before the firstresurface_after_downtimewould let a test ack the generation first). Recommendation: do not run another mechanical round chasing an unreachable fixture. Either (a) keep the generalized gate as documented defensive hardening and correct the two comments plus the test's stated premise to say what the case actually pins - that the reclaim path reaches recovery through a marker the steal itself publishes, and that the discriminating race-only state is deliberately untested - or (b) if a pinned regression test is required, add the watcher-side test seam. This is your call because it turns on whether a production test seam is acceptable for a defensive branch; the production behaviour itself is correct and strictly safer than the round-1 form either way.bin/fm-test-run.sh:934-tests/fm-watch-arm.test.shnow invokesbin/fm-pr-check-migrate.shdirectly and hard-fails on its marker short-circuit (lines 946-951), butfamilies_for_changed_pathmapsbin/fm-pr-*topr-forgeonly, so editing the migration's short-circuit conditions would not select thewatcher-wake-lockfamily in--changedmode. The dependency is pre-existing -bin/fm-watch.shalready runs that binary as its first action, andtests/fm-watcher-lock.test.shalready relied on the same short-circuit - so this commit hardens rather than creates it, and--allplus the portable shards still cover it. Noting it only because the map's own stated policy is to over-select rather than under-select; addingwatcher-wake-lockto that case arm would restore that property. No action needed for this change.🔧 Fix: correct reclaim-path descriptions, map migration to watcher family
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-watch-arm.test.sh(all 17 cases, including the three new presentation-source, empty-fleet-silence, and stale-lock-reclaim cases)bash tests/fm-watcher-lock.test.sh(31 cases, covering the reused-pid and dead-pid reclaim assertions reseeded withseed_open_decision)bash tests/fm-classify-decision-key.test.sh,bash tests/fm-wake-drain-open-decisions.test.sh,bash tests/fm-wake-drain-open-decisions-cursor.test.sh,bash tests/fm-wake-drain-unread-status.test.sh(output-neutrality of the newFM_DECISION_OPENING_VERB_REpre-filter inscan_open_decisions)bash tests/fm-decision-hold-lifecycle.test.sh,bash tests/fm-watch-triage.test.sh,bash tests/fm-pending-reply.test.sh(remaining consumers of the decision fold)Manual E2E reproduction:bash e2e-rearm-resurface.sh <pre-fix-tree @89bdcb8> 'BEFORE the fix' 11- realbin/fm-watch-arm.sh --restart, realbin/fm-watch.sh, realbin/fm-wake-drain.shin a disposable FM_HOME; work done, handled, acknowledged, fleet torn down, then 11 re-arms each closing a live watcherManual E2E re-run of the same script against this change:bash e2e-rearm-resurface.sh <worktree> 'AFTER the fix' 11bash bin/fm-test-run.sh --list --changed --base 89bdcb8to confirm the watcher suites are selected for this diff✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.