Resend a model step after a mid-stream gateway failure
Cloud V4 BrowserCode runs fail when a provider error arrives after the reply started streaming (about 6 runs a day): the gateway sends it in shapes that parseStreamError does not recognise (the Chat Completions SDK passes only the message string, the Anthropic SDK passes {type: "api_error", message}, and Responses carries upstream_stream_failed without a transport prefix), so it becomes UnknownError and the run ends. With BCODE_STREAM_RETRY set (the Cloud worker sets it per project through the stream-retry release switch), those shapes map to the existing upstream_stream_failed transport recovery: at most two resends of the same request on the same model, never after a tool executed, removing only the failed attempts parts. Only the gateways transport prefixes and its three generic failure messages qualify, so refusals, request rejections and context overflow stay terminal; without the variable nothing changes. Red-green: a local table test over the exact production error values (packages/opencode/test/zz_midstream_retry_local.test.ts, kept out of the repo) fails 3/7 on main and passes 7/7 here; the existing gateway transport recovery tests pass 7/7 and typecheck is clean. Codex review found two over-broad matches (Anthropic and Responses permanent errors), both fixed and re-verified.
Changelog
- Fix: Runs no longer fail when the model provider errors partway through a reply; the step is retried up to twice on the same model.
š¤ Generated with Claude Code
Summary by cubic
Fixes Cloud V4 BrowserCode runs failing when a provider error arrives after the reply started streaming. The model step is now retried up to twice on the same model instead of ending the run.
Bug Fixes
- Maps mid-stream error shapes from Chat Completions (bare message), Anthropic (
api_error/overloaded_error), and Responses (unprefixedupstream_stream_failed) to the existingupstream_stream_failedrecovery. - Adds the
BCODE_STREAM_RETRYflag to gate the new behavior; without it, nothing changes. - Keeps refusals, rejections, and context overflow terminal.