Skip to content

perf(bin): tune watcher wake cadence for quiet fleets - #354

Closed
kingstyles wants to merge 4 commits into
kunchenguid:mainfrom
kingstyles:fm/watcher-cadence-tune
Closed

kingstyles wants to merge 4 commits into
kunchenguid:mainfrom
kingstyles:fm/watcher-cadence-tune

Conversation

@kingstyles

Copy link
Copy Markdown

Intent

Tune firstmate watcher/wake cadence to reduce supervising LLM token churn without weakening supervision. The requested change was to investigate the wake path, batch benign wakes harder, and consider longer effective heartbeat cadence when the fleet is small or only secondmates are running. The implemented decision keeps ordinary crewmates on the existing stale/heartbeat safety cadence, leaves per-task check poll semantics unchanged, and preserves the absorb-only-when-provably-working rule for no-verb signals and stale panes. It extends signal coalescing so status/turn-end bursts wait for a quiet grace window up to FM_SIGNAL_COALESCE_MAX, defaulting to 90 seconds only when FM_SIGNAL_GRACE is not explicitly set. It adds secondmate-only heartbeat defaults of 1800s base and 14400s cap, while explicit FM_HEARTBEAT/FM_HEARTBEAT_MAX keep the old values unless the secondmate-specific knobs are set. Expected impact: typical idle secondmate-only fleets still wake the LLM 0 times per hour on no-change heartbeats because those remain absorbed, but heartbeat fleet scans drop from 6/hour initially to 2/hour initially and from a 2h cap to a 4h cap, reducing bash supervision churn; bursty status plus turn-end completions that previously could cost two supervisor wake turns should now collapse to one. Documentation, configuration docs, and tests were updated, including hermetic missing-tool tests for hosts that already have node or orca installed.

What Changed

  • Extended bin/fm-watch.sh signal coalescing so bursts of status/turn-end wakes wait for a quiet grace window capped at FM_SIGNAL_COALESCE_MAX (default 90s when FM_SIGNAL_GRACE is unset), collapsing what used to be two supervisor wakes into one.
  • Added secondmate-only heartbeat defaults (1800s base doubling to a 14400s cap) applied when every in-flight task is kind=secondmate, while explicit FM_HEARTBEAT/FM_HEARTBEAT_MAX still override; kept the watcher beacon touched during the coalescing wait loop so fm-guard.sh liveness checks don't false-alarm.
  • Updated AGENTS.md, CONTRIBUTING.md, docs/architecture.md, docs/configuration.md, and docs/scripts.md to document the new cadence knobs, and added/extended tests/fm-watch-triage.test.sh (28 assertions), tests/lib.sh, and related backend/bootstrap/session-start tests to cover the new behavior, including a fix to the fm-send conformance test's asymmetric preflight-line stripping.

Risk Assessment

✅ Low: The change is a well-scoped, backward-compatible tuning of watcher cadence (signal-coalescing quiet-window loop and secondmate-only heartbeat defaults), guarded by explicit-override fallbacks that preserve old behavior, a beacon-freshness fix for the new wait loop, and thorough new tests exercising both cadences and the beacon property.

Testing

Ran the baseline command plus the full 49-file test suite (and re-ran the three files touched by this branch individually for close inspection); every test passes with no failures, confirming the round-1 fm-send conformance failure was resolved by the final commit and the new watcher-cadence behavior (secondmate-only heartbeat backoff, extended signal coalescing, beacon liveness during coalescing) is exercised and passing.

  • Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (22m50s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

🔧 **Test** - 1 issue found → auto-fixed ✅
  • 🚨 tests failed with exit code 1
  • 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"

🔧 Fix: Fix fm-send conformance test's asymmetric preflight-line stripping
✅ Re-checked - no issues remain.

  • 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 (28 assertions covering secondmate-only heartbeat defaults, signal coalescing up to FM_SIGNAL_COALESCE_MAX, beacon freshness, wedge-escalation, absorb-only-when-provably-working)
  • bash tests/fm-backend.test.sh (includes the fm-send old-vs-new conformance test whose asymmetric preflight-stripping bug was the round-1 failure)
  • bash tests/fm-bootstrap.test.sh
  • bash tests/fm-session-start.test.sh
  • Full suite: for t in tests/*.test.sh; do bash "$t"; done — all 49 files exit 0 with no 'not ok' lines
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kingstyles
kingstyles force-pushed the fm/watcher-cadence-tune branch from 13caf39 to d1d5f28 Compare July 9, 2026 00:44
@kunchenguid

kunchenguid commented Jul 10, 2026 •

Copy link
Copy Markdown
Owner

Thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#354 at d1d5f28d.

@kunchenguid

Copy link
Copy Markdown
Owner

Automated reminder: this PR still looks blocked on a rebase or merge conflict fix.

If you are still interested, please rebase onto the current base branch, resolve the conflict, and push.

If I do not hear back, I may close this as inactive.

@kunchenguid

Copy link
Copy Markdown
Owner

I am closing this because it has been waiting on a rebase or merge-conflict fix since 2026-07-10, and I have not seen a comment or push since then.

If you still want to keep working on this, please reopen it or open a new PR and mention this one.

Happy to take another look when there is an update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants