Repository navigation
Description
Why
When a provider refuses a run because of a usage limit, the transcript shows a plain failure line. OpenCode v2 now tells clients how long to wait (retryAfterMs) and which limit was hit (new error types), so the app can say when to try again and offer the right next step.
Upstream (anomalyco/opencode)
- feat(core): typed free-limit error with reset time anomalyco/opencode#57146: new error type
provider.free-limit(released in v2.1.2). - fix(core): forward retryAfterMs across provider session errors anomalyco/opencode#57589: optional
retryAfterMsonSession.StructuredErrorfor every provider error that has one:provider.rate-limit,provider.quota,provider.free-limit, provider internal errors (released in v2.1.2). Spec comment: "How long the provider asked to wait before trying again, counted from when the failure was recorded." A non-negative integer. - feat(core): read OpenCode Console usage limits and classify budget refusals anomalyco/opencode#58694 (commit e42f6d1016):
provider.budget-limitandprovider.model-budget-limit. Ondevonly, not in v2.1.4. - For all three new types the server already replaces
messagewith user-facing text, e.g. "Free usage limit reached. Connect a provider or subscribe to OpenCode Go to keep going, or switch models." The app shows that text as is and does not write its own copy. - Classic v1 servers send neither field nor these types.
Where this lives in the apps
These errors are run failures, not HTTP request errors. They reach the app as a SessionFailure (Android domain/message/MessageModels.kt, iOS Domain/Message/MessageModels.swift), built from the v2 error DTO (Android V2UnknownErrorDto in data/remote/dto/V2MessageDtos.kt, iOS Data/Remote/V2MessageDTOs.swift), and appear as the failure mark in the Session Chat transcript. ServerErrorMessage is not involved.
The live retry countdown card above the composer (SessionRetryCountdown, driven by the session retry status and its next time) already covers the case where the server is still retrying. coversLiveRetry() hides the transcript mark for provider.rate-limit / provider.quota while that card is up. This issue does not change that card.
Scope (Android + iOS, one Feature Slice)
- Read
retryAfterMs. Add it to the v2 error DTO and toSessionFailure, along with the time the failure was recorded (the failed message's completion time; if that is missing, the time the app received the failure). - "Try again in N s" on the failure mark. When the failure on the last turn (no user message after it) has
retryAfterMs, its transcript failure mark shows "Try again in N s" on its own line below the existing caption (HTTP 429 · <message>stays unchanged, so the long server message is not cut off), counting down to recorded time +retryAfterMs. Use minutes once it is over 90 s ("Try again in 4 min"). At zero the line disappears and the mark reads as it does today. If the time has already passed when the session opens, show no line. Failures on earlier turns never show a countdown. - Live retry takes priority. While the session is in
retrystatus, the composer countdown card is the only countdown: no failure mark shows the "Try again" line, whatever its error type.coversLiveRetry()keeps hidingprovider.rate-limit/provider.quotamarks as it does today. - Actions for the new types (in the existing provider failure sheet /
action()):provider.free-limit→ "Pick a model" (FailureAction.PickModel).provider.model-budget-limit→ "Pick a model".provider.budget-limit→ no action; the countdown (ifretryAfterMsis present) is the guidance.- Add the budget types now: servers that don't send them are unaffected.
- No change for v1 or older v2 servers. No
retryAfterMsmeans no hint; unknown types keep today's caption and actions.
Out of scope
- A Retry / resend button when the countdown ends. The app has no "resend last prompt" action; that needs its own issue.
- Changes to the composer retry countdown card.
ServerErrorMessage(HTTP request error text).
Done when
- On a v2.1.2+ server, a failure with
retryAfterMson the last turn shows a "Try again in …" countdown line under its transcript failure mark on both platforms, it disappears at zero, and it never shows while the session is inretrystatus. provider.free-limitshows the server's limit message and a "Pick a model" action on both platforms.provider.budget-limitandprovider.model-budget-limitmap as above (covered by unit tests with payloads from feat(core): read OpenCode Console usage limits and classify budget refusals anomalyco/opencode#58694, since no release sends them yet).- v1 servers and failures without
retryAfterMslook exactly as they do today (unit test on each platform).
Activity
[-]Session errors: retry-in hint and limit/budget error messages[/-][+]Session failures: retry-after countdown and usage-limit error types[/+]#832 Add a v2 free-limit scenario with retry-after to the harness
#832 Retry-after countdown and usage-limit actions on session failures (
#832 Treat an overflowing iOS retry-after as no hint (#835)