Skip to content

feat(bin): declare Claude usage-limit stops with their reset time and resume due workers - #23

Merged
demy00 merged 4 commits into
mainfrom
feature/fm-limit-aware-r2
Nov 9, 2026
Merged

demy00 merged 4 commits into
mainfrom
feature/fm-limit-aware-r2

Conversation

@demy00

@demy00 demy00 commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Intent

The captain's own words, 2026-09-08, when the fleet went silent and nobody could tell why:

"we shall not spin up fable agents, just opus 5. only you should be fable. if a task would
require fable ask me for approval, if approval is not given after asking it 2 times, use opus."

That rule was his response to the symptom. This task is about the symptom itself, which he chose from four proposed firstmate improvements on 2026-09-09, in the order he set: this one is second.

WHY IT MATTERS, FROM LIVED EVIDENCE. On 2026-09-08 the account's session and monthly limits stopped firstmate and every worker at once, twice in one day. On 2026-09-09 it happened twice more - once overnight, resetting at 04:40, and again mid-morning, resetting at 11:40. On each occasion between six and twelve workers stopped mid-sentence and nothing anywhere recognised why. Nothing appends a status line; the pane simply shows the limit message and idles. Firstmate spent real time diagnosing jams that were not jams, and each recovery needed a hand-written nudge to every single worker telling it where it had stopped.

Captain 2026-11-09, releasing the held firstmate fixes: "5 yup" (start them, two at a time).

What Changed

  • Added bin/fm-claude-usage.sh, which bin/fm-spawn.sh now hooks into each Claude worker's StopFailure and UserPromptSubmit hooks:
    • Declaring the wait: a rate_limit stop appends a paused: usage limit - <Claude's limit text> until <UTC> status line. The reset time is read from Claude's own message, including the timezone and dates for weekly resets.
    • Closing the wait: when the next turn starts, the hook appends resolved to close that wait.
    • Other errors: any error kind other than rate_limit behaves exactly as before.
  • Added fm-claude-usage.sh resume <id>... | resume --due:
    • It steers workers the reset left idle through bin/fm-send.sh.
    • It refuses while a declared reset is still ahead.
    • --due picks up every live task whose limit wait has passed.
  • Added tests and docs:
    • A portable regression test that replays recorded limit texts.
    • A live e2e test that runs the real claude -p against a local stand-in API answering HTTP 429. It is registered in bin/fm-test-run.sh.
    • A "Claude usage-limit stop" verification section, plus updates to the Claude harness adapter reference and the CHANGELOG.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The new script is additive. Its hooks always exit 0 and fall back to || true. It reuses the existing paused/until absorb path. The round-1 fixes are in place: resolved is written before the steer and the failed-steer path restores the wait, and the dedupe is gone. Tests drive the public interface, and the change meets the intent (limit stops declare their own wait and can be resumed with one command).

Testing

I ran the targeted unit suite for bin/fm-claude-usage.sh and the live end-to-end test with real Claude Code 2.1.319, spawned through the real fm-spawn hooks. Both passed. The live test shows a real limit stop declaring the wait with the correct until, and the next turn closing it. I also walked through the CLI by hand, replaying the 2026-09-09 11:40 reset scenario, and saved the transcript. There is no UI surface, so the evidence is the status-file and CLI output. The worktree is left clean.

Evidence: Manual CLI transcript: limit stop declares the wait, resume refuses before the reset, turn-start closes it

Source: Manual CLI transcript: limit stop declares the wait, resume refuses before the reset, turn-start closes it

# 10:05 Budapest: worker w1 hits the session limit; StopFailure hook payload: {"error":"rate_limit","last_assistant_message":"You have hit your session limit · resets 11:40am (Europe/Budapest)"}
# worker w2 hits a server_error (not a limit)
$ cat state/w1.status
paused [at=1788941100]: usage limit - You have hit your session limit · resets 11:40am (Europe/Budapest) until 2026-09-09T09:41Z; after the reset: bin/fm-claude-usage.sh resume w1
$ cat state/w2.status
(no status written)

# 10:30, before reset: $ fm-claude-usage.sh resume w1
refused w1: its usage limit resets at 2026-09-09T09:41Z, not yet
exit=1
# 10:30: $ fm-claude-usage.sh resume --due
no worker is waiting on a usage limit that has reset
exit=0

# 11:41: Claude auto-continues; UserPromptSubmit hook fires turn-start
$ cat state/w1.status
paused [at=1788941100]: usage limit - You have hit your session limit · resets 11:40am (Europe/Budapest) until 2026-09-09T09:41Z; after the reset: bin/fm-claude-usage.sh resume w1
resolved [at=1788946860]: a new turn started after the usage-limit stop
Evidence: Live e2e against real Claude Code 2.1.319

Source: Live e2e against real Claude Code 2.1.319

ok - Claude 2.1.319 (Claude Code): a real limit stop declares the wait with its reset, and the next turn start closes it

1..1
ok - Claude 2.1.319 (Claude Code): a real limit stop declares the wait with its reset, and the next turn start closes it
FM_TEST_COMPLETE
Evidence: Unit behavior tests TAP output

Source: Unit behavior tests TAP output

1..10
ok - a real session-limit stop declares a usage-limit wait that clears at the published reset
ok - all 23 recorded real limit texts declare a usage-limit wait that resets inside the window they name
ok - small-hours, midnight, and dated weekly resets resolve to the right UTC instant
ok - a reset minute that has just begun is declared as due, not rolled a day or a year forward
ok - the 6 recorded non-limit API errors declare nothing
ok - a spawned Claude worker declares its own usage-limit stop and still closes its busy turn
ok - a new turn after a usage-limit stop closes the wait the stop declared, and nothing else
ok - resume refuses before the reset, and after it steers the worker on and closes its declared wait
ok - resume --due steers every worker whose limit has reset in one call, and leaves the rest waiting
ok - resume keeps a limit the steered turn hits declared, and an undelivered steer leaves the wait declared
FM_TEST_COMPLETE

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-claude-usage.test.sh (10 behavior tests: reset parsing for 23 recorded limit texts, 6 non-limit errors declare nothing, a spawned worker's hook wiring, turn-start closes the wait, resume refuse/steer, resume --due, the resolved line is written before the steer and the wait is restored when the steer fails)
  • FM_CLAUDE_USAGE_LIVE=1 bash tests/fm-claude-usage-live-e2e.test.sh against real Claude Code 2.1.319 and a local stand-in limit API
  • Manual CLI walkthrough of the 2026-09-09 11:40 Budapest reset scenario: stop-failure declaration, a server_error is ignored, resume refused before the reset, resume --due finds nothing before the reset, turn-start closes the wait
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…eset time

When the account's plan limit stopped workers, each pane showed Claude's
limit message and idled. Nothing appended a status line, so the watcher read
the silence as a possible wedge, and recovery meant a hand-written nudge to
every worker.

bin/fm-claude-usage.sh is wired by bin/fm-spawn.sh into the worker's existing
Claude hooks and writes the declared wait the absorb path already handles. It
adds no new worker state, classification tier, or watcher check:

- stop-failure (StopFailure hook): when `error` is `rate_limit`, append
  `paused: usage limit - <Claude's own limit text> until <UTC>; ...`. The
  `until` comes from the text's reset ("resets 11:40am (Europe/Budapest)",
  "resets Oct 7 at 5pm (Africa/Casablanca)"), one minute after the minute
  Claude shows, because Claude floors it. The same limit is declared once.
  Every other API error behaves as before.
- turn-start (UserPromptSubmit hook): close that wait when the next turn
  starts. Claude Code continues a limited session by itself after the reset
  (autoContinueAtUsageLimit, default on since 2.1.234; verified live in the
  worker launch shape on 2.1.319), and that continue fires UserPromptSubmit.
- resume <id>... | resume --due: firstmate's one-step recovery for workers
  the reset left idle. It refuses before the declared reset, then steers each
  worker through fm-send and closes its wait.

The status-line command that the survey proposed does fire in the worker
launch shape (checked live, 2.1.319). It is not needed here, because the
StopFailure payload already carries both the stop and its reset text.

Real samples: the 23 distinct rate_limit texts (session, 5-hour, weekly,
Europe/Budapest and Africa/Casablanca, 2.1.288-2.1.318) and 6 other API
error texts from this host's Claude transcripts. Each limit text is replayed
at the moment it was recorded. The default-on live guard
tests/fm-claude-usage-live-e2e.test.sh runs real `claude -p` (2.1.319) in a
real fm-spawn worktree against a local stand-in API that answers 429 like a
spent plan window. It spends no tokens.

Regression runs with each fix reverted:

- fm-spawn wiring reverted to main:
  not ok - the spawned worker's limit stop did not declare a usage-limit wait (got: )
  not ok - Claude 2.1.319 (Claude Code): the real limit stop declared no usage-limit wait (status: )
- UserPromptSubmit entry removed:
  not ok - the continued turn must close the declared wait (expected '', got 'paused [at=1794242922]: usage limit - You've hit your 5-hour limit · resets 2:10pm (Europe/Budapest) until 2026-11-10T13:11Z; ...')
  not ok - Claude 2.1.319 (Claude Code): the second stop must declare again after the turn start closed the first (expected '2', got '1')
- reset taken as the shown minute (no +60s):
  not ok - the declared wait must clear just after the vendor's own reset time (expected '1788946860', got '1788946800')
- no grace for a just-begun reset minute:
  not ok - a just-begun reset minute stays today (expected '1788946860', got '1789033260')
- no once-per-limit check:
  not ok - the same limit must be declared once, not once per failed turn (expected '1', got '2')
- turn-start closing any usage-limit pause:
  not ok - a pause this script did not declare must be left alone (expected 'paused [at=...]: ...')

With the fixes in place, tests/fm-claude-usage.test.sh passes 10 of 10 and
the live guard passes 1 of 1.
@demy00 demy00 changed the title feat(bin): let a Claude worker declare its own usage-limit stop and reset time feat(bin): declare Claude usage-limit stops with their reset time and resume due workers Nov 9, 2026
@demy00
demy00 merged commit 23cdb5c into main Nov 9, 2026
23 of 24 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