-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: prevent context condensing on settings save when provider/model unchanged #9108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…unchanged Fixes #4430 The issue was that saving settings during an active task would unconditionally rebuild the API handler in both upsertProviderProfile and activateProviderProfile, even when the provider and model hadn't changed. This caused transient changes to model metadata (contextWindow, maxTokens) which triggered the allowedTokens fast-path in context condensing logic, causing immediate condensing regardless of the configured threshold. Changes: - Added guard in upsertProviderProfile to only rebuild API handler when provider OR model changes - Added guard in activateProviderProfile to only rebuild API handler when provider OR model changes - Added comprehensive test suite to verify handler is not rebuilt unnecessarily This prevents the "condense on save" behavior reported in issue #4430 while still rebuilding the handler when genuinely needed (provider or model change).
Review complete. Code duplication successfully resolved with clean DRY refactoring. No new issues found.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
src/core/webview/__tests__/ClineProvider.apiHandlerRebuild.spec.ts
Outdated
Show resolved
Hide resolved
- Capture original API reference before upsertProviderProfile call - Assert against original reference instead of self-comparison - Addresses ellipsis-dev review comment
Review Response@ellipsis-dev comment: FIXED - Updated test to capture original API reference and assert against it instead of self-comparison. @roomote comment: INCORRECT - The current logic handles all cases correctly: Why roomote's suggestion would break the fix:Current logic (
Roomote's suggested logic (
The undefined transitions ARE valid model changes:
The current implementation is correct. All tests pass including the new comprehensive test suite. |
Analysis Complete: PR Author Is CorrectAfter thorough analysis of the guard logic and the The Guard Logic Is CorrectThe current implementation: if (currentProvider !== newProvider || currentModelId !== newModelId) {
task.api = buildApiHandler(providerSettings)
}Why
|
Problem
Fixes #4430
When clicking Save in Settings during an active task, context condensing would trigger immediately even when the configured threshold was 100%. This happened because the extension unconditionally rebuilt the running task's API handler, causing transient changes to model metadata (contextWindow, maxTokens) which triggered the
allowedTokensfast-path in context condensing logic.Root Cause
The issue was NOT about UI component unmounting or model info flicker (PR #9101). The actual problem:
upsertProviderProfileoractivateProviderProfiletask.api = buildApiHandler(providerSettings)contextPercent >= threshold(user's 100% setting)prevContextTokens > allowedTokens(fast-path based on contextWindow/maxTokens)Solution
Added guards in both methods to only rebuild the API handler when provider OR model ID actually changes:
Changes
getModelIdimport to ClineProviderupsertProviderProfileto prevent unnecessary handler rebuildsactivateProviderProfileto prevent unnecessary handler rebuildsTesting
Impact
This targeted fix prevents the "condense on save" behavior while preserving handler rebuilds when genuinely needed (provider or model change).
Important
Fixes unnecessary context condensing by ensuring API handler rebuilds only on provider/model changes in
ClineProvider.ClineProvider.updateTaskApiHandlerIfNeeded()inClineProviderto check for provider/model changes before rebuilding.upsertProviderProfileandactivateProviderProfileto use the new guard.ClineProvider.apiHandlerRebuild.spec.tswith 9 tests to verify handler rebuild logic.This description was created by
for 5a2be5b. You can customize this summary. It will automatically update as commits are pushed.