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

@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".

@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".

@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.

@ethanndickson ethanndickson force-pushed the context-model-s5f2 branch 2 times, most recently from 0417ca9 to 3b88432 Compare January 15, 2026 08:07
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
- 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
- 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)
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.
@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: d769b9655f

ℹ️ 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".

- Replace raw emoji icon with AlertTriangle SVG (AGENTS.md compliance)
- Validate higher-context compaction suggestions against current tokens
  using getEffectiveContextLimit before offering 'Compact with ...' action
@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: 6990a4a5fc

ℹ️ 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".

Gate the 'tokens became available' re-check to only fire on 0 -> >0
transition. This prevents the warning from immediately reappearing
after user dismissal while still allowing it to trigger on initial
usage data load.
@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: bead5a6705

ℹ️ 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".

- Add shared parseModelString() and isModelAllowedByPolicy() to policyUi.ts
- Remove duplicate helpers from useModelsFromSettings and ModelsSection
- Thread policy into getExplicitCompactionSuggestion and getHigherContextCompactionSuggestion
- Add ContextSwitchOptions to checkContextSwitch for provider config + policy validation
- Update useContextSwitchWarning and useCompactAndRetry to pass effective policy

This prevents the context switch warning from suggesting compaction models that
are blocked by policy or have unconfigured providers. Previously, the warning
derived compaction models from persisted preference or previous assistant model,
which could become invalid after provider keys are removed or policy changes.
@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: 43c447a66f

ℹ️ 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
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: 138f0b5df6

ℹ️ 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
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: 0d7c2ec526

ℹ️ 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
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: 9831364688

ℹ️ 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
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: 0a7b30af28

ℹ️ 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 added this pull request to the merge queue Feb 2, 2026
Merged via the queue into main with commit a73bcfa Feb 2, 2026
23 checks passed
@ethanndickson ethanndickson deleted the context-model-s5f2 branch February 2, 2026 02:58
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