fix: warn before context-heavy model switches - #112
Open
danielkov wants to merge 2 commits into
Open
Conversation
danielkov
commented
Sep 5, 2026
danielkov
commented
Sep 5, 2026
danielkov
commented
Sep 5, 2026
danielkov
commented
Sep 5, 2026
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
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.