Skip to content

Mirror: Profile condense override with model-aware token caps (#5845)#43

Closed
jeremylongshore wants to merge 2 commits intomainfrom
mirror/PR-5845
Closed

Mirror: Profile condense override with model-aware token caps (#5845)#43
jeremylongshore wants to merge 2 commits intomainfrom
mirror/PR-5845

Conversation

@jeremylongshore
Copy link
Copy Markdown
Owner

Mirror of Kilo-Org#5845

Field Value
Upstream PR #5845
Author @Neonsy
Category feature
Tier 6
Size 1628 lines, 38 files

This PR mirrors the upstream change for multi-AI review analysis.

Bot Review Tracker

  • CodeRabbit
  • Gemini Code Assist
  • Greptile
  • CodeQL
  • Qodo PR-Agent

Links

@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 15, 2026

Warning

Rate limit exceeded

@jeremylongshore has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mirror/PR-5845

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qodo-code-review
Copy link
Copy Markdown

ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

Review Summary by Qodo

Redesign context condensing thresholds with model-aware profile overrides

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Redesigned context condensing thresholds with model-aware token caps
  - Adds profile-specific override system supporting percent or token modes
  - Implements hard limit based on model's context window and reserved tokens
  - Auto-clamps token overrides when model capacity reduces
• Refactored trigger resolution logic into reusable resolveCondenseTrigger function
  - Centralizes threshold calculation for both willManageContext and manageContext
  - Supports three modes: global percent, profile percent, profile tokens
• Updated UI to show current profile override controls with effective budget display
  - Removed legacy profile selector from condensing threshold section
  - Added mode toggle, percent slider, and token input with validation
• Added comprehensive test coverage for profile override behavior
  - Tests token threshold triggering, percent mode conversion, hard overflow handling
  - Tests UI state management, clamping notices, and independent global slider updates
Diagram
flowchart LR
  A["Global Percent<br/>Setting"] --> B["resolveCondenseTrigger"]
  C["Profile Override<br/>Config"] --> B
  D["Model Context<br/>Window"] --> B
  E["Reserved<br/>Tokens"] --> B
  B --> F["Trigger Resolution<br/>Mode + Threshold"]
  F --> G["willManageContext<br/>Decision"]
  F --> H["manageContext<br/>Action"]
  G --> I["Condense or<br/>Truncate"]
  H --> I
Loading

Grey Divider

File Changes

1. src/core/context-management/index.ts ✨ Enhancement +143/-45

Add profile override resolution and refactor trigger logic

src/core/context-management/index.ts


2. src/core/context-management/__tests__/context-management.spec.ts 🧪 Tests +124/-0

Add profile condense override test suite

src/core/context-management/tests/context-management.spec.ts


3. src/core/task/Task.ts ✨ Enhancement +12/-0

Pass profile overrides to context management functions

src/core/task/Task.ts


View more (35)
4. src/core/webview/ClineProvider.ts ✨ Enhancement +9/-0

Expose profile overrides in state and settings

src/core/webview/ClineProvider.ts


5. src/core/webview/__tests__/ClineProvider.spec.ts 🧪 Tests +29/-0

Test profile overrides state handling

src/core/webview/tests/ClineProvider.spec.ts


6. packages/types/src/vscode-extension-host.ts ✨ Enhancement +9/-0

Add profile override type to extension state

packages/types/src/vscode-extension-host.ts


7. packages/types/src/global-settings.ts ✨ Enhancement +14/-0

Define profile override schema with validation

packages/types/src/global-settings.ts


8. webview-ui/src/components/settings/ContextManagementSettings.tsx ✨ Enhancement +180/-80

Redesign UI with profile override controls

webview-ui/src/components/settings/ContextManagementSettings.tsx


9. webview-ui/src/components/settings/__tests__/ContextManagementSettings.spec.tsx 🧪 Tests +212/-463

Rewrite tests for new override UI behavior

webview-ui/src/components/settings/tests/ContextManagementSettings.spec.tsx


10. webview-ui/src/components/settings/SettingsView.tsx ✨ Enhancement +46/-4

Calculate effective budget and pass to settings component

webview-ui/src/components/settings/SettingsView.tsx


11. webview-ui/src/context/ExtensionStateContext.tsx ✨ Enhancement +17/-0

Add profile override state management

webview-ui/src/context/ExtensionStateContext.tsx


12. webview-ui/src/context/__tests__/ExtensionStateContext.spec.tsx 🧪 Tests +1/-0

Add profile override to test state

webview-ui/src/context/tests/ExtensionStateContext.spec.tsx


13. webview-ui/src/components/settings/__tests__/SettingsView.unsaved-changes.spec.tsx 🧪 Tests +1/-0

Add profile override to test fixtures

webview-ui/src/components/settings/tests/SettingsView.unsaved-changes.spec.tsx


14. webview-ui/src/components/settings/__tests__/SettingsView.change-detection.spec.tsx 🧪 Tests +1/-0

Add profile override to test fixtures

webview-ui/src/components/settings/tests/SettingsView.change-detection.spec.tsx


15. webview-ui/src/i18n/locales/en/settings.json 📝 Documentation +11/-2

Add English translations for override UI

webview-ui/src/i18n/locales/en/settings.json


16. webview-ui/src/i18n/locales/de/settings.json 📝 Documentation +10/-0

Add German translations for override UI

webview-ui/src/i18n/locales/de/settings.json


17. webview-ui/src/i18n/locales/es/settings.json 📝 Documentation +10/-0

Add Spanish translations for override UI

webview-ui/src/i18n/locales/es/settings.json


18. webview-ui/src/i18n/locales/fr/settings.json 📝 Documentation +10/-0

Add French translations for override UI

webview-ui/src/i18n/locales/fr/settings.json


19. webview-ui/src/i18n/locales/it/settings.json 📝 Documentation +10/-0

Add Italian translations for override UI

webview-ui/src/i18n/locales/it/settings.json


20. webview-ui/src/i18n/locales/ja/settings.json 📝 Documentation +10/-0

Add Japanese translations for override UI

webview-ui/src/i18n/locales/ja/settings.json


21. webview-ui/src/i18n/locales/pt-BR/settings.json 📝 Documentation +10/-0

Add Portuguese translations for override UI

webview-ui/src/i18n/locales/pt-BR/settings.json


22. webview-ui/src/i18n/locales/zh-CN/settings.json 📝 Documentation +10/-0

Add Simplified Chinese translations for override UI

webview-ui/src/i18n/locales/zh-CN/settings.json


23. .changeset/bright-taxis-share.md Additional files +5/-0

...

.changeset/bright-taxis-share.md


24. webview-ui/src/i18n/locales/ar/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/ar/settings.json


25. webview-ui/src/i18n/locales/ca/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/ca/settings.json


26. webview-ui/src/i18n/locales/cs/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/cs/settings.json


27. webview-ui/src/i18n/locales/hi/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/hi/settings.json


28. webview-ui/src/i18n/locales/id/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/id/settings.json


29. webview-ui/src/i18n/locales/ko/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/ko/settings.json


30. webview-ui/src/i18n/locales/nl/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/nl/settings.json


31. webview-ui/src/i18n/locales/pl/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/pl/settings.json


32. webview-ui/src/i18n/locales/ru/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/ru/settings.json


33. webview-ui/src/i18n/locales/sk/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/sk/settings.json


34. webview-ui/src/i18n/locales/th/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/th/settings.json


35. webview-ui/src/i18n/locales/tr/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/tr/settings.json


36. webview-ui/src/i18n/locales/uk/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/uk/settings.json


37. webview-ui/src/i18n/locales/vi/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/vi/settings.json


38. webview-ui/src/i18n/locales/zh-TW/settings.json Additional files +10/-0

...

webview-ui/src/i18n/locales/zh-TW/settings.json


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider


Action required

1. react-hooks lint disabled 📘 Rule violation ⛯ Reliability
Description
A new eslint-disable-line react-hooks/exhaustive-deps suppression was added, weakening lint
enforcement and potentially hiding real hook dependency bugs. This violates the requirement to not
disable lint rules.
Code

webview-ui/src/components/settings/ContextManagementSettings.tsx[156]

+	}, [currentProfileId, hardLimitTokens, profileCondenseOverrides, t]) // eslint-disable-line react-hooks/exhaustive-deps
Evidence
PR Compliance ID 11 prohibits introducing new lint suppressions. The added `eslint-disable-line
react-hooks/exhaustive-deps` comment is a new suppression in this PR.

AGENTS.md
webview-ui/src/components/settings/ContextManagementSettings.tsx[156-156]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new lint suppression (`// eslint-disable-line react-hooks/exhaustive-deps`) was introduced. This violates the compliance rule forbidding disabling lint rules and can hide real React hook dependency issues.

## Issue Context
The effect should either have a correct dependency list, or be refactored (e.g., by memoizing callbacks/values or restructuring logic) so it no longer requires suppressing `react-hooks/exhaustive-deps`.

## Fix Focus Areas
- webview-ui/src/components/settings/ContextManagementSettings.tsx[141-156]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Token override clobbered 🐞 Bug ✓ Correctness
Description
If a user has an enabled per-profile token-mode override, the Settings UI can clamp it down to 1
token when model metadata is temporarily unavailable (effective budget computed as 0) and persist
that reduced value. When model info later loads, the original override value cannot be recovered
automatically, causing silent configuration loss.
Code

webview-ui/src/components/settings/ContextManagementSettings.tsx[R141-156]

+	React.useEffect(() => {
+		const existingOverride = profileCondenseOverrides[currentProfileId]
+		if (!existingOverride || !existingOverride.enabled || existingOverride.mode !== "tokens") {
+			return
		}
-	}
+
+		const clampedTokens = clampNumber(Math.floor(existingOverride.tokens), 1, hardLimitTokens)
+		if (clampedTokens !== existingOverride.tokens) {
+			updateCurrentProfileOverride({ tokens: clampedTokens })
+			setTokenClampNotice(
+				t("settings:contextManagement.condensingThreshold.profileTokenClamped", {
+					tokens: clampedTokens,
+				}),
+			)
+		}
+	}, [currentProfileId, hardLimitTokens, profileCondenseOverrides, t]) // eslint-disable-line react-hooks/exhaustive-deps
Evidence
SettingsView computes a 0 effective budget whenever the selected model info is unavailable, because
it falls back to contextWindow=0. ContextManagementSettings then derives hardLimitTokens as at least
1 and, for enabled token-mode overrides, clamps and persists the override via setCachedStateField;
since the clamp is one-way (min with hardLimitTokens), later increases in the hard limit do not
restore the prior value.

webview-ui/src/components/settings/SettingsView.tsx[276-305]
webview-ui/src/components/ui/hooks/useSelectedModel.ts[118-150]
webview-ui/src/components/settings/ContextManagementSettings.tsx[103-156]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
When `condenseModelInfo` is temporarily unavailable (common for dynamic providers while model lists load), the UI computes an effective budget of `0`, which becomes a `hardLimitTokens` of `1`. If the current profile has an enabled token-mode override, the `useEffect` clamp runs and **persists** the reduced value (often to 1), permanently overwriting the user&#x27;s saved threshold.

## Issue Context
- `useSelectedModel()` can return `info: undefined` while `isReady` is false.
- `SettingsView` uses `condenseModelInfo?.contextWindow ?? 0`, which yields a 0 budget when `info` is undefined.
- `ContextManagementSettings` clamps and persists token override values whenever `hardLimitTokens` changes.

## Fix Focus Areas
- webview-ui/src/components/settings/SettingsView.tsx[276-305]
- webview-ui/src/components/settings/ContextManagementSettings.tsx[103-156]
- webview-ui/src/components/ui/hooks/useSelectedModel.ts[118-150]

## Suggested approach
1. Treat the effective budget as **unknown** when `condenseModelInfo` is undefined (e.g., use `null` instead of `0`) and pass that through.
2. In `ContextManagementSettings`, **skip the clamping+persist effect** unless the budget is known and &gt; 0 (or unless `useSelectedModel().isLoading` is false).
3. Optionally disable token-mode inputs/select until the cap is known, or show a loading indicator.
4. Add a regression test that simulates `condenseEffectiveBudgetTokens` temporarily being 0/unknown and verifies the saved override is not overwritten.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

}),
)
}
}, [currentProfileId, hardLimitTokens, profileCondenseOverrides, t]) // eslint-disable-line react-hooks/exhaustive-deps
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. react-hooks lint disabled 📘 Rule violation ⛯ Reliability

