Repository navigation
Conversation
|
This pull request has been automatically marked as stale due to inactivity. |
…#25371) OpenRouter 402 errors ('requires more credits, or fewer max_tokens') contain token/limit language that matches CONTEXT_OVERFLOW_HINT_RE, causing misclassification as context overflow. This triggers futile auto-compaction retries that drain remaining credits. Changes: - Add 'more credits', 'can only afford', 'requires more credits' to billing error patterns so isBillingErrorMessage catches OpenRouter 402 - Add isBillingErrorMessage guard in isLikelyContextOverflowError (mirrors existing isRateLimitErrorMessage guard) - Add tests for OpenRouter 402 billing detection, overflow exclusion, and failover classification
Contributor
Author
|
Rebased onto latest main and resolved merge conflicts; force-pushed updates. CI re-running. If the only failure is the Windows shard timeout in src/plugin-sdk/root-alias.test.ts, it appears flaky across multiple PRs. |
Contributor
Author
|
Follow-up: removed unused ERROR_PATTERNS table (was tripping oxlint) and increased plugin-sdk root-alias test timeout to reduce Windows shard flake. CI re-running. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
max_tokens,tokens,limit) that matchesCONTEXT_OVERFLOW_HINT_REinisLikelyContextOverflowError(). Meanwhile,isBillingErrorMessage()fails to detect this error because its patterns only match "insufficient credits" / "payment required" — not OpenRouter's "requires more credits" / "can only afford" wording."more credits","can only afford","requires more credits"to billing error patternsisBillingErrorMessage()guard inisLikelyContextOverflowError()(mirrors existingisRateLimitErrorMessage()guard)isContextOverflowError()(strict patterns) does not match the 402 message, so no change needed there.formatAssistantErrorText()ordering is unaffected since the strict check runs first.Change Type
Scope
Linked Issue/PR
User-visible / Behavior Changes
OpenRouter 402 billing errors now correctly show a billing error message instead of "Context overflow: prompt too large for the model". Auto-compaction retries are no longer triggered for billing errors, preventing unnecessary credit drain.
Security Impact
NoNoNoNoNoEvidence
Compatibility / Migration
YesNoNoFailure Recovery
Greptile Summary
This PR fixes a bug where OpenRouter 402 billing errors containing token/limit language were misclassified as context overflow errors, triggering wasteful auto-compaction retries that drained remaining credits.
Key changes:
ERROR_PATTERNS.billing:"more credits","can only afford","requires more credits"(lines 653-655 inerrors.ts)isBillingErrorMessage()guard inisLikelyContextOverflowError()before the broadCONTEXT_OVERFLOW_HINT_REcheck (lines 124-129), mirroring the existing rate limit guard patternHow it works:
The OpenRouter error "402 This request requires more credits, or fewer max_tokens. You requested up to 32000 tokens, but can only afford 11771" contains words like "max_tokens" and "tokens" that match the broad
CONTEXT_OVERFLOW_HINT_REpattern. The fix ensures billing errors are excluded early in the detection flow, preventing incorrect classification.Impact:
Users will now see accurate billing error messages instead of confusing "Context overflow" messages, and the system won't waste credits on pointless retry attempts.
Confidence Score: 5/5
Last reviewed commit: 57845d4