Skip to content

fix(bin): detect and surface workers parked on the account allowance - #6

Merged
x45dev merged 6 commits into
mainfrom
fm/fm-supervision-dies-with-allowance
Aug 29, 2026
Merged

x45dev merged 6 commits into
mainfrom
fm/fm-supervision-dies-with-allowance

Conversation

@x45dev

@x45dev x45dev commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Intent

Notice and recover workers parked on the account allowance.

Evidence, 2026-08-17: two crewmates spawned at 05:47 UTC hit the account session limit immediately, printed "You've hit your session limit - resets 8:30am (UTC) - Press Enter to continue after reset", and parked. The reset happened at 08:30. Nothing resumed them. They were still parked at 11:07 UTC - about two and a half hours of dead time past the reset - and were only found because an unrelated stale notification fired on one of the two panes. A third worker spawned in the same batch never hit the limit and ran normally, so nothing at the fleet level looked wrong. Recovery was a single Enter followed by one steer per worker, after which both picked up their briefs and ran. The cost is entirely in not noticing.

Two separate defects, which must not be conflated because the fixes differ:

  1. Nothing notices a worker parked on the allowance. The pane stays alive and the process stays alive, so the ordinary liveness check reads healthy and no wake fires. The stale notification that eventually found it was incidental. Detection is the primary deliverable.

  2. Nothing resumes a worker after the reset passes. The condition is trivially detectable - the pane prints its own reset time, and quota-axi reports the account position directly (at 11:07 the account had 84 percent of the session window and 42 percent of the week left, so the allowance was not the constraint by then).

Accepted scope decision carried into this change: fix 1 first and completely, since it is the defect that cost two and a half hours. Fix 2 only if it falls out cleanly from the same change - an automatic resume that fires at the wrong moment is worse than a notification that reaches firstmate, so where there is any doubt, ship the detection and file the resume as separate work. This change ships detection only and the automatic resume is deliberately excluded, to be filed separately.

Whatever is built must not be more elaborate than the observed recovery, which was a single Enter plus one steer per worker.

Constraints:

  • Read quota-axi's current help rather than assuming its flags.
  • The detection must not classify a healthy long-running worker as parked. There is a separate open item for false wedge alarms; this must not add a second source of them.

Tests: ship a test that fails without the change - a pane rendering the allowance-parked message is detected as parked, and a pane rendering ordinary working output is not.

What Changed

  • Add bin/fm-allowance-lib.sh, the single owner of allowance-park detection: per-harness session-record (Claude transcript isApiErrorMessage/apiErrorStatus: 429) and rendered-pane signature checks, gated to only verified harnesses (currently claude*) so unsupported adapters behave exactly as before.
  • Wire the detection into bin/fm-crew-state.sh as the highest-priority state source (outranks the no-mistakes run lookup and status-log reconciliation) and into bin/fm-watch.sh, which surfaces a parked worker as a named "stale" wake (once per park episode, tracked via a .allowance-<key> marker) instead of waiting out an ordinary wedge timer; a structural-only probe (no settled pane yet) can detect and wake but never clears a prior marker, while a call carrying a settled pane tail is treated as the complete evidence for the cycle.
  • Register fm-allowance-park.test.sh and fm-allowance-park-live-e2e.test.sh in bin/fm-test-run.sh's test families, and move wait_poll_cycle/file_mtime out of tests/fm-watch-triage.test.sh into the shared tests/wake-helpers.sh for reuse across test files.
  • Update AGENTS.md, docs/architecture.md, and docs/scripts.md to document the new .allowance-* state files, the allowance-park priority over crew-state's other sources, and the new script's entry in the inventory table.

Risk Assessment

✅ Low: The fix commit correctly threads a final flag through allowance_park_check so only the call that has seen every available signal for a window this cycle (the settled-pane call, or a secondmate's structural-only call when no pane check follows) may clear the marker; a structural-only probe ahead of the pane check for an ordinary worker or admitted mate now leaves the marker intact on an inconclusive failure, closing the wake-storm path the prior round identified. Traced both call sites, the marker-clear/write/dedup logic, and fm_allowance_park_detail's signal precedence, and the new test exercises the previously-buggy pane-only fallback across two watcher relaunches, asserting no double wake and no marker loss.

Testing

Ran the targeted suite tests/fm-allowance-park.test.sh via bin/fm-test-run.sh: all 13 tests pass, including the new regression test test_watcher_surfaces_a_pane_only_park_once_across_relaunches, which reproduces the exact wake-storm scenario from the recorded decision (pane-only-detected park with an unresolvable transcript). I confirmed this is a genuine regression test by checking out the pre-fix bin/fm-watch.sh (commit 09e6b43) with the new test file and re-running: the new test failed with the same symptom described in the bug report ("the same pane-only park woke firstmate twice"), while all other tests still passed. Restoring the fixed bin/fm-watch.sh made all 13 tests pass again, and the working tree was left clean.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-watch.sh - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • 🚨 bin/fm-watch.sh:772 - The previously-identified and user-approved-to-fix defect (allowance-marker-cleared-before-pane-check) is still present in this diff, unchanged in substance. allowance_park_check() (fm-watch.sh:762-781) is still called twice per poll for the same $key: once with an empty tail ahead of the secondmate skip (line 1376) and once with the settled pane tail once the capture is byte-identical across polls (line 1398). Inside the function, ANY failure of fm_allowance_park_detail unconditionally does rm -f &#34;$marker&#34; (line 773), with no distinction between 'this call saw every signal available for this window' and 'this call only had the empty-tail structural probe'. For an ordinary (non-mate) worker whose session-record transcript cannot be resolved/trusted for its worktree (relocated CLAUDE_CONFIG_DIR store, or a worktree cwd-prefix mismatch after a cd) but whose pane still renders the limit notice: call 1 (tail='') fails structurally and deletes the marker; call 2 (tail=$tail40, same poll) detects the park via the pane fallback, finds the marker absent, and fires fm_wake_append/wake as though it were a brand-new park. Because a parked pane stays byte-identical across polls, this repeats on every subsequent poll, directly violating the 'surfaces once per episode' guarantee the user explicitly required in the prior round ('the once-per-episode contract is the only thing keeping a parked worker from becoming a wake storm'). tests/fm-allowance-park.test.sh's test_watcher_surfaces_each_park_once (line 326) still cannot catch this: build_parked_case always uses transcript-mode 'parked' (a locatable, trusted transcript), so its call 1 succeeds via the session-record signal and never reaches the rm -f branch; the pane-only fallback path is only exercised via direct fm_allowance_park_detail calls (test_either_signal_alone_carries_the_verdict), never through two watcher poll cycles on the same window. The user's required invariants from the prior round (marker cleared only by a call that saw every signal available for that window; a secondmate's structural-only call must still be able to clear its own marker since its pane is never captured; a worker whose hash changed since the last poll never reaches the settled-pane call site) are not implemented - the code has no logic distinguishing these cases at all.

🔧 Fix: fix(bin): stop allowance marker clearing on inconclusive empty-tail probe
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • ./bin/fm-test-run.sh tests/fm-allowance-park.test.sh (post-fix, target commit 69174d4): 13/13 pass
  • ./bin/fm-test-run.sh tests/fm-allowance-park.test.sh with bin/fm-watch.sh reverted to pre-fix commit 09e6b43: 12/13 pass, test_watcher_surfaces_a_pane_only_park_once_across_relaunches fails reproducing the wake-storm bug
  • restored bin/fm-watch.sh to the fixed version and reran the suite to confirm clean pass and clean working tree
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

x45dev added 6 commits August 28, 2026 22:39
…ed in)

