fix: trim conversation history to fit context window (prevents 'No response came') - #167
Closed
Fahad090NP wants to merge 4 commits into
Closed
fix: trim conversation history to fit context window (prevents 'No response came')#167Fahad090NP wants to merge 4 commits into
Fahad090NP wants to merge 4 commits into
Conversation
…ontext window Long multi-turn conversations (or many repeated turns without Compact Conversation) can grow past the model context limit, so the upstream rejects the oversized request (HTTP 400) or returns an empty stream — surfaced by VS Code as 'No response came'. Add a pure helper that drops the oldest messages until the payload fits the input budget, preserving the anchor and current prompt and never splitting a tool-call group. Add HISTORY_TRIM_SAFETY_MARGIN_TOKENS.
…hatResponse Call trimOldMessagesToFitContext after the image-history trim, before the prompt-token estimate, so the request payload is bounded to the model's input context window. Logs a [history-trim] diagnostic when messages are dropped.
Add unit tests for no-op when fitting, dropping oldest while keeping anchor + last, never splitting a tool-call group, and no-op when only anchor + last remain.
Add a Fixed entry to CHANGELOG and a concise issue doc (68-20260820) describing the conversation-history trimming that prevents oversized-payload 'No response came' errors.
Contributor
Author
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.
Summary
Fixes two related "No response came" failure modes with a single root-cause fix:
Root cause
provideLanguageModelChatResponsesent the entire conversation history as the request payload. The only history guard was image trimming (trimOldImagesFromHistoryInPlace) — there was no text-history truncation. So a long conversation grows past the model's context window and the upstream either:finish_reason: null), orCompact Conversation shrinks the history, which is exactly why it "fixes" the symptom. (This also explains the reported Muse Spark ~990 KB payload — it is the uncompacted history, not a model-specific quirk.)
Changes
src/provider/historyTrim.ts(new, pure) —trimOldMessagesToFitContextdrops the oldest messages until the estimated prompt tokens fitcontextWindow − maxOutputTokens − safetyMargin. It preserves the first (system/anchor) and last (current prompt) messages, and never splits a tool-call group (stops before the first assistant message carryingtool_calls), so no tool reference is orphaned.src/provider/OpenCodeProvider.ts— calls it right after the image-history trim, before the prompt-token estimate, with a[history-trim]diagnostic log.src/config.ts—HISTORY_TRIM_SAFETY_MARGIN_TOKENS = 2048.src/test/messages.test.ts(no-op when fitting, drops oldest keeping anchor + last, never splits a tool group, no-op when only anchor + last remain).docs/issues/68-20260820-history-trim-context-overflow.md.Verification
npm test— 337/337 passnpm run lint— all 7 gates pass (Editorconfig, ESLint, Markdown, Prettier, Shell, TypeScript, Tests)PEACE BE UPON YOU