Repository navigation
Commit 45f155d
fix(ai): exclude tools from the HTTP continuation request-equality check (#132951)
* fix(ai): exclude tools from the HTTP continuation request-equality check
`requestWithoutInput()` already excludes `instructions` from the
turn-to-turn request comparison in `resolveResponsesContinuationRequest`,
with the reasoning that it's rebuilt fresh every request from live
runtime state and comparing it just moves a false-positive rejection
into `request_changed`. `tools` was never given the same exclusion,
even though it's exactly the same class of field: the agent's
model-visible tool surface legitimately shifts turn to turn
(tool-search activation, session-scoped gating, MCP servers
connecting/disconnecting) independent of whether the prior turn's
server-side response state is still a valid continuation baseline.
Any ordinary tool-list change between two turns on the same connection
fell through to `request_changed`, silently and permanently disabling
HTTP continuation for the rest of that connection's life -- every
later attempt keeps comparing against the same now-stale cached tool
list. Confirmed live against a real OpenAI-Responses-compatible
endpoint: continuation held across a tool-calling round and a plain
new-turn round, then broke exactly at the turn where a second tool
became available, with `resolve: request_changed` and a JSON diff
whose only differing key was `tools`.
Add `tools` to the same destructure-and-drop as `instructions`, and a
regression test mirroring the existing `instructions` test that fails
pre-fix (`request_changed`) and passes post-fix (`continued`, with the
current turn's tools kept on the wire).
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6
* fix(ai): trim invariant comment; prove tools-list-change continuation live against api.openai.com
Addresses ClawSweeper review on #132951:
- P2: HTTP continuation is native-api.openai.com-only on current main, so
the earlier OmniRoute-only live proof didn't establish whether the
official Responses API actually accepts previous_response_id after the
turn's `tools` list changes, versus rejecting it. Added a live test
(gated on OPENCLAW_LIVE_TEST=1 + OPENAI_API_KEY, matching the sibling
continuation.live.test.ts pattern exactly, including the secret-recall
proof that continuation genuinely resolved server-side history) that
hits the real endpoint with a tool list that grows between turn 1 and
turn 2. Passed: the real API accepts the changed tools with
previous_response_id, the trimmed request never re-sent the secret, and
the reply correctly recalled it -- proving genuine server-side
continuation, not a lucky self-contained answer or a silent
full-history fallback.
- P1: compressed the new `tools` exclusion comment to the short invariant
(matching the sibling `instructions` comment's density) instead of
restating the PR rationale, and pointed it at the new live test as the
evidence backing the claim.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6
* fix(ai): scope the tools-exclusion to HTTP continuation only
Addresses ClawSweeper P2 on #132951: resolveResponsesContinuationRequest
is shared by both the HTTP and WebSocket Responses transports. The
`tools` exclusion was only ever proven live over HTTP; WebSocket has its
own pre-existing test ("resets continuation on tool schema change" in
openai-responses-websocket.test.ts) asserting that a tool-schema change
resets continuation, which the unscoped exclusion silently broke for
that transport too, without any corresponding proof it's safe there.
Added a required `{ excludeTools: boolean }` option threaded through
`requestWithoutInput()`/`resolveResponsesContinuationRequest()` so every
caller states its own proof status instead of inheriting one implicitly:
- HTTP (`claimOpenAIResponsesHttpContinuation`): `excludeTools: true` --
the option this PR's live evidence actually covers.
- WebSocket (`openai-responses-websocket.ts`): `excludeTools: false` --
unchanged behavior, still resets on a tool-schema change, matching its
existing test.
- Other call sites (compaction-replay test, cache-stability test): they
don't vary tools, so `excludeTools: false` (the conservative default)
doesn't change their outcome; passed explicitly since the parameter is
required, not defaulted, so no call site can silently coast on an
unproven assumption.
Added a companion unit test proving the WebSocket path still resets
(`excludeTools: false` -> `request_changed`) alongside the existing
HTTP-path test (`excludeTools: true` -> `continued`), so the scoping
itself has regression coverage, not just a comment. Reran the full
existing WebSocket suite (including the pre-existing "resets
continuation on tool schema change" case) and the native api.openai.com
live test -- both still pass unchanged.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6
* test(ai): widen live tools-change continuation proof to 4 real-API scenarios
Addresses ClawSweeper P1 on #132951: the live proof only covered adding
one unused tool after a plain-text turn -- too narrow to back a change
that ignores every HTTP tool difference. Extended
openai-responses-client.continuation-tools-change.live.test.ts, all run
live against the real api.openai.com and all passing:
- tool added (existing scenario, now via a shared helper)
- tool removed
- an existing tool's schema mutated (same name, different
description/parameters)
- tools change on the turn immediately after a completed tool-calling
round -- the shape closest to real production dynamic tool-gating,
and the one exercising the reasoning-replay/tool-call machinery a
plain text-only round doesn't touch
Also fixed a bug in the refactor: the shared secret-recall helper never
restored the patched globalThis.fetch on return, which would have
leaked the capture across scenarios; wrapped in try/finally.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6
* refactor(ai): compress the tools-exclusion invariant comment further
Addresses ClawSweeper P1 on #132951 (production LOC growth). Trims the
comment to a single short paragraph naming what's proven, where, and
why WebSocket differs -- same information, fewer lines.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vk2cBRQdErwRtPea8VuhG6
* fix(ai): satisfy strict lint/typecheck in the tools-change live test
Post-rebase gaps found on the exact-head check pass, matching the same
class of finding already caught and fixed on the sibling unsafe-integer
live test (#134423):
- no-unsafe-optional-chaining (4x): (x?.field as T).prop on a value that
could be undefined. Fixed with ?? / optional chaining after the cast,
same pattern already established.
- no-array-sort: .sort() mutates; switched to .toSorted().
- runSecretRecallToolsChangeScenario's declared return type claimed a
non-optional Record even though capture.requests[1] is a genuine array
index access that can be undefined; widened the type to match reality
instead of asserting past it.
- toolResultMsg missing ToolResultMessage's required toolName/isError
fields.
Verification: oxfmt/oxlint clean, scoped tsgo clean, and the exact live
scenarios still pass for real against api.openai.com:
$ OPENCLAW_LIVE_TEST=1 OPENAI_API_KEY=*** node --import ./scripts/tsx.mjs scripts/test-live.mts \
packages/ai/src/transports/openai-responses-client.continuation-tools-change.live.test.ts
✓ tool added: accepts previous_response_id and carries the current (grown) tool list 4233ms
✓ tool removed: accepts previous_response_id and carries the current (shrunk) tool list 2975ms
✓ tool schema mutated: accepts previous_response_id with the same tool name but a changed definition 1882ms
✓ tools change immediately after a completed tool-calling round: accepts previous_response_id on the next turn 4253ms
Test Files 1 passed (1)
Tests 4 passed (4)
* fix(openai): share tool-change continuation across transports
Keep current tools out of history equality for native Responses continuation over HTTP and WebSocket. Remove the per-transport comparison switch while preserving strict request settings, history, credential and session ownership checks.
Exercise real HTTP/SSE and WebSocket request shapes, strict negative controls and third-turn baseline advancement through one scoped wire fixture. Preserve unsafe integer replay normalization.
Co-authored-by: Markus Hartung <[email protected]>
---------
Co-authored-by: Claude Sonnet 5 <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Markus Hartung <[email protected]>1 parent 95383b3 commit 45f155d
7 files changed
Lines changed: 528 additions & 108 deletions
File tree
- packages/ai/src/transports
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
| 1 | + | |
| 2 | + | |
7 | 3 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
21 | 8 | | |
22 | 9 | | |
23 | 10 | | |
| |||
81 | 68 | | |
82 | 69 | | |
83 | 70 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 71 | + | |
| 72 | + | |
137 | 73 | | |
138 | 74 | | |
139 | | - | |
| 75 | + | |
140 | 76 | | |
141 | 77 | | |
142 | 78 | | |
| |||
218 | 154 | | |
219 | 155 | | |
220 | 156 | | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
| 157 | + | |
233 | 158 | | |
234 | 159 | | |
235 | 160 | | |
0 commit comments