Skip to content

feat(menubar): cache-read usage and quota pace in the Capacity Dock - #1314

Merged
iamtoruk merged 6 commits into
mainfrom
fix/dock-pace-followups
Sep 12, 2026
Merged

iamtoruk merged 6 commits into
mainfrom
fix/dock-pace-followups

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Supersedes #1267 by @ozymandiashh. Same commits, unchanged, plus three of mine on top. Close #1267 in favour of this.

What is here

1267 as authored: provider-scoped cache-read tokens in the Capacity Dock's Today row, and a pace caption under every quota window in the dock panel and the agent-tab hover card, computed from a real window length the adapter reports.

Then:

  • test(menubar): two escaped mutations. Widening the on-pace band from 2 points to 20, or flipping the six-hour ETA suppression from <= to <, left all 528 tests green. Both are the thresholds the caption is about.
  • fix(menubar): the pace slot reserved height only while connected, so the panel relaid out on every refresh, which is the opposite of what 1267's own changelog promises. Reservation is now a property of the window shape. And a Claude or Codex summary now reads stale on sample age alone, which the manual refresh cadence makes permanent, so "Last known usage - refreshing" and Settings' "Refreshing..." became standing lies. Both now ask whether a fetch is really in flight.

Panel height, real Claude shapes, connected vs stale

Windows block, then whole panel. Before is 1267 as authored.

windows before after
1 91 / 77, panel 263 / 276 91 / 91, panel 263 / 290
2 91 / 77, panel 263 / 276 91 / 91, panel 263 / 290
3 164 / 136, panel 336 / 335 164 / 164, panel 336 / 363

The windows block no longer moves. The panel still differs by 27, which is CapacityDockGlance.noticeHeight: the staleness band is its own reserved section and predates this branch. Removing that last 27 means not demoting connection on sample age at all, which would unwind the refresh state machine, so it is left alone.

Pace, on real data

quota --format json on a real machine, now = 2026-09-12T18:59:50Z, every window fed through the shipped function:

claude  5-hour          u=0.060 e=0.0994 ws=18000   -> "4% in reserve"
claude  Weekly          u=0.060 e=0.2143 ws=604800  -> "Lasts until reset"  (proj 28%)
claude  Weekly . Fable  u=0.050 e=0.2143 ws=604800  -> "Lasts until reset"  (proj 23%)
codex   30-day          u=0.400 e=0.8719 ws=2592000 -> "Lasts until reset"  (proj 46%)
cursor  Monthly         u=0.095          ws=nil     -> silent
cursor  Auto            u=0.004          ws=nil     -> silent
cursor  API             u=1.000          ws=nil     -> silent

Only Claude and Codex carry a validated duration. Every other adapter builds its windows with the nil default and stays silent, including Cursor's exhausted API window, since the duration guard runs before the exhausted branch.

Silent as required on: u=0 e=0, e below the 3% floor, u>1, negative, NaN, infinity, missing reset, reset in the past, reset beyond one window, missing or zero or negative duration with the label reading "Weekly", an 11 minute old sample, nil or future fetchedAt, and stale, loading or transient-failure connections.

Cache read changes no price

Both CLIs run against a frozen past-day range, full structural diff of the payloads, with a main-versus-main run as the volatility baseline:

total diffs main -> branch: 9
  6 float and timestamp diffs that ALSO appear main-vs-main
  /current/providerDetails[0]/cacheReadTokens  added
  /current/providerDetails[1]/cacheReadTokens  added
  /generated                                   volatile

Costs identical to the digit, total and per provider. Absent stays unknown rather than becoming zero, a known zero prints as zero, and multi-id tiles (cursor plus cursor-agent) keep the 1237 folding rule with a stricter one for the new field.

Checks

swift build                   ok
swift test                    531 tests / 61 suites  passed   (main: 494 / 59)
swift build -c release        ok
npx tsc --noEmit              clean
npx vitest run (4 touched)    73 passed

No Timer, Task, await, TimelineView or onReceive added anywhere under the views, so no new polling. A user who never hovers sees nothing new: the whole detail panel, Today row included, is behind model.hoveredProvider.

One doc nit left for the author: the changelog says four quota windows move to a two-column grid, but windowColumnCount is min(count, 2), so three windows wrap too.

ozymandiashh and others added 6 commits September 7, 2026 05:22
Main took render revision 6 for `sessionCountBasis` and changed the
provider-slice session fold from a sum to a per-day max. Both had to
survive the merge, so the resolutions are unions rather than sides:

- `addProviderSlice` keeps main's `Math.max` for `sessions` (per-day
  ticks are not distinct identities) and adds the cache-read sum beside
  it, with a comment saying why one is additive and the other is not.
- `ProviderSliceTotal`, `ProviderCost`, `providerDetails` and the Swift
  `ProviderDetail` carry both `sessionCountBasis` and `cacheReadTokens`.
- The snapshot revision stays 7, which is still the next free number
  above main's 6. Its doc comment said v6 was PR1265's per-model counts;
  it is main's `sessionCountBasis`, so the comment now says that.

The status-menubar suite hard-codes render revisions. Main's assertion
that a rejected v5 snapshot is rewritten as `:render-6:` auto-merged
cleanly while this branch moved the current revision to 7, which would
have failed silently on the next bump too. Those assertions now derive
the tag from `STATUS_SNAPSHOT_RENDER_VERSION`, so the current and
previous revisions follow the constant; the deliberately historical
`:render-5:` and `:render-2:` plants stay literal.
Ports the two parts of #1287 the maintainer asked to keep, expressed
through this branch's `QuotaPacePresentation` rather than through
`QuotaPace.Verdict`:

- Placement: `QuotaDetailRow` in the agent-tab quota hover card becomes
  a VStack and draws the pace line under the bar, indented past the
  label column, with the three tones the dock already uses. The card is
  fitted, so a silent caption collapses there instead of reserving a
  slot the way the dock's computed frame must.
- Wording: the long-window caption drops "est. N% at reset" /
  "est. out in X" for the plain "Lasts until reset" / "Runs out in X",
  and the exhausted state becomes "Limit reached". The projected
  percentage it came from stays in the hover text, which has room for
  the reasoning. Short windows keep the on-pace / deficit / reserve
  stage (#726), and the freshness, connection and duration gates are
  untouched.

`QuotaPace.inferredWindowSeconds(label:)` is deliberately NOT ported.
Grok Build chooses its window label from the distance to the reset, so
a monthly cycle passing through the 4-12 day band is labeled "Weekly"
and a label round trip paces a month's budget against seven days. The
adapter's real `windowSeconds` is the only source here, and a new test
pins that shape: 72% used with six days to a monthly reset reads
"Lasts until reset", while the same sample against an inferred 7-day
window overflows and would have printed "Runs out in 9h 20m". The same
test asserts a window with no duration metadata stays silent rather
than falling back to its label.

Verified with a standalone swiftc harness over QuotaPace,
QuotaPacePresentation and QuotaSummary: this host has Command Line
Tools only, so `swift test` cannot load the Testing module.

Closes #1267
Widening the on-pace band from 2 to 20 points, or flipping the six-hour
ETA suppression from <= to <, left all 528 tests green. Both are the
thresholds the caption is about.
… doing

Reserving the pace slot only while connected made the panel relayout on
every refresh: the slot collapsed and the staleness band appeared. The
reservation is a property of the window shape, so it no longer asks the
connection. Windows block on the real Claude shapes, connected vs stale:
91/77 -> 91/91 at one and two windows, 164/136 -> 164/164 at three.

A Claude or Codex summary now reads stale on sample age alone, and the
manual cadence never refreshes, so "Last known usage - refreshing" and
the Settings "Refreshing..." became permanent lies. Both now ask whether
a fetch is actually in flight.
@iamtoruk
iamtoruk force-pushed the fix/dock-pace-followups branch from 8e7e603 to d5e2d22 Compare September 12, 2026 19:32
@iamtoruk
iamtoruk merged commit 9715637 into main Sep 12, 2026
21 checks passed
iamtoruk added a commit that referenced this pull request Sep 12, 2026
Rebase resolution for #1289 onto main (#1306, #1313, #1314, #1315, #1328,
#1329). Conflicts kept both intents: main's second-row title composition,
glance-window accessibility actions, cache-read line, host field and merged
Notifications section keep their behaviour and now resolve through L(…).

Adds 14 keys to both tables, drops 4 that no longer have a call site, and
retranslates the two Copilot explanations main rewrote.
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