Repository navigation
fix(opencode): end a turn whose provider asked for a long retry wait, instead of sleeping in it - #265
Merged
Merged
Conversation
… instead of sleeping in it opencode retries a refused model call itself and sleeps the response's retry-after, capped only at 2^31 ms, while `run --format json` prints nothing (it never emits the session.status retry event). The free seat (opencode/glm-5.3-flash-free) answers a spent quota with 429 and retry-after: 47331 (13.1 h). magnetar-rust-20261019b's root slept from 06:28:51Z until this bridge's 4 h turn cap aborted it; agent-runtime classed the abort terminal and the 48 h run ended. A per-turn opencode plugin in the profile's private config directory prints opencode's own retry status as one stdout line. A wait over OPENCODE_RETRY_WAIT_MAX_MS (default 60 s) ends the turn with error type upstream_unavailable (a code agent-runtime pauses on, with no status inferred) and the reset time, which agent-runtime 0.326.0 holds for when it is inside its hold window.
tangletools
approved these changes
Oct 19, 2026
tangletools
left a comment
There was a problem hiding this comment.
✅ Auto-approved PR — faba90da
Blanket team auto-approval is intentional. This is not a code review.
No automated review runs on this PR. This approval rests on the rule above alone.
tangletools · auto-approval · reason: blanket_auto_approve · 2026-10-19T11:01:53Z
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. opencode retries a refused model call itself and sleeps the response's
retry-after, capped only at 2^31 ms (session/retry.ts).opencode run --format jsonprints nothing during that wait: it never emits thesession.statusretry event. The free seat (opencode/glm-5.3-flash-free) answers a spent quota with429andretry-after: 47331(13.1 h; probed 2026-10-19 10:51Z). discovery-lab's magnetar-rust-20261019b root logged the 429 at 06:28:45Z and then nothing until this bridge'sCLI_TIMEOUT_MS(4 h) aborted the turn. agent-runtime received "turn aborted" with no status, classed it terminal, and ended a 48 h run at 4 h, with 0 workers spawned.#264 does not cover this: the 429 never reaches the bridge as an error event while opencode is sleeping.
Change. In
src/backends/opencode.ts:OPENCODE_CONFIG_DIR,plugin/cli-bridge-retry-signal.js. Itseventhook prints opencode's ownsession.statusretry status as one stdout line,{"type":"cli-bridge.opencode-retry", attempt, message, next, timestamp}.OPENCODE_RETRY_WAIT_MAX_MS(default 60 s; opencode's own header-less backoff stays at or under 32 s) ends the turn with error typeupstream_unavailable. The message names the wait andreset at <ISO>. Thefinallystops the sleeping process.upstream_unavailablewithout spending an attempt, and agent-runtime#1849 holds until the reset when it falls inside its 6 h window.Upstream: anomalyco/opencode#57049.
Proof.
tests/opencode-retry-wait-real.test.tsruns the REAL opencode against a local endpoint that answers every call429withretry-after: 3600. Before this change the turn stays silent until killed. After it, the turn ends codedupstream_unavailablewith the reset time, in under 2 minutes. The gate installs opencode 1.18.33 so the test does not skip.Live bar: the next host free-seat run that meets a spent quota records a paused row instead of a 4 h abort.
Run ID: run_6f83ac468d6e44b1319f450ca91b8e57