A new eslint-disable-line react-hooks/exhaustive-deps suppression was added, weakening lint
enforcement and potentially hiding real hook dependency bugs. This violates the requirement to not
disable lint rules.
Agent Prompt
## Issue description
A new lint suppression (`// eslint-disable-line react-hooks/exhaustive-deps`) was introduced. This violates the compliance rule forbidding disabling lint rules and can hide real React hook dependency issues.

## Issue Context
The effect should either have a correct dependency list, or be refactored (e.g., by memoizing callbacks/values or restructuring logic) so it no longer requires suppressing `react-hooks/exhaustive-deps`.

## Fix Focus Areas
- webview-ui/src/components/settings/ContextManagementSettings.tsx[141-156]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +141 to +156
React.useEffect(() => {
const existingOverride = profileCondenseOverrides[currentProfileId]
if (!existingOverride || !existingOverride.enabled || existingOverride.mode !== "tokens") {
return
}
}

const clampedTokens = clampNumber(Math.floor(existingOverride.tokens), 1, hardLimitTokens)
if (clampedTokens !== existingOverride.tokens) {
updateCurrentProfileOverride({ tokens: clampedTokens })
setTokenClampNotice(
t("settings:contextManagement.condensingThreshold.profileTokenClamped", {
tokens: clampedTokens,
}),
)
}
}, [currentProfileId, hardLimitTokens, profileCondenseOverrides, t]) // eslint-disable-line react-hooks/exhaustive-deps
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Token override clobbered 🐞 Bug ✓ Correctness

If a user has an enabled per-profile token-mode override, the Settings UI can clamp it down to 1
token when model metadata is temporarily unavailable (effective budget computed as 0) and persist
that reduced value. When model info later loads, the original override value cannot be recovered
automatically, causing silent configuration loss.
Agent Prompt
## Issue description
When `condenseModelInfo` is temporarily unavailable (common for dynamic providers while model lists load), the UI computes an effective budget of `0`, which becomes a `hardLimitTokens` of `1`. If the current profile has an enabled token-mode override, the `useEffect` clamp runs and **persists** the reduced value (often to 1), permanently overwriting the user's saved threshold.

## Issue Context
- `useSelectedModel()` can return `info: undefined` while `isReady` is false.
- `SettingsView` uses `condenseModelInfo?.contextWindow ?? 0`, which yields a 0 budget when `info` is undefined.
- `ContextManagementSettings` clamps and persists token override values whenever `hardLimitTokens` changes.

## Fix Focus Areas
- webview-ui/src/components/settings/SettingsView.tsx[276-305]
- webview-ui/src/components/settings/ContextManagementSettings.tsx[103-156]
- webview-ui/src/components/ui/hooks/useSelectedModel.ts[118-150]

## Suggested approach
1. Treat the effective budget as **unknown** when `condenseModelInfo` is undefined (e.g., use `null` instead of `0`) and pass that through.
2. In `ContextManagementSettings`, **skip the clamping+persist effect** unless the budget is known and > 0 (or unless `useSelectedModel().isLoading` is false).
3. Optionally disable token-mode inputs/select until the cap is known, or show a loading indicator.
4. Add a regression test that simulates `condenseEffectiveBudgetTokens` temporarily being 0/unknown and verifies the saved override is not overwritten.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@github-actions
Copy link
Copy Markdown

Failed to generate code suggestions for PR

@jeremylongshore
Copy link
Copy Markdown
Owner Author

@greptileai review

@jeremylongshore
Copy link
Copy Markdown
Owner Author

@greptileai

@jeremylongshore
Copy link
Copy Markdown
Owner Author

Merged into batch-6-combined-20-mirrors branch for combined testing. Bot reviews collected. Review artifacts preserved in .reviews/.

@jeremylongshore jeremylongshore deleted the mirror/PR-5845 branch February 16, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants