Skip to content

fix(bin): dedupe watcher stale wakes for already-delivered terminal status - #2701

Closed
peterOC26 wants to merge 3 commits into
kunchenguid:mainfrom
peterOC26:fm/fm-watcher-upstream-2573-w2
Closed

peterOC26 wants to merge 3 commits into
kunchenguid:mainfrom
peterOC26:fm/fm-watcher-upstream-2573-w2

Conversation

@peterOC26

Copy link
Copy Markdown

Intent

Fix issue https://github.com/peterOC26/firstmate/issues/2573 with the smallest upstream-compatible change: stop routine terminal footer redraws from repeatedly invoking the primary model after the current terminal lifecycle/status transition has already been durably delivered.

What changed

bin/fm-watch.sh - the terminal-stale branch now absorbs a new pane hash when the task's last status line is already byte-identical to state/.hb-surfaced-<task> (the durable delivered-lifecycle marker mark_surfaced already writes at every enqueue-complete site). It advances the existing .stale-<key> bookkeeping and clears the existing stale/wedge timers instead of queuing a wake. Pane hashes remain liveness input only, never delivery identity. No new durable state and no new resurfacing cadence were added.

Preserved exactly:

  • The first undelivered terminal state still wakes exactly once.
  • Genuine blocked, failed, keyed-decision, PR-ready, and merged transitions still wake.
  • Merge polling, blind-stop protection, and the watcher liveness beacon are untouched.
  • Raw pane hashes still drive liveness and wedge evidence.
  • Enqueue-before-mark-surfaced ordering is unchanged; the absorb path never marks a line delivered.
  • Away-mode ownership and heartbeat batching are unaffected.

Out of scope (deliberately not touched): footer-text filtering, Claude/Pi/Codex supervision or delivery policy, the already-merged watcher re-arm fix, issue #2614's non-terminal wedge behavior, and teardown cleanup of the delivery/hash markers.

Tests

  • tests/fm-watch-triage.test.sh - added a changing-footer fixture proving a delivered terminal lifecycle absorbs repeated cosmetic pane-hash changes, plus coverage that the first undelivered terminal state still wakes once and a later genuine transition still delivers. Full suite passes.
  • tests/fm-claude-stop-autoarm.test.sh - added coverage that Claude Stop stays quiet for a delivered changing-footer state and rewakes exactly once for the first undelivered state. Full suite passes.
  • tests/fm-pi-watch-extension.test.sh - added coverage that Pi sends no follow-up for a delivered changing-footer state and sends exactly one for the first undelivered state. Full suite passes (one unrelated timing-sensitive assertion, Pi session transitions must rearm through an explicit generation owner, is flaky identically on unmodified upstream/main - confirmed by repeated runs on both trees, 2/3 pass either way).
  • tests/fm-watch-checkpoint.test.sh - added coverage that a delivered changing-footer state stays quiet through the Codex checkpoint and the first undelivered state wakes it once. Full suite passes.
  • bin/fm-lint.sh - clean (ShellCheck 0.11.0 and actionlint 1.7.12, both pinned versions).
  • bin/fm-doc-audience-check.sh - clean (surfaces=69 local_links=255).
  • bin/fm-test-run.sh --changed --base upstream/main - total=150 failed=12 duration_ms=3551569. None of the 12 failures touch any file this change modifies (bin/fm-watch.sh, tests/fm-claude-stop-autoarm.test.sh, tests/fm-pi-watch-extension.test.sh, tests/fm-watch-checkpoint.test.sh, tests/fm-watch-triage.test.sh, tests/lib.sh, tests/wake-helpers.sh, README.md, docs/architecture.md, docs/configuration.md). Each reproduces identically on an unmodified upstream/main checkout (confirmed directly for tests/fm-wake-queue.test.sh) or is a local-environment gap unrelated to this change (actionlint not on PATH for fm-lint.test.sh/fm-lint-workflows.test.sh, both green once installed; a stray leftover temp directory in fm-gotmp.test.sh).

Documentation

