#8661: fix: display rate limit errors correctly instead of as context overflow
agents
stale
Cluster:
Error Handling Improvements
## Summary
- Rate limit errors were being displayed as "Context overflow" to users
- This was misleading since the actual error was a rate limit, not context size
## Root cause
- In `formatAssistantErrorText`, the context overflow check happened before the rate limit check
- Both error types can contain "request" keywords, causing false positives
## Changes
- Added rate limit check before the context overflow check in error formatting
- Users now see "Rate limit exceeded. Please wait a moment before trying again."
## Test plan
- [x] Run type checking (`npm run check`)
- [x] Run error helper tests (`vitest run src/agents/pi-embedded-helpers`)
Fixes #8047
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adjusts assistant error formatting so rate limit errors are detected and surfaced to users before the more general context overflow check, preventing rate-limit payloads that contain "request" wording from being mislabeled as context overflow. The change is localized to `src/agents/pi-embedded-helpers/errors.ts` in `formatAssistantErrorText`.
One inconsistency remains: `sanitizeUserFacingText` still maps rate limit errors to the same message as overloaded errors, which may continue to misreport rate limits in any flow that uses that sanitizer rather than `formatAssistantErrorText`.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge and fixes the reported misclassification in the primary formatter.
- The change is a small reordering in `formatAssistantErrorText` and should not affect unrelated error cases. The main remaining concern is user-facing consistency: rate limit errors may still be mislabeled as overloaded in code paths using `sanitizeUserFacingText`, which could partially negate the intended UX fix depending on call sites.
- src/agents/pi-embedded-helpers/errors.ts (sanitizeUserFacingText rate limit handling)
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#15109: fix: distinguish transient API errors from billing errors
by jwchmodx · 2026-02-13
87.9%
#9173: Fix: Improve error messaging for API rate limits and billing errors
by vishaltandale00 · 2026-02-04
85.4%
#13318: fix(agents): prevent sanitizeUserFacingText from rewriting conversa...
by hleliofficiel · 2026-02-10
83.2%
#10792: Agents: avoid context overflow false positives
by arunsanna · 2026-02-07
79.6%
#20539: fix: detect additional context overflow error patterns to prevent l...
by echoVic · 2026-02-19
78.7%
#18997: fix: improve context overflow error messages and docs
by realhoratiobot · 2026-02-17
78.6%
#15749: fix: improve context overflow error with diagnostic details
by superlowburn · 2026-02-13
78.5%
#11174: Fix/fried chicken error
by jfgrissom · 2026-02-07
77.6%
#19451: fix(errors): surface provider hint for role-ordering failures
by rafaelipuente · 2026-02-17
77.4%
#14368: fix: skip auth profile cooldown on format errors to prevent provide...
by koatora20 · 2026-02-12
77.4%