fix(converters): batch consecutive tool results before emitting images - #84
Merged
Merged
Conversation
When an assistant turn contains multiple parallel tool calls (such as reading multiple images), messagesToCC previously emitted a user message with the image immediately after each individual tool result. This interleaved a user message into the middle of the tool-result sequence. The Command Code generate transport closes the tool turn upon seeing a user message and rejects the request with "Tool result is missing for tool call <id>." Batch consecutive tool results first, then emit the attached images in a single following user message.
Star-233
force-pushed
the
fix/converters-batch-tool-results
branch
from
September 5, 2026 09:48
48e8da1 to
7a9a429
Compare
Owner
|
Integrated main and added a mixed image/text/error parallel-result regression. Both image-ordering tests fail against the main converter and pass with this implementation. Full npm test passes with real Pi and OMP, plus format/diff checks. Waiting for CI. |
Owner
|
Shipped in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
When an assistant turn issues multiple parallel tool calls that include images (for example, reading multiple preview screenshots in Oh My Pi), the generate transport fails with:
Cause
In
src/converters.ts,messagesToCC()iterated throughmessagesone by one. For eachtoolResultcontaining an image, it pushed therole: "tool"entry and immediately pushed arole: "user"message with the image.When an assistant turn contains multiple parallel tool calls:
assistant(call_1,call_2)tool(call_1result)user(call_1image)tool(call_2result)The Command Code
/alpha/generategateway closes the tool turn once it sees the user message. Becausecall_2result has not arrived yet, the gateway considerscall_2unanswered and aborts withserver_error.Fix
Batch consecutive
toolResultmessages before emitting image content:toolResultmessages and emit theirrole: "tool"entries first.role: "user"message with the accumulated images only after all tool results are in place.This matches the pattern used by
@earendil-works/pi-aiandoh-my-pi.Verification
npm run typecheck— cleannpm run test:unit— 50 tests pass, including new regression test intests/test-pure-functions.tsnpm run format:check— cleangit diff --check— cleanQwen/Qwen3.8-Flashvia/alpha/generatewith parallel image reads; response completed with status 200 without missing tool call errors.