Skip to content

fix: stop misclassifying rate-limit errors as context overflow#10003

Open
maxtongwang wants to merge 1 commit intoopenclaw:mainfrom
maxtongwang:fix/rate-limit-misclassified-as-overflow
Open

fix: stop misclassifying rate-limit errors as context overflow#10003
maxtongwang wants to merge 1 commit intoopenclaw:mainfrom
maxtongwang:fix/rate-limit-misclassified-as-overflow

Conversation

@maxtongwang
Copy link

@maxtongwang maxtongwang commented Feb 6, 2026

Summary

The CONTEXT_OVERFLOW_HINT_RE regex (introduced in #1266) was too broad — its third alternative (?:prompt|request|input).*(exceed|over|limit|max) matched Anthropic rate-limit messages like "Number of request tokens has exceeded your per-model limit", causing them to be surfaced as "Context overflow" errors to users.

Root cause: When the Anthropic usage quota is nearly exhausted, rate-limit 429 errors are returned. The broad regex in isLikelyContextOverflowError matched these, so the agent runner showed "Context overflow" instead of the actual rate-limit error.

Fix:

  • Tightened the regex third branch to only match (prompt|request|input) [is] too (large|long) — genuine overflow messages
  • Added guard clauses to exclude rate-limit and billing errors before applying the hint regex
  • Added test cases covering the false positives

Test plan

  • All 77 test files pass (pnpm test)
  • New test cases verify rate-limit messages like "Number of request tokens has exceeded your per-model limit" are no longer misclassified
  • New test case verifies billing errors are excluded
  • Existing context overflow detection tests still pass

Fixes a regression from #1266.

🤖 Generated with Claude Code

Greptile Overview

Greptile Summary

This PR narrows CONTEXT_OVERFLOW_HINT_RE in src/agents/pi-embedded-helpers/errors.ts to avoid matching rate-limit phrasing (e.g., “request tokens exceeded your per-model limit”), and adds explicit early returns in isLikelyContextOverflowError for rate-limit and billing errors before applying the hint regex. It also adds regression tests in src/agents/pi-embedded-helpers.islikelycontextoverflowerror.test.ts to ensure rate-limit and billing messages are not misclassified as context overflow.

This fits into the existing error-classification pipeline: formatAssistantErrorText and related helpers rely on isContextOverflowError/isLikelyContextOverflowError to decide whether to present a “Context overflow” user message vs. other provider errors.

Confidence Score: 4/5

  • This PR is likely safe to merge once the test file compiles/linters pass.
  • The production change is narrowly-scoped (regex tightening + explicit guard clauses) and aligns with existing error-classification helpers, but the added test file appears to reference an undefined type via dead code, which can break CI typecheck/lint depending on repo configuration.
  • src/agents/pi-embedded-helpers.islikelycontextoverflowerror.test.ts

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

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.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 6, 2026

Additional Comments (1)

src/agents/pi-embedded-helpers.islikelycontextoverflowerror.test.ts
Broken test helper

This test file defines _makeFile with a WorkspaceBootstrapFile type, but neither WorkspaceBootstrapFile nor _makeFile is used/imported here. In a TS project, this will fail typechecking (Cannot find name 'WorkspaceBootstrapFile') unless it’s a global type, and even then it’s dead code in this test. Removing the helper (and unused imports like DEFAULT_AGENTS_FILENAME if no longer needed) will avoid compile/lint failures.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers.islikelycontextoverflowerror.test.ts
Line: 5:11

Comment:
**Broken test helper**

This test file defines `_makeFile` with a `WorkspaceBootstrapFile` type, but neither `WorkspaceBootstrapFile` nor `_makeFile` is used/imported here. In a TS project, this will fail typechecking (`Cannot find name 'WorkspaceBootstrapFile'`) unless it’s a global type, and even then it’s dead code in this test. Removing the helper (and unused imports like `DEFAULT_AGENTS_FILENAME` if no longer needed) will avoid compile/lint failures.

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

@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 6, 2026
@maxtongwang maxtongwang force-pushed the fix/rate-limit-misclassified-as-overflow branch from 05cbfc6 to fefbe05 Compare February 7, 2026 08:10
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: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments