feat: size rate-limit backoff from CLI-reported reset time - #97
Merged
Conversation
The Claude CLI names the exact time capacity returns ("resets 12:40pm
(UTC)"), but the circuit breaker guessed exponentially (1h x 2^(n-1)),
which last night scheduled a retry 39 minutes after capacity was
already back.
The worker entrypoint now parses the reset time on limit detection and
saves it as a 'rate-limit-reset' task output (best-effort; workers get
write access to the task-outputs table). Reconcile reads the hint and
the breaker waits until reset + 2 min instead of guessing, ignoring
hints that are in the past or more than 24h out. Exponential backoff
remains the fallback when no hint is available.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Follow-up to #95. During the 09:17Z limit window, the breaker's exponential backoff scheduled recovery for 13:19Z even though the CLI output said capacity returned at 12:40pm UTC — 39 minutes wasted (recovered manually). The CLI tells us exactly when to retry; use it.
Changes
packages/worker/src/entrypoint.ts—parseResetTime()parsesresets <h>(:mm)?<am|pm> (UTC)from CLI output and resolves it to the next UTC occurrence (rolls to tomorrow when the time already passed; handles 12am/12pm).runClaudenow returns{ exitCode, rateLimitResetAt? }, and on a limit hit the entrypoint saves the hint as arate-limit-resettask output keyed by RUN_ID (best-effort: failures are logged and swallowed).packages/core/src/dynamodb/rate-limit-service.ts—tripBreaker(now, resetAt?): when a hint is present, valid, in the future, and within 24h,backoffUntil = resetAt + 2 min buffer; otherwise the existing 1h × 2^(n−1) schedule (cap 24h) applies. Failure counting unchanged.packages/lambdas/src/handlers/reconcile.ts— onRATE_LIMIT_EXIT_CODE, reads the hint from task-outputs and passes it totripBreaker.packages/cdk/src/constructs/compute.ts— task-outputs grant widened from read to read/write so workers can save the hint.Verification
Full workspace suite: 45 files, 1111 tests pass. New coverage: reset-time parsing (am/pm, hour-only, day rollover, 12am/12pm, malformed), breaker hint usage (hint honored with buffer; past/far-future/unparseable hints fall back to exponential), runClaude return shape.
🤖 Generated with Claude Code