Skip to content

fix(watch): stop two supervision wake loops on idle panes - #4

Merged
7hoenix merged 3 commits into
mainfrom
fm/fix-pause-recheck-window-8u
Jul 14, 2026
Merged

7hoenix merged 3 commits into
mainfrom
fm/fix-pause-recheck-window-8u

Conversation

@7hoenix

@7hoenix 7hoenix commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Intent

Fix two watcher wake-loop bugs in the supervision damping machinery (bin/fm-watch.sh + bin/fm-classify-lib.sh), both reproduced live on 2026-07-13 causing sustained loops that repeatedly interrupted the primary firstmate.

Bug 1 - expired declared-pause recheck loop: a crew whose status still declares paused, but whose authoritative current-state read (fm-crew-state.sh via crew_absorb_class) momentarily flickered to 'none' (a bounded no-mistakes probe timing out, a mis-attributed stale run), escaped into surface_nonterminal_stale, which both surfaced un-throttled AND deleted the durable .paused-resurfaced- throttle, so the recheck re-fired on essentially every watcher cycle (observed at pause ages 3604/4202/4469/4598s). Design decision: mirror the away-mode daemon's already-correct 'create-if-absent marker, reset-on-surface, once per PAUSE_RESURFACE_SECS' pattern. Concretely: (a) pause_state_class now maps ANY non-working verdict for a still-declared pause to a throttled paused recheck - only an authoritative 'working' verdict cancels the declared pause; (b) the first-sight stale path routes through pause_state_class instead of crew_absorb_class so a paused crew's transient 'none' never reaches surface_nonterminal_stale (for a non-paused crew the two are identical, so ordinary stopped-crew surfacing is unchanged); (c) surface_nonterminal_stale no longer deletes .paused-resurfaced- (belt-and-suspenders; that marker is owned by handle_paused_stale and cleared only by a genuine unpause via clear_pause_state). Requirement kept: a forgotten pause DOES still recheck once per window, durably, surviving watcher restarts and crew re-declaration.

Bug 2 - idle-pane footer animation defeats stale dedupe: a fully idle claude crew pane still redraws its context-meter sparkline, so the raw capture hashed differently every poll, defeating the .stale- dedupe and firing a fresh stale wake ~every 20s. Fix: hash the capture with animated chrome stripped. strip_animated_chrome removes exactly two Unicode blocks that never appear in real conversation/code - Block Elements (U+2580-259F sparkline bars) and Braille Patterns (U+2800-28FF dot spinners) - byte-wise under LC_ALL=C, reading the whole capture as one record (RS=NUL) so it is byte-exact and adds no trailing newline (a glyph-free capture hashes identically to the old raw path, preserving existing seeded-hash tests). It works identically for the tmux and herdr plain-text capture paths (both feed fm_backend_capture plain text - no tmux-vs-herdr split). It normalizes ONLY the hash input; tail40 stays raw for window_is_busy, and any meaningful content change still changes the hash, so real staleness detection is not weakened.

Constraints honored: provably-working crews stay absorbed, secondmate pane exemption preserved, demand-deep-inspection escalation still works. Extended the existing tests/fm-watch-triage.test.sh with two regression tests (test-level repro of both loops: fail before, one-surface-then-silence after) rather than a new runner. Updated docs/architecture.md 'Event-driven supervision' (the owning doc). fm-lint.sh green; watch-triage/daemon/watcher-lock/pi-watch/checkpoint suites green.

What Changed

  • Reworked the declared-pause recheck in bin/fm-watch.sh so a still-declared pause whose authoritative state momentarily flickers to non-working now routes through pause_state_class and stays throttled to once per resurface window; only a genuine working verdict cancels the pause, and surface_nonterminal_stale no longer deletes the durable .paused-resurfaced-<key> marker, ending a loop that re-fired every watcher cycle.
  • Added strip_animated_chrome to normalize only the hash input by removing Block Elements and Braille glyphs (context-meter sparklines and spinners) via a byte-exact perl -0777 slurp with a raw cat fallback when perl is absent, so an otherwise-idle pane no longer defeats the .stale-<key> dedupe; tail40 stays raw for busy detection and real content changes still change the hash.
  • Extended tests/fm-watch-triage.test.sh with two regression tests reproducing both loops (fail on base, one-surface-then-silence after) and updated the "Event-driven supervision" section of docs/architecture.md.

Risk Assessment

✅ Low: Well-bounded supervision-damping fix with a consistent return-contract change across all call sites, correct UTF-8 byte-range stripping, a safe perl-absent fallback, and matching regression tests; both prior-round findings are already incorporated.

Testing

