Repository navigation
feat(bin): declare Claude usage-limit stops with their reset time and resume due workers - #23
Merged
Merged
Conversation
…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.
…e-r2 # Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
bin/fm-claude-usage.sh, whichbin/fm-spawn.shnow hooks into each Claude worker'sStopFailureandUserPromptSubmithooks:rate_limitstop appends apaused: 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.resolvedto close that wait.rate_limitbehaves exactly as before.fm-claude-usage.sh resume <id>... | resume --due:bin/fm-send.sh.--duepicks up every live task whose limit wait has passed.claude -pagainst a local stand-in API answering HTTP 429. It is registered inbin/fm-test-run.sh.🤖 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
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 itEvidence: Unit behavior tests TAP output
Source: Unit behavior tests TAP output
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.shagainst real Claude Code 2.1.319 and a local stand-in limit APIManual 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 --duefinds nothing before the reset, turn-start closes the wait✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.