Repository navigation
Conversation
|
The following comment was made by an LLM, it may be inaccurate: |
There was a problem hiding this comment.
Looks good. I reproduced the #56127 script on the base: a streaming tool call with argument text not-json compiles to an Anthropic tool_use.input of "not-json". With this change it compiles to {}, and valid JSON arguments still lower to the parsed object. session-runner-message.test.ts passes (30/30) and packages/core typechecks cleanly.
The {} fallback matches how settling a stale call already treats leftover string input (message-updater.ts, session.tool.failed), so lowering and settlement now agree. As the issue notes, the runner settles stuck streaming calls before building a request, so this is hardening at the lowering step rather than a fix for a path a normal session has been shown to reach.
The public API is unchanged. No concerns.
Issue for this PR
Closes #56127
Type of change
What does this PR do?
toLLMMessageslowered a tool call still instreamingstate to the raw argument text when that text was not valid JSON. The Anthropic lowerer copiesinputonto the wire unchanged, so the request carriedtool_use.input: "not-json"and Anthropic rejected it with400 tool_use.input: Input should be an object.The streaming state stores the accumulated argument text as a
Stringwhile every other tool state stores a record, so lowering now decodes the text as a JSON object and falls back to{}when it cannot: unparseable text, a truncated stream, or valid JSON that is not an object (an array, a number,null) all lower to an empty object rather than a non-object value. Nothing else changes — a streaming call whose arguments do parse still lowers to the parsed object, and running, completed and error states are untouched.How did you verify your code works?
Regression test
lowers unparseable streaming tool arguments to an objectinpackages/core/test/session-runner-message.test.tslowers one assistant message containing five tool parts throughtoLLMMessages:tool-call.inputnot-json{}["pwd"]{}{"command":"pwd"(truncated){}{"command":"pwd"}{ command: "pwd" }{ command: "pwd" }{ command: "pwd" }It fails on the base with the string and array inputs passed through as raw text (29 pass / 1 fail before the fix, 30 pass / 0 fail after).
bun test test/session-runner-message.test.ts— 30 passbun test test/session-runner-message.test.ts test/session-generate.test.ts test/session-runner-retry.test.ts— 36 passbun run typecheckinpackages/core— cleanoxlinton both changed files — 0 warnings, 0 errorsThe test asserts the lowering boundary, which is where the defect lives: the Anthropic lowerer copies
inputverbatim, so an object here is what makestool_use.inputan object on the wire. It does not contact a live provider.AI-assisted implementation and tests; reviewed before publication.
Screenshots / recordings
Not applicable; message lowering only.
Checklist