Updated README.md, docs/architecture.md, and docs/configuration.md (one sentence per line, plain dashes) to state that background watcher waiting is tokenless, while surfaced Claude Stop feedback, Pi follow-up, or a Codex checkpoint return that invokes the primary consumes an ordinary model turn, and that the pane hash is liveness evidence while the delivered status line is lifecycle delivery evidence.

Measured impact (the task this fix was extracted from)

  • About 4h42m, 176 model requests, 33.77m cache-read tokens, 536,926 cache-creation tokens, and 130,210 output tokens.
  • Three captain prompts caused 16 requests.
  • Watcher notifications caused 31 requests, about 9.303m cache-read tokens, 29,000 cache-creation tokens, and 17,500 output tokens.
  • Startup material was about 30,716 conservative text tokens.
  • The first request after context clear reported 34,378 newly cached plus 22,367 cached system/tool tokens.
  • Anthropic does not publish its subscription-limit accounting formula, so these figures prove repeated model invocation and context processing, not an exact quota formula.

Caveat

This is a fork-maintained PR opened for upstream review. It makes no claim of upstream acceptance.

@peterOC26

Copy link
Copy Markdown
Author

@kunchenguid This focused fix is ready for review. The relevant watcher, Claude Stop, Pi, and Codex checkpoint suites pass; lint and documentation checks are clean. The broader local changed-test run only reports failures reproduced on upstream/main or caused by local environment gaps, as detailed in the PR body. No CI, workflow, runner, or unrelated watcher behavior is changed.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Scheduled firstmate-oss pass. Diff reviewed against main (head aef9691d9423c5dc7c353bcfdca05a192fc48b9b). No security risk. Approving the pending first-time fork workflow runs.

Classification: corrective. Terminal-stale path was re-waking the primary on cosmetic pane-hash changes after the lifecycle line was already in state/.hb-surfaced-<task>. Absorb advances .stale-<key> and clears stale/wedge timers; pane hash stays liveness-only; absorb never marks a line delivered. First undelivered terminal state still wakes once; later blocked/failed/keyed-decision/PR-ready/merged lines still surface. Merge polling, blind-stop protection, and the liveness beacon are untouched.

VISION:

  • One captain, one interface: aligns. Batching/silence here is presentation of an already-delivered terminal state, not hiding a new failure, decision, or risk. Docs now say background waiting is tokenless while a surfaced Stop/Pi/Codex return costs a turn — honest.
  • Authority is explicit and never inferred: aligns. No new grant.
  • Scripts own the mechanics, agents own the judgment: aligns. Byte-identical status vs durable marker is a script comparison.
  • A restart is a non-event: aligns. Uses the existing durable surfaced marker; no new durable state.
  • Delegation with a spine: aligns. Does not blur ship/scout or weaken merge authority.
  • The fleet outlives any vendor: aligns. Watcher core plus Claude Stop / Pi / Codex checkpoint coverage.
  • Scope: aligns. Supervision, not workshop. Token efficiency is the point.

Merge-eligible: YES.

@kunchenguid kunchenguid left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking as Kun's firstmate: reviewed the full diff. No security risk. Corrective watcher stale-wake dedupe. Approve pending first-time fork CI.

@greptile-apps

greptile-apps Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge because no eligible blocking failure remains in the follow-up review scope.

@peterOC26
peterOC26 force-pushed the fm/fm-watcher-upstream-2573-w2 branch from 3a049f4 to 1d30efa Compare September 8, 2026 22:15
peterOC26 and others added 3 commits September 9, 2026 09:45
Absorb a terminal-stale pane whose status line already matches
state/.hb-surfaced-<task> instead of resurfacing on every cosmetic
footer redraw; pane hash stays liveness evidence only.
@peterOC26
peterOC26 force-pushed the fm/fm-watcher-upstream-2573-w2 branch from 1d30efa to 27baeac Compare September 9, 2026 08:05
@peterOC26

Copy link
Copy Markdown
Author

Hi @kunchenguid, this was approved on Aug 21 but has drifted into conflicts twice as main moved on. The fix is still needed: upstream main still re-wakes the primary for already-delivered terminal status on cosmetic pane changes. Would you be willing to merge it, or have your firstmate take it over and rebase? If you'd prefer I rebase once more, I'm happy to, if it can be merged soon after so it doesn't drift again.

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