Skip to content

fix(usage): drop the 5-hour forecast once the block is at its limit - #766

Merged
sirmalloc merged 2 commits into
sirmalloc:mainfrom
eric-engberg:fix/block-forecast-at-limit
Oct 30, 2026
Merged

sirmalloc merged 2 commits into
sirmalloc:mainfrom
eric-engberg:fix/block-forecast-at-limit

Conversation

@eric-engberg

Copy link
Copy Markdown
Contributor

What

Block Forecast and Block Limit Timer are now gone by the time Block Reset Timer's countdown takes Block Usage's place at the 5-hour limit. Before, →100% Limit in: 1m could stay next to the countdown until the reset.

Why

Seen on my own line when the 5-hour block hit its limit, with Block Usage (at-limit, label 5h ), Block Forecast, Block Limit Timer and Block Reset Timer (under-limit, label 5h reset ):

Opus 5.5 (xhigh) [██████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 175k/1.0M (17%) →100% Limit in: 1m 5h reset 1hr 56m Weekly: 28%

The two hide states decide the limit from the usage API's percent, which every session shares. The forecast went by this session's percent, which comes from its last response and still said 99% while the API said 100%. A session blocked at the limit gets no new responses, so that number stays under 100 until the reset. The forecast kept projecting →100%, and with no new usage the 30-minute pace flattened, so Limit in grew: sixteen minutes later the line read →100% Limit in: 2m.

How

  • computeSessionForecastIfNeeded() returns no forecast once isAtSessionLimit() (from feat(usage): Block Usage can hide at 100%, swapping with Block Reset Timer #747) says the block is at its limit, so both forecast widgets render nothing from the render where the swap happens. If this session's percent reaches 100 first, they're already gone, as before. It records the session's reading first, so the history is kept as before.
  • That check uses the API's percent only when it was fetched for one of the two hide states. Otherwise it falls back to the session's percent, where the forecast already stopped at 100%, so lines without those states render exactly as before.
  • No new fetches: the API's percent is already fetched for those states.
  • docs/USAGE.md says both forecast widgets go away at 100%, by whichever percent gets there first.

Demo

Block Usage (at-limit), Block Forecast, Block Limit Timer and Block Reset Timer (under-limit, label 5h reset ), piped from a seeded reading history and a fresh usage API cache (fake login and data, reset 1hr 55m away), in three states: the session and the API both at 99%; the API at 100% while the session still says 99%; both at 100%. Before is without the fix.

Powerline

Before:

Before: at the API's limit the forecast stays next to the countdown, Powerline

After:

After: at the API's limit only the countdown shows, Powerline

Plain

Before:

Before: at the API's limit the forecast stays next to the countdown, plain

After:

After: at the API's limit only the countdown shows, plain

Testing

  • Two new cases in session-forecast-prefetch.test.ts: with the API at 100% and the session at 99% there's no forecast and the reading is still recorded (without the fix it returns limitInMs: 75000, shown as Limit in: 1m); with the API at 99.7% the forecast comes from the session's percent as before. The file passes 13/13 under Bun and under Node (Vitest).
  • On current main: bun run lint is clean; bun test: 3691 pass, 0 fail (Bun 1.4.2).
  • The built dist under Bun 1.4.2 and Node 26.10.0, plain and Powerline, piped from a scratch HOME with a seeded API cache (nothing fetched): before, the at-limit state rendered →100.0% | Limit in: 1m | 5h reset 1hr 55m; after, 5h reset 1hr 55m. The 99%/99% and 100%/100% states render the same before and after.
  • runtime-check.sh: both runtimes agree with main in plain and Powerline, and the TUI opens and exits under both.

eric-engberg and others added 2 commits October 30, 2026 11:45
Block Forecast and Block Limit Timer went by this session's percent, which
comes from its last response. A session blocked at the 5-hour limit gets no
new responses, so it can say 99% while the usage API says 100%, and the
forecast kept `→100% Limit in: 1m` next to Block Reset Timer's countdown
until the reset.

computeSessionForecastIfNeeded() now returns no forecast once
isAtSessionLimit() says the block is at its limit, after recording the
session's reading. That check reads the API's percent only when it was
fetched for Block Usage's or Block Reset Timer's hide states, so other lines
render as before and nothing new is fetched.
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.

2 participants