Skip to content

fix(opencode): stop retrying when the provider asks to wait for hours - #47641

Open
ApexMene wants to merge 3 commits into
anomalyco:devfrom
ApexMene:bound-retry-wait
Open

fix(opencode): stop retrying when the provider asks to wait for hours#47641
ApexMene wants to merge 3 commits into
anomalyco:devfrom
ApexMene:bound-retry-wait

Conversation

@ApexMene

@ApexMene ApexMene commented Sep 6, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #39790

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

SessionRetry.delay() returns whatever the provider puts in retry-after, capped only by RETRY_MAX_DELAY (~24.8 days). policy() then schedules the next attempt that far out, so an exhausted quota window parks the session on one pending attempt that can be a full day away. Nothing is logged after the first stream error, no session.error is published, and the session never reaches idle.

zen is one concrete source: getRetryAfterDay() in packages/console/app/src/routes/zen/util/ipRateLimiter.ts sets retry-after to the seconds left until the next daily reset, so an exhausted free tier can answer with up to 86400.

The change stops the schedule when the requested wait is longer than RETRY_MAX_WAIT (5 minutes). The retry status is published first, so the free tier and Go limit dialogs fire exactly as they do today, then Cause.done lets the error reach halt in the processor and the session goes idle. Waits inside the ceiling are untouched, so normal 429 and 5xx backoff behaves as before.

How this relates to the other open PRs on the issue, since the duplicate bot flagged them:

I hit this through a subagent, which is where it hurts most: the retry status is published on the child session ID, and both the TUI and the app ignore session.status for sessions other than the routed one, so the parent turn shows a spinning task tool and no dialog at all. Two of my sessions sat like that for 9h26m and 8h52m before I noticed.

How did you verify your code works?

Free tier actually exhausted, isolated XDG_DATA_HOME, same command both times:

bun dev run -m opencode/muse-spark-1.3-contributor-free "say pong"
  • without the change: no output at all, killed by timeout 120
  • with the change: Error: Rate limit exceeded. Please try again later., exit 1, 3.8s

Two new tests in packages/opencode/test/session/retry.test.ts, one per side of the ceiling. The first one fails on dev and passes with the change. bun test test/session/ gives 415 pass and bun typecheck is clean, both run from packages/opencode.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

delay() honors retry-after up to RETRY_MAX_DELAY (~24.8 days), so an
exhausted quota window parks the session on a single attempt that can be
a full day out. Give up past RETRY_MAX_WAIT instead, after publishing the
retry status so the limit dialog still fires.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 6, 2026
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found 2 potentially related PRs:

  1. fix(session): stop retrying free and Go usage quotas #47339: fix(session): stop retrying free and Go usage quotas

  2. fix: restore Go signup prompts and stop free-tier retries #46994: fix: restore Go signup prompts and stop free-tier retries

  3. fix(cli): stop run from sleeping through an exhausted quota #42340: fix(cli): stop run from sleeping through an exhausted quota

These PRs appear to address related concerns around stopping long waits during rate limiting and quota exhaustion scenarios. PR #47339 in particular seems closely aligned with the current PR's goals around free tier and Go limit handling.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Sep 6, 2026
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@xam1986 xam1986 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test

@ApexMene

ApexMene commented Sep 8, 2026

Copy link
Copy Markdown
Author

Thanks for the thorough review!

Applied both non-blocking notes in f258440:

  • Clamped published next to wait > RETRY_MAX_WAIT ? now : now + wait so the status never advertises an attempt that won't be scheduled.
  • Clarified RETRY_MAX_WAIT comment to distinguish it from RETRY_MAX_DELAY and point to policy().

Verified with bun test test/session/ (415 pass) and bun typecheck (clean) from packages/opencode.

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.

Session retries fixed-window usage quota errors until reset

2 participants