Repository navigation
fix(ai): recover missing OpenAI WebSocket response state - #122727
Merged
Merged
Conversation
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Contributor
Author
|
Land-ready evidence on
@clawsweeper re-review |
Contributor
|
🦞👀 Command router queued. I will update this comment with the next step. |
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 13, 2026
…2727) * fix(ai): recover rejected WebSocket continuations * fix(ai): keep WebSocket server error internal
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.
Closes #122717
Related: #122483
Related: #122542
What Problem This Solves
Fixes an issue where direct OpenAI API-key users on an explicit Responses WebSocket mode would receive a terminal agent error when the provider rejected a stale or unavailable
previous_response_id, even though the provider explicitly reported that generation had not started and a full-history retry was safe.The same flattening also hid
websocket_connection_limit_reached, so an expired provider connection could fail the turn instead of recovering through the existing SSE fallback.Why This Change Was Made
OpenAI SDK 6.49.0 declares a flat
ResponseErrorEvent, but the live Responses WebSocket service currently sends a wrapped frame with nestederror.codeand HTTPstatus. The SDK type-casts that frame without runtime normalization, leaving the structured JSON inWebSocketError.message. OpenClaw previously discarded it and projected every post-send failure as unknown-outcome ambiguity.This repair normalizes both documented and observed SDK shapes, preserves code/status/param, and allowlists only
previous_response_not_foundandwebsocket_connection_limit_reachedas safe retries. Those codes close the rejected socket without poisoning the cooldown, rebuild the canonical full-history request, and continue the same user turn over SSE. Every other post-dispatch failure remains replay-unsafe and fails closed.The nearby provider documentation now matches the shipped product: direct API-key Responses defaults to SSE;
autoandwebsocket-cachedreuse a session socket; transientwebsocketand cached modes retain pre-dispatch SSE fallback; there is no automatic reconnect/retry before dispatch.Production LOC: +85/-6 (net +79) | Tests: +153/-4 (net +149) | Docs: +24/-17 (net +7)
User Impact
An OpenAI WebSocket session can recover transparently when its prior response state is gone or the provider's 60-minute connection limit is reached. The current user turn completes from full history instead of returning an ambiguity error, and later turns start with a fresh WebSocket state.
Direct API-key defaults do not change: SSE remains the default. This does not ship preconnect or
generate:falseprewarm; the closed experiment in #122542 remains rejected by latency evidence.Evidence
Regression and focused proof
stopReason: "error"because the wrapped error was flattened into post-dispatch ambiguity.node scripts/run-vitest.mjs packages/ai/src/transports/openai-responses-websocket.test.ts packages/ai/src/transports/openai-responses-websocket-client.test.ts packages/ai/src/transports/openai-responses-client.continuation.test.ts packages/ai/src/transports/openai-responses-continuation.test.tsoxfmtandoxlint: clean.git diff --check: clean.pnpm docs:list: clean.Authenticated live OpenAI proof
A direct product-path call on this head deliberately injected a nonexistent response ID into the finalized first payload. The live service returned its current wrapped HTTP 400
previous_response_not_foundframe. The same OpenClaw stream call then:buildRequest("full-history");previous_response_idon the SSE retry;continuation-rejectedprompt observation;stopReason=stopand exactlyOK;Observed result:
{ "stopReason": "stop", "text": "OK", "payloadBuilds": 2, "safeFallbackObserved": true, "completedOverSse": true, "warningCount": 0 }A separate raw protocol probe confirmed the service's exact wrapped shape and that a subsequent full request on a fresh connection succeeds.
Dependency and sibling contract
Personally inspected current sibling Codex at
91d6f48992ad:codex-rs/codex-api/src/endpoint/responses_websocket.rs:158-162defines the two safe codes.responses_websocket.rs:582-648parses the wrapped error frame and maps those codes to retryable outcomes.responses_websocket.rs:718-725performs that mapping before ordinary Responses event decoding.codex-rs/core/src/client.rs:1663-1750owns continuation request and failed-connection replacement.Also inspected OpenAI SDK 6.49.0:
resources/responses/internal-base.ts:24-34stores a typedResponseErrorEventonWebSocketError.resources/responses/ws-base.ts:341-378JSON-parses and type-casts without runtime validation.ResponseErrorEventtype documents a flat shape, while the live service returned the nested wrapper captured above.Review
Codex autoreview (
gpt-5.6-sol, high): TruffleHog clean; no accepted/actionable findings; patch correctness 0.97.Provenance: clear. The generic error flattening and ambiguity classification were introduced in
f09a33ce4124by Peter Steinberger in #121687. The current repair is also maintainer-authored.AI-assisted: yes. The implementation, dependency review, focused tests, live provider proof, and final diff were reviewed by the maintainer.