fix(pi): use per-model context window for status bar display#1033
Open
KorenKrita wants to merge 1 commit into
Open
fix(pi): use per-model context window for status bar display#1033KorenKrita wants to merge 1 commit into
KorenKrita wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Findings
- [Minor] Pi context-window lookup ignores provider identity —
session.modelstores only the legacy model id, and Pi explicitly persistsmetadata.piSelectedModelso the web can disambiguate providers that expose the samemodelId(shared/src/schemas.ts:73). The new lookup uses the first matchingmodelId, 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
b5d5652 to
1bf81b2
Compare
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.
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
contextWindowviaget_available_models, and this data is already stored inpiAvailableModelsmetadata — but it was never used for the status bar.Root Cause
Pi's
turn_endusage events don't includecontext_window(unlike Claude/Codex which report it via ACP usage updates). Soreduced.latestUsage?.contextWindowis alwaysnullfor Pi sessions, causing the fallback to the hardcoded default.Changes
In
SessionChat.tsx:piContextWindowby looking up the current model'scontextWindowfrompiAvailableModelscontextWindow={reduced.latestUsage?.contextWindow ?? piContextWindow}piModelsvariable to avoid duplicate computationBehavior