Skip to content

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions