fix(usage): use shared resolveUsedFraction in TUI path, fixing missing remainingFraction fallback#3317
Conversation
…g remainingFraction fallback
The TUI usage renderer (command-controller.ts) had a local
resolveFraction() that was missing the inverted-remaining fallback
present in the shared resolveUsedFraction() from @oh-my-pi/pi-ai:
// Shared (usage.ts) — has this:
if (amount.remainingFraction !== undefined)
return Math.max(0, 1 - amount.remainingFraction);
// Local (command-controller.ts) — was MISSING this
This meant the TUI path failed to resolve a fraction for limits that
only populate remainingFraction (no usedFraction, used/limit, or
percent+used) — showing an empty bar instead of the correct fill.
The CLI path (usage-cli.ts) already used the shared function and
handled these limits correctly.
Replaced the local resolveFraction with the shared resolveUsedFraction
from @oh-my-pi/pi-ai, eliminating the duplication and fixing the bug.
roboomp
left a comment
There was a problem hiding this comment.
Thanks @oldschoola. lgtm.
Rank: P0. Tight root-cause fix: the local resolveFraction in command-controller.ts was missing the if (amount.remainingFraction !== undefined) return Math.max(0, 1 - amount.remainingFraction) branch that packages/ai/src/usage.ts:101 (resolveUsedFraction) already implements. Verified the two functions are otherwise byte-equivalent against origin/main, so swapping all four callsites onto the shared helper restores the inverted-remaining fallback (e.g. Antigravity/Gemini quotas that only populate remainingFraction) and removes the duplication. CHANGELOG entry under [Unreleased] > Fixed is in place.
No inline findings. The shared helper has existing coverage via the providers in packages/ai/test/* that exercise remainingFraction-only limits; a TUI-side regression test would be nice-to-have but isn't required given the change is a direct delegation.
Problem
The TUI usage renderer (
command-controller.ts) had a localresolveFraction()that was missing the inverted-remaining fallback present in the sharedresolveUsedFraction()from@oh-my-pi/pi-ai:This meant the TUI path failed to resolve a fraction for limits that only populate
remainingFraction(nousedFraction,used/limit, orpercent+used) — showing an empty bar (·) instead of the correct fill level.The CLI path (
usage-cli.ts) already used the shared function and handled these limits correctly.Fix
Replaced the local
resolveFractionwith the sharedresolveUsedFractionfrom@oh-my-pi/pi-ai. This:remainingFractionfallback in the TUI pathTests
bun checkpasses (all 16 packages)