Repository navigation
Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
…g tool loop (continuedev#13383) In long agent sessions with substantial tool execution outputs, compileChatMessages prunes message history from the top until it fits within the context budget. Because extractToolSequence separates only trailing assistant toolCalls and tool outputs, the opening and latest user queries were previously eligible for pruning from the history array. When all prior turns were pruned, the request reached models/providers (e.g. Ollama with Qwen 3.8 renderers) without any user turn, causing HTTP 500 ('no user query found in messages'). This patch pins the latest user turn when the trailing sequence is an assistant/tool loop, budgeting its tokens alongside the system message and tool sequence, and preserving it in place during history pruning. Adds vitest regression coverage. Closes continuedev#13383 Signed-off-by: David Vance <devops@ribbsaetersystems.com>
DevOps22X
force-pushed
the
fix/compile-chat-preserve-user-query-13383
branch
from
October 19, 2026 20:46
86a6822 to
439d298
Compare
Author
|
I have read the CLA Document and I hereby sign the CLA |
This branch has not been deployed
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.
Description
Addresses #13383.
In long agent sessions with substantial tool execution outputs,
compileChatMessagesprunes message history from the top until it fits within the context budget. BecauseextractToolSequenceseparates only trailing assistanttoolCallsand tool outputs, the opening and latest user queries were previously eligible for pruning from the history array.When all prior turns were pruned, the request reached models/providers (e.g. Ollama with Qwen 3.8 renderers) without any user turn, causing HTTP 500 (
no user query found in messages).This patch pins the latest user turn when the trailing sequence is an assistant/tool loop, budgeting its tokens alongside the system message and tool sequence, and preserving it in place during history pruning.
Changes
core/llm/countTokens.ts: Separate the latest user message from prunable history when trailing turns comprise an active tool loop, budgeting its tokens upfront.core/llm/compileChatMessages.vitest.ts: Added regression tests verifying that the user turn is preserved and older intermediate turns are pruned first.Validation
npx vitest run compileChatMessages: 2/2 tests passed (100% green).