Skip to content

fix(tui): use effective model window in context inspector#2521

Draft
cyq1017 wants to merge 1 commit into
Hmbown:mainfrom
cyq1017:codex/2497-context-window
Draft

fix(tui): use effective model window in context inspector#2521
cyq1017 wants to merge 1 commit into
Hmbown:mainfrom
cyq1017:codex/2497-context-window

Conversation

@cyq1017
Copy link
Copy Markdown
Contributor

@cyq1017 cyq1017 commented Jun 1, 2026

Problem

/context estimates its max context window from the literal UI model string. In auto mode that string is auto, so the inspector falls back to the legacy DeepSeek 128k window even after routing has resolved the turn to a concrete V4 model.

Change

Use the app effective model for the context-window lookup while keeping the displayed model label unchanged.

Refs #2487. This only addresses the /context window display slice from the stalled-turn investigation; it does not claim to fix stalled turn dispatch/liveness.

Verification

  • cargo test -p codewhale-tui inspector_uses_effective_auto_model_context_window --all-features --locked -- --nocapture
  • cargo test -p codewhale-tui context_inspector --all-features --locked -- --nocapture
  • cargo fmt --all -- --check
  • cargo check -p codewhale-tui --all-features --locked
  • cargo clippy -p codewhale-tui --all-features --locked -- -D warnings
  • git diff --check origin/main..HEAD

Greptile Summary

This PR fixes the /context inspector displaying an incorrect (128K) context window when the app is in auto model mode, by switching the window-size lookup from app.model (the literal "auto" string) to app.effective_model_for_budget() (which resolves to the last concrete model the router used). The display label is unchanged.

  • The one-line change in context_usage is correct: effective_model_for_budget() already handles the None/"auto" fallback case by returning DEFAULT_TEXT_MODEL (deepseek-v4-pro).
  • A new focused test verifies both the label invariant (Model: auto) and the resolved window size (/1000000 tokens) after a concrete V4 routing.

Confidence Score: 4/5

Safe to merge; the change is minimal and well-tested, and the only note is a pre-existing inconsistency in sibling commands that was intentionally left out of scope.

The one-line fix correctly delegates to effective_model_for_budget(), the new test covers both the display-label invariant and the resolved window size, and the fallback path (DEFAULT_TEXT_MODELdeepseek-v4-pro) is coherent. The only observation is that commands/status.rs and sidebar.rs carry the same old pattern, meaning those surfaces will still display 128K for auto mode — but the PR explicitly scopes itself to the /context inspector.

commands/status.rs and sidebar.rs have the same &app.model pattern and would benefit from a follow-up pass.

Important Files Changed

Filename Overview
crates/tui/src/tui/context_inspector.rs Core fix: context_usage now calls effective_model_for_budget() instead of reading app.model directly, correctly resolving auto-mode to the last dispatched concrete model. New test covers the happy path. Two sibling usages of &app.model in commands/status.rs and sidebar.rs remain unfixed (pre-existing, out of scope per PR description).

Sequence Diagram

sequenceDiagram
    participant User
    participant TUI as TUI /context
    participant Inspector as context_inspector
    participant App
    participant Models as models::context_window_for_model

    User->>TUI: types /context
    TUI->>Inspector: "build_context_inspector_text(&app)"
    Inspector->>App: app.model (display label only)
    Note over Inspector,App: "auto" string used for display
    Inspector->>App: app.effective_model_for_budget()
    App-->>Inspector: "deepseek-v4-pro" (resolved from last_effective_model)
    Inspector->>Models: context_window_for_model("deepseek-v4-pro")
    Models-->>Inspector: Some(1_000_000)
    Inspector-->>TUI: "Model: auto ... ~X/1000000 tokens"
    TUI-->>User: shows correct 1M window
Loading

Reviews (1): Last reviewed commit: "fix(tui): use effective model window in ..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the context_usage function in context_inspector.rs to determine the context window using the effective model for budget (app.effective_model_for_budget()) instead of the raw &app.model. It also adds a unit test to verify that the context inspector correctly resolves and displays the context window limit when the model is set to "auto". There are no review comments, and I have no feedback to provide.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant