You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix the VSCode IDE Companion issue where the context-left indicator kept showing the previous model context window size after switching models within the same chat tab.
This change makes model switch events reuse the full cached model metadata instead of emitting a minimal model object, so _meta.contextLimit is preserved and the indicator updates immediately for the newly selected model.
Screenshots / Video Demo
Dive Deeper
The root cause was in QwenAgentManager.setModelFromUi().
After a successful model switch, the extension proactively emitted onModelChanged, but it used a synthetic object containing only the selected model id and a fallback name. That object dropped _meta.contextLimit, which the webview uses to derive the context window limit for the indicator. As a result, switching models in place could leave the indicator showing a stale total context size until a new chat tab reinitialized the full model state.
This fix updates the switch path to:
look up the selected model in baselineAvailableModels
reuse the full ModelInfo when present
refresh baselineModelInfo
fall back to the minimal object only if no cached model metadata is available
A regression test was added to ensure setModelFromUi() emits the selected model with _meta.contextLimit intact.
Reviewer Test Plan
Launch the VSCode IDE Companion.
Open an existing chat tab or start a new one.
Note the total context size shown by the bottom context-left indicator.
Switch to a model with a meaningfully different context window size.
Confirm the context-left indicator immediately updates to the new model total context size.
Repeat with multiple model switches to confirm the value stays correct.
Run regression tests:
cd packages/vscode-ide-companion
npm test -- src/services/qwenSessionUpdateHandler.test.ts src/services/qwenAgentManager.test.ts
Run type checking:
cd packages/vscode-ide-companion
npm run check-types
Testing Matrix
🍏
🪟
🐧
npm run
❓
❓
❓
npx
❓
❓
❓
Docker
-
-
-
Podman
-
-
-
Seatbelt
-
-
-
Local verification completed:
npm test -- src/services/qwenSessionUpdateHandler.test.ts src/services/qwenAgentManager.test.ts
This PR fixes a state synchronization issue in the VSCode IDE Companion where the context-left indicator showed stale model context window sizes after switching models within the same chat tab. The fix ensures that setModelFromUi() reuses the full cached ModelInfo (including _meta.contextLimit) from baselineAvailableModels instead of emitting a minimal synthetic model object. A regression test has been added to verify the behavior.
🔍 General Feedback
Clean, focused fix: The change is minimal and directly addresses the root cause identified in the PR description
Good test coverage: The new test properly validates that _meta.contextLimit is preserved when switching models
Defensive programming: The fallback to minimal model object (?? { modelId, name }) ensures the code doesn't break if the model isn't found in cache
Consistent pattern: The fix aligns with how baselineModelInfo is used elsewhere in the codebase (lines 1475-1479)
🎯 Specific Feedback
🟢 Medium
File: packages/vscode-ide-companion/src/services/qwenAgentManager.ts:385-392 - Consider extracting the model lookup logic into a private helper method for better testability and reusability:
This would make the setModelFromUi method more readable and allow testing the lookup logic independently.
🔵 Low
File: packages/vscode-ide-companion/src/services/qwenAgentManager.test.ts:77-88 - The test uses type casting to access private properties (baselineAvailableModels and connection). Consider exposing these through protected getters or using a test spy pattern to make the test more maintainable and less fragile to refactoring.
File: packages/vscode-ide-companion/src/services/qwenAgentManager.test.ts:63 - The test imports QwenAgentManager and ModelInfo but doesn't test the return value of setModelFromUi(). Consider adding an assertion to verify the method returns the full model info:
File: packages/vscode-ide-companion/src/services/qwenAgentManager.ts:391 - Consider adding a comment explaining why we update baselineModelInfo here (to ensure consistency with the model metadata emitted to the UI):
this.baselineModelInfo=modelInfo;// Keep baseline in sync with emitted model
✅ Highlights
Excellent root cause analysis: The PR description clearly explains the issue and the fix
Comprehensive testing: The regression test covers the exact scenario that was broken
Defensive fallback: The ?? operator ensures graceful degradation if cached metadata is unavailable
Good verification plan: The reviewer test plan is detailed and covers both manual and automated testing
Proper type safety: The fix maintains TypeScript type correctness throughout
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
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.
TLDR
Fix the VSCode IDE Companion issue where the context-left indicator kept showing the previous model context window size after switching models within the same chat tab.
This change makes model switch events reuse the full cached model metadata instead of emitting a minimal model object, so _meta.contextLimit is preserved and the indicator updates immediately for the newly selected model.
Screenshots / Video Demo
Dive Deeper
The root cause was in
QwenAgentManager.setModelFromUi().After a successful model switch, the extension proactively emitted
onModelChanged, but it used a synthetic object containing only the selected model id and a fallback name. That object dropped_meta.contextLimit, which the webview uses to derive the context window limit for the indicator. As a result, switching models in place could leave the indicator showing a stale total context size until a new chat tab reinitialized the full model state.This fix updates the switch path to:
baselineAvailableModelsModelInfowhen presentbaselineModelInfoA regression test was added to ensure
setModelFromUi()emits the selected model with_meta.contextLimitintact.Reviewer Test Plan
cd packages/vscode-ide-companionnpm test -- src/services/qwenSessionUpdateHandler.test.ts src/services/qwenAgentManager.test.tscd packages/vscode-ide-companionnpm run check-typesTesting Matrix
Local verification completed:
npm test -- src/services/qwenSessionUpdateHandler.test.ts src/services/qwenAgentManager.test.tsnpm run check-typesnpx eslint src/services/qwenAgentManager.ts src/services/qwenAgentManager.test.tsLinked issues / bugs
Resolves #2515