Commit dd1d753
authored
🤖 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- src
- browser/utils/messages
- node/services
2 files changed
+9
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | | - | |
61 | | - | |
62 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
938 | 938 | | |
939 | 939 | | |
940 | 940 | | |
| 941 | + | |
941 | 942 | | |
942 | 943 | | |
943 | 944 | | |
| |||
0 commit comments