Skip to content

[Bug]: sanitizeUserFacingText false-positive replaces normal responses containing 'context overflow' and other error keywords #12309

@aunknown

Description

@aunknown

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

  1. Send a message to the assistant asking about "context overflow" errors
  2. 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 overflow
  • timeout / timed out
  • maximum context length
  • prompt is too long
  • etc.

This is problematic because:

  1. WebChat receives messages directly from emitAgentEvent and bypasses sanitizeUserFacingText()
  2. External channels (Feishu, Telegram, etc.) use createReplyDispatcher which calls normalizeReplyPayloadsanitizeUserFacingText()
  3. 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:

  1. Strip <final> tags
  2. Collapse duplicate blocks
  3. 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions