Fix: count all tool tokens in budget and add summarization UserMessage priority#5000
Merged
bhavyaus merged 1 commit intorelease/0.43from Apr 6, 2026
Merged
Conversation
…ools Deferred tools (defer_loading: true) still count against the API context window. The 3/30 change (#4834) excluded them from toolTokens, causing the message budget to be ~31K tokens too generous and leading to context_length_exceeded errors followed by summarization failures ("No messages provided").
eleanorjboyd
approved these changes
Apr 6, 2026
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.
Cherry-pick of #4992 into release/0.43.
Problem
Two issues causing summarization failures:
1. Tool token under-counting (context_length_exceeded → "No messages provided")
The 3/30 change (#4834) excluded deferred tools from
toolTokens, making the message budget ~31K too generous. The summarization call usesChatLocation.Otherwhere all tools count fully, causing conversations to overflow the context window.2. Summarization UserMessage has no priority (empty messages)
The final "Summarize the conversation..."
UserMessagehad no explicit priority (defaulting to 0). Under tight budgets, prompt-tsx would prune it, resulting in empty messages → "No messages provided".Changes
agentIntent.ts: Count all tools fortoolTokens(removeeffectiveToolsfiltering)summarizedConversationHistory.tsx: Add tool-token budget reduction ingetSummary(Full), add priority to summarization UserMessagesummarization.spec.tsx: Add repro test for empty messages with small budget