Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Dec 24, 2025

Related GitHub Issue

Closes: #10246

Description

This PR improves context overflow error detection to handle third-party API proxies (like LiteLLM) that may return error messages in different formats than the original providers.

Key changes:

  • Added checkIsLiteLLMContextWindowError() for LiteLLM proxy-specific error patterns
  • Added checkIsGenericContextWindowError() as a catch-all for various error formats including:
    • String errors (e.g., from JSON parse failures)
    • Nested error structures
    • Cause chains
  • Added checkMessageForContextOverflow() helper for comprehensive pattern matching
  • Support for Chinese, Japanese, and Korean error messages (common in regional LLM services)

Why this matters:
When editing large files (e.g., 1500 lines of JS code), the context can exceed API limits. Third-party proxies may return plain text errors like "Error occurred..." instead of JSON, causing JSON parse failures. This PR ensures these errors are properly detected as context overflow errors, triggering automatic context truncation instead of failing with cryptic JSON parse errors.

Test Procedure

  1. Run the test suite:
    cd src && npx vitest run core/context/context-management/__tests__/context-error-handling.test.ts
  2. All 53 tests pass, including new tests for:
    • LiteLLM error patterns
    • Generic context window errors
    • String errors
    • Nested error structures
    • Cause chains
    • Chinese, Japanese, and Korean error messages

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

This is an attempt to address the context overflow detection issue reported in #10246. The implementation adds more permissive error detection patterns to catch context overflow errors from various sources, which may result in some previously undetected errors now being properly handled.

Feedback and guidance are welcome!

- Add checkIsLiteLLMContextWindowError() for LiteLLM proxy errors
- Add checkIsGenericContextWindowError() as catch-all for various error formats
- Add checkMessageForContextOverflow() helper for pattern matching
- Support Chinese, Japanese, and Korean error messages
- Handle string errors, nested error structures, and cause chains
- Add comprehensive tests for new error detection functions

Addresses issue #10246 where third-party API proxies return plain text
error messages that were not being detected as context overflow errors.
@roomote
Copy link
Contributor Author

roomote bot commented Dec 24, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. Found 1 minor issue:

  • Remove redundant code block in checkIsLiteLLMContextWindowError() (lines 156-159)

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Comment on lines +156 to +159
// Also check for status 400 with context-related keywords
if (String(status) === "400" && LITELLM_CONTEXT_PATTERNS.some((pattern) => pattern.test(message))) {
return true
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check on lines 157-159 is redundant. If execution reaches line 157, it means the pattern check at lines 152-154 already failed (patterns didn't match the message). Since lines 157-159 check the same LITELLM_CONTEXT_PATTERNS against the same message, adding the status 400 requirement won't make the patterns match. This block can be safely removed.

Suggested change
// Also check for status 400 with context-related keywords
if (String(status) === "400" && LITELLM_CONTEXT_PATTERNS.some((pattern) => pattern.test(message))) {
return true
}

Fix it with Roo Code or mention @roomote and request a fix.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Triage

3 participants