Skip to content

OpenAI WebSocket 1009 retries the same oversized response.create five times before HTTP fallback #42572

Description

@romanilyin

Description

With the OpenAI Responses WebSocket enabled, an oversized request containing base64 image tool outputs is deterministically rejected with:

ProviderResponseStreamError: WebSocket closed before response.completed (code 1009: message too big)

OpenCode retries the same oversized WebSocket request five times with backoff before falling back to HTTP. The session therefore appears stuck for about a minute and repeats a request that cannot succeed over that transport. Cancelling or restarting before fallback starts the cycle again.

The session eventually recovered over HTTP and then compacted, so this report is about delayed recovery and unnecessary retries, not permanent data loss.

In the observed session, one tool round read six 1920x1080 PNG files. Their base64 data URLs totaled 17,390,364 bytes. Including an image from the immediately preceding round, the request history contained 19,895,594 bytes of image data before JSON overhead. The next model request produced five consecutive code 1009 failures.

In v1.18.18, the complete response.create payload is sent as one WebSocket message:
https://github.com/anomalyco/opencode/blob/v1.18.18/packages/opencode/src/plugin/openai/ws.ts#L289-L295

Code 1009 is currently only annotated as message too big:
https://github.com/anomalyco/opencode/blob/v1.18.18/packages/opencode/src/plugin/openai/ws.ts#L350-L354

Expected behavior: code 1009 should immediately bypass WebSocket and retry once over HTTP, or OpenCode should preflight the serialized payload size and use HTTP for oversized requests. It should not replay the same known-too-large WebSocket message five times.

Related issues:

Plugins

telegram-notify.js (not involved in request construction)

OpenCode version

1.18.18

Steps to reproduce

  1. Start OpenCode with OPENCODE_EXPERIMENTAL_WEBSOCKETS=true.
  2. Use the OpenAI provider with gpt-5.6-sol.
  3. In one tool round, read enough PNG images for the base64 tool-result attachments to exceed the WebSocket message-size limit (six 1920x1080 PNGs totaling about 17.4 MB reproduced it here).
  4. Continue the turn so OpenCode sends the next response.create.
  5. Observe five consecutive code 1009 errors before HTTP fallback succeeds.

Screenshot and/or share link

No public share link. The raw error and measured payload sizes are included above.

Operating System

Windows 11 Pro 10.0.26200 host; Ubuntu 24.04 on WSL2 (kernel 6.18.33.1-microsoft-standard-WSL2)

Terminal

PowerShell 7 launcher; headless opencode serve running in WSL2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions