Skip to content

fix(errorDetector): classify HTTP 400 context overflow responses correctly#9

Open
hariom888 wants to merge 1 commit into
Ruthwik000:mainfrom
hariom888:fix-context-overflow-detection
Open

fix(errorDetector): classify HTTP 400 context overflow responses correctly#9
hariom888 wants to merge 1 commit into
Ruthwik000:mainfrom
hariom888:fix-context-overflow-detection

Conversation

@hariom888
Copy link
Copy Markdown

@hariom888 hariom888 commented May 16, 2026

Fixes context overflow detection for providers that return HTTP 400 responses with overflow information embedded in the response body.

Previously, Anthropic-style errors such as:

prompt is too long: 130000 tokens > 100000 maximum

were classified as unknown instead of context_overflow, preventing the router's context-based fallback strategy from activating correctly.

Changes

  • Expanded context overflow detection logic in errorDetector

  • Added support for additional overflow indicators:

    • too long
    • maximum
  • Preserved existing behavior for:

    • rate limits
    • model unavailable errors
    • access denied errors

Verification

  • Added reproduction test cases
  • Verified OpenAI and Anthropic overflow scenarios
  • Confirmed all test cases pass (7 passed, 0 failed)

Closes #6

…dies

classifyHttpError() returned 'unknown' for HTTP 400 errors without inspecting the response body, so context overflow responses were never reaching classifyApiError().

Fix: for status 400, delegate to classifyApiError() when a response body exists. Also expand overflow detection to recognize provider-specific wording like 'prompt is too long' and 'maximum'.

This allows context-based routing fallback to work correctly for OpenAI and Anthropic overflow responses while leaving other status classifications unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(errorDetector): classify HTTP 400 with context_length_exceeded body as context_overflow

1 participant