#18415: fix(agents): suppress benign exec exit code 1 from tool error surfacing
agents
stale
size: XS
trusted-contributor
Cluster:
Tool Execution and Error Handling
## Problem
Since v2026.2.14, tool calls that exit with code 1 (e.g. `grep` finding no matches, `diff` finding differences) are surfaced to users as ⚠️ failure warnings. This is noisy and confusing because exit code 1 is normal behavior for many CLI tools.
The root cause: `exec` is classified as a mutating tool, and `shouldShowToolErrorWarning` always surfaces mutating tool failures.
## Fix
Add `isBenignExecExit()` that checks if the tool is `exec`/`bash` and the error indicates exit code 1. This check runs before the mutation check, so benign exits are never surfaced.
Exit codes >= 2 continue to be surfaced normally, as they indicate real errors.
## Changes
- `src/agents/pi-embedded-runner/run/payloads.ts`: Add `isBenignExecExit()` helper and early-return in `shouldShowToolErrorWarning`
- `src/agents/pi-embedded-runner/run/payloads.e2e.test.ts`: Update existing test + add test for exit code >= 2
## Testing
- Updated existing test that expected exit code 1 to surface (now suppressed)
- Added test confirming exit code 2 still surfaces as error
- All 21 tests in payloads.e2e.test pass
Closes #18283
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Suppresses noisy exit-code-1 warnings from exec/bash tools (e.g. `grep` returning no matches, `diff` finding differences) that were incorrectly surfaced as failure warnings since v2026.2.14. Adds a targeted `isBenignExecExit()` check before the mutation-based warning logic so exit code 1 is treated as benign while exit codes >= 2 continue to surface normally.
- Adds `EXEC_TOOL_NAMES` set and `BENIGN_EXIT_CODE_RE` regex to identify benign exec exit code 1 errors
- Inserts an early-return in `shouldShowToolErrorWarning` before the mutation check
- Updates existing test to verify exit code 1 suppression; adds new test confirming exit code 2 still surfaces
- Note: suppression only applies when the error message string literally ends with "exited with code 1" — if the command produced aggregated output, the error text will be the first line of that output (due to `normalizeToolErrorText`), and the warning will still surface. This is acceptable for the targeted fix scope.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it's a narrowly scoped fix with correct regex behavior and good test coverage.
- The change is small and well-targeted. The regex `/exited with code 1$/i` correctly avoids false positives for multi-digit exit codes (verified via testing). The early-return placement before the mutation check is intentional and correct. Tests cover both the suppression (exit code 1) and passthrough (exit code 2) paths. One minor gap: no test for the "bash" tool name variant, but the implementation is straightforward Set lookup. The fix correctly addresses the reported regression.
- No files require special attention
<sub>Last reviewed commit: 19c023c</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#20382: fix: move suppressToolErrors check before mutating tool check
by klawdius-noodle · 2026-02-18
82.9%
#18992: fix: suppress spurious tool error warnings for read-only exec commands
by Phineas1500 · 2026-02-17
81.9%
#19632: fix: suppressToolErrors now suppresses exec tool failure notifications
by Gitjay11 · 2026-02-18
81.6%
#22087: Preserve assistant reply when exec fails under suppressToolErrors
by graysurf · 2026-02-20
81.6%
#3864: fix(agents): suppress exec/bash exit code errors from user display
by HirokiKobayashi-R · 2026-01-29
81.0%
#18466: fix: suppress recoverable mutating tool errors when agent already r...
by stijnhoste · 2026-02-16
80.4%
#18934: fix(agents): suppress exec tool output from channel delivery
by BinHPdev · 2026-02-17
80.0%
#10261: fix(agents): prevent exec tool errors from leaking to channels (#9651)
by nu-gui · 2026-02-06
78.8%
#17552: fix(agents): suppress tool error warnings when assistant already re...
by AytuncYildizli · 2026-02-15
78.5%
#20209: fix(node): respect tools.exec.notifyOnExit for node exec events
by zerone0x · 2026-02-18
77.1%