Skip to content

Commit dd1d753

Browse files
🤖 fix: infer tool failure from error field (#999)
## Problem When in Plan Mode, file edit tools (`file_edit_*`) are disabled via tool policy. However, the model doesn't know about this policy and may still attempt to call these tools*. When this happens: 1. The AI SDK emits a `tool-error` event with the error message 2. The error output was `{ error: "Model tried to call unavailable tool..." }` 3. The frontend's `hasFailureResult()` only checked for `success === false` 4. Since there was no `success` field, the tool call showed **"completed"** status instead of **"failed"** This made it appear the edit succeeded when it actually failed, and the error wasn't visible in the dropdown. ## Solution Update `hasFailureResult()` to infer failure from the presence of an `error` field, not just explicit `success: false`: ```typescript function hasFailureResult(result: unknown): boolean { if (typeof result !== "object" || result === null) return false; // Explicit failure if ("success" in result && result.success === false) return true; // Implicit failure - error field present if ("error" in result && result.error) return true; return false; } ``` This is more defensive and handles any tool error that includes an `error` field, regardless of whether `success` is explicitly set. *This only appears to happen when the context includes usage of those tools. I assume this isn't an easily solvable problem as an agent author, the model sees the tool is disabled, but it also sees it being used dozens of times in the context. How does it know it's really disabled? --- _Generated with `mux`_
1 parent c3a6641 commit dd1d753

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/browser/utils/messages/StreamingMessageAggregator.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ function hasSuccessResult(result: unknown): boolean {
5454
}
5555

5656
/**
57-
* Check if a tool result indicates failure (for tools that return { success: boolean })
57+
* Check if a tool result indicates failure.
58+
* Handles both explicit failure ({ success: false }) and implicit failure ({ error: "..." })
5859
*/
5960
function hasFailureResult(result: unknown): boolean {
60-
return (
61-
typeof result === "object" && result !== null && "success" in result && result.success === false
62-
);
61+
if (typeof result !== "object" || result === null) return false;
62+
// Explicit failure
63+
if ("success" in result && result.success === false) return true;
64+
// Implicit failure - error field present
65+
if ("error" in result && result.error) return true;
66+
return false;
6367
}
6468

6569
export class StreamingMessageAggregator {

src/node/services/streamManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ export class StreamManager extends EventEmitter {
938938

939939
// Format error output
940940
const errorOutput = {
941+
success: false,
941942
error:
942943
typeof toolErrorPart.error === "string"
943944
? toolErrorPart.error

0 commit comments

Comments
 (0)