Skip to content

fix: distinguish transient API errors from billing errors#15109

Open
jwchmodx wants to merge 1 commit intoopenclaw:mainfrom
jwchmodx:fix/issue-15055-billing-error-message
Open

fix: distinguish transient API errors from billing errors#15109
jwchmodx wants to merge 1 commit intoopenclaw:mainfrom
jwchmodx:fix/issue-15055-billing-error-message

Conversation

@jwchmodx
Copy link

@jwchmodx jwchmodx commented Feb 13, 2026

Fixes #15055

Summary

Fix error message handling to distinguish between transient API failures (rate limits, timeouts) and actual billing issues.

Problem

Previously, all API failures showed the same billing error message, making it impossible for users to distinguish between:

  • Genuine billing issues (insufficient credits)
  • Temporary errors (rate limiting, timeouts)

Changes

  • Check isRateLimitErrorMessage() before isBillingErrorMessage()
  • Check isTimeoutErrorMessage() before isBillingErrorMessage()
  • Add tests for rate limit (429) and timeout error handling
  • Ensure transient errors show appropriate retry messages

Test Results

  • ✅ All existing tests pass (16/16 in formatassistanterrortext.test.ts)
  • ✅ New tests added for rate limit and timeout scenarios
  • ✅ Full test suite: 6235 tests passed

AI-Assisted Development

This PR was developed with assistance from Claude Opus 4.6. The code has been reviewed and tested to ensure correctness.

Co-Authored-By: Claude Opus 4.6 [email protected]

Greptile Overview

Greptile Summary

This PR updates formatAssistantErrorText to classify rate-limit and timeout errors before billing errors, and adds tests to ensure transient errors don’t display the billing/credits messaging.

Within the wider codebase, assistant text is also passed through sanitizeUserFacingText(..., { errorContext: true }) in multiple user-facing pipelines (assistant text extraction and reply normalization). That sanitizer still collapses rate-limit errors into the generic “temporarily overloaded” message in its ERROR_PREFIX_RE rewrite path, which can negate the PR’s goal on those surfaces.

Confidence Score: 4/5

  • Mostly safe to merge, but there is one remaining user-facing classification inconsistency for rate limits.
  • The change to formatAssistantErrorText is small and well-covered by targeted tests, but another sanitizer used in user-facing flows still rewrites rate-limit errors to the overloaded message, which conflicts with the stated behavior change and can cause incorrect messaging in some surfaces.
  • src/agents/pi-embedded-helpers/errors.ts

Last reviewed commit: 7e1df79

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

Check rate limit and timeout errors before billing errors to avoid
showing misleading billing messages for temporary API failures.

Fixes openclaw#15055

Changes:
- Check isRateLimitErrorMessage() before isBillingErrorMessage()
- Check isTimeoutErrorMessage() before isBillingErrorMessage()
- Add tests for rate limit (429) and timeout error handling
- Ensure transient errors show appropriate retry messages

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 13, 2026

Additional Comments (1)

src/agents/pi-embedded-helpers/errors.ts
Rate limit misreported

sanitizeUserFacingText(..., { errorContext: true }) still rewrites rate limit errors to the generic overloaded message via if (isOverloadedErrorMessage(trimmed) || isRateLimitErrorMessage(trimmed)) return "The AI service is temporarily overloaded..."; (around ERROR_PREFIX_RE). Since sanitizeUserFacingText is used in user-facing pipelines (e.g. extractAssistantText and reply normalization), some surfaces may continue to show the overloaded copy for rate limits, undermining the intent of distinguishing transient failures from other error classes.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/errors.ts
Line: 528:531

Comment:
**Rate limit misreported**

`sanitizeUserFacingText(..., { errorContext: true })` still rewrites *rate limit* errors to the generic overloaded message via `if (isOverloadedErrorMessage(trimmed) || isRateLimitErrorMessage(trimmed)) return "The AI service is temporarily overloaded...";` (around `ERROR_PREFIX_RE`). Since `sanitizeUserFacingText` is used in user-facing pipelines (e.g. `extractAssistantText` and reply normalization), some surfaces may continue to show the overloaded copy for rate limits, undermining the intent of distinguishing transient failures from other error classes.

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Billing error message is generic/misleading for transient API failures

1 participant

Comments