fix: clamp maxAllowedPromptTokens to zero to prevent silent autocomplete failures - #13045
Open
rekha0suthar wants to merge 1 commit into
Open
fix: clamp maxAllowedPromptTokens to zero to prevent silent autocomplete failures#13045rekha0suthar wants to merge 1 commit into
rekha0suthar wants to merge 1 commit into
Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Author
|
recheck |
rekha0suthar
force-pushed
the
fix/autocomplete-negative-prune-length
branch
from
July 28, 2026 07:13
fb543fb to
8fe6f59
Compare
Author
|
recheck |
When the LLM contextLength is less than or equal to the sum of maxTokens and the safety buffer (e.g. when Ollama num_ctx equals Continue default maxTokens), the calculation contextLength - reservedTokens - safetyBuffer produced a negative value. This caused pruneLength() to return a very large positive number, making the prompt pruner strip all context and silently produce an empty completion. Fixed by clamping maxAllowedPromptTokens to 0 with Math.max(), so the pruner never attempts to remove more tokens than the prompt contains. Fixes continuedev#13038
rekha0suthar
force-pushed
the
fix/autocomplete-negative-prune-length
branch
from
July 28, 2026 07:27
8fe6f59 to
a32931c
Compare
Author
|
I have read the CLA Document and I hereby sign the CLA |
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.
Problem
When using Ollama with a
num_ctxvalue equal to (or smaller than) Continue's defaultmaxTokens, autocomplete silently produces no output. No error is shown, no completion appears — it just does nothing.Root Cause
In
renderPromptWithTokenLimit, thepruneLengthhelper calculates how many tokens to remove from the prompt:When
contextLength ≤ reservedTokens + safetyBuffer(which happens when Ollama'snum_ctxequals Continue's defaultmaxTokens),maxAllowedPromptTokensbecomes negative. This causespruneLengthto returnpromptTokenCount - (negative), i.e. a very large positive number. The pruner then tries to drop more tokens than the entire prompt contains, reducing it to nothing.Fix
Clamp
maxAllowedPromptTokensto a minimum of0:This ensures the pruner never requests removal of more tokens than the prompt has, preventing the silent empty-output failure.
Reproducing
num_ctxto the same value as Continue's defaultmaxTokens(600)Fixes #13038
🤖 Generated with Claude Code