Skip to content

fix(usage): use shared resolveUsedFraction in TUI path, fixing missing remainingFraction fallback#3317

Open
oldschoola wants to merge 1 commit into
can1357:mainfrom
oldschoola:fix/usage-tui-missing-remainingFraction-fallback
Open

fix(usage): use shared resolveUsedFraction in TUI path, fixing missing remainingFraction fallback#3317
oldschoola wants to merge 1 commit into
can1357:mainfrom
oldschoola:fix/usage-tui-missing-remainingFraction-fallback

Conversation

@oldschoola

Copy link
Copy Markdown
Contributor

Problem

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 level.

The CLI path (usage-cli.ts) already used the shared function and handled these limits correctly.

Fix

Replaced the local resolveFraction with the shared resolveUsedFraction from @oh-my-pi/pi-ai. This:

  • Fixes the missing remainingFraction fallback in the TUI path
  • Eliminates the code duplication (4 callsites updated)
  • Ensures the TUI and CLI paths resolve fractions identically

Tests

  • bun check passes (all 16 packages)
  • All usage rendering tests pass (18/18)

…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.
@github-actions github-actions Bot added the vouched Passed the vouch gate label Jun 23, 2026
@roboomp roboomp added fix review:p0 triaged tui Terminal UI rendering and display labels Jun 23, 2026

@roboomp roboomp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

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

Labels

fix review:p0 triaged tui Terminal UI rendering and display vouched Passed the vouch gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants