Skip to content

fix(watch): preserve declared-pause stale suppression - #720

Closed
raywest wants to merge 4 commits into
kunchenguid:mainfrom
raywest:fm/fm-watch-mergewait-stale-b1
Closed

raywest wants to merge 4 commits into
kunchenguid:mainfrom
raywest:fm/fm-watch-mergewait-stale-b1

Conversation

@raywest

@raywest raywest commented Jul 19, 2026 •

Copy link
Copy Markdown

Intent

Fix a live, reproducible watcher bug in bin/fm-watch.sh: a done-then-declared-paused crewmate (e.g. a green-CI PR sitting idle awaiting the captain's merge decision) refired a bare 'stale: ' wake on EVERY freshly-armed watcher, even though the .stale- hash suppressor was already correctly set to the current pane hash. Root cause: once a stale hash is already classified for a task whose status log's last line is 'paused:', the watcher re-derives the absorb verdict via crew_absorb_class/pause_state_class on every recheck. A stale/misattributed no-mistakes run-step (e.g. an aborted run whose terminal outcome predates the crew's LATER paused: declaration) can report a non-working, non-paused verdict from fm-crew-state.sh; the old code treated ANY such verdict the same as a fresh 'crew has stopped' first-sight event, firing the bare stale wake and also deleting the .paused- marker as a side effect - which guaranteed the identical misfire on every subsequent poll or watcher restart forever, since crew_absorb_class kept re-reading the same stale aborted-run record. Fix: at the call sites in bin/fm-watch.sh that consume pause_state_class/crew_absorb_class for a crew whose current status-log line is 'paused:', only a definitive 'working' verdict now breaks the paused treatment; any other verdict (including this misattributed non-working/non-paused case) stays in the existing paused/long-recheck-cadence treatment instead of surfacing immediately. Genuine wedge detection for a plain (non-paused) stale pane is completely untouched.

Update: upstream merged #743 ("fix(watcher): bound stale wakes for parked crew") in the same area of bin/fm-watch.sh while this PR was open, fixing a related but distinct defect class (bounding stale wakes for a parked crew based on confirmed backend agent liveness). This branch has been merged forward onto current upstream main and narrowed to the delta #743 does not cover, so the two fixes are complementary rather than overlapping: #743 handles a confirmed-dead agent behind an unchanged pane; this PR handles a misattributed run-step outcome that outranks a crew's own later paused: declaration. #743's own new regression test (test_exited_declared_pause_is_bounded_but_live_gate_surfaces) is retained unmodified alongside this PR's test.

What Changed

  • Keep stale panes on declared-pause handling unless the watcher has definitive working evidence, preventing stale/misattributed run-state reads from repeatedly surfacing bare stale wakes - now expressed as the delta on top of fix(watcher): bound stale wakes for parked crew #743's own liveness-based bounding.
  • docs/architecture.md documents both fixes as complementary parts of the same paused-crew cadence.
  • Regression coverage for the restart case (test_nonterminal_stale_paused_survives_misattributed_run_step_across_restarts) sits alongside fix(watcher): bound stale wakes for parked crew #743's already-merged live/dead-agent coverage.

Risk Assessment

✅ Low: the change narrows an existing branch of the paused-recheck path; the plain (non-paused) stale wedge-detection path, and #743's own liveness-based logic, are untouched.

Testing

bash tests/fm-watch-triage.test.sh and bash tests/fm-watcher-lock.test.sh both pass in full against the merged branch, including the new regression test, every pre-existing case, and #743's own dead-agent/live-gate coverage. bin/fm-lint.sh (shellcheck 0.11.0, the pinned CI version) is clean.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-watch.sh:973 - For the persistent none verdict this now absorbs, pause_state_class removes .paused-rechecked-*, so every subsequent poll re-runs crew_absorb_class instead of using its paused recheck throttle. That can invoke the bounded no-mistakes state read every FM_POLL (up to 10 seconds each) for the exact misattributed-run condition. Retain/rearm the recheck marker for non-working paused verdicts while preserving the periodic working-state check.

🔧 Fix: Throttle paused stale rechecks
✅ Re-checked - no issues remain.

⏭️ **Test** - skipped
  • 🚨 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: Preserve declared-pause stale suppression
1 error still open:

  • 🚨 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: Validate watcher stale suppression
1 error still open:

  • 🚨 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: Confirm watcher tests pass
1 error still open:

  • 🚨 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: Preserve declared-pause stale suppression
1 error still open:

  • 🚨 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"
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

* feat(harness): verify and land the kimi-code crewmate adapter

Verify kimi-code 0.27.0 empirically and land the complete adapter, scoped
to crewmate/scout duty on the tmux backend.

Empirical facts (isolated KIMI_CODE_HOME + scratch tmux; dated captures):
- kimi rejects a positional prompt and -p is print-mode only, so the brief
  is delivered post-launch via tmux bracketed paste into the composer and
  submitted with the verify-and-retry Enter (multi-line arrives as ONE
  message, verified live).
- kimi fires a Stop hook at every completed turn (payload carries cwd and
  stop_hook_active); hooks load only from $KIMI_CODE_HOME/config.toml, so
  the turn-end signal adapts the grok pattern: a token-guarded global
  script + fm-turn-end.d registry + per-task .fm-kimi-turnend pointer,
  plus ONE idempotent, kimi-doctor-validated [[hooks]] Stop append that
  restores a backup and aborts the spawn on rejection.
- busy signature "ctrl+c: cancel" (space after colon, unlike grok); the
  shared default regex now covers both via 'Ctrl\+c: ?cancel'. Narrow-pane
  under-reporting is documented; the Stop-hook marker is authoritative.
- no env marker exists; detection is process-ancestry on the kimi binary.
- --model verified; no effort flag exists (record-only effort).
- the shared composer classifier reads kimi's idle bordered composer as
  empty unchanged (dark-truecolor border strips as ghost).

End-to-end proof through the modified scripts: normal-path spawn into a
treehouse worktree, brief pasted and executed under --yolo, busy read
mid-turn, turn-end marker fired per turn (including a mid-turn queued
fm-send steer), /skill:no-mistakes visible in the crewmate pane, clean
/exit, and teardown removing pointer, token, and state.

Scope refusals fail loudly: kimi --secondmate and any non-tmux backend
are refused at spawn (the herdr refusal fired live during verification).
kimi is deliberately absent from the tmux agent-liveness allowlist and
the bootstrap secondmate-liveness case (both secondmate-only surfaces).

Claude-Session: https://claude.ai/code/session_01U5XNJupDTm8CPSAx8rWtLH

* no-mistakes(review): Harden Kimi spawn recovery and teardown

* no-mistakes(review): Create state before Kimi metadata

* no-mistakes(document): Clarify Kimi's tmux-only crewmate scope

* no-mistakes(review): Fix Kimi raw scope and config locking

* no-mistakes(review): Prevent gate-state mutation before refusal

* no-mistakes(test): Restore Orca abort cleanup after Kimi lock import

* no-mistakes(document): Clarify Kimi template scope

---------

Co-authored-by: Ray West <[email protected]>
raywest and others added 2 commits July 19, 2026 06:35
…rge panes (#2)

* fix(watch): stop a declared pause from refiring bare stale on restart

A done-then-paused crew (a green-CI PR awaiting the captain's merge
decision) refired a bare "stale: <window>" wake on every freshly-armed
watcher, even though .stale-<key> already held the current pane hash.

Root cause: once a stale hash is already classified and the crew's own
status log still says paused:, the watcher re-derives the verdict via
crew_absorb_class on every recheck. A stale/misattributed no-mistakes
run-step (e.g. an aborted run whose terminal outcome predates the later
paused: line) can report a non-working, non-paused verdict; the old code
treated any such verdict as a first-sight surface, which also deleted the
.paused-<key> flag - guaranteeing the identical misfire on the next poll
or restart forever.

Fixed by making only a definitive working verdict break a declared
pause; any other verdict (including a misattributed run-step outcome)
stays in the paused/long-recheck-cadence treatment, at all three sites
that read pause_state_class/crew_absorb_class. Genuine wedge detection
for a non-paused stale pane is untouched.

This fixes the restart-suppression defect only. The larger question of
how firstmate should distinguish a done-awaiting-merge crew from a
wedged one (kunchenguid#703, kunchenguid#694) is out of scope here.

* no-mistakes(review): Throttle paused stale rechecks

* no-mistakes(document): Document paused stale-wake precedence

---------

Co-authored-by: Ray West <[email protected]>
* fix: repair two pre-existing flaky/failing test-suite bugs

The watcher-restart-vs-healthy-peer test in tests/fm-watcher-lock.test.sh
simulated a TERM-resistant live watcher peer with a bare
`node -e 'process.on("SIGTERM", ...)' &`, then immediately captured its
pid identity and exercised the restart path. Under load (e.g. right
after the suite's 40-process concurrency tests), node's own startup can
still be registering the signal handler when the restart logic signals
it, so the signal falls through to the default disposition and the
"TERM-resistant" peer dies. The arm script then correctly starts a
fresh watcher instead of reporting the peer healthy, and since a real
watcher blocks for a wake, the arm never exits within the test's
timeout. Confirmed via instrumented liveness-check tracing: the peer
pid transitioned from alive to gone mid-loop while the restart logic
was still polling it. Fixed by having the peer write a ready marker
(fs.writeFileSync, which JS guarantees runs after process.on() in the
same tick) and waiting for it before any signal is sent, removing the
race without weakening the assertion.

tests/fm-brief.test.sh's "secondmate charter must declare its role"
assertion still expected the pre-kunchenguid#685 wording "persistent domain
supervisor". Commit 1182883 (fix: accept secondmate house vocabulary,
kunchenguid#685) intentionally changed the charter text to "a persistent second
mate" as part of adopting nautical house vocabulary, and updated
tests/fm-captain-translation-contract.test.sh to match, but missed this
assertion in tests/fm-brief.test.sh. Not a code bug: the production
wording change was deliberate. Updated the stale assertion to match.

Verified: 20 consecutive green runs of each fixed test individually,
plus one full clean run of all 79 tests/*.test.sh files (0 failures).
shellcheck (bin/fm-lint.sh) clean.

* no-mistakes(review): Captain, reap TERM-resistant watcher peer

---------

Co-authored-by: Ray West <[email protected]>
@raywest
raywest force-pushed the fm/fm-watch-mergewait-stale-b1 branch from c7b3836 to 3701264 Compare July 19, 2026 22:51
@kunchenguid

Copy link
Copy Markdown
Owner

Automated reminder: 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#720 at 37012647.

# Conflicts:
#	bin/fm-spawn.sh
#	bin/fm-watch.sh
#	docs/architecture.md
#	tests/fm-watch-triage.test.sh
#	tests/fm-watcher-lock.test.sh
@kunchenguid

kunchenguid commented Jul 26, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: 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#720 at bf0d8d84.

@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 kunchenguid removed the wheelhouse:pending-contributor-action Managed by Wheelhouse label Aug 11, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

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. Reopen if you want to pick it back up.

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.

2 participants