Feed malformed client-side tool call args back to the model#47
Feed malformed client-side tool call args back to the model#47ScriptSmith wants to merge 2 commits into
Conversation
Greptile SummaryThis PR fixes two bugs in the client-side tool-call pipeline: the SSE tracker was keyed on the provider
Confidence Score: 5/5Safe to merge; the changes are narrowly scoped to error-handling paths that previously either silently dropped tool calls or crashed the streaming handler. Both the tracker key fix and the invalid-argument recovery are well-tested by the new test suite. The only rough edge is that the functionCallItems continuation reconstructs an invalid call's arguments as "{}" rather than the original malformed string, which may slow the model's self-correction but does not break the loop. The functionCallItems block in useChat.ts around line 2193 is the one spot where the new invalid-call flow interacts with pre-existing logic that was not updated to preserve the raw argument buffer. Important Files Changed
Sequence DiagramsequenceDiagram
participant SSE as SSE Stream
participant Parser as toolCallParser
participant Tracker as ToolCallTracker
participant Executor as executeToolCalls
participant Model as Model (next round)
SSE->>Parser: "output_item.added (id=fc_xxx, call_id=toolu_xxx)"
Parser->>Tracker: set(fc_xxx, state)
SSE->>Parser: "function_call_arguments.delta (item_id=fc_xxx)"
Parser->>Tracker: get(fc_xxx) accumulate buffer
SSE->>Parser: "function_call_arguments.done (item_id=fc_xxx, args=malformed)"
Parser->>Tracker: get(fc_xxx), JSON.parse fails, state.invalid set
SSE->>Parser: "output_item.done (id=fc_xxx, args=malformed)"
Parser->>Tracker: get(fc_xxx), retry parse fails, state.invalid updated
Parser-->>Executor: tool_call_complete (invalid set)
Executor->>Executor: toolCall.invalid? skip tool, build error message
Executor-->>Model: function_call_output with call_id toolu_xxx and parse error
Model->>Model: self-correct and retry
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
ui/src/pages/chat/useChat.ts:2193-2199
**Invalid call reconstructed with `"{}"` args in continuation**
When `toolCall.invalid` is set, `tc.arguments` is `{}` (the fallback from `state.parsedArguments ?? {}`), so the `function_call` item sent back to the model has `arguments: "{}"` instead of the original malformed string. The model sees a call it apparently made with empty arguments, paired with a `function_call_output` error saying the JSON was invalid — a contradiction that may confuse the model and require extra rounds to self-correct. Preserving `argumentsBuffer` (the raw string) in `ParsedToolCall` and using it here for invalid calls would give the model accurate context about what it originally emitted.
Reviews (3): Last reviewed commit: "Review fixes" | Re-trigger Greptile |
No description provided.