Skip to content

fix(auto-resume): wait out rate limits, stop on other agent errors - #83

Open
pratikgajjar wants to merge 2 commits into
davebcn87:mainfrom
pratikgajjar:feat/rate-limit-aware-auto-resume
Open

fix(auto-resume): wait out rate limits, stop on other agent errors#83
pratikgajjar wants to merge 2 commits into
davebcn87:mainfrom
pratikgajjar:feat/rate-limit-aware-auto-resume

Conversation

@pratikgajjar

@pratikgajjar pratikgajjar commented Aug 1, 2026

Copy link
Copy Markdown

Problem

A turn that dies on a provider rate limit ends through agent_end like any successful turn, so ensurePendingResume schedules the resume on the 800 ms settle window and the loop walks straight back into the cooldown. Every retry fails the same way until AUTORESUME_TURN_LIMIT or 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-After header, so the wait has to be read out of the message text.

Change

agent_end now looks at the final assistant message before scheduling:

  • Rate limited — resume is scheduled with the wait parsed from the error text (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.
  • Any other agent error — no resume; notify and let the user decide.
  • Clean turn — unchanged.

schedulePendingResume takes an optional delay (default SETTLED_WINDOW_MS, so every existing call site behaves exactly as before), and reschedulePendingResume reuses the stored delay so a settle-window reschedule cannot shorten an active cooldown.

Notes

  • New pure module extensions/pi-autoresearch/provider-errors.ts (~55 lines) — no I/O, no session state.
  • 4 new tests in tests/provider-errors.test.mjs; full suite is 50 passing.
  • Verified by loading the patched extension in pi.

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.
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