Repository navigation
fix(ai): continue cached OpenAI WebSocket turns - #122483
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 12, 2026, 2:19 AM ET / 06:19 UTC. ClawSweeper reviewWhat this changesThe PR normalizes cached OpenAI Responses WebSocket replay comparisons so equivalent reconstructed turns continue with a previous response ID and only newly appended input. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep open for normal maintainer merge review: this is a focused repair at the cached-WebSocket owner, with no actionable patch defect found, but exact-head CI and independent SDK-source inspection remain incomplete in this environment. Priority: P2 Review scores
Verification
How this fits togetherThe OpenAI Responses transport builds an agent conversation request, then selects SSE or the official OpenAI WebSocket path. Cached WebSockets compare the reconstructed conversation against the prior completed response to choose suffix continuation or a full-history request. flowchart LR
A[Agent conversation] --> B[Responses request builder]
B --> C[Cached WebSocket transport]
C --> D{Replay matches?}
D -->|yes| E[Previous response ID and suffix]
D -->|no| F[Full history request]
E --> G[OpenAI Responses API]
F --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource +17, Tests +36, Docs 0. Total +53 across 4 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Merge only after exact-head CI is green, retaining the narrow delivery-metadata whitelist and the existing full-history fallback for every other replay difference. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main compares provider output against reconstructed replay with raw JSON serialization, while the replay builder deliberately emits empty annotations; the supplied issue also gives a focused two-turn path. Is this the best way to solve the issue? Yes. The cache owner makes the continuation decision, and this repair normalizes only known reconstruction differences while retaining fail-closed checks for semantic changes. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b8ddddd702aa. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Closes #122482
Related: #122194
What Problem This Solves
Fixes an issue where direct OpenAI API-key users who selected cached WebSocket transport would reuse the socket but still resend the full conversation on each warm turn. Real provider output was rejected as changed history, so
previous_response_idcontinuation never activated.Why This Change Was Made
Continuation matching now compares JSON values independently of object insertion order while preserving normal JSON omission semantics. At the assistant replay boundary, it removes only provider delivery metadata that reconstructed history cannot contain (
id,status,output_text.annotations, andoutput_text.logprobs) while keeping semantic fields such as role, phase, text, reasoning shape, and tool-call data fail-closed.The direct API-key default remains SSE. This PR does not add WebSocket preconnect/prewarm or the broader SSE continuation cache proposed in #122194.
Production LOC: +31/-14 (net +17) | Tests: +43/-7 (net +36) | Docs: +2/-2 (net 0)
User Impact
Explicit
websocket-cachedandautousers on the built-in OpenAI Responses runtime now get the continuation behavior those modes promise: one session socket,previous_response_id, and suffix-only input when history is unchanged. Semantic history or request changes still invalidate continuation and send a full request.The provider reference now accurately documents SSE as the direct API-key default and lists all supported explicit transport modes.
Evidence
previous_response_id; the new regression fails on the old comparator and passes with this fix.node scripts/run-vitest.mjs packages/ai/src/transports/openai-responses-websocket.test.ts packages/ai/src/transports/openai-responses-websocket-client.test.ts-> 2 files, 29 tests passed.git diff --checkpassed.dabe607efda854be74cc70e7432e19c321f15e6c.previous_response_id.AI-assisted: yes. The implementation, proof, and final diff were reviewed by the maintainer.