Skip to content

fix: context limit display uses stale model after model switch #35072

Closed as not planned

Description

@Ivaloz

Description

After switching models mid-session, the context limit percentage in the sidebar continues to display based on the previous model's context window, not the currently selected model.

Example

  1. Start session with model A (128k context)
  2. Use model A for several messages, context shows 50% used (64k/128k)
  3. Switch to model B (32k context)
  4. Context still shows 50% used, but should show 200% (64k/32k) or at least use model B's limit

Root Cause

In the sidebar context component, the context limit is calculated using the model from the last assistant message, not the currently selected model:

\\ ypescript
const model = props.api.state.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
\\

Proposed Fix

Use the currently selected model for context limit display when available:

\\ ypescript
const currentModel = local.model.current()
const model = currentModel
? props.api.state.provider.find((item) => item.id === currentModel.providerID)?.models[currentModel.modelID]
: props.api.state.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
\\

MiMo Code Reference

This fix has been implemented in MiMo Code PR #1522: XiaomiMiMo/MiMo-Code#1522

Environment

  • OpenCode version: 1.17.8
  • OS: Windows 11
  • Terminal: PowerShell

Activity

  1. tiffanychum commented on Jul 4, 2026

    @tiffanychum

    I'd like to work on this. Confirmed the root cause in packages/tui/src/feature-plugins/sidebar/context.tsx: the context percentage is computed from the model of the last assistant message (last.providerID/last.modelID), so after a mid-session model switch it keeps using the previous model's context window. Fix: prefer the currently selected model via useLocal().model.current() and fall back to the last message's model when none is selected. PR incoming.

  2. added a commit that references this issue on Jul 6, 2026
    9fd3a17
  3. github-actions commented on Sep 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions