Repository navigation
menubar: detect early quota resets and say so - #1329
Merged
Merged
Conversation
Vendors sometimes reset a usage window ahead of schedule as a goodwill gesture. Nothing in the app noticed, so the capacity that was handed back went unused. The decision is two pure pieces so it can be tested without a view or a network: a detector that takes the previous and current reading of one window and returns an optional event, and a summariser that reads a window's early-reset pattern out of the snapshots already on disk. Detection needs both signals to be defensible on their own. A reset time that jumps to a genuinely new cycle while the stored one still had time to run is one; usage emptying while the advertised reset time stands still is the other, for vendors that grant the reset without moving the time. Both carry the same identity for the cycle they cut short, so the second cannot re-announce what the first already said. The thresholds are deliberately conservative, because a false "you have your capacity back" is worse than silence. Inside a cycle reported usage only rises, moving down by a point or two of rounding, so the drop signal asks for a fall of at least 40 points that lands at or under 10% — far outside rounding, with room for a refresh interval of real use after the reset. A new cycle cannot start before our last look at the old one, so its reset time must sit about a window past that look; a reset time that merely creeps forward is a rolling window, not a reset. Silence is the answer for a scheduled reset, a plan change, clock or timestamp skew (the discipline QuotaPace already applies), a window appearing or disappearing, a window's first observation, a reconnect after a failure, and a reading that is missing or malformed. The monitor around it keeps the previous fetch's readings, the plan label and the reset times it has already announced, and delivers through the existing UpdateNotifier rather than a second notification stack. The snapshot store keeps each cycle's highest reading, which is right for "what did the cycle end at" and wrong for "what did the last fetch say", so the baseline is kept alongside the announcement record instead. History is derived from the stored reset times alone: a fixed window starting at t ends at t + length, so a cycle ending sooner than a full window after the previous cycle's scheduled end began early by the difference. No network, no external feed.
Detection rides the refresh lifecycle that already runs: it happens where each successful Claude fetch is captured into the snapshot store, before the store is written, so it costs no request. Issue #725 names "no new network polling loops" a hard non-goal, and this adds none. Three surfaces, because the user can be looking at any of them. A system notification names the provider, the window and the lead. The Capacity Dock carries a band saying the same for twelve hours after the reset was seen, drawn and reserved exactly like the staleness notice, because the panel's frame is computed rather than fitted. The quota hover card gains this Mac's own pattern next to the pace captions. The state before the fetch decides whether the stored baseline can be compared against it: a provider coming back from a terminal failure, a fresh bootstrap or no credentials has a baseline from the far side of a gap, where stale state looks like a jump. A window the API did not report this time is passed as absent rather than omitted, so a window that comes and goes is never read as a reset. Disconnect drops the baseline along with the snapshots, so a reconnect under another account starts clean. The Settings switch is on by default, and turning it off withholds only the notification — the dock band still appears, since it is a caption on data the user is already looking at rather than an interruption.
The Capacity Dock design doc gains the band, the switch and the two new code boundaries; the Claude provider doc explains what the detection reads, how the local history is derived from stored reset times, and why it stays quiet, so the next person changing the snapshot store knows what depends on it. Refs #725, rather than Closes: that issue is a five-part epic and this is one slice of its surfaces, so it should not close on this PR. No issue tracks early-reset detection on its own.
swift-testing's `#expect` captures each operand separately, so the literal `18 * 3600` on the right of a `TimeInterval` comparison was typed as Int and the equality never resolved as Double == Double. CI reported `(event?.earlyBySeconds → 64800.0) == (18 * 3600 → 64800)` as a failure while the two numbers plainly agree. A bare literal in the same position (`percentBefore == 80`) is inferred as Double and passed, which is why only the two compound expressions failed. The lead is now one explicitly typed `TimeInterval` constant, the event is unwrapped with `#require` so a nil event fails with a clear message rather than a silently false comparison, and the percent expectations are spelled as Double literals. The rest of the file was swept for the same shape: the remaining equalities are Int counts, CGFloat, enums, strings, or already explicitly typed TimeIntervals. The standalone swiftc harness could not have caught this — plain Swift infers the same literal as Double, and the harness does not reproduce the macro's per-operand capture. It now forces the comparison through a TimeInterval parameter, which at least pins the type.
Both early-reset signals shared one sentence, so a window whose counter the vendor emptied mid-cycle was announced as "reset 18h early" even though its reset time had not moved and the cycle still ended when it always would have. Replaying this Mac's own 30 days of snapshots through the monitor produces exactly that: on 2026-09-01 the weekly counter went 81% to 0% with resets_at still at 2026-09-04T07:00:00Z, and the copy promised a new window that was not coming. usageDropped now gets its own title, body, band and help text; the reset-moved-forward wording is unchanged. lead() rounds to the unit it prints instead of truncating, so a 1h57m lead reads "2h", not "1h". Tests pin both, assert a usage-drop event never says "reset early", and pin the notice expiry and the cycle anchor tolerance by value rather than by reading the constants back.
Updates, Codex banked resets and early quota resets each had their own one-toggle Section in General. Three sibling headers for three checkboxes is not an information architecture. One Notifications section, three toggles, each keeping its own help text and defaults key. Also assert the early-reset notification identifier does not carry UpdateChecker's prefix, so the delegate's tap guard cannot install an update from it.
This was referenced Sep 12, 2026
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.
ozymandiashh
added a commit
to ozymandiashh/codeburn
that referenced
this pull request
Sep 12, 2026
A day's worth of menubar work landed: getagentseal#1328 (Codex banked limit resets), getagentseal#1329 (early quota reset detection), 138ef34 folding the three notification switches into one Settings section, cbcd984 rewording the usage-drop early reset, the Copilot per-rung host work, and the dock's cache-read row and pace captions. Four files conflicted, ten hunks. Every one resolved as a union: main's behaviour lands verbatim and the catalog routing is re-applied on top. - MenubarSecondRow.swift: main rebuilt `secondRow` around a `row` binding it clamps through `clampToRowBudget`, and rebuilt `quotaRow` so the provider label is abbreviated against the budget left over by the figures. The routing is reshaped to fit rather than reverting either: the figures go through `L("%lld%% left")` and the label joins with a plain space, which is the word order in both locales. The old `"%@ %lld%% left"` key cannot survive that restructure, and a `"%@ %@"` key to replace it would be nothing but specifiers, which LocalizationCatalogTests rejects on purpose. - CapacityDockView.swift: main's cache-read line kept, and its new stale-but-idle distinction kept as two routed strings rather than one. - HeatmapSection.swift: main moved the reset-credits label into the new `CodexBankedResetPresentation`, so the local helper it replaced is deleted rather than kept alongside it. - SettingsView.swift: the Updates section becomes main's consolidated Notifications section; the Copilot help paragraph and token footer take main's longer wording under new keys; the pasted-token section gains main's host field; `.dormant` and the stale connection title route through main's new presentation helpers. Verified mechanically: outside `mac/` the tree is byte-identical to main, and every one of the seven `L(...)` keys that disappeared is accounted for — three reworded by main, one dropped by the `quotaRow` restructure above, and three whose code main moved into `CodexBankedResetPresentation` and `CopilotQuotaPresentation.dormantSettingsDetail`. Those three, and the much larger set of new strings the features shipped unrouted, are the next commit.
ozymandiashh
added a commit
to ozymandiashh/codeburn
that referenced
this pull request
Sep 12, 2026
getagentseal#1328's banked limit resets, getagentseal#1329's early quota reset detection, the consolidated notifications section, the Copilot per-rung host work and the dock's cache-read row all shipped user-facing copy with no `L(` calls. 67 new keys, 5 retired by main's rewrites and restructures: 551 keys become 613. Most of it was invisible to the guard test, which is the next commit's problem. Both features put their wording in a new pure presentation type — exactly the shape the views render as `Text(presentation.caption)` — so the call-site pass had nothing to look at. Routed here: - Notifications: the section itself plus the banked-reset and early-reset toggles and their help text. - Codex banked resets: the Plan-tab row label, the detail parts the hover card and Plan tab share, the notification title and body, and the compact-age vocabulary. - Early quota resets: both notification shapes, the dock band, the hover help text and the three history-summary sentences, plus the Claude window names and the lead formatter. - Quota pace: the captions, the projection sentences and the window-length and countdown labels. The countdown reuses the popover's own `%lldd %lldh` / `%lldh %lldm` / `%lldm` keys so the two can never disagree. - Copilot: the host-aware dormant and rejection messages, the new host field. - Capacity Dock: the cache-read row and the window/reset accessibility labels. Two notes on judgement calls: `CodexBankedResetPresentation.detail` and `compactAge` carry a documented character-identical mirror in `src/quota/codex.ts`. Routing them keeps that mirror exact — `en` is an identity table, so they emit byte-for-byte what they did before — while letting a zh-Hans menubar say it in Chinese. The CLI stays English-only, so the two diverge in a translated build exactly as every other menubar string already does. The doc comments now say so. `EarlyQuotaResetFormat.windowNoun` trims " limit" and `capitalizedFirst` upper-cases: English morphology that degrades to the identity in Chinese. Left that way deliberately — the trim exists to avoid "weekly limit resets" in English, a repetition Chinese does not produce — rather than keying a second catalog entry per window purely to shorten a noun. Both are commented. Argument order is preserved in every multi-argument key, including the history summary, where the natural Chinese phrasing wanted to reorder two counts: `String(format:)` binds positionally, so the parity test would have caught it, but the reordered sentence would have been wrong in a way no test can see. Verified with the standalone swiftc harness (`swift test` cannot run here) and `swift build`.
ozymandiashh
added a commit
to ozymandiashh/codeburn
that referenced
this pull request
Sep 12, 2026
The previous commit had to add 67 keys, and the guard test caught almost none of them. getagentseal#1328 and getagentseal#1329 each arrived as a new pure presentation type holding a feature's whole vocabulary — `CodexBankedResetPresentation`, `EarlyQuotaResetFormat`, `QuotaPacePresentation` — and the views only ever render `Text(presentation.caption)`. There is no literal at a call site to see, and these are not enum display labels either, so two of the three passes were blind. Only the catalog round-trip noticed anything, and only for the four keys whose code main happened to move. So the display-label pass becomes a copy-bearing-declaration pass, anchored on the convention this codebase already follows: every `String` returned by a type whose name ends in `Presentation` or `Format` is copy, as is every `displayName` / `settingsLabel` / `notificationTitle` / `notificationBody` / `noticeText` / `noticeHelpText` / `caption` / `helpText` / `rowLabel` anywhere. A return-type rule was tried first — any declaration returning String — and rejected: it reports 378 findings on this tree, almost all enum raw values and CLI argument strings. Anchoring on the naming convention gives 29, every one of which is either already denylisted or a bug fixed below. Three bugs the probe exposed: - `->` drove the header parser's bracket depth negative, because `>` was treated as closing a generic. Every `func … -> String` was invisible while the `var` form was caught — so `QuotaPacePresentation.caption`, the single biggest source of new copy, would have sailed through. - A `case "five_hour":` pattern read as produced copy rather than as a value being matched, so any string-keyed switch reported its own match keys. - `enclosingTypeName` rescanned the file per member, which is quadratic; on AppStore.swift the pass took minutes. It now indexes each file once. Denylist grows by two entries, both documented: `ExportFormat.cliName` and `.suffix`, caught only because that enum's name ends in "Format" — it is an export-format enum, and those return a CLI argument value and a file extension. Mutation-checked: un-routing `EarlyQuotaResetEvent.notificationTitle` and `QuotaPacePresentation.caption` both fail the new pass, and each of the three bugs above has a test that fails without its fix. Known imprecision, documented in the source: the owning type is the nearest preceding declaration rather than a brace-scoped one, so a member after a nested type's closing brace is attributed to the nested type. A finding prints the qualified name it used and that is the string to paste into the denylist, so the two cannot disagree — and it errs toward guarding more, never less.
ozymandiashh
added a commit
to ozymandiashh/codeburn
that referenced
this pull request
Sep 12, 2026
getagentseal#1329 (early quota resets) and getagentseal#1328 (banked Codex resets) both landed, so the two features this forecast reads from are now on main. Conflicts, all resolved as unions: - CHANGELOG.md, the usual: both sides' entries kept in their sections. - SettingsView.swift, the seam this branch flagged. Main folded the notification switches into one `Section("Notifications")` (138ef34), so the forecast's opt-in notice and its threshold picker move into that section rather than adding a fourth one. The standalone "Codex Reset Forecast" section is gone. - AppStore.swift, five hunks: both announcers, both post-fetch observe calls, both stores cleared on disconnect, and the Codex summary now carrying main's banked-reset footer line alongside this branch's `forecastLines`. Nothing from either side dropped. - HeatmapSection.swift: main replaced `resetCreditsLabel` with `CodexBankedResetPresentation`; that deletion is kept and this branch's forecast rows stay. - src/quota/index.ts: main's `notes` and this branch's `resetForecast` are both on `QuotaCommandProvider`. They stay separate on purpose - `notes` is for facts the provider reported, `resetForecast` is an estimate over a public record, and folding one into the other is what the footer-lines fix earlier on this branch was about. With both features on main, the local-event loader now decodes through their real `Codable` types - `EarlyQuotaResetMonitor.ProviderState`, `EarlyQuotaResetEvent` and `CodexBankedResetState` - instead of the private mirror structs it carried while they were unmerged. Drift is now a compile error rather than a silent misread. It still reads the two stores by address rather than calling them, because neither exposes a read this can use: `CodexBankedResetStore.load()` is async and hard-wired to the real cache path with nothing to inject, and the forecast is evaluated synchronously from view bodies; and `EarlyQuotaResetMonitor.visibleEvent` applies the twelve-hour dock-visibility window, which is the wrong filter here - a reset twenty hours ago is no longer worth a band in the dock and is still exactly what "since last reset" should count from. The `UserDefaults` key prefix is still a literal, because `EarlyQuotaResetMonitor` is @mainactor and its static cannot initialise a nonisolated one; a test asserts the two strings are equal, so drift fails there instead of silently reading nothing.
This was referenced Sep 12, 2026
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.
Supersedes #1320 by @ozymandiashh. Same four commits, rebased, plus three follow-ups from review. The design, the detector and the surfaces are theirs.
Built on #1328, which has since merged to main. That PR fixes a real bug this one would otherwise have shipped into: the notification delegate added in #1283 ran
performFullUpdate()for any notification tapped, so tapping an early-reset alert would have installed a CLI and app update. #1328 gates the handler onUpdateChecker.notificationIdentifierPrefix, and a test here asserts the early-reset identifier does not carry that prefix, so the guard cannot drift out from under this feature.What #1320 does
Vendors sometimes reset a usage window ahead of schedule. CodeBurn showed the new percentage but never said it had happened. Two signals catch it on the refresh lifecycle that already runs, with no new polling: a reset time that jumps to a genuinely new cycle while the stored one still had time, and usage emptying (a fall of at least 40 points landing at or under 10%) while the advertised reset time stands still. Three surfaces: a system notification through the existing notifier, a 12-hour Capacity Dock band drawn and reserved like the staleness notice, and a hover-card line derived from the 30 days of snapshots already on disk. Claude only, because it is the provider whose quota readings are persisted.
The three follow-ups
1. The usage-drop signal said something untrue. Both signals shared one sentence, so a window whose counter the vendor emptied mid-cycle was announced as "reset 18h early" even though its reset time had not moved and the cycle still ended when it always would have. A user reading that would budget a fresh window that is not coming.
usageDroppednow gets its own title, body, dock band and help text;resetMovedForwardwording is unchanged, and a test asserts a usage-drop event never says "reset early".2.
lead()truncated instead of rounding. A 1h57m lead printed "1h". It now rounds to the unit it prints.3. Two constants were not actually pinned by tests. The expiry test read
EarlyQuotaResetNotice.visibleSecondsback, so no value change could fail it, and nothing heldcycleAnchorToleranceat all: mutating them to 240h and 120h left the suite green. The expiry is now pinned with a literal twelve hours, and a new case covers a weekly reset time jumping only four days, which is not a cycle boundary however far it moved.Real data
Replayed this Mac's own snapshot store through the monitor, grouped by
capturedAtexactly ascaptureSnapshotscalls it: 2351 snapshots, 1276 distinct fetches, 2026-08-13 to 2026-09-12.There was a real early reset in the window: on 2026-09-01 the weekly counter went 81% to 0% while
resets_atheld at 2026-09-04T07:00:00Z, and the five-hour window jumped a cycle in the same fetch. The monitor coalesces the two to one notification named after the longer window. One notification in 1276 fetches, at the one real event, and the old wording on that exact event is what motivated follow-up 1.The history summariser returns nil for every weekly key on this machine, which is correct: the six observed cycles are exactly 168.000h apart.
Testing
cd mac && swift buildclean,swift build -c releaseclean.swift test: 606 tests in 68 suites, all pass. The original author could not run this (CLT-only machine); nothing they wrote fails under a real runner.Settings
The early-reset toggle joins Updates and the Codex banked-reset toggle that landed in #1328 (superseding #1322) in a single
Notificationssection rather than adding a third sibling one-toggle section. Each keeps its own help text and defaults key. This is the merge #1320 and #1322 would otherwise have conflicted over, and resolving it was the one conflict in the rebase.Not verified
No notification was delivered and the dock band and hover caption were not seen in a running app. The band's reserved height is asserted arithmetically, as the neighbouring dock tests do.
Refs #725.