-
-
Notifications
You must be signed in to change notification settings - Fork 69k
sanitizeUserFacingText false positive: normal responses containing billing/payment keywords replaced with billing error warning #25661
Description
Bug Description
sanitizeUserFacingText() in pi-embedded-helpers falsely classifies normal assistant responses as API billing errors when the response content contains certain keyword combinations.
Root Cause
The function isBillingErrorMessage() checks if text contains "billing" AND one of ("payment", "credits", "upgrade", "plan"):
function isBillingErrorMessage(raw) {
const value = raw.toLowerCase();
if (!value) return false;
if (matchesErrorPatterns(value, ERROR_PATTERNS.billing)) return true;
return value.includes("billing") && (value.includes("upgrade") || value.includes("credits") || value.includes("payment") || value.includes("plan"));
}This function is called on the full assistant response text inside sanitizeUserFacingText(), not just on API error payloads. When the assistant writes a legitimate response that happens to contain these words (e.g., discussing a billing feature, payment methods, pricing plans), the entire response is replaced with:
⚠️ API provider returned a billing error — your API key has run out of credits or has an insufficient balance. Check your provider's billing dashboard and top up or switch to a different API key.
Steps to Reproduce
- Send a message to the agent via Telegram (or any channel) that will elicit a response containing both "billing" and "payment" (e.g., ask about a billing/payment feature)
- The agent generates a valid response in the session
- Before delivering to the channel,
sanitizeUserFacingTextrewrites the response into the billing error warning - User sees the billing error instead of the actual response
Expected Behavior
sanitizeUserFacingText should only match against actual API error payloads, not against regular assistant response content. The billing error detection should be scoped to error messages from the LLM provider, not applied to successful assistant responses.
Actual Behavior
Any assistant response mentioning billing + payment/credits/plan keywords gets silently replaced with a billing error warning on the messaging channel, while the correct response is visible in the session/webchat.
Environment
- OpenClaw version: 2026.2.9
- Channel: Telegram (likely affects all channels)
- Model: anthropic/claude-opus-4-6
Suggested Fix
Either:
- Only run
isBillingErrorMessageon messages withstopReason === "error"(not on successful responses) - Require the text to match actual API error structure (e.g., starts with
"Error:"or contains HTTP status codes) before classifying as billing error - Add a minimum confidence threshold — short error-like strings only, not full multi-paragraph responses