The pre-run baseline of all tests/*.test.sh already passed; I additionally exercised the two new regression tests directly against both the base and target versions of bin/fm-watch.sh, confirming each bug reproduces on base (expired-pause raw stale wake, and idle-pane sparkline defeating the stale dedupe) and is resolved on target, and captured a CLI transcript showing strip_animated_chrome makes animated footer frames hash identically while preserving real-content and glyph-free byte-exact hashing. Full fm-watch-triage suite (35 tests) is green and the worktree was left clean.

Evidence: Fail-before: bug 1 (expired-pause loop) reproduced on base fm-watch.sh

not ok - expired-pause recheck was not the throttled paused recheck: stale: test:fm-forgotten

=== Running full watch-triage suite with TARGET tests against BASE fm-watch.sh (expect the 2 new tests to FAIL) ===
ok - signal_reason_is_actionable: benign absorbed, captain verbs and coalesced batches surfaced
ok - stale_is_terminal: terminal status surfaces, non-terminal and no-status are benign
ok - scan_captain_relevant_statuses lists only captain-relevant statuses
ok - classifier primitives: last line, captain-relevance, window->task, FM_CAPTAIN_RE override
ok - crew_is_provably_working: only working+run-step/pane is provable; idle/finished/parked/failed/unknown surface
ok - status_is_paused: only the leading paused verb matches, and paused is not captain-relevant
ok - crew_absorb_class: working/paused/none from one read; crew_is_paused and crew_is_provably_working agree
ok - signal_crew_provably_working: benign only when every referenced crew is provably working
ok - a no-verb signal whose crew is provably working is absorbed (no exit, no queue, suppressor advanced, beacon present)
ok - a bare turn-end whose crew is provably working (busy pane) is absorbed
ok - a bare turn-end whose crew is not provably working is surfaced (the swallowed-finish fix)
ok - a no-verb working: note whose crew is idle with no running pipeline is surfaced
ok - captain-relevant signal is surfaced (queue + exit) and marked surfaced
ok - a stale pane sitting on a terminal status is surfaced (queue + exit)
ok - a stale terminal-looking status is overridden and absorbed while a run is actively working, then wedge-escalated
ok - provably-working non-terminal stale is absorbed on first sight, then wedge-escalated past the threshold
ok - consecutive wedge escalations on the same pane accumulate and demand deep inspection at the threshold
ok - a pane becoming active again resets the consecutive wedge-escalation counter
ok - a not-provably-working non-terminal stale is surfaced immediately (never left to wait out the timer)
ok - a declared pause is absorbed on first sight, then re-surfaced as a recheck past the threshold, never wedge-escalated
ok - a declared paused secondmate re-surfaces on the bounded normal-mode cadence
ok - a non-paused secondmate retains normal stale suppression
ok - a resumed secondmate clears pause and stale tracking before stale exemption
ok - unchanged stale hashes reclassify when a crew enters or leaves pause
ok - a declared pause is periodically rechecked against authoritative active-run state
ok - a paused status overridden by authoritative working preserves its wedge timer and escalates
not ok - expired-pause recheck was not the throttled paused recheck: stale: test:fm-forgotten
Evidence: Fail-before: bug 2 (animated footer defeats dedupe) reproduced on base fm-watch.sh

not ok - a footer-only sparkline redraw defeated the stale dedupe and re-surfaced an idle pane

=== Bug 2 repro: animated footer test against BASE fm-watch.sh (expect FAIL) ===
not ok - a footer-only sparkline redraw defeated the stale dedupe and re-surfaced an idle pane
Evidence: strip_animated_chrome hashing demo (footer frames dedupe, real change still surfaces)

frame A stripped = e5ad72cf0a99c5347963ca0e45b4d3aa frame B stripped = e5ad72cf0a99c5347963ca0e45b4d3aa <- IDENTICAL -> dedupes, no wake loop real-change stripped = 4d72e3d56db89de0eb019934c0944b13 <- DIFFERENT -> still surfaces glyph-free: raw = stripped = d4e90a60011b924e32b32f117468f9f4

=== Idle-pane stale-hash dedupe: animated footer stripped before hashing ===

Pane frame A (visible):
crewmate finished its turn.

The assistant message ended. Nothing running.
  ▁▃▅▇  23% context left

Pane frame B (visible, only the sparkline advanced):
crewmate finished its turn.

The assistant message ended. Nothing running.
  ▇▅▃▁  23% context left

RAW hashes (base behavior - differ every poll -> fresh stale wake every cycle):
  frame A raw = a099f1a4ee48c38c641c18f68f907ada
  frame B raw = 85b991e1c77fd02d053730f4d57e2fb8

STRIPPED hashes (fix - animated chrome removed before hashing):
  frame A stripped = e5ad72cf0a99c5347963ca0e45b4d3aa
  frame B stripped = e5ad72cf0a99c5347963ca0e45b4d3aa   <- IDENTICAL -> dedupes, no wake loop

A REAL body change still changes the stripped hash (staleness not weakened):
  real-change stripped = 4d72e3d56db89de0eb019934c0944b13   <- DIFFERENT -> still surfaces

Byte-exact invariant: a glyph-free capture hashes identically stripped vs raw:
  raw      = d4e90a60011b924e32b32f117468f9f4
  stripped = d4e90a60011b924e32b32f117468f9f4   <- IDENTICAL -> preserves seeded-hash tests

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed (2) ✅
  • ⚠️ bin/fm-watch.sh:193 - strip_animated_chrome relies on RS=&#34;\0&#34; to read the whole capture as one byte-exact record, but on macOS BSD awk (this environment, awk 20200816) &#34;\0&#34; is an empty string, which puts awk into PARAGRAPH MODE: it splits on blank lines, collapses blank-line runs, and drops the trailing newline. Verified live: a glyph-free capture line1\n\nline2\n hashes DIFFERENTLY through this function than through the raw path (9acd21... vs ce8bc0...), directly contradicting the comment's 'hashes identically to the old raw path' invariant. The primary idle-animation dedupe still functions because the transform is applied consistently on every poll (hash comparisons are stripped-vs-stripped internally), so no meaningful staleness is missed - but the documented byte-exact/one-record guarantee is false on the target platform, and any future test or code that seeds a raw-computed hash with blank-line content will silently break. The two new regression tests pass only because their captures contain no blank lines and no trailing-newline sensitivity. Recommend a byte-exact whole-input strip that doesn't depend on RS, e.g. LC_ALL=C perl -pe &#39;s/\xe2\x96[\x80-\x9f]//g; s/\xe2[\xa0-\xa3][\x80-\xbf]//g&#39; (perl -p preserves record separators exactly, last-line included).

🔧 Fix: replace awk RS slurp with byte-exact perl -0777 in strip_animated_chrome
1 warning still open:

  • ⚠️ bin/fm-watch.sh:195 - strip_animated_chrome (bin/fm-watch.sh:195) calls perl unconditionally on the per-window-per-poll hot path, breaking the codebase's own convention of guarding perl with command -v perl plus a non-perl fallback (fm-crew-state.sh:207, fm-bearings-snapshot.sh:165, run_check at :451). The script sets only set -u (no pipefail), so at :768 printf &#39;%s&#39; &#34;$tail40&#34; | strip_animated_chrome | hash_pane swallows a missing-perl exit 127 and hash_pane hashes empty input. If perl is absent, every window yields the identical empty-string md5 every poll, .hash-/.stale- markers always match, and stale/wedge detection is silently defeated with no error surfaced. Add a graceful fallback that passes the capture through raw when perl is unavailable (degrades to the old raw-hash behavior rather than collapsing detection).

🔧 Fix: guard strip_animated_chrome perl call with raw cat fallback
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • 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"
  • bash tests/fm-watch-triage.test.sh on target commit - all 35 tests pass including test_expired_pause_rechecks_once_per_window_not_loop and test_animated_footer_does_not_defeat_stale_dedupe
  • Ran target test file against BASE bin/fm-watch.sh (swapped in git show 1e67e2b:bin/fm-watch.sh): bug 1 test fails with not ok - expired-pause recheck was not the throttled paused recheck: stale: test:fm-forgotten
  • Ran the animated-footer test against BASE source in isolation: fails with not ok - a footer-only sparkline redraw defeated the stale dedupe and re-surfaced an idle pane
  • Product-level CLI transcript of strip_animated_chrome/hash_pane: two footer frames (▁▃▅▇ vs ▇▅▃▁) hash identically after stripping, a real body change changes the hash, and a glyph-free capture hashes identically stripped-vs-raw
  • Confirmed git status --porcelain clean after restoring temporarily-swapped source/test files
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

7hoenix added 3 commits July 14, 2026 09:35
Bug 1 - expired declared-pause recheck loop. A crew whose status still
declares paused, but whose authoritative current-state read flickered to
`none`, escaped to surface_nonterminal_stale, which both surfaced un-
throttled and wiped the durable .paused-resurfaced-<key> throttle, so the
recheck re-fired on essentially every watcher cycle (observed at pause
ages 3604/4202/4469/4598s). Now only an authoritative `working` verdict
cancels a still-declared pause: pause_state_class maps any other verdict
(paused, or a transient none) to a throttled recheck, the first-sight
stale path routes through it too, and surface_nonterminal_stale no longer
deletes the resurface throttle. The recheck now surfaces at most once per
PAUSE_RESURFACE_SECS, durably, surviving restarts and re-declaration.

Bug 2 - idle-pane footer animation defeats stale dedupe. A fully idle
pane still redraws its context-meter sparkline, so the raw capture hashed
differently every poll and re-surfaced the same quiet pane ~every 20s.
The staleness hash is now taken over the capture with animated chrome
(Block Elements / Braille glyphs) stripped byte-wise under LC_ALL=C, so a
footer-only redraw dedupes while any meaningful content change still
changes the hash. Works identically for the tmux and herdr plain-text
capture paths; window_is_busy still reads the raw capture.

Adds test-level repros of both loops (fail before, one-surface-then-
silence after) and updates docs/architecture.md.
@7hoenix
7hoenix merged commit ebdb626 into main Jul 14, 2026
4 checks passed
7hoenix added a commit 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
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.

1 participant