Skip to content

#832 Retry-after countdown and usage-limit actions on session failures - #834

Merged
ivanfenenko merged 2 commits into
mainfrom
feature/832-retry-after-limit-errors
Oct 25, 2026
Merged

ivanfenenko merged 2 commits into
mainfrom
feature/832-retry-after-limit-errors

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #832

What

v2 run failures can now tell the user when to try again, and the new usage-limit error types get the right next step. Android and iOS, one Feature Slice.

  • Read retryAfterMs. The v2 error DTO (V2UnknownErrorDto / V2UnknownErrorDTO) has an optional retryAfterMs. SessionFailure carries it plus the time the failure was recorded: the failed message's time.completed, or the receive time when that is missing. The live session.step.failed translation keeps retryAfterMs in the v1-shaped error data (MessageErrorDataDto.retryAfterMs), so live failures and REST history behave the same. The session cache keeps both fields.
  • "Try again in N s" under the failure mark. The failure on the last turn (no user message after it) shows a second line below the unchanged HTTP 429 · <message> caption, counting down to recorded time + retryAfterMs. Above 90 s it shows minutes ("Try again in 4 min"). The line disappears at zero, and shows nothing if the time has already passed. Earlier turns never count down.
  • Live retry wins. While the session is in retry status (SessionActivity.Retrying / .retrying, including content-filter retries that have no card), no failure mark shows the line. coversLiveRetry() and the composer SessionRetryCountdown are unchanged.
  • Actions. provider.free-limit and provider.model-budget-limit → "Pick a model" (FailureAction.PickModel); provider.budget-limit → no action. The server's message is shown as is; the app adds no copy of its own.
  • v1 and older v2 servers: no retryAfterMs means retryAfterMs/recordedAtEpochMs stay null, so the SessionFailure is equal to what it was before and the mark looks the same. Unknown types keep their caption and actions.

ServerErrorMessage (HTTP request errors) is untouched. No Retry/resend button (out of scope).

Checks

Tests were written before the code on both platforms.

  • Android ./gradlew :app:testDebugUnitTest :app:assembleDebug: passed, 2764 tests, 0 failures (1 skipped, as before). No ktlint violations on any changed line (the rest of the repo's ktlint and lint violations are unchanged).
  • iOS xcodebuild test -only-testing:"OpenCode MobileTests" on an iPhone 17 simulator: ** TEST SUCCEEDED **, 2704 tests in 260 suites.
  • New tests on both platforms: action mapping for provider.free-limit / provider.model-budget-limit / provider.budget-limit; retry time counted from time.completed, or from receive time when it is missing; budget payloads shaped like feat(core): read OpenCode Console usage limits and classify budget refusals anomalyco/opencode#58694; label rules (seconds up to 90 s, then minutes, none at zero or below); negative retryAfterMs ignored; live session.step.failed keeps retryAfterMs; countdown only on the last turn; and v1 failures plus failures without retryAfterMs stay exactly as before (equal SessionFailure).
  • Live evidence: evidence page (LAN / Tailscale). Both apps were run against a real opencode v2 server (dev) through the scenario harness, using the new provider-free-limit-retry-after scenario (429, retry-after: 75, FreeUsageLimitError body). The server sends provider.free-limit with retryAfterMs: 75000. On both platforms:
    • the last turn's mark counts down ("Try again in 63 s" on Android, "67 s" on iOS);
    • earlier failures, and failures already past their time, show no line;
    • the sheet offers Pick a model, which opens the model picker;
    • the line is gone after 75 s.

Risks / Follow-ups

  • Unit tests only, not checked in the app: minute formatting (over 90 s); the line being hidden while the session is in retry status; and the budget types, which the local v2 dev checkout does not have yet.
  • The harness scenario is v2 only: on v1 the same 429 is retried live (composer retry card) instead of failing the turn.
  • provider.budget-limit / provider.model-budget-limit are only on upstream dev (feat(core): read OpenCode Console usage limits and classify budget refusals anomalyco/opencode#58694). Tests use payloads shaped like that PR's to-session-error.ts.
  • When a v2 message has no time.completed, the countdown starts at the receive time, so a REST reload before upstream stamps the completion could restart it. Upstream stamps time.completed on session.step.failed, so this should not happen in practice.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith with what you need.

ivanfenenko and others added 2 commits October 25, 2026 21:46
…ilures

Read v2 `retryAfterMs` into SessionFailure with the failure's recorded
time. Show a "Try again in N s" line under the last turn's failure mark
until it passes, except while the session is retrying. Map
provider.free-limit and provider.model-budget-limit to Pick a model;
provider.budget-limit gets no action. v1 and failures without
retryAfterMs are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A 429 with a FreeUsageLimitError body and retry-after: 75 makes v2 fail
the turn as provider.free-limit with retryAfterMs 75000. v1 retries the
429 live instead, so the scenario is v2 only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@github-actions github-actions Bot 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.

Automated review: no finding that 2+ of 3 passes agreed on.

2 finding(s) from a single pass, not posted
  • ios/OpenCode Mobile/OpenCode Mobile/Domain/Message/MessageModels.swift:213 high: Int64 overflow crash on huge retryAfterMs (muse-spark-1.3-contributor)
  • android/app/src/main/java/dev/opencode/mobile/ui/sessionchat/failure/SessionFailureChrome.kt:93 low: Countdown mixes server-stamped recorded time with device clock (glm-5.3-flash)

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.195

@ivanfenenko
ivanfenenko merged commit c903156 into main Oct 25, 2026
2 checks passed
@ivanfenenko
ivanfenenko deleted the feature/832-retry-after-limit-errors branch October 25, 2026 21:06
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 failures: retry-after countdown and usage-limit error types

1 participant