Repository navigation
Commit 763a08a
fix(anthropic): keep tool_result blocks contiguous by grouping image blocks separately (Zoo-Code-Org#2243)
* fix(anthropic): keep tool_result blocks contiguous by grouping image blocks separately
When a turn issued multiple tool_use blocks and tool results carried image
blocks (read_file on images, screenshots, feedback images),
presentAssistantMessage pushed each tool_result followed immediately by its
images, yielding tool_result/image interleaving in userMessageContent.
Task.ts then consumed the array verbatim, and the Anthropic API rejected the
request with a 400: "tool_use ids were found without tool_result blocks
immediately after" (Zoo-Code-Org#1307).
pushToolResultToUserContent is the single choke point every tool_result push
flows through, so it now maintains the invariant: when a new tool_result is
appended, image blocks already accumulated are moved after it. The resulting
user message is tool_results first (in tool_use order), then images, then
other blocks — matching the shape the issue expects. A single tool result
with images and image-free messages are unchanged.
* fix(anthropic): keep all tool_result blocks ahead of other user-message content
* test(anthropic): bind the real tool_result grouping and cover mixed interleave
Addresses edelauna's two review asks on Zoo-Code-Org#1705.
1. presentAssistantMessage-images.spec.ts bound a hand-copied partition of
Task.pushToolResultToUserContent, so the Zoo-Code-Org#1307 tests were tautological:
deleting the grouping from Task.ts still passed them. The mock now binds
the real Task.prototype.pushToolResultToUserContent via vi.importActual.
Verified: removing the partition from Task.ts fails both Zoo-Code-Org#1307 tests.
2. Task.spec.ts only covered "images after the first result". Added the
mixed interleave [image, text, r1, text, r2] -> [r1, r2, image, text,
text2], which fails under an image-only grouping and only passes with the
full tool_result-first partition.
Also carries main's new policySnapshot argument at the 2 integration call
sites, and drops this spec's no-explicit-any suppressions from 16 to 14.
* refactor(task): drop redundant guard in pushToolResultToUserContent
---------
Co-authored-by: Zoo (VP) <[email protected]>
Co-authored-by: Elliott de Launay <[email protected]>
(cherry picked from commit 70eba96)1 parent a0bd097 commit 763a08a
2 files changed
Lines changed: 110 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
472 | 479 | | |
473 | 480 | | |
474 | 481 | | |
| |||
484 | 491 | | |
485 | 492 | | |
486 | 493 | | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
487 | 504 | | |
488 | 505 | | |
489 | 506 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6270 | 6270 | | |
6271 | 6271 | | |
6272 | 6272 | | |
6273 | | - | |
| 6273 | + | |
6274 | 6274 | | |
6275 | 6275 | | |
6276 | 6276 | | |
| |||
6279 | 6279 | | |
6280 | 6280 | | |
6281 | 6281 | | |
6282 | | - | |
6283 | | - | |
6284 | | - | |
6285 | | - | |
| 6282 | + | |
| 6283 | + | |
| 6284 | + | |
| 6285 | + | |
| 6286 | + | |
6286 | 6287 | | |
6287 | 6288 | | |
6288 | 6289 | | |
| |||
6294 | 6295 | | |
6295 | 6296 | | |
6296 | 6297 | | |
6297 | | - | |
6298 | | - | |
6299 | | - | |
| 6298 | + | |
| 6299 | + | |
| 6300 | + | |
| 6301 | + | |
| 6302 | + | |
| 6303 | + | |
| 6304 | + | |
| 6305 | + | |
| 6306 | + | |
| 6307 | + | |
| 6308 | + | |
| 6309 | + | |
| 6310 | + | |
| 6311 | + | |
| 6312 | + | |
| 6313 | + | |
| 6314 | + | |
| 6315 | + | |
| 6316 | + | |
| 6317 | + | |
| 6318 | + | |
| 6319 | + | |
| 6320 | + | |
| 6321 | + | |
| 6322 | + | |
| 6323 | + | |
| 6324 | + | |
| 6325 | + | |
| 6326 | + | |
| 6327 | + | |
| 6328 | + | |
| 6329 | + | |
| 6330 | + | |
| 6331 | + | |
| 6332 | + | |
| 6333 | + | |
| 6334 | + | |
| 6335 | + | |
| 6336 | + | |
| 6337 | + | |
| 6338 | + | |
| 6339 | + | |
| 6340 | + | |
| 6341 | + | |
| 6342 | + | |
| 6343 | + | |
| 6344 | + | |
| 6345 | + | |
| 6346 | + | |
| 6347 | + | |
| 6348 | + | |
| 6349 | + | |
| 6350 | + | |
| 6351 | + | |
| 6352 | + | |
| 6353 | + | |
| 6354 | + | |
| 6355 | + | |
| 6356 | + | |
| 6357 | + | |
| 6358 | + | |
| 6359 | + | |
| 6360 | + | |
| 6361 | + | |
| 6362 | + | |
| 6363 | + | |
| 6364 | + | |
| 6365 | + | |
| 6366 | + | |
| 6367 | + | |
| 6368 | + | |
| 6369 | + | |
| 6370 | + | |
| 6371 | + | |
| 6372 | + | |
| 6373 | + | |
| 6374 | + | |
| 6375 | + | |
| 6376 | + | |
| 6377 | + | |
| 6378 | + | |
| 6379 | + | |
| 6380 | + | |
| 6381 | + | |
| 6382 | + | |
| 6383 | + | |
| 6384 | + | |
6300 | 6385 | | |
6301 | 6386 | | |
0 commit comments