Skip to content

Bug: User messages containing error-pattern phrases get rewritten to error text #3594

@vatsal28

Description

@vatsal28

Bug Description

User and assistant messages containing certain phrases (like the two words "context" + "overflow" together) are incorrectly passed through sanitizeUserFacingText(), which rewrites them to error messages.

Steps to Reproduce

  1. Start a fresh session with /new
  2. Type a message containing "context" followed by "overflow" (as one phrase)
  3. Observe that the message is replaced with: "Context overflow: prompt too large for the model. Try again with less input or a larger-context model."

This happens even with minimal context usage (e.g., 8-15% of context window).

Expected Behavior

User messages should pass through unchanged. The sanitizeUserFacingText() function should only be applied to actual API error responses, not user/assistant chat messages.

Actual Behavior

Any message containing error-pattern phrases gets rewritten. This includes:

  • User input messages
  • Assistant responses (if they mention the phrase)

The bug affects both directions of chat.

Root Cause

In dist/agents/pi-embedded-helpers/errors.js:

export function sanitizeUserFacingText(text) {
    // ...
    if (isContextOverflowError(trimmed)) {
        return ("Context overflow: prompt too large for the model. " +
            "Try again with less input or a larger-context model.");
    }
    // ...
}

And isContextOverflowError() matches on lower.includes("context overflow").

This function is being called somewhere in the message flow where it processes regular chat messages, not just error payloads.

Suggested Fix

Either:

  1. Add a flag/context to sanitizeUserFacingText() to distinguish error payloads from regular messages
  2. Or ensure this function is only called on actual API error responses, not on user/assistant message content

Environment

  • Clawdbot version: npm latest 2026.1.24-3
  • Model: claude-opus-4-5
  • Channel: Telegram

Workaround

Avoid typing the exact phrase in messages until fixed.

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