-
Notifications
You must be signed in to change notification settings - Fork 43
🤖 feat: warn when switching to model that can't fit current context #1667
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
base: main
Are you sure you want to change the base?
Conversation
Add a soft warning banner when users switch from a high-context model (e.g., Sonnet with 1M) to a lower-context model (e.g., GPT-4o 128K) while current context exceeds 90% of the target model's limit. Features: - Warning banner appears above chat input on model switch - One-click "Compact with <model>" action using preferred/previous model - Dismissible (session-only, re-shows on next model switch) - Recomputes when 1M toggle changes (both directions) - Only one compaction warning shows at a time (context-switch takes priority) Implementation: - New useContextSwitchWarning hook encapsulates all warning logic - checkContextSwitch utility determines if warning is needed - ContextSwitchWarning component renders the banner - Storybook story demonstrates the feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70d776494f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
- Move onModelChange call before early returns so warning works even offline or with custom agents active - Track previous pending model via ref instead of using last assistant message's model, so compaction fallback works even when user switches without sending a message first
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0928d0e264
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
- Extract shared getEffectiveContextLimit helper for 1M toggle logic - Fix ContextSwitchWarning story to use data-tutorial selector (avoids 'multiple elements' error) - Fix handleCompact to pass model at top-level of executeCompaction (prevents global preference override)
|
@codex review |
d7c727e to
cdc6fbb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7c727ebd8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
e12a4e8 to
4b56412
Compare
|
@codex review |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
4b56412 to
0417ca9
Compare
WorkspaceModeAISync can update pendingModel via localStorage when mode/agent changes. Add effect to detect these external changes and recompute warning.
0417ca9 to
3b88432
Compare
Initialize prevPendingModelRef to null so the effect triggers on first render, detecting model 'change' from null to current model and showing the warning when context exceeds limit.
When the basic compaction model resolution (preferred → previous) fails, fall back to searching all known models for one with larger context that the user can access (has provider credentials or gateway routing). Also changed warning text from 'is near' to 'may exceed' since the warning can trigger when context actually exceeds the target limit.
Summary
Add a soft warning banner when users switch from a high-context model (e.g., Sonnet with 1M) to a lower-context model (e.g., GPT-4o 128K) while current context exceeds 90% of the target model's limit.
Features
Implementation
useContextSwitchWarninghook encapsulates all warning logiccheckContextSwitchutility determines if warning is neededgetHigherContextCompactionSuggestionfinds usable models with larger context when basic resolution failsContextSwitchWarningcomponent renders the bannerLimitations
The warning uses token counts from the previous model's tokenizer as an approximation. Different models have different tokenizers, so the actual token count for the target model may vary. We can't compute the exact count without making a request to the target model's tokenizer. The 90% threshold provides some buffer for this variance.
Generated with
mux• Model:anthropic:claude-opus-4-5• Thinking:high• Cost:$45.19