codex - 💡(How to fix) Fix Warn before switching models in a long-running session [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#19877Fetched 2026-04-28 06:35:42
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×3unlabeled ×1

Error Message

  • Only warn after the session is meaningfully deep, not during the first few turns.
  • Do not warn for a no-op selection where the selected model is already active.
  • warn when current token usage exceeds a fixed threshold;
  • warn when context usage exceeds a percentage of the active model context window;
  • Do not warn on every model picker interaction.

Root Cause

OpenAI's public Codex agent-loop writeup describes prompt caching as sensitive to exact prompt-prefix reuse, and notes that changing the target model in the middle of a conversation can cause a cache miss because model-specific instructions can affect the prompt prefix:

https://openai.com/index/unrolling-the-codex-agent-loop/

This is an easy detail for users to miss. The current resume warning already acknowledges that a model mismatch can affect Codex performance. A similar, carefully scoped warning during in-session model changes would make the same tradeoff visible at the moment the user can still choose whether to continue.

Code Example

This session was recorded with model `{previous_model}` but is resuming with `{current_model}`. Consider switching back to `{previous_model}` as it may affect Codex performance.

---

Switch models in this long session?

Switching from `{current_model}` to `{new_model}` may reduce prompt-cache reuse and affect latency or cost for upcoming turns.

---

Switch model
Keep current model
Don't show again
RAW_BUFFERClick to expand / collapse

What variant of Codex are you using?

CLI / TUI

What feature would you like to see?

Show a lightweight warning or confirmation when a user switches models from /model after an active session has accumulated substantial context.

Codex already warns when resuming a recorded session with a different model:

This session was recorded with model `{previous_model}` but is resuming with `{current_model}`. Consider switching back to `{previous_model}` as it may affect Codex performance.

The same class of user surprise can happen inside a live session. A user may work for many turns with one model, switch to another model for a specific task, and not realize that this can change the performance characteristics of the rest of the session.

The warning should avoid implying that the new model is lower quality. The more precise concern is that switching models mid-session can affect prompt-cache continuity and model-specific context handling. In practice, that can show up as slower responses, higher cost, or weaker session continuity in a long-running thread.

One possible UX:

Switch models in this long session?

Switching from `{current_model}` to `{new_model}` may reduce prompt-cache reuse and affect latency or cost for upcoming turns.

Actions:

Switch model
Keep current model
Don't show again

Suggested behavior:

  • Only warn after the session is meaningfully deep, not during the first few turns.
  • Do not warn for a no-op selection where the selected model is already active.
  • Do not block startup-time model selection or explicit CLI flags.
  • Prefer one warning per session, or a persisted opt-out, to avoid warning fatigue.
  • Keep model switching available; this is only about making the tradeoff visible.

Potential threshold options:

  • warn when current token usage exceeds a fixed threshold;
  • warn when context usage exceeds a percentage of the active model context window;
  • fall back to a completed-turn count if token usage is unavailable.

I do not have a strong preference on the exact threshold. The important part is to avoid early-session noise while helping users avoid surprising behavior in deep sessions.

Why this matters

OpenAI's public Codex agent-loop writeup describes prompt caching as sensitive to exact prompt-prefix reuse, and notes that changing the target model in the middle of a conversation can cause a cache miss because model-specific instructions can affect the prompt prefix:

https://openai.com/index/unrolling-the-codex-agent-loop/

This is an easy detail for users to miss. The current resume warning already acknowledges that a model mismatch can affect Codex performance. A similar, carefully scoped warning during in-session model changes would make the same tradeoff visible at the moment the user can still choose whether to continue.

Possible implementation area

From a quick read of the current repo, the relevant areas appear to be:

  • resume warning: codex-rs/core/src/session/mod.rs
  • model-switch developer-message handling: codex-rs/core/src/context/model_switch_instructions.rs
  • TUI model picker and /model flow: codex-rs/tui/src/chatwidget.rs
  • likely TUI coverage area: codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs

This could be implemented entirely as a TUI warning before applying the existing model-selection action, without changing model-switch semantics.

Acceptance criteria

  • Switching models early in a session behaves as it does today.
  • Switching models deep in a session shows a concise warning before applying the change.
  • Confirming applies the same model switch behavior as today.
  • Canceling keeps the current model and reasoning effort unchanged.
  • The warning is not shown for no-op model selections.
  • The behavior has focused TUI test or snapshot coverage.
  • The copy describes prompt-cache/performance tradeoffs without claiming that model quality necessarily degrades.

Non-goals

  • Do not remove or discourage model switching.
  • Do not change model-selection semantics.
  • Do not warn on every model picker interaction.
  • Do not make claims about one model being categorically worse than another.

If the Codex team agrees this is the right UX, I would be happy to prepare a focused PR for the warning path.

extent analysis

TL;DR

Implement a warning mechanism in the TUI model picker to inform users of potential performance impacts when switching models mid-session.

Guidance

  • Identify a suitable threshold for determining when a session is "meaningfully deep" to trigger the warning, such as token usage or context window percentage.
  • Modify the chatwidget.rs file to display a concise warning before applying model changes, using the suggested UX as a starting point.
  • Update the model_switch_instructions.rs file to handle the new warning behavior without changing model-switch semantics.
  • Add focused TUI test coverage in popups_and_settings.rs to ensure the warning behaves as expected.

Example

No code snippet is provided as the implementation details are not specified, but the warning message could be similar to:

Switch models in this long session?

Switching from `{current_model}` to `{new_model}` may reduce prompt-cache reuse and affect latency or cost for upcoming turns.

Notes

The implementation should avoid implying that the new model is lower quality and focus on the potential performance impacts of switching models mid-session.

Recommendation

Apply a workaround by implementing the suggested warning mechanism in the TUI model picker to inform users of potential performance impacts when switching models mid-session. This approach addresses the user's concern without removing or discouraging model switching.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Warn before switching models in a long-running session [1 participants]