Skip to content

sanitizeUserFacingText false-positive: normal assistant responses about billing/pricing replaced with billing error warning #12676

@CodeNameR

Description

@CodeNameR

Bug

sanitizeUserFacingText() in pi-embedded-helpers replaces normal assistant responses that discuss billing/pricing topics with the billing error warning message:

⚠️ API provider returned a billing error — your API key has run out of credits or has an insufficient balance...

This happens because isBillingErrorMessage() pattern-matches on content keywords, not just actual API errors.

Steps to Reproduce

  1. Have a conversation where the assistant discusses pricing, billing, credits, or payment (e.g. "Stripe billing integration", "AI credits per plan")
  2. The response generates fine and appears correctly on webchat
  3. On Telegram (and likely other messaging channels), the entire response is replaced with the billing error warning

Root Cause

sanitizeUserFacingText (line ~528 in pi-embedded-helpers) calls isBillingErrorMessage() on the assistant's response text. That function returns true if the text contains "billing" AND any of "upgrade", "credits", "payment", or "plan":

// pi-embedded-helpers, isBillingErrorMessage()
return value.includes("billing") && (
  value.includes("upgrade") || 
  value.includes("credits") || 
  value.includes("payment") || 
  value.includes("plan")
);

Normal assistant text discussing billing topics triggers this check, and the entire response gets replaced.

Expected Behavior

sanitizeUserFacingText should only apply billing error detection to messages that are already flagged as errors (e.g. stopReason === "error"), not to normal assistant responses.

Suggested Fix

Either:

  1. Check stopReason === "error" before applying billing/error pattern detection in sanitizeUserFacingText
  2. Only run isBillingErrorMessage on messages that came from the error handling path, not on all outbound text
  3. Make the pattern matching stricter (e.g. require JSON error payload structure, not just keyword co-occurrence)

Environment

  • OpenClaw 2026.2.6-3 (85ed6c7)
  • Channel: Telegram
  • Model: anthropic/claude-opus-4-6

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