fix(agents): suppress tool error warnings when assistant already replied#17552
fix(agents): suppress tool error warnings when assistant already replied#17552AytuncYildizli wants to merge 4 commits intoopenclaw:mainfrom
Conversation
|
Thanks for the checklist! Updated the PR description to align with CONTRIBUTING.md:
Let me know if anything else is needed for review! 🦞 |
|
Just resolved the merge conflict with upstream's new The two guards are complementary and don't overlap:
This is a pretty common pain point for anyone running OpenClaw on messaging channels (WhatsApp, Telegram, Discord) — the duplicate error bubbles are confusing for end users and make the assistant look broken even when it handled the error gracefully. Happy to address any feedback! 🙏 |
ff9be9a to
3599d86
Compare
When the assistant composes a user-facing reply, tool errors are no longer surfaced as separate warning payloads. Previously, `shouldShowToolErrorWarning` unconditionally returned `true` for mutating tools (exec, write, bash, …), causing every failed command — including benign non-zero exits like `grep` returning code 1 — to produce a `⚠️ … failed` message on messaging channels (Telegram, WhatsApp, Discord). The fix moves the `hasUserFacingReply` check above the mutating-tool branch: when the assistant already addressed the error in its reply, duplicating it as a separate chat bubble is noise. When no reply exists, mutating-tool errors are still always surfaced as the sole failure signal. Additionally guards `emitToolOutput` with `!isToolError` so error payloads are not emitted as regular tool output on verbose channels — matching the existing guard used for media delivery. Fixes openclaw#9651 Co-Authored-By: Claude Opus 4.6 <[email protected]>
6f4ad96 to
fdaa39f
Compare
|
Thanks @stijnhoste! Appreciate you linking this, happy to see both approaches converge. 🤝 |
|
Closing as AI-assisted stale-fix triage. Linked issue #9651 ("[Bug]: Exec tool error output (non-zero exit code) sent as message to active WhatsApp/Telegram channel") is currently CLOSED and was closed on 2026-02-23T01:47:22Z with state reason COMPLETED. If the underlying bug is still reproducible on current main, please reopen this PR (or open a new focused fix PR) and reference both #9651 and #17552 for fast re-triage. |
|
Closed after AI-assisted stale-fix triage (closed issue duplicate/stale fix). |
Summary
Fixes #9651
When the assistant composes a user-facing reply,
shouldShowToolErrorWarningnow returnsfalse— the error is not surfaced as a separate⚠️ … failedpayload. Previously, the function unconditionally returnedtruefor any tool inMUTATING_TOOL_NAMES, bypassing thehasUserFacingReplycheck entirely.Because
execandbashare inMUTATING_TOOL_NAMES, every non-zero exit — including perfectly normal ones likegrepreturning code 1 (no match) orfindwith no results — produced a warning message that leaked to messaging channels (Telegram, WhatsApp, Discord) as a separate chat bubble.Root cause
isMutatingToolCallunconditionally returnstrueforexec/bash(tool-mutation.ts:107-108), sobuildToolMutationStatealways setsmutatingAction = true, and the early return fires on every failed command.Fix
payloads.ts: Move thehasUserFacingReplycheck above the mutating-tool branch. When the assistant already addressed the error in its reply, duplicating it as a separate chat bubble is noise. When no reply exists, mutating-tool errors are still always surfaced as the sole failure signal.handlers.tools.ts: GuardemitToolOutputwith!isToolErrorso error payloads are not emitted as regular tool output on verbose channels — matching the existing guard already used for media delivery (line 279).What changes
execfails, assistant replies with explanation⚠️ Exec: … failedleaked as separate messagewritefails, assistant replies "Done."writefails, no assistant replymessage sendfails, no assistant replysuppressToolErrorsenabled, mutating, no replyLocal validation
pnpm build— clean ✅pnpm check— clean ✅pnpm test— all 5,136 unit tests pass ✅⚠️ Exec: … failedbubbles no longer appear when the assistant has already replied with an explanation.Tests
Scope
Single focused change: fix the duplicate error-message leak on messaging channels. Two files modified (
payloads.ts,handlers.tools.ts), both addressing the same root cause from different angles.AI-assistance transparency
exectool error was discovered during daily usage of an OpenClaw agent on WhatsApp, and the fix was developed interactively.pnpm build && pnpm check && pnpm testsuite passes, and the fix was validated on a live production instance.Related
emitToolOutputbut notshouldShowToolErrorWarning)Greptile Summary
Fixes duplicate error messages on messaging channels by prioritizing assistant replies over raw tool errors. Previously, mutating tool errors (like
execorbashnon-zero exits) always generated separate warning bubbles even when the assistant already explained the situation - this was especially noisy on WhatsApp/Telegram/Discord where each payload becomes a distinct chat bubble.Key changes:
payloads.ts: ReorderedshouldShowToolErrorWarninglogic to checkhasUserFacingReplybefore the mutating-tool branch, suppressing duplicate error warnings when assistant has already repliedhandlers.tools.ts: Added!isToolErrorguard toemitToolOutputpreventing error payloads from being emitted as regular tool output (matches existing guard on line 294 for media delivery)The fix maintains the safety guarantee: mutating tool errors are still surfaced when there's NO assistant reply (the only failure signal).
Confidence Score: 5/5
Last reviewed commit: 9f7eca5
(2/5) Greptile learns from your feedback when you react with thumbs up/down!