Skip to content

feat(watch): per-pause recheck cadence with exponential backoff and supervisor ack - #11

Merged
7hoenix merged 3 commits into
mainfrom
fm/quota-efficiency-4x
Jul 24, 2026
Merged

7hoenix merged 3 commits into
mainfrom
fm/quota-efficiency-4x

Conversation

@7hoenix

@7hoenix 7hoenix commented Jul 24, 2026

Copy link
Copy Markdown
Owner

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

  • Added per-pause recheck cadence: a declared paused status may carry an inline [recheck=<dur>] token (s/m/h/d or bare seconds), with fm-classify-lib.sh:pause_recheck_secs as the single owner of the grammar (clamped to [FM_PAUSE_RECHECK_MIN_SECS, FM_PAUSE_RECHECK_MAX_SECS]) and status_line_verb generalized 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.
  • Added asymmetric exponential backoff on unchanged pauses via fm-classify-lib.sh:pause_backoff_secs (base×2^streak, capped at FM_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.
  • Added bin/fm-pause-ack.sh so firstmate can defer the next recheck at the current widened interval by touching a supervisor-owned state/.paused-ack-<key> marker without a crew turn; the recheck age now anchors on max(status-file mtime, ack mtime) to avoid tripping a spurious signal wake.
  • Added tests/fm-watch-triage.test.sh coverage 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, and docs/scripts.md, and a queue-first parallelism bias note in intake with a broadened cheap-mechanical routing example in docs/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 driving fm-pause-ack.sh to 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)
### Demo 1 - exponential backoff cadence (fm-classify-lib.sh:pause_backoff_secs)
One parked lane, base recheck = 1h (3600s). Each unchanged recheck widens the window base*2^streak, capped at 12h.

streak   effective      human         
------   -------------  ------------- 
0        3600s          1.0h          
1        7200s          2.0h          
2        14400s         4.0h          
3        28800s         8.0h          
4        43200s         12.0h         
5        43200s         12.0h         
6        43200s         12.0h         

Old behavior: every parked lane rechecked hourly forever. New: an idle lane's rechecks/day collapse from 24 to a handful.
Rechecks over 24h for one idle lane -- OLD (fixed 1h) vs NEW (backoff from 1h base):
  OLD rechecks/day = 24       NEW rechecks/day = 5
  For 10 parked high-context lanes: OLD = 240/day vs NEW = 50/day full-context turns.
Evidence: [recheck=] token clamping + fm-pause-ack.sh defer/refuse transcript
### Demo 2 - inline [recheck=<dur>] token (captain-gated lane starts on a long window)
  paused: awaiting review                        -> 3600s
  paused [recheck=8h]: awaiting the release cut  -> 28800s
  paused [recheck=10s]: x                        -> 300s
  paused [recheck=3d]: x                         -> 86400s
  paused [recheck=lol]: x                        -> 3600s
  (10s clamps up to the 300s floor; 3d clamps down to the 86400s/24h ceiling; unparseable falls back to 3600s default)
  verb of 'paused [recheck=8h]: ...' is still: 'paused'  (token stripped, backward compatible)

### Demo 3 - fm-pause-ack.sh: defer a recheck with a zero-token supervisor touch (no crew turn)
before ack: ack marker exists = no; crew status mtime = 1784900051
$ bin/fm-pause-ack.sh merge-gate
fm-pause-ack: deferred the next recheck for task merge-gate (sess:fm-merge-gate) by one pause window
after ack:  ack marker exists = yes; resurface-throttle cleared = yes
crew status file mtime UNCHANGED (1784900051 == 1784900051) -> no signal-scan trip, no crew turn spent

### Demo 4 - fm-pause-ack.sh refuses when there is nothing to defer
$ bin/fm-pause-ack.sh merge-gate  (task no longer paused)
fm-pause-ack: task merge-gate is not in a declared pause (last status: working: building); nothing to defer
  exit=1
$ bin/fm-pause-ack.sh nope        (no such task)
fm-pause-ack: no task metadata at /var/folders/2_/dz7_pwrs2_s0nx0y3lq0rznc0000gn/T/tmp.eTDRkJxIDr/state/nope.meta
  exit=1
$ bin/fm-pause-ack.sh             (no argument)
usage: fm-pause-ack.sh <task-id>
  exit=2
Evidence: fm-pause-ack.sh: defer paused lane without touching crew status (no crew turn)
$ bin/fm-pause-ack.sh merge-gate
fm-pause-ack: deferred the next recheck for task merge-gate (sess:fm-merge-gate) by one pause window
after ack: ack marker exists = yes; resurface-throttle cleared = yes
crew status file mtime UNCHANGED (1784900051 == 1784900051) -> no signal-scan trip, no crew turn spent

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ 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 new test_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_script
  • bash 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: sourced bin/fm-classify-lib.sh and ran pause_backoff_secs 3600 &lt;streak&gt; 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_secs on default/[recheck=8h]/[recheck=10s](clamped up)/[recheck=3d](clamped down)/[recheck=lol](fallback), plus status_line_verb still returning bare paused
  • Manual end-to-end run of bin/fm-pause-ack.sh merge-gate against 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.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 127)

🔧 Fix: no lint fixes needed; shellcheck 0.11.0 passes clean
1 warning still open:

  • ⚠️ linter found issues (exit code 127)

🔧 Fix: no lint fixes needed; scripts pass clean under pinned shellcheck 0.11.0
1 warning still open:

  • ⚠️ linter found issues (exit code 127)

🔧 Fix: no lint fixes needed; scripts pass clean under pinned shellcheck 0.11.0
1 warning still open:

  • ⚠️ linter found issues (exit code 127)
✅ **Push** - passed

✅ No issues found.

7hoenix added 3 commits July 24, 2026 09:08
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.
@7hoenix
7hoenix merged commit 30ce4a3 into main Jul 24, 2026
4 checks passed
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