-
-
Notifications
You must be signed in to change notification settings - Fork 39.9k
Description
Bug Description
sanitizeUserFacingText() runs on all outgoing messages to external channels (Feishu, Telegram, Slack, etc.) and incorrectly replaces normal AI responses with error messages when the response text contains certain keywords.
Reproduction Steps
- Send a message to the assistant asking about "context overflow" errors
- The assistant's response mentioning "context overflow" is replaced with:
Context overflow: prompt too large for the model. Try again with less input or a larger-context model.
Root Cause
In sanitizeUserFacingText(), the function calls isContextOverflowError(trimmed) which matches any text containing keywords like:
context overflowtimeout/timed outmaximum context lengthprompt is too long- etc.
This is problematic because:
- WebChat receives messages directly from
emitAgentEventand bypassessanitizeUserFacingText() - External channels (Feishu, Telegram, etc.) use
createReplyDispatcherwhich callsnormalizeReplyPayload→sanitizeUserFacingText() - Result: Same message appears correctly in WebChat but is replaced with error text in external channels
Affected Keywords (likely to appear in normal conversation)
| Keyword | Risk Level | Common Use Case |
|---|---|---|
context overflow |
🔴 High | Discussing LLM errors |
timeout |
🔴 High | Discussing networking, programming |
timed out |
🔴 High | Discussing networking, programming |
overloaded |
🟡 Medium | Discussing server load |
rate limit |
🟡 Medium | Discussing API usage |
Suggested Fix
Similar to PR #12226 which removed isBillingErrorMessage() from sanitizeUserFacingText(), the context overflow and other error pattern checks should also be removed from this function.
Real errors are already caught by formatAssistantErrorText() which correctly gates on stopReason === "error" before checking these patterns.
The sanitizeUserFacingText() function should only:
- Strip
<final>tags - Collapse duplicate blocks
- NOT perform error pattern matching on normal assistant responses
Environment
- OpenClaw version: 2026.2.1 (also verified in 2026.2.6-3)
- Channel: Feishu
- WebChat shows correct response, Feishu shows error replacement