fix(auto-resume): wait out rate limits, stop on other agent errors - #83
Open
pratikgajjar wants to merge 2 commits into
Open
fix(auto-resume): wait out rate limits, stop on other agent errors#83pratikgajjar wants to merge 2 commits into
pratikgajjar wants to merge 2 commits into
Conversation
A turn killed by a provider 429 ends like any other turn, so the settle-window resume fired straight back into the cooldown and burned retries until the guards tripped. Parse the wait from the error (with a 1 min buffer, 30 min default) and delay the pending resume by it; reschedules keep the longer delay. Non-rate-limit agent errors stop auto-resume and notify instead of replaying the failure.
One regex with a unit group replaces three prefix-duplicated patterns, the buffer moves inside rateLimitWaitMs so no caller has to remember it, and pendingResumeDelayMs is a plain number seeded with SETTLED_WINDOW_MS instead of a nullable that needed a reset and a coalesce.
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.
Problem
A turn that dies on a provider rate limit ends through
agent_endlike any successful turn, soensurePendingResumeschedules the resume on the 800 ms settle window and the loop walks straight back into the cooldown. Every retry fails the same way untilAUTORESUME_TURN_LIMITor the consecutive-failure override trips — the session is spent, and nothing tells the user why.Same shape for non-transient failures (bad request, context overflow, network): the resume message replays a turn that cannot succeed.
In practice the 429 often arrives as a bare JSON error body with no
Retry-Afterheader, so the wait has to be read out of the message text.Change
agent_endnow looks at the final assistant message before scheduling:try again in 17 minutes,resets in 2 hours,retry-after: 45s), plus a 1 min buffer. No duration in the message means a 30 min default. The user gets a notification with the ETA.schedulePendingResumetakes an optional delay (defaultSETTLED_WINDOW_MS, so every existing call site behaves exactly as before), andreschedulePendingResumereuses the stored delay so a settle-window reschedule cannot shorten an active cooldown.Notes
extensions/pi-autoresearch/provider-errors.ts(~55 lines) — no I/O, no session state.tests/provider-errors.test.mjs; full suite is 50 passing.