Repository navigation
feat(watch): per-pause recheck cadence with exponential backoff and supervisor ack - #11
Merged
Merged
Conversation
Parked/paused lanes were each rechecked hourly, and deferring one meant steering the crew to re-append a line - a full-context turn on a resident high-context session. Add an inline `paused [recheck=<dur>]:` cadence for captain-gated lanes and bin/fm-pause-ack.sh to defer a confirmed wait without a crew turn; the crew's append-only status file is never touched, since its changed mtime would trip the signal scan. Add a queue-first intake bias and broaden the example dispatch config's cheap mechanical routing.
An unchanged parked/paused lane now widens its recheck interval base*2^streak (capped at FM_PAUSE_RESURFACE_MAX_SECS, default 12h) instead of a fixed hourly recheck, so ten parked lanes are not each woken hourly all day. The backoff is asymmetric: the streak resets to base only on a fresh crew status line or an authoritative working verdict, never on an ambiguous read, and an ack defers at the current widened interval. pause_backoff_secs is the single owner of the math, shared by the watcher and the afk daemon so they never drift.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Cut the fleet's Claude-quota burn, targeting the biggest bucket: parked/paused crew lanes sitting resident at high context (300-700k tokens) that the watcher rechecks hourly, where deferring each recheck meant steering the crew to re-append a paused: line - a full-context turn on a huge session. Ten parked lanes rechecked hourly is ~240 huge-context turns/day for zero work.
This branch has two commits. Commit 1 (per-pause cadence + supervisor ack): (a) a declared pause may carry an inline 'paused [recheck=]:' token (s/m/h/d or bare seconds) so a captain-gated merge/release lane starts on a long window; token grammar has ONE owner, fm-classify-lib.sh:pause_recheck_secs, read by both the always-on watcher and the afk daemon; clamped to [FM_PAUSE_RECHECK_MIN_SECS=300, FM_PAUSE_RECHECK_MAX_SECS=86400]. (b) bin/fm-pause-ack.sh: firstmate touches a supervisor-owned state/.paused-ack- marker to defer the next recheck without a crew turn; the crew's append-only status file is deliberately NOT touched because its size:mtime change would trip the watcher's signal scan and fire a spurious wake, so the recheck age anchors on max(status-file mtime, ack mtime). status_line_verb was generalized to strip any [tok=...] bracket token so [recheck=] shares the existing [key=] grammar slot (backward compatible).
Commit 2 (asymmetric exponential backoff), designed after a second-opinion review by Codex which recommended a hybrid over full AIMD: from the per-pause base, the recheck interval widens base*2^streak, capped at a new FM_PAUSE_RESURFACE_MAX_SECS (default 12h). fm-classify-lib.sh:pause_backoff_secs is the ONE owner of the backoff math, shared by watcher and daemon so they never drift on next-due timing. Asymmetric: the streak resets to base ONLY on a positive signal (a fresh crew status line, detected by a changed status-file mtime stored alongside the streak, or an authoritative working verdict on resume), never on an ambiguous 'none' read (reuses the existing 2026-07-13 expired-pause-loop guard); an ack defers at the current widened interval, not base. The streak is keyed by the logical window/pause, not the pane hash, so a churny idle pane cannot fabricate pauses or reset the widening (a concern Codex explicitly raised). A declared base above the 12h cap keeps its declared base (never shortened by backoff). Safety property preserved: a forgotten pause still re-surfaces within the cap, and a genuinely wedged (non-paused) crew is a separate path, unaffected.
Reviewer note: the watcher anchors the recheck clock on the status-file mtime (+ack), while the afk daemon keeps anchoring on its existing .subsuper-paused- epoch marker; both now honor the ack and use the shared pause_backoff_secs so the widening curve is identical, but the exact anchor EVENT still differs slightly (a pre-existing difference Codex flagged; full anchor unification is deliberately left as a follow-up rather than a daemon refactor in this PR). Lower-leverage additions: a queue-first parallelism bias in AGENTS.md intake and a broadened cheap-mechanical-routing rule in the EXAMPLE docs/examples/crew-dispatch.json (config/ is local) with a captain-approval-only note. Tests: tests/fm-watch-triage.test.sh (41) and tests/fm-daemon.test.sh (95) green under BSD coreutils; bin/fm-lint.sh clean under pinned shellcheck 0.11.0. Deliberately NOT guessed (surfaced to the captain as policy calls): the standard captain-gated cadence number, codifying salute-as-release-cleanup, and adopting cheap-model routing.
What Changed
pausedstatus may carry an inline[recheck=<dur>]token (s/m/h/d or bare seconds), withfm-classify-lib.sh:pause_recheck_secsas the single owner of the grammar (clamped to[FM_PAUSE_RECHECK_MIN_SECS, FM_PAUSE_RECHECK_MAX_SECS]) andstatus_line_verbgeneralized to strip any[tok=...]bracket so the new token shares the existing[key=]slot; both the watcher (fm-watch.sh) and the afk daemon (fm-supervise-daemon.sh) read it.fm-classify-lib.sh:pause_backoff_secs(base×2^streak, capped atFM_PAUSE_RESURFACE_MAX_SECS, default 12h), shared by watcher and daemon; the streak is keyed by the logical pause/window and resets to base only on a positive signal (fresh crew status line or authoritative working verdict), never on an ambiguous read, and a declared base above the cap is preserved.bin/fm-pause-ack.shso firstmate can defer the next recheck at the current widened interval by touching a supervisor-ownedstate/.paused-ack-<key>marker without a crew turn; the recheck age now anchors onmax(status-file mtime, ack mtime)to avoid tripping a spurious signal wake.tests/fm-watch-triage.test.shcoverage for the new classifiers, token widening, ack deferral, and the pause-ack script, plus doc syncs across AGENTS.md,docs/architecture.md,docs/configuration.md, anddocs/scripts.md, and a queue-first parallelism bias note in intake with a broadened cheap-mechanical routing example indocs/examples/crew-dispatch.json.Risk Assessment
✅ Low: The change is well-bounded and backward-compatible, with the token grammar and backoff math each having a single shared owner, defensive input validation throughout, consistent key derivation across the new script/watcher/daemon, complete cleanup of new state files, and six new tests covering parsing, clamping, widening, reset, and ack-defer.
Testing
The pre-run baseline test command passed. I ran the two targeted suites this change touches - fm-watch-triage (30 ok, all 6 new pause-cadence/backoff/ack tests included) and fm-daemon (95 ok, EXIT=0) - both green under BSD coreutils. Since passing unit tests alone aren't sufficient evidence, I also produced two CLI transcripts driving the actual scripts an end user (firstmate) would invoke: one showing the exponential-backoff cadence widening an idle lane's rechecks from 24/day to 5/day (the ~4x quota reduction the branch targets, 240→50/day across 10 parked lanes) and the clamped
[recheck=]token, and one drivingfm-pause-ack.shto defer a real paused lane while leaving the crew status file byte-for-byte unchanged (no spurious signal wake, zero crew turn) and rejecting non-paused/missing/no-arg cases with the right exit codes. This is a shell-CLI feature with no UI surface, so evidence is CLI transcripts rather than screenshots. Worktree left clean; transient state used only ephemeral /var/folders temp dirs.Evidence: Backoff cadence demo (rechecks/day: old 24 → new 5; ×10 lanes 240→50)
Evidence: [recheck=] token clamping + fm-pause-ack.sh defer/refuse transcript
Evidence: fm-pause-ack.sh: defer paused lane without touching crew status (no crew turn)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-supervise-daemon.sh:1011- Watcher and afk daemon diverge on streak reset: the watcher (bin/fm-watch.sh:375) resets the backoff streak to base when the crew writes a fresh status line (detected via the status-mtime stored alongside the streak), but the daemon (bin/fm-supervise-daemon.sh:1011) stores only a bare streak count and never resets it on a fresh crew status line - it only clears the streak when the pane flips busy/gone. So in afk mode a pause that is re-declared with a new reason while never flipping busy keeps widening (up to the 12h cap) instead of being rechecked promptly again. The forgotten-pause safety property still holds (bounded by the cap), and the author flagged full anchor unification as a deliberate follow-up, so this is a documented tradeoff rather than a defect.✅ **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- 30 ok, including newtest_pause_recheck_secs_classifier,test_pause_backoff_secs_classifier,test_paused_recheck_token_widens_window,test_paused_backoff_widens_and_resets,test_paused_ack_defers_recheck,test_pause_ack_scriptbash tests/fm-daemon.test.sh- 95 ok, EXIT=0, no failure lines (grep of 'fail' matched only descriptions like 'a failing channel falls back')Manual CLI transcript: sourcedbin/fm-classify-lib.shand ranpause_backoff_secs 3600 <streak>for streak 0-6 showing 1h→2h→4h→8h→12h(cap) widening, and computed old-vs-new rechecks/day (24 vs 5; ×10 lanes = 240 vs 50)Manual CLI transcript:pause_recheck_secson default/[recheck=8h]/[recheck=10s](clamped up)/[recheck=3d](clamped down)/[recheck=lol](fallback), plusstatus_line_verbstill returning barepausedManual end-to-end run ofbin/fm-pause-ack.sh merge-gateagainst a paused task (creates window-keyed ack marker, clears resurface throttle, leaves crew status mtime unchanged) and refusal on non-paused task (exit 1), missing task (exit 1), and no-arg (exit 2)✅ **Document** - passed
✅ No issues found.
🔧 Fix: no lint fixes needed; shellcheck 0.11.0 passes clean
1 warning still open:
🔧 Fix: no lint fixes needed; scripts pass clean under pinned shellcheck 0.11.0
1 warning still open:
🔧 Fix: no lint fixes needed; scripts pass clean under pinned shellcheck 0.11.0
1 warning still open:
✅ **Push** - passed
✅ No issues found.