Skip to content

Agents: guard billing error detection with length check (#11649)#11680

Closed
lailoo wants to merge 1 commit intoopenclaw:mainfrom
lailoo:fix/sanitize-billing-false-positive-11649
Closed

Agents: guard billing error detection with length check (#11649)#11680
lailoo wants to merge 1 commit intoopenclaw:mainfrom
lailoo:fix/sanitize-billing-false-positive-11649

Conversation

@lailoo
Copy link
Contributor

@lailoo lailoo commented Feb 8, 2026

Summary

Fixes #11649

sanitizeUserFacingText() runs isBillingErrorMessage() against all assistant reply text, not just error payloads. When the assistant naturally discusses billing, credits, or payment topics, the sanitizer false-positives and replaces the entire reply with the canned billing error message.

Root Cause

isBillingErrorMessage() matches broadly on keyword combinations (e.g. "billing" + "credits"/"payment"/"plan"). This is correct for short API error messages, but false-positives on normal assistant replies that happen to discuss those topics.

Fix

Add a length guard (trimmed.length < 500) before the isBillingErrorMessage check in sanitizeUserFacingText. Real API billing errors are short error strings (<500 chars). Normal assistant replies discussing billing topics are longer and should pass through unchanged.

This is the same pattern already used for context overflow detection (shouldRewriteContextOverflowText has conversational-length guards).

Changes

  • src/agents/pi-embedded-helpers/errors.ts: Add trimmed.length < 500 guard (1 line)
  • Test: Add 2 test cases — short billing errors still caught, long billing discussions pass through
  • CHANGELOG.md: Add entry

Verification

Bug reproduced on main branch ❌

Case 1: Short API error "402 Payment Required" (20 chars)
  Caught as billing error: true ✅

Case 2: Short billing combo (58 chars)
  Caught as billing error: true ✅

Case 3: Long assistant reply discussing billing (618 chars)
  Result preserved: false
  False-positive (replaced with billing error): true ❌ BUG

❌ BUG REPRODUCED: Long assistant reply was replaced with billing error message.

A 618-char assistant reply discussing billing/credits/payment was entirely replaced with the canned billing error string.

Fix verified on feature branch ✅

Case 1: Short API error "402 Payment Required" (20 chars)
  Caught as billing error: true ✅

Case 2: Short billing combo (58 chars)
  Caught as billing error: true ✅

Case 3: Long assistant reply discussing billing (618 chars)
  Result preserved: true
  False-positive: false ✅ CORRECT

✅ FIX VERIFIED: Short billing errors caught, long replies pass through.

Unit tests ✅

Test Files  1 passed (1)
     Tests  12 passed (12)

Lint ✅

Found 0 warnings and 0 errors.

@Takhoffman
Copy link
Contributor

Fixed in #12988.

This will go out in the next OpenClaw release.

If you still see this after updating to the first release that includes #12988, please open a new issue with:

  • your OpenClaw version
  • channel (Telegram/Slack/etc)
  • the exact prompt/response that got rewritten
  • whether Web UI showed the full text vs the channel being rewritten
  • relevant logs around send/normalize (if available)

Link back here for context.

@Takhoffman
Copy link
Contributor

Closing as superseded by the merged sanitize/error-context work:

This PR’s intent appears covered by those merged changes and current mainline tests.

@Takhoffman Takhoffman closed this Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sanitizeUserFacingText false-positive: normal assistant replies containing billing keywords get replaced with billing error message

2 participants

Comments