Skip to content

fix(pi): use per-model context window for status bar display#1033

Open
KorenKrita wants to merge 1 commit into
tiann:mainfrom
KorenKrita:fix/pi-context-window-display
Open

fix(pi): use per-model context window for status bar display#1033
KorenKrita wants to merge 1 commit into
tiann:mainfrom
KorenKrita:fix/pi-context-window-display

Conversation

@KorenKrita

Copy link
Copy Markdown
Contributor

Problem

The Pi context bar always displays usage against a hardcoded 190k token budget (DEFAULT_PI_CONTEXT_WINDOW_TOKENS - CONTEXT_HEADROOM_TOKENS = 200000 - 10000), regardless of the actual model's context window. For example, a model with 128k context window would show incorrect percentages.

Pi reports each model's contextWindow via get_available_models, and this data is already stored in piAvailableModels metadata — but it was never used for the status bar.

Root Cause

Pi's turn_end usage events don't include context_window (unlike Claude/Codex which report it via ACP usage updates). So reduced.latestUsage?.contextWindow is always null for Pi sessions, causing the fallback to the hardcoded default.

Changes

In SessionChat.tsx:

  • Compute piContextWindow by looking up the current model's contextWindow from piAvailableModels
  • Pass it as a fallback: contextWindow={reduced.latestUsage?.contextWindow ?? piContextWindow}
  • Extract the piModels variable to avoid duplicate computation

Behavior

  • Pi sessions now show context usage against the correct model-specific context window
  • Falls back to the 200k default only when model metadata is unavailable
  • No changes to Claude, Codex, or other session types

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings

  • [Minor] Pi context-window lookup ignores provider identity — session.model stores only the legacy model id, and Pi explicitly persists metadata.piSelectedModel so the web can disambiguate providers that expose the same modelId (shared/src/schemas.ts:73). The new lookup uses the first matching modelId, so the status bar can display the wrong context window for duplicate Pi models. Evidence: web/src/components/SessionChat.tsx:654.
    Suggested fix:
    const model = piSelectedModel
        ? piModels.find((m) => m.provider === piSelectedModel.provider && m.modelId === piSelectedModel.modelId)
        : piModels.find((m) => m.modelId === props.session.model)
    return model?.contextWindow ?? undefined

Summary

  • Review mode: initial
  • One issue found in the Pi status-bar fallback: it should use the provider-qualified selected model before falling back to the bare legacy model id.

Testing

  • Not run (automation)

HAPI Bot

Comment thread web/src/components/SessionChat.tsx Outdated
@KorenKrita KorenKrita force-pushed the fix/pi-context-window-display branch from b5d5652 to 1bf81b2 Compare July 13, 2026 16:19
Use provider-qualified model lookup (provider + modelId) to resolve the
correct context window for the Pi status bar, falling back to legacy
modelId when selected-model metadata is absent. This prevents showing
the wrong context window when two providers share the same modelId.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings
No issues found.

Summary
Review mode: follow-up after new commits
No diff-introduced correctness, security, data-loss, performance, or maintainability issues found in the current changes. Residual risk: only the touched web unit test was attempted locally, and it could not run because bun is unavailable in this runner shell.

Testing
Not run (automation: bun not found)

HAPI Bot

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