Skip to content

fix: recover rejected ChatGPT tool continuations - #168055

Merged
steipete merged 2 commits into
mainfrom
fix/chatgpt-responses-tool-continuation-replay
Oct 10, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/chatgpt-responses-tool-continuation-replay

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

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_id when 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

  • Final main baseline: f8239ea9470d13d70cd222d992b79582604db816, merged before final proof; the transport is byte-identical to the earlier 8cc90d08c0a04e6878722abb1ff247e827d5197e baseline. The new real-WebSocket regression fails with only production reverted: recovery returns error instead of stop; the bounded full-request test sees two requests instead of three. The post-start and unrelated-error controls pass.
  • node scripts/run-vitest.mjs over every non-live test in packages/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).
  • Local native ChatGPT module: 70 tests across six files passed, 15.13 seconds. Test budget: 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) in checks-node-changed-compact-small-19; that complete job took 165 s.
  • Final AWS pnpm tsgo:core and pnpm tsgo:core:test packages pass. 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.
  • Hosted CI passed at the exact candidate head: 42 successful jobs, 25 intentionally skipped lanes, no failures. ClawSweeper reviewed the same head with zero findings and sufficient proof, while explicitly retaining partial linked-issue scope.
  • Required committed-branch Codex autoreview: scoped-clean, no actionable P0–P2 findings. No changelog, dependency, configuration, protocol, or schema changes.
  • Real Gateway / fake provider proof passed on fresh AWS Crabbox cbx_d2cf08778eef, r7a.xlarge (30 GiB observed), run run_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.
Gateway source Provider requests Cached rejections Actual tool executions Final result
Main transport 2 1 1 HTTP 500, failed response
Fixed transport 3 1 1 HTTP 200, RUSTPONSES_TOOL_CONTINUATION_OK

The 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 main f8239ea9470d13d70cd222d992b79582604db816 plus the exact reviewed four-file patch. Its index tree b25d29bc661ed55e7b3ac2148679423c44b5ad71 equals 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 were 47942e65342e57b687fca07cebb0f2f74a50685c86a9a15c6cf032af403f586d and daf321ec1c481c50885efb4fd936e331dbc87805fbcbf4ac10e928e07d80f37e.

node scripts/crabbox-wrapper.mjs run --provider aws \
  --id cbx_d2cf08778eef --no-sync --timing-json \
  --script /private/tmp/oc-r7-rustponses/remote-live-payload.sh

# Inside that already-synchronized, verified checkout:
node /tmp/oc-r7-rustponses-proof/gateway-replay-proof.mjs \
  "$PWD" /tmp/oc-r7-rustponses-proof/main-openai main
node /tmp/oc-r7-rustponses-proof/gateway-replay-proof.mjs \
  "$PWD" /tmp/oc-r7-rustponses-proof/fixed-openai fixed
pnpm tsgo:core
pnpm tsgo:core:test packages

The standalone harness uses the supported pnpm openclaw gateway run entry 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 one exec that 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 in finally.

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 --script instead of exceeding Linux's argument limit. None were counted as behavior proof.

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.
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The turn ends with an error despite retaining the completed tool result.
  • After: A fresh WebSocket sends the complete input without previous_response_id, allowing the turn to finish without executing the tool again.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused implementation and shipped-entry-point proof support the bounded repair; overall scope remains partial relative to the linked issue.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied exact-candidate evidence exercises pnpm openclaw gateway run and POST /v1/responses on isolated Linux state with the native WebSocket client: the injected cached rejection fails on baseline and recovers on the candidate with one actual tool execution; real ChatGPT backend acceptance was not exercised.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: A ChatGPT turn can stop after completed tool work when the backend rejects its cached response reference.
Reason: The narrow recovery preserves completed work and has direct boundary evidence, while the PR correctly uses Related for the broader unresolved report.

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
Reviewed head: 1f3f990889088e1065ef9b028592a2e014a9c806

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Bounded pre-start reconnect and post-start recovery keeps the original intent (5ea80c8: The existing reconnect handles connection-limit rejection; subsequent expiry recovery deliberately leaves started requests to the runner.)
  • Cached continuation prefix matching keeps the original intent (unknown: The cache optimization is carried through the runtime internalization and later renames; scoped history and symbol searches do not establish its original introduction before the available historical boundary.)
  • Runtime-owned WebSocket state keeps the original intent (8a2d2ff: Independent runtimes must not inherit another runtime's authenticated socket, continuation, or fallback state.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned introduced patch: The introduced patch adds exact-error recovery to the existing reconnect loop and consolidates the cache-prefix helper without changing its matching contract. (packages/ai/src/providers/openai-chatgpt-responses.ts:429, 1f3f99088908)
  • Recovery and authority boundaries: Failure clears the rejected continuation and retires its socket; every subsequent dispatch still performs beforeDispatch and assertCurrent immediately before sending. (packages/ai/src/providers/openai-chatgpt-responses.ts:1277, 1f3f99088908)
  • Current-main behavior: The fetched main transport remains identical to the merge-base transport and lacks this explicit rejection recovery. (packages/ai/src/providers/openai-chatgpt-responses.ts:429, afb4f0ff366b)
  • Supplied shipped-entry-point proof: The PR body records isolated Gateway runs through POST /v1/responses with the native WebSocket client and a synthetic provider: baseline fails, candidate returns HTTP 200 and RUSTPONSES_TOOL_CONTINUATION_OK, and both execute the tool exactly once; the candidate retry retains the call and result without previous_response_id. (1f3f99088908)
  • Meaningful regression controls: Real loopback WebSocket cases cover successful recovery, terminal rejection of full input, no replay after response.created, and an unrelated rejection; the supplied baseline comparison records the intended recovery failures. (packages/ai/src/providers/openai-chatgpt-responses.replay.test.ts:48, 1f3f99088908)
  • Exact-head checks: The complete paginated check-run read contains 72 successful, 99 skipped, and one neutral result, with no failing or unfinished check runs. (1f3f99088908)

PR surface

Source -14, Tests +200, Docs +7. Total +193 across 4 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 34 48 -14
Tests 1 200 0 +200
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 241 48 +193

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +34/-48; tests +200/-0 Production shrinks while the real-WebSocket regression adds recovery and terminal-failure controls.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported provider rejection interrupts active tool-using workflows after completed work.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-10T00:55:36.920Z sha 1f3f990 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T01:02:06.457Z sha 1f3f990 :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 9:23 PM ET / October 10, 2026, 01:23 UTC (Revision 3).

@steipete
steipete marked this pull request as ready for review October 10, 2026 00:56
@steipete
steipete merged commit c715a8a into main Oct 10, 2026
175 checks passed
@steipete
steipete deleted the fix/chatgpt-responses-tool-continuation-replay branch October 10, 2026 01:39
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
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.
RomneyDa pushed a commit that referenced this pull request Oct 10, 2026
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.
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant