fix: address review findings for context window management#730
fix: address review findings for context window management#7302witstudios wants to merge 1 commit intoclaude/fix-context-length-errors-WFBfzfrom
Conversation
- Fix wasTruncated message inversion: non-truncated error no longer
claims messages were trimmed
- Guard empty messages: return 413 when truncation leaves zero messages
instead of sending empty context to streamText
- Fix estimateMessageTokens: match actual Vercel AI SDK tool-{name}
part format (input/output/state) instead of legacy tool-call/tool-result
- Reconcile context windows: extract MODEL_CONTEXT_WINDOWS into shared
model-context-windows.ts as single source of truth (fixes glm-5
200000→202752, minimax m2.5 via OpenRouter 1M→204800 divergence)
- Fix isContextLengthError: replace broad '413' string match with
specific HTTP status pattern to prevent false positives
- Fix estimateTokens: replace regex array allocation with efficient
charCode loop for CJK detection
- Add 42 unit tests for isContextLengthError, estimateTokens,
estimateMessageTokens, getContextWindowSize, determineMessagesToInclude
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes issues identified by both the Claude Code review and Codex review of PR #708.
!wasTruncatedbranch incorrectly told users "Older messages have been trimmed" when no trimming occurredtool-{name}part format (input/output/statefields) instead of non-existenttool-call/tool-resulttypesMODEL_CONTEXT_WINDOWSinto sharedmodel-context-windows.tsas single source of truth, fixing divergence (e.g. glm-5: 200k→202,752, minimax m2.5 via OpenRouter: 1M→204,800)/\b(?:status|http|code|error)\s*413\b/i) to prevent false positivescharCodeAtloopisContextLengthError,estimateTokens,estimateMessageTokens,getContextWindowSize,determineMessagesToInclude,getAIErrorMessage,isRateLimitErrorTest plan
packages/lib/src/monitoring/__tests__/ai-context-calculator.test.tsapps/web/src/lib/ai/shared/__tests__/error-messages.test.ts🤖 Generated with Claude Code