Skip to content

fix(quota): accurate Cursor totals and restore missing Kimi usage#159

Closed
Wibias wants to merge 1 commit into
lidge-jun:mainfrom
Wibias:fix/cursor-kimi-quota-accuracy
Closed

fix(quota): accurate Cursor totals and restore missing Kimi usage#159
Wibias wants to merge 1 commit into
lidge-jun:mainfrom
Wibias:fix/cursor-kimi-quota-accuracy

Conversation

@Wibias

@Wibias Wibias commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Cursor period-usage now keeps totalPercentUsed as the monthly meter (matching Settings → Usage) while still showing First-party / API pool bars as secondary windows, and parses Connect RPC unix-ms reset strings.
  • Kimi quota probing is hardened: unwrap data envelopes, map weekly windows from limits[] when top-level usage is absent, accept direct percent fields, and probe coding-host API-key providers (kimi-code) without ever sending credentials to non-canonical hosts.

Test plan

  • bun test tests/provider-quota.test.ts tests/quota-bars-rows.test.ts
  • GUI: Cursor OAuth provider shows monthly % matching Cursor Settings, plus optional First-party/API bars
  • GUI: Kimi OAuth and/or kimi-code API-key on https://api.kimi.com/coding/v1 shows 5h / weekly / total subscription credits
  • Force refresh: GET /api/provider-quotas?refresh=1 returns cursor:period-usage and kimi:usages without leaking tokens/raw payloads

Prefer Cursor totalPercentUsed as the monthly meter (keep auto/API pools secondary), parse unix-ms reset strings, and harden Kimi parsing for data envelopes, weekly limits, and coding-host API keys.
lidge-jun added a commit that referenced this pull request Jul 19, 2026
Docs-only Phase-0 cycle: dependency-ordered phase map (010-080), immutable
source refs codex/source-pr{152,153,154,156,157,158,159}-*, attribution
contract per 260718 precedent, and Sol review verdicts folded per phase:

- PR#152 FAIL -> pid-identity guard, captured-port wait, activation tests
- PR#157 FAIL -> honest error codes, /findsid verification, deadline budget
- PR#156 GWF  -> legacy identity-less migration, cross-token user_id preference
- PR#158 GWF  -> matcher narrowed to local abort contract, compact activation
- PR#159 GWF  -> active-key-only probe, envelope null handling, key-mode gate
- PR#153 GWF4 -> key-compat override, grant renewal repr, token redaction,
                identity-required persistence, poll cadence, 401 replay,
                terminal refresh codes, host fail-closed
- PR#154 FAIL -> close-origin-aware focus restore

Roadmap A-gate: 4 audit rounds vs Sol reviewer, final VERDICT PASS.
lidge-jun pushed a commit that referenced this pull request Jul 19, 2026
Prefer Cursor totalPercentUsed as the monthly meter (keep auto/API pools secondary), parse unix-ms reset strings, and harden Kimi parsing for data envelopes, weekly limits, and coding-host API keys.

(cherry picked from commit 90eca76)

Community PR #159 absorb; source head 90eca76.
lidge-jun added a commit that referenced this pull request Jul 19, 2026
…ey-mode gate

Repairs for community PR #159 absorb (source head 90eca76), Sol review
findings (all P2):

- resolveKimiQuotaBearer: only the ACTIVE key is used; an unresolved env
  reference no longer silently walks apiKeyPool — the meter would belong to a
  different account than the one routing requests.
- unwrapKimiQuotaPayload: null outer placeholders ({ usage: null, data: {...} })
  no longer mask a usable nested payload.
- maybeFetchProviderQuota: the key-auth Kimi probe requires authMode === 'key';
  forward/local modes carry no credential of ours and are not probed.
- Activation tests: unresolved-env no-probe, forward-mode no-probe,
  null-envelope unwrap.

Co-authored-by: Wibias <37517432+Wibias@users.noreply.github.com>
@lidge-jun

Copy link
Copy Markdown
Owner

Thanks — both the Cursor totalPercentUsed fix and the Kimi limits[] mapping were right, and it's landed on dev with your authorship preserved plus a maintainer repair:

  • 5ea37069 — your PR fix(quota): accurate Cursor totals and restore missing Kimi usage #159 commit, absorbed as-is (author: @Wibias, source head 90eca76).
  • df0361dd — maintainer repair (Co-authored-by: @Wibias) closing three review findings:
    1. an unresolved active env key silently fell back to the first resolvable apiKeyPool entry — the meter could belong to a different account than the one routing requests; the probe now uses the active key only;
    2. envelope detection used !== undefined, so { usage: null, data: {...} } kept the dead outer object — null placeholders no longer mask the nested payload;
    3. authMode !== "oauth" also matched forward/local modes — the key-auth probe now requires authMode === "key".

Full suite green (3,087 tests). Closing in favor of the dev-landed commits; ships with the next release.

@lidge-jun lidge-jun closed this Jul 19, 2026
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