#18970: Fix #18937: Don't leak API errors to user channel
agents
size: XS
Cluster:
HEARTBEAT_OK Suppression Fixes
## Problem
API error messages (e.g. `401 User not found`) were being sent directly to users' WhatsApp/Telegram channels instead of being kept internal.
## Changes
1. **Heartbeat error suppression** (`agent-runner-execution.ts`): When a heartbeat run fails, return an empty payload instead of forwarding the error text to the user channel. Errors are still logged via `defaultRuntime.error()`.
2. **Auth error sanitization** (`errors.ts`):
- `formatRawAssistantErrorForUi`: HTTP 401/403 errors now return a generic "Authentication error" message instead of the raw error body
- `formatAssistantErrorText`: Added early auth error detection before the generic fallback
Fixes #18937
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR prevents API error messages from leaking to user channels by sanitizing authentication errors and suppressing heartbeat failures.
**Changes:**
- `formatRawAssistantErrorForUi` now returns a generic "Authentication error" message for HTTP 401/403 errors instead of exposing raw error bodies like "401 User not found"
- `formatAssistantErrorText` adds early auth error detection before the generic fallback
- Heartbeat runs that fail now return empty payload instead of forwarding error text to user channel (errors still logged via `defaultRuntime.error()`)
The implementation correctly addresses the security issue by catching auth errors in multiple places and preventing sensitive API error details from reaching end users.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with no identified issues
- The changes are focused security improvements that prevent API error leakage. The implementation leverages existing error detection patterns (`isAuthErrorMessage` already includes 401/403 patterns), adds appropriate sanitization in two key locations, and maintains backward compatibility by only affecting error display logic without changing error handling behavior. Errors are still logged internally for debugging.
- No files require special attention
<sub>Last reviewed commit: 3774c38</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#19303: Fix WhatsApp internal error leakage + cron.run timeout defaults
by koala73 · 2026-02-17
76.8%
#16321: Fix #12767: suppress HEARTBEAT_OK leakage in Telegram DM replies
by tdjackey · 2026-02-14
76.3%
#8175: fix: suppress raw API errors for non-owners
by Rakshi2609 · 2026-02-03
76.0%
#9173: Fix: Improve error messaging for API rate limits and billing errors
by vishaltandale00 · 2026-02-04
75.6%
#7353: fix: prevent silent message drops after config.patch restart
by 18-RAJAT · 2026-02-02
75.2%
#19406: fix(heartbeat): filter error payloads from heartbeat reply selection
by namabile · 2026-02-17
74.3%
#11340: Telegram: skip empty message text instead of throwing (#11238)
by lailoo · 2026-02-07
74.2%
#19339: fix(heartbeat): skip isError payloads when resolving heartbeat reply
by aldoeliacim · 2026-02-17
74.1%
#15109: fix: distinguish transient API errors from billing errors
by jwchmodx · 2026-02-13
74.0%
#16548: fix(telegram): enhance chat_id validation and diagnostics
by tanujbhaud · 2026-02-14
73.8%