Handle malformed server-side tool call args correctly by feeding back to the model#45
Conversation
Greptile SummaryThis PR addresses a class of silent failures where a server-side tool call (shell, web_search, file_search, MCP, tool_search) with unparseable arguments was either dropped — leaving the agentic loop in a false-completed state — or dispatched with null args, causing confusing downstream errors. The fix introduces a
Confidence Score: 5/5Safe to merge; the change is well-scoped and each tool's invalid-args path is covered by new tests, including the previously-flagged edge cases. All six changed files follow the same pattern consistently. The two issues raised in previous review rounds (the No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Model
participant Orchestrator
participant Tool as Tool Executor
Model->>Orchestrator: SSE chunk with function_call (malformed args)
Orchestrator->>Tool: "detect(chunk) → DetectedToolCall{invalid: Some(err)}"
Orchestrator->>Tool: execute(call) [call.invalid is Some]
Note over Tool: synthesize_*_invalid_handle
Tool-->>Orchestrator: "ToolExecutionHandle{events: [in_progress, failed], result: Ok}"
Orchestrator-->>Model: SSE: tool_call in_progress → failed
Orchestrator->>Model: "Continuation: FunctionCallOutput{output: "Invalid arguments …"}"
Model->>Orchestrator: Next turn with corrected tool call
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
src/services/mcp/executor.rs:501-507
**`invalid_arguments_text` uses the generic `"mcp"` label instead of the actual tool name**
`tool_name` is computed just a few lines earlier (from `__mcp_tool` in the arguments, falling back to `call.call_id`) and is already passed to `synthesize_failed_call` for the MCP call item itself. But the error text fed back to the model still says "Invalid arguments for tool `mcp`" instead of naming the specific tool (e.g., "Invalid arguments for tool `jira_create`"). The SSE event and the model-facing error therefore disagree on the tool name, making the model's self-correction loop marginally harder.
Reviews (3): Last reviewed commit: "Review fixes" | Re-trigger Greptile |
No description provided.