Repository navigation
fix: recover rejected ChatGPT tool continuations - #168055
Conversation
Retry explicitly rejected cached response references once with complete input, preserving completed tool results and encrypted state. Keep post-start and full-input failures terminal. Related: #167667.
|
🦞👀 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. What this changesThis PR retries an explicitly rejected cached ChatGPT continuation once using retained full input and completed tool results. Example: A cached continuation referencing resp_tool is rejected with the reported Rustponses error after a tool completes.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review This PR provides a bounded, useful recovery absent from current main, with no actionable findings; its partial scope does not resolve the entire linked report. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe native ChatGPT Responses adapter converts conversation history into provider requests, caches connection-scoped continuations, and returns streamed assistant events to the agent runner. flowchart TD
A[Agent runner and completed tools] --> B[ChatGPT Responses adapter]
B --> C[Cached WebSocket continuation]
C --> D[Provider rejection before response starts]
D --> E[Fresh WebSocket with retained full input]
E --> F[Assistant response stream]
Technical reviewBest possible solution: Land this bounded transport recovery and retain the linked report for failures outside its verified scope. Do we have a high-confidence way to reproduce the issue? Source and the supplied baseline/candidate Gateway transcript establish the exact injected cached-rejection path; this read-only review ran no target code, and the original report's backend trigger remains unknown. Is this the best way to solve the issue? The existing transport owner is the appropriate repair boundary: it retains the logical request, discards rejected connection state, retries only before response acceptance, and leaves completed tools untouched. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against afb4f0ff366b. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -14, Tests +200, Docs +7. Total +193 across 4 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReviewed October 9, 2026, 9:23 PM ET / October 10, 2026, 01:23 UTC (Revision 3). |
|
Merged via squash.
|
Retry explicitly rejected cached response references once with complete input, preserving completed tool results and encrypted state. Keep post-start and full-input failures terminal. Related: openclaw#167667.
Retry explicitly rejected cached response references once with complete input, preserving completed tool results and encrypted state. Keep post-start and full-input failures terminal. Related: #167667. (cherry picked from commit c715a8a) Release adaptation: ported the dispatch capture and replay-rejection reconnect onto release's retry loop; kept release's getCachedWebSocketInputDelta helper and connection-limit guard; docs omit an unrelated main-only SSE paragraph.
Retry explicitly rejected cached response references once with complete input, preserving completed tool results and encrypted state. Keep post-start and full-input failures terminal. Related: openclaw#167667. (cherry picked from commit c715a8a) Release adaptation: ported the dispatch capture and replay-rejection reconnect onto release's retry loop; kept release's getCachedWebSocketInputDelta helper and connection-limit guard; docs omit an unrelated main-only SSE paragraph. (cherry picked from commit 5af2a9e) Co-authored-by: RomneyDa <[email protected]>
Related: #167667
What Problem This Solves
Fixes: a cached ChatGPT Responses tool continuation stops after completed tool work when the backend rejects its saved response state with “Rustponses cannot replay.”
User Impact
OpenClaw retries that explicitly rejected continuation once with the complete input, preserving reasoning, compaction, tool calls, and completed tool results. Tools are not re-executed. No configuration change or migration is required.
This is a bounded recovery for the cached WebSocket path. The original report lacks a request capture, so this does not establish the cause of every reported failure. Full-input/SSE rejections and the separate generic-error display remain unresolved; this PR does not close the issue.
Why This Change Was Made
The transport already retains the complete logical request but sends only new input with
previous_response_idwhen its cache matches. Previously, this rejection retired the connection and ended the turn. It now uses the existing one-retry reconnection path only when a cached response reference was actually dispatched and no response event was accepted. A fresh connection sends the retained full request, including completed results, without stripping opaque state or restarting the agent run.The cache helper consolidation removes redundant handoffs and its unused internal type export. Production changes are 34 additions / 48 deletions (net −14); tests are +200; docs are +7. Reported by @nikosml.
Evidence
f8239ea9470d13d70cd222d992b79582604db816, merged before final proof; the transport is byte-identical to the earlier8cc90d08c0a04e6878722abb1ff247e827d5197ebaseline. The new real-WebSocket regression fails with only production reverted: recovery returnserrorinstead ofstop; the bounded full-request test sees two requests instead of three. The post-start and unrelated-error controls pass.node scripts/run-vitest.mjsover every non-live test inpackages/ai/src/providers, plus every test directly importing the changed transport: 928 tests across 54 files passed, 54.04 seconds of test-wrapper wall time on the final AWS candidate (also passed on the earlier Blacksmith Testbox).pnpm test packages/ai/src/providers/openai-chatgpt-responses.replay.test.ts --maxWorkers=1: 4 passed, 9.05 seconds command wall / 0.293 seconds test execution. Hosted CI: the four regression cases took 7/4/2/2 ms (0.015 s total) inchecks-node-changed-compact-small-19; that complete job took 165 s.pnpm tsgo:coreandpnpm tsgo:core:test packagespass. Before the main merge, all 27 core-test graphs, typed lint, formatting, docs MDX sanity, and the remaining changed-file guards passed; the touched source is unchanged by that merge. Dead-export scans pass. The changed-check runner caught an unused internal export from the helper consolidation; that export was removed and all unused-export scans then passed.cbx_d2cf08778eef,r7a.xlarge(30 GiB observed), runrun_11be971525f5308ca3cedb1f5951c32a. The campaign fallback was used after a fresh Testbox remained queued without a runner for over 15 minutes. Both Gateways used isolated state, homes, workspaces, and ephemeral loopback ports; the fake provider returned the exact reported rejection.RUSTPONSES_TOOL_CONTINUATION_OKThe fixed third request included the original function call and completed result, without
previous_response_id. Both cases used only WebSocket requests. Gateway phases took 83.659 s and 83.993 s respectively; the combined remote tests, typechecks, builds, and proof command took 589.949 s.The optional real ChatGPT probe was not exercised: credential preflight found no hydrated ChatGPT credentials on the AWS lane. This proof establishes the real Gateway and native transport behavior against the exact synthetic backend rejection, not acceptance by the real backend.
Commands and source binding
The checked source is candidate
1f3f990889088e1065ef9b028592a2e014a9c806. For efficient remote preparation, a task-owned checkout used published mainf8239ea9470d13d70cd222d992b79582604db816plus the exact reviewed four-file patch. Its index treeb25d29bc661ed55e7b3ac2148679423c44b5ad71equals the candidate commit tree. The remote command checked that base and SHA-256 hashes of all four changed files before testing. Main and fixed transport hashes were47942e65342e57b687fca07cebb0f2f74a50685c86a9a15c6cf032af403f586danddaf321ec1c481c50885efb4fd936e331dbc87805fbcbf4ac10e928e07d80f37e.The standalone harness uses the supported
pnpm openclaw gateway runentry point and POST/v1/responses, with an isolated synthetic OpenAI token profile, explicit embedded runtime, cached WebSocket transport, and utility-model narration disabled. Its fake server requests oneexecthat appends a marker line, rejects the next cached continuation, and accepts only full input containing that call and its successful output. Baseline and fixed processes are separate; only the transport production bytes change between them. Gateway processes and fake servers stop infinally.Earlier fixture/setup failures were resolved: a custom provider name selected generic HTTP rather than the native OpenAI route; a macOS temporary path was invalid on Linux; one Testbox expired and another never acquired a runner; AWS's initial full-source sync timed out, so native Git seeding was used; the large proof payload was uploaded with
--scriptinstead of exceeding Linux's argument limit. None were counted as behavior proof.