Repository navigation
fix: recover ChatGPT turns after websocket connection expiry - #167063
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 4:45 AM ET / 08:45 UTC. ClawSweeper reviewWhat this changesThe branch classifies ChatGPT WebSocket connection expiry as a transient transport failure so existing transcript recovery can finish interrupted turns. Example: A ChatGPT reply streams past the WebSocket connection-age limit.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a remaining recovery gap on current main. The supplied Gateway proof covers interrupted replies and aged sockets, and source review found no actionable defect. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe ChatGPT subscription transport sends agent requests and converts streamed provider events into assistant messages. Its error metadata tells the agent runner whether to continue the saved conversation, change models, or stop. flowchart TD
A[Agent request and transcript] --> B[ChatGPT WebSocket transport]
B --> C[Streamed reply or connection expiry]
C --> D[Transient error projection]
D --> E[Existing bounded recovery policy]
E --> F[Continue saved transcript]
F --> G[Completed reply or terminal error]
Technical reviewBest possible solution: Keep connection-expiry classification in the transport and continuation, cancellation, and replay-safety decisions in the existing runner. Do we have a high-confidence way to reproduce the issue? Yes: a normal streamed response followed by websocket_connection_limit_reached reaches the current-main classification gap; supplied baseline Gateway observations corroborate it. This read-only review did not execute the scenario. Is this the best way to solve the issue? Yes: the patch supplies the missing transient error fact to the existing recovery owner while preserving bounded pre-stream reconnect and avoiding post-stream request replay. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e86387d3b267. Provenance checked
TestingProof path: shipped entry point. Added test files: 1. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -2, Tests +48, Docs +4. Total +50 across 3 files. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment |
|
Merged via squash.
|
(cherry picked from commit 2095264)
Fixes #166708
What Problem This Solves
Fixes: an interactive ChatGPT Responses turn fails when its reused WebSocket reaches the connection-age limit while a reply is streaming.
User Impact
Connection expiry now reaches the existing bounded transcript recovery policy, so an interrupted turn can reconnect and finish. Existing safeguards for completed actions, visible output, cancellation, and model fallback remain in force. No configuration or migration is required.
Why This Change Was Made
The transport already rotates sockets at 55 minutes and reconnects once when expiry happens before streaming. A long response can still cross the server limit. After the bounded pre-stream reconnect, this change projects the provider's expiry error to the existing transient transport code, retaining the original error as its cause. The transport retires the failed socket and leaves continuation to the runner; it does not replay a started request.
The separate SDK Responses socket pool is unchanged. Inlining the single-use timeout-signal helper preserves its existing behavior and keeps production net negative: +18/-20 production, +48/-0 tests, +4/-0 docs.
Evidence
pnpm test packages/ai/src/providers/openai-chatgpt-responses.test.ts --maxWorkers=1: 1.14 s Vitest, 1.86 s wrapper on Testbox. The new cases take milliseconds and use no real timers.pnpm tsgo:coreandpnpm tsgo:core:test packagespass on Testbox. Local changed-file lint, formatting, type graphs, ratchets, dead-export, import-cycle, and storage guards pass. Capacity interruption lost the fullcheck:changedsummary; its final pairing-account guard was run separately and passed.git diff --checkpasses.state:errorfor both mid-stream and aged-socket expiry with no recovery; candidate returnsstate:finalfor both, using a new socket and the transcript-continuation prompt. The client observes a partial reply before expiry. Final replies contain the prefix once; an unfinished tool call never executes. The aged case reuses a 54-minute socket and advances its clock past 60 minutes mid-stream. Complete baseline/candidate command: 233.300 s, exit 0.Proof uses a real isolated Gateway process, native
chat.send, and a local scripted Responses WebSocket server with synthetic credentials. It is not a real OpenAI service soak. A separate local probe found that HTTP chat-completions streaming can still reject its append-only terminal projection after recovery; this PR does not change that HTTP behavior. Native interactive chat recovery is the verified surface.Commands and source identity
Candidate head:
d8728b5b1f6a590f6205616ae771e086c1563ae4. Base:a06612710e674f493a3ae8fe1158f60bb56d3924; the affected transport/recovery sources were unchanged on fetched main8a31a24302f1c. Testbox source checks verify the materialized candidate file hashes because Testbox creates a carrier commit.The task-owned live harness invokes
pnpm openclaw gateway runwith isolated home/state and ephemeral loopback ports. In one synced invocation it runs baseline production, restores the candidate, and runs the same scenarios again. Proof scratch is not part of the product diff. Lease:tbx_01m4d82s9r2z02nd754kyfyah3(Blacksmith Testbox); hydration run. Wrapper command exit codes are the proof outcome; the lease has been stopped and is absent from the active lease list.The initial baseline live assertion expected the historical “Agent run failed” wording; current main instead returned “OpenClaw couldn’t finish this reply.” The fixture now asserts the terminal error and absence of recovery requests, retaining its requirement to observe partial output before injection.
The first remote attempt stopped before tests because a source check expected the original HEAD rather than Testbox's carrier commit; the corrected check verified the wrapper's recorded source and exact file hashes. No product failure was hidden by that correction.