Skip to content

Conversation

@ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Jan 15, 2026

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

  • Warning banner appears above chat input on model switch
  • One-click "Compact with <model>" action using preferred/previous model
  • Falls back to smarter model search when preferred/previous don't fit (searches all known models for one with larger context the user can access)
  • 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
  • getHigherContextCompactionSuggestion finds usable models with larger context when basic resolution fails
  • ContextSwitchWarning component renders the banner
  • Storybook story demonstrates the feature

Limitations

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

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
@github-actions github-actions bot added the enhancement New feature or functionality label Jan 15, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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
@ethanndickson
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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)
@ethanndickson
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@ethanndickson ethanndickson force-pushed the context-model-s5f2 branch 2 times, most recently from e12a4e8 to 4b56412 Compare January 15, 2026 05:12
@ethanndickson
Copy link
Member Author

@codex review

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

WorkspaceModeAISync can update pendingModel via localStorage when mode/agent
changes. Add effect to detect these external changes and recompute warning.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant