Commit efc9a95
fix(cache): emit tools before input in OpenAI Responses request body
`buildOpenAIResponsesParams` was inserting `params.tools = ...` AFTER
the literal that already contained `input: messages`. JS object
property insertion order determines JSON key order, which determines
the byte stream the upstream prompt cache matches against. With
`input` enumerated first, the (large, per-session-stable) tools
schema landed past the per-turn divergence point and was excluded
from the cached prefix every turn.
Hoist tool conversion above the literal and place `tools` between
`stream` and `instructions`; move `input` to the end of the literal
so per-turn mutations sit downstream of the cache-stable prefix.
Semantics unchanged: the same fields with the same values, only
their on-the-wire byte order changes.
Adds a regression test that asserts `Object.keys(params)` enumerates
`tools` before `input` (and double-checks via `JSON.stringify`).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>1 parent 96c0309 commit efc9a95
3 files changed
Lines changed: 67 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| 166 | + | |
166 | 167 | | |
167 | 168 | | |
168 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5294 | 5294 | | |
5295 | 5295 | | |
5296 | 5296 | | |
| 5297 | + | |
| 5298 | + | |
| 5299 | + | |
| 5300 | + | |
| 5301 | + | |
| 5302 | + | |
| 5303 | + | |
| 5304 | + | |
| 5305 | + | |
| 5306 | + | |
| 5307 | + | |
| 5308 | + | |
| 5309 | + | |
| 5310 | + | |
| 5311 | + | |
| 5312 | + | |
| 5313 | + | |
| 5314 | + | |
| 5315 | + | |
| 5316 | + | |
| 5317 | + | |
| 5318 | + | |
| 5319 | + | |
| 5320 | + | |
| 5321 | + | |
| 5322 | + | |
| 5323 | + | |
| 5324 | + | |
| 5325 | + | |
| 5326 | + | |
| 5327 | + | |
| 5328 | + | |
| 5329 | + | |
| 5330 | + | |
| 5331 | + | |
| 5332 | + | |
| 5333 | + | |
| 5334 | + | |
| 5335 | + | |
| 5336 | + | |
| 5337 | + | |
| 5338 | + | |
| 5339 | + | |
| 5340 | + | |
| 5341 | + | |
| 5342 | + | |
| 5343 | + | |
5297 | 5344 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1336 | 1336 | | |
1337 | 1337 | | |
1338 | 1338 | | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
1339 | 1353 | | |
1340 | 1354 | | |
1341 | | - | |
1342 | 1355 | | |
| 1356 | + | |
| 1357 | + | |
1343 | 1358 | | |
1344 | 1359 | | |
1345 | | - | |
1346 | 1360 | | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
1347 | 1364 | | |
1348 | 1365 | | |
1349 | 1366 | | |
| |||
1358 | 1375 | | |
1359 | 1376 | | |
1360 | 1377 | | |
1361 | | - | |
1362 | | - | |
1363 | | - | |
1364 | | - | |
1365 | | - | |
1366 | | - | |
1367 | | - | |
1368 | 1378 | | |
1369 | 1379 | | |
1370 | 1380 | | |
| |||
0 commit comments