Skip to content

fix(tui): use current model for context-limit display after switch#35542

Open
chethanuk wants to merge 1 commit into
anomalyco:devfrom
chethanuk:fix/issue-35072-context-limit-current-model
Open

fix(tui): use current model for context-limit display after switch#35542
chethanuk wants to merge 1 commit into
anomalyco:devfrom
chethanuk:fix/issue-35072-context-limit-current-model

Conversation

@chethanuk

Copy link
Copy Markdown

Issue for this PR

Addresses upstream #35072. Opened against my own fork first as a staging/review step — not raised upstream yet.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The context-limit percentage derived its denominator from the last assistant message's model. After a mid-session model switch it kept showing the previous model's limit until a new assistant message arrived — e.g. switching from a 128k model to a 32k model still displayed the 128k-based percentage.

The fix uses the currently-selected model (local.model.current()) as the denominator, falling back to the last assistant message's model when nothing is selected yet:

  • packages/tui/src/component/prompt/index.tsx — composer footer usage memo.
  • packages/tui/src/feature-plugins/sidebar/context.tsx — the sidebar meter named in the issue. The sidebar can display a subagent session, where the global model picker is unrelated to the subagent's own model, so it uses current() only for top-level sessions (via a session()?.parentID guard) and otherwise keeps the session's own last-message model.

Token count still comes from the last message (real occupancy); only the limit denominator changed. subagent-footer.tsx is intentionally left unchanged — a completed subagent's model is fixed, so its last-message model is already the correct denominator there.

How did you verify your code works?

  • bun run typecheck (tsgo) in packages/tui passes clean.
  • Traced the switch flow: local.model.current() resolves to the just-selected model, so the denominator updates on the next render instead of waiting for an assistant reply. The ?? last-message fallback preserves the pre-existing behavior when no model is selected yet, and both call sites read current() inside a createMemo, so reactive tracking is preserved.

Screenshots / recordings

TUI-only change; no screenshot.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

POTENTIAL DUPLICATE FOUND:

Why it's related: PR #35287 appears to address the same issue (issue #35072) with nearly identical scope: fixing the context-limit display in the TUI sidebar to use the current model after a model switch. The title is extremely similar to PR #35542, and both target the same files and fix the same root cause.

Please check PR #35287 to determine if it's already merged or if PR #35542 is a duplicate submission.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant