Repository navigation
Conversation
…ge prints A Claude usage-limit prompt error has no `data.rateLimit` when a freshly started agent process refuses the turn: the CLI turns the prompt away from its own saved limit state without calling the API, so the SDK sends no `rate_limit_event` and the bridge has nothing to attach. Every message sent to an idle session while over the limit and every refused auto-resume starts such a process (75 of 140 rate-limit errors in one user's DB). Those pauses fell back to the 40–50 min `usage_limit_backoff`, retrying up to hours after the window reopened or before it did. When neither `data.rateLimit.resetsAt` nor `_meta["_claude/rateLimit"] .resetsAt` (nor a reset on the error's own data) is present, the reset is now read from the usage-limit message the wording check already picks out: - `resets 4:10pm (Australia/Melbourne)` / `resets 4pm (...)`: the next occurrence of that wall-clock time in the zone, possibly the next day; - `resets Dec 3 at 2am (Australia/Melbourne)` (or `Jun 30, 7pm`): the year of the nearest occurrence, across New Year. A reset up to an hour past is kept rather than rolled to the next day or year, so a just-passed window goes to the minute-scale backoff instead of waiting a day. DST gaps move forward by the gap and repeated times take the first occurrence (jiff's `compatible`). The parsed instant goes through the same epoch normalisation and `reset_exceeds_allowance` check as a structured one, so `retry_schedule` treats it exactly like `reset_at`. Unparseable text, unknown zones and non-usage-limit kinds (an `overloaded` failure) keep today's behaviour. The kind stays `usage_limit` (or the bridge's limit type), as before. Uses `jiff` (already in the lock via other crates) for the IANA tz database. Also corrects the comment in `rate_limit_recovery_details`, which said `data.rateLimit` is the only copy such refused turns get; they get none. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ay-late retries Follow-ups from review of fe562a4, which reads the reset a bare Claude usage-limit message prints (`resets 4:10pm (Australia/Melbourne)`): - Minute precision: the printed time is truncated to the minute, so a real reset of 16:10:45 prints as `4:10pm`. A retry at reset + 30 s grace with low jitter could land before the window reopened, spend a counted attempt, and drop to the minute backoff because the same `4:10pm` now reads as just passed. A parsed reset is now taken as the end of its printed minute (+60 s). A CLI that rounds instead costs at most a minute. Structured resets are unchanged. - Time-only reset rolled to tomorrow: a printed reset more than an hour past (CLI clock skew, e.g. a workstation, or stale saved state) rolls to its next occurrence. A date form rolls a year and is dropped by the allowance, so it falls back to the 40–50 min slow schedule, but a time of day rolled a day was within the allowance and parked the pause for about 22 h. When the message names a 5-hour or session limit, a time-only reset more than 6 h ahead is now dropped the same way. The trade-off (including a weekly limit printed with a time alone, which keeps the day's wait) is documented next to `JUST_PASSED_GRACE_MS`. - Stale structured reset: a structured reset still wins when it is ahead, but one already past no longer shadows a printed reset that is still ahead; a stale `rejected` info would otherwise send the pause to the minute backoff. With no usable printed reset, the structured one stays. `rate_limit_scheduler::parse_reset_timestamp_millis` is now crate-visible for that check. Tests pin the just-passed grace at exactly 59 and 61 minutes for both forms, both in the parser and through `rate_limit_recovery_details` (61 min gives no reset and keeps `usage_limit`, the safe slow-schedule fallback), plus the 6 h boundary, the weekly and dated cases it leaves alone, the end-of-minute rounding, and the stale-structured fallback. Existing assertions on message-read resets move one minute later. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tale limit type Follow-ups from review of 90176e2: - Time-only cap now fails closed. A printed time-of-day reset more than 6 h ahead used to be dropped only when the message named a 5-hour or session limit, so any other wording (a bare `You've hit your limit · resets 4pm (…)`, a future rewording) skipped the cap and could park the pause for ~22 h on a past reset rolled to the next day. The cap now applies unless the message names a long window: `week`, `7-day` / `seven-day`, `Opus` or `Sonnet`. An unrecognised wording falls back to the 40–50 min slow schedule instead of a day's wait; the cost is that a long window in an unrecognised wording, 6–24 h ahead, also takes the slow schedule. `SESSION_LIMIT_MAX_LEAD_MS` becomes `TIME_OF_DAY_MAX_LEAD_MS` and the trade-off is documented next to `JUST_PASSED_GRACE_MS`. - No stale limit type beside a printed reset. When a printed reset replaces a structured reset that is already past, the `limit_type` from that stale info is dropped too, so the kind falls back to `USAGE_LIMIT_KIND` from the wording. Before, a stale `five_hour` info beside `weekly limit · resets Jun 30, 7pm` stored a weekly reset under `five_hour`, and the pause copy and auto-resume prompt named the wrong limit. A structured reset that is kept (still ahead, or with no usable printed one) keeps its limit type, and so does info that gave a type but no reset. Tests: the bare `You've hit your limit` wording (with and without minutes) and `out of extra usage` are capped at 6 h; a bare wording within 6 h is kept; weekly, Opus and Sonnet time-only resets keep the next day's; a printed reset that replaces a stale one gives kind `usage_limit` (from both the prompt error and the usage update), and a kept stale reset keeps `five_hour`. Signed-off-by: Matt Toohey <contact@matttoohey.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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
A Claude usage-limit prompt error sometimes arrives with no structured reset time (
data.rateLimitis absent). Staged then had nothing to schedule the auto-resume on and fell back to the 40–50 minusage_limit_backoff, so the session resumed well after the window reopened, or spent retry attempts before it did. This PR reads the reset time from the error message itself (resets 4:10pm (Australia/Melbourne)) and schedules the pause on it, the same way as a structured reset.The structured reset is missing whenever a freshly started agent process refuses the turn: the CLI turns the prompt away from its own saved limit state without calling the API, so the SDK sends no
rate_limit_eventand the bridge has nothing to attach. Every message sent to an idle session while over the limit, and every refused auto-resume, starts such a process. In one user's DB that was 75 of 140 rate-limit errors.What changes
Parser (new
session_runner/usage_limit_reset.rs). It only runs on a message the existing usage-limit wording check has already picked out, and only on the prompt error's own message, so aresets …in agent output can't plant a reset.resets 4:10pm (Zone)/resets 4pm (Zone): the next occurrence of that wall-clock time in the zone, possibly the next day.resets Dec 3 at 2am (Zone)/resets Jun 30, 7pm (Zone): the year of the nearest occurrence, across New Year.overloadedfailure keep the old behaviour.Guards on the parsed time
4:10pm. Without the rounding, a retry could land before the window reopened and spend a counted attempt. The pause copy may show 4:11pm where the CLI printed 4:10pm.week,7-day/seven-day,Opus,Sonnet). Otherwise clock skew or stale saved state could roll a past reset to tomorrow and park a 5-hour-limit pause for about 22 h. Dropped resets fall back to the 40–50 min schedule.reset_exceeds_allowancecheck as a structured reset.Precedence in
rate_limit_recovery_detailslimit_typefrom that stale info is dropped with it, so the kind falls back tousage_limitand the pause copy doesn't name the wrong limit.rate_limit_scheduler::parse_reset_timestamp_millisbecomespub(crate)for the staleness check. The comment inrate_limit_recovery_detailsthat saiddata.rateLimitis the only copy refused turns get is corrected: they get none.Dependency:
jiff = "0.2"for the IANA tz database. It was already inCargo.lockthrough other crates, so the lock only gains the direct edge.Known limitations
Australia/Melbourne.rate_limit_eventon a locally refused prompt) is not addressed here; it belongs withclaude-agent-acp/ the Claude Agent SDK.Testing
usage_limit_reset.rs: both forms, 12am/12pm, a DST gap, New Year, the grace at exactly 59 and 61 minutes, the 6 h boundary, and the wordings the cap applies to and leaves alone.tests/usage_limit_details.rscovers the path throughrate_limit_recovery_details: a bare error parks on its printed reset (including a second refused auto-resume), the stale-structured fallback, and the resulting kind.cargo fmt,cargo clippy -D warningsand thesrc-tauritest suite passed locally before the last commit. The branch was pushed with--no-verify, so the pre-push hook did not run on it.🤖 Generated with Claude Code