A worker whose harness refuses a turn on the account allowance keeps a live
pane and a live process, so every liveness probe firstmate owns reads healthy
and no wake fires. On 2026-08-17 two crewmates parked seconds after launch,
their reset passed at 08:30, and nothing surfaced or resumed them until an
unrelated wedge timer happened to fire on one of the two panes hours later.

This adds bin/fm-allowance-lib.sh, the one owner of that detection, with two
independent signals so no single vendor string is load-bearing:

- session-record: the harness's own transcript records the refusal as an
  assistant record carrying isApiErrorMessage with an HTTP 429 status.
  Structural, and preferred. Reading the LAST conversational record is what
  makes it current-state rather than history.
- pane: the rendered notice matched against a per-harness signature in a
  bounded tail of the capture, for a worker whose transcript firstmate cannot
  locate or a harness that reworded its records.

Per-harness support is a gate, not a default: only claude has a verified
signature, and every other adapter reports not-parked, so firstmate's
behaviour for them is unchanged. The library is deliberately kept out of the
semantic busy-state contract in bin/fm-busy-lib.sh, which forbids rendered
text as a state source; this one can only ever ADD a wake or name a cause.

Both signals were verified against real evidence on this machine: 106 refusal
records across ~/.claude/projects, all carrying apiErrorStatus 429, with the
last-record test separating 27 still-parked transcripts from 28 that resumed
after their refusal.

PARTIAL WORK, committed so nothing is lost while the account allowance is
exhausted. Still to come on this branch:

- wiring into bin/fm-watch.sh so a park surfaces immediately as a named wake
  instead of waiting out a wedge timer, detected independently of the busy
  verdict;
- wiring into bin/fm-crew-state.sh so recovery reads the cause instead of
  "harness busy";
- the portable regression and the opt-in live guard both required for a
  harness-dependent check, and the docs/verification/supervision.md entry;
- the AGENTS.md state-file line for the new watcher marker.

Nothing calls this library yet, so this commit changes no firstmate behaviour.
A worker whose provider refused the turn on the account allowance keeps a live
process, a live endpoint, and a normally rendered pane, so every liveness probe
firstmate owns reads it as healthy and no wake fires. On 2026-08-17 two
crewmates parked seconds after launch, their reset passed at 08:30, and nothing
surfaced them until an unrelated wedge alarm happened to fire on one of the two
panes two and a half hours later - and what it said then was "possible wedge",
not the cause.

Wire bin/fm-allowance-lib.sh into the two places that decide whether a worker
needs attention:

- bin/fm-watch.sh surfaces the park as a named wake that says what happened and
  that recovery is a single Enter, once per park episode (state/.allowance-<key>
  remembers what was already reported, and is dropped as soon as the worker is
  no longer parked). It runs ahead of the busy gate and independently of the
  busy verdict, because a refused turn need not close the turn-end hook that
  would mark the worker idle, in which case the pane reads as provably working
  indefinitely. It also runs ahead of the secondmate skip, from the structural
  signal alone, so an idle-by-design mate is covered without reading its pane.
- bin/fm-crew-state.sh reports it as the crew's current state ahead of every
  other source, so recovery reads the cause rather than "harness busy".

Detection only. Automatic resume once the reset passes is deliberately not part
of this change: a resume that fires at the wrong moment is worse than a
notification that reaches firstmate.

tests/fm-allowance-park.test.sh pins the classifier and both integration points
with real processes and no harness, including that either signal alone carries
the verdict; reverting the two wired scripts fails three of its cases.
tests/fm-allowance-park-live-e2e.test.sh is the opt-in drift guard over every
installed harness, and docs/verification/supervision.md records the dated
per-harness evidence and the command that refreshes it.
…-park's priority over crew-state and add script inventory row
@x45dev
x45dev merged commit c8536c4 into main Aug 29, 2026
25 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