Skip to content

fix: warn before context-heavy model switches - #112

Open
danielkov wants to merge 2 commits into
mainfrom
fix/issue-18-context-switch
Open

fix: warn before context-heavy model switches#112
danielkov wants to merge 2 commits into
mainfrom
fix/issue-18-context-switch

Conversation

@danielkov

Copy link
Copy Markdown
Contributor

Summary

Warn before a model switch when the estimated current transcript occupies at least 80% of the target model's context window. The Kit TUI offers Continue anyway, Compact, and Cancel, with compaction using the original model before applying the requested selection.

Motivation

Addresses #18: switching to a smaller context window can make both the next request and subsequent compaction fail if the new model is selected first.

Impact

Cancel preserves the selection, transcript, and input draft. Compaction failure or cancellation keeps the original model selected; a replacement that already completed is retained. Unknown transcript usage or target context limits allow an explicitly documented unchecked switch rather than forcing compaction or guessing a limit.

External ACP clients receive an actionable confirmation-required error instead of a Kit dialog. Both ACP versions accept the same one-shot confirmation extension for continuing or compacting before switching.

Technical details

Provider catalogs retain reported context-window metadata in memory. The guard uses ceil(latest_transcript_tokens 脳 1.20) >= target_context_window 脳 0.80, not accumulated historical usage or double-counted cached tokens.

Actor-owned confirmations bind the original selection, target, transcript, and cancellation generation. The TUI handles requests asynchronously and correlates completions with session generation and operation ID. A unique manual-compaction marker, consumed only after successful transcript replacement, gates selection changes; uncorrelated runtime notifications cannot complete a pending switch.

kit-code-agent[bot]
kit-code-agent Bot previously approved these changes Sep 5, 2026

@kit-code-agent kit-code-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found. The changes look good to merge.

Comment thread src/protocols/acp/v2.rs Outdated
Comment thread src/tui/mod.rs Outdated
Comment thread src/tui/mod.rs Outdated
Comment thread src/tui/ui.rs Outdated

@kit-code-agent kit-code-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found. The changes look good to merge.

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.

1 participant