Add z.ai peak/off-peak quota burn rate row - #2721
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c058b7d87
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| calendar.timeZone = TimeZone(secondsFromGMT: 0) ?? calendar.timeZone | ||
|
|
||
| let hour = calendar.component(.hour, from: reference) | ||
| let isPeak = hour >= Self.peakStartHourUTC && hour < Self.peakEndHourUTC |
There was a problem hiding this comment.
Keep weekends in the off-peak window
When reference falls on a Saturday or Sunday between 06:00 and 10:00 UTC, this hour-only check reports 3x (peak) and points the next transition to the same-day 10:00 boundary. The current z.ai coding-plan docs state that peak hours are Monday to Friday, 14:00–18:00 UTC+8, and that weekend usage is off-peak all day (see https://docs.z.ai/devpack/overview and https://docs.z.ai/devpack/notice/usage-revision), so weekend snapshots would display the wrong burn rate and countdown until the next refresh.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch — confirmed against both cited docs and fixed in 5a93ef9. Peak is now gated on Mon–Fri, and since the coefficients differ by plan generation (3x/1x quota plans per the usage-revision notice, 1x/0.5x credits plans per the overview), the row now shows phase + transition countdown instead of a hardcoded multiplier. Added Saturday-inside-window and Friday-evening-skips-to-Monday test cases (7/7 passing on Linux).
|
Codex review: needs maintainer review before merge. Reviewed August 8, 2026, 5:51 PM ET / 21:51 UTC. ClawSweeper reviewWhat this changesAdds a credit-plan-only z.ai quota-rate row that shows peak or off-peak status and time to the next rate transition, plus a deterministic plugin clock helper and focused coverage. Merge readinessKeep open as a normal merge candidate: the owner approved the feature and public clock contract, the credit-only schedule logic is bounded and covered, and no patch defect was found. Priority: P2 Review scores
Verification
How this fits togetherCodexBar’s bundled z.ai provider fetches quota limits and converts them into generic usage details consumed by the menu bar and CLI. The new row derives the documented pricing phase from the refresh clock only when the quota response contains a credit limit. flowchart LR
A[z.ai quota response] --> B[Quota limit parsing]
B --> C{Credit plan present?}
C -->|Yes| D[Injected refresh clock]
D --> E[Peak schedule calculation]
E --> F[Quota details row]
C -->|No| G[Existing quota details]
F --> H[Menu bar and CLI]
G --> H
Before merge
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Merge the additive credit-plan row while preserving the documented clock helper as a stable plugin contract. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: fixed-clock parity cases cover peak, off-peak, weekend, and legacy-plan behavior, and the PR records a production QuickJS CLI gate check. Is this the best way to solve the issue? Yes. A credit-limit gate plus a deterministic UTC schedule is the narrowest maintainable approach and avoids claiming a rate for legacy token plans. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b772c66b741b. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (15 earlier review cycles; latest 8 shown)
|
Peak hours are Mon-Fri only (docs.z.ai/devpack/overview and /devpack/notice/usage-revision) - weekend runs inside 06:00-10:00 UTC previously showed a false 3x peak marker. The 2x off-peak/promo-1x scheme was superseded by z.ai's usage revision: quota plans burn 3x peak / 1x off-peak; off-peak boundary now skips to Monday 06:00. Surfaced by Codex review on the CodexBar port of this logic (steipete/CodexBar#2721). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
ClawSweeper's two findings split cleanly, so handling them separately: Epoch-zero defect (P2): fixed in 4099b4f. The Public plugin clock API (P1): this one is your call, since
Context for why it exists at all: the z.ai quota-rate row is wall-clock-derived, and 🤖 Generated with Claude Code |
|
Thanks — the schedule itself is well-researched (matches z.ai's documented Mon–Fri 14:00–18:00 UTC+8 peak windows and multipliers), but three changes are needed before this can land:
Separate note: the new |
|
Maintainer ruling on the API question: |
4099b4f to
6e7497d
Compare
|
All three asks plus the ruling conditions are in — rebased branch force-pushed as
Per the ruling, the 🤖 Generated with Claude Code |
6e7497d to
6c62805
Compare
|
Re-ported onto the JavaScript-only z.ai provider from #2758 — force-pushed as a single commit
🤖 Generated with Claude Code |
Credit-based plans charge 1x during peak (Mon-Fri 14:00-18:00 UTC+8; weekends off-peak all day) and 0.5x off-peak, but no z.ai endpoint exposes the phase, so derive it from ctx.date.now() and render "Quota rate: Off-peak - peak in 2h 21m" in the quota details. Gated to CREDIT_LIMIT plans: legacy TOKENS_LIMIT plans charge model- dependent flat rates where a phase display would claim a rate that isn't being charged. Golden-covered at four fixed-clock epochs (weekday peak, weekday off-peak, Friday-night weekend skip, Saturday-inside-window). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
6c62805 to
6504584
Compare
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary
z.ai's credit-based (CREDIT_LIMIT) coding plans charge 1x during peak hours (Monday–Friday, 14:00–18:00 UTC+8, i.e. 06:00–10:00 UTC) and 0.5x off-peak; weekends are off-peak all day — see docs.z.ai/devpack/overview and the usage-revision notice. No z.ai endpoint exposes the phase — it is purely a function of the clock — so CodexBar shows how much quota is left but not that the same prompt costs 2x as much for the next four hours.
Now that z.ai is a JavaScript-only provider (#2758), this is a single-commit, 2-file, +75-line diff: a
quotaRateRow()inzai.jsderived from the injectedctx.date.now()clock, and golden coverage.TOKENS_LIMITplans charge model-dependent flat rates (GLM-4.7 is 1x all day), where a phase display would claim a rate that isn't being charged — verified live below.ctx.date.now()injected clock — deterministic under golden tests, no new API surface. (The earlier revisions'ctx.date.nowMillis()plumbing is superseded by the cutover's own clock and is gone from this diff.)UsageFormatter.resetCountdownDescriptionso the row reads like native reset text.Prior art: a similar client-side marker has been running in cclimits (Python CLI) since early 2026 — improved here per current z.ai docs, with the weekend fix ported back there.
Behavior proof
Fixed-clock golden renders (all passing on Linux/QuickJS — the production engine for this provider on Linux):
zai CREDIT_LIMIT fixture matches the cut-over golden— pins the full details including("Quota rate", "Off-peak", "peak in 2h 21m")at epoch 1_786_073_946 (Friday 03:39 UTC).zai quota rate row tracks the credit-plan peak schedule— four fixed-clock epochs: weekday peak (Peak · off-peak in 2h 30m), weekday off-peak, Friday 23:00 skipping the weekend (peak in 2d 7h), Saturday inside the window staying off-peak (peak in 1d 23h).zai fixture matches the cut-over golden(legacy TOKENS_LIMIT) — unchanged: no row, demonstrating the gate.Live gate verification: Linux
CodexBarCLIfrom this branch (QuickJSzai.jspath) against a real legacyTOKENS_LIMITaccount renders noQuota raterow, as intended. Earlier PR revisions include the pre-gating transcript where the row appeared on the same account.Commands run
swift test --filter ProviderPluginDetailsParityTests— 12/12 passed on Linux/QuickJS (swift:6.2 container), including both zai goldens and the new schedule test.swift build --product CodexBarCLI+ liveusage --provider zai— gate verification above.swiftformat/swiftlintand macOS CI — theirs to confirm; happy to fix anything flagged.🤖 Generated with Claude Code