Skip to content

[codex] Add Kimi monthly subscription usage#1839

Merged
steipete merged 4 commits into
steipete:mainfrom
zhiyue:codex/kimi-monthly-subscription-usage
Jul 4, 2026
Merged

[codex] Add Kimi monthly subscription usage#1839
steipete merged 4 commits into
steipete:mainfrom
zhiyue:codex/kimi-monthly-subscription-usage

Conversation

@zhiyue

@zhiyue zhiyue commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fetch Kimi membership usage concurrently with the existing web billing request.
  • Surface the shared subscription pool as a Monthly window alongside Weekly and five-hour usage.
  • Bound optional membership enrichment to a two-second total budget, so it cannot inherit the shared 30-second HTTP timeout after required usage succeeds.
  • Clamp Kimi percentages and cover successful, partial, slow, and missing membership responses.

Why

Kimi exposes monthly subscription consumption separately from its coding usage response. This keeps the useful Monthly window while preserving the availability of the existing Weekly and Rate Limit data when membership enrichment is slow or unavailable.

Validation

  • swift test --filter KimiProviderTests — 46 tests across 6 suites passed on exact head.
  • make check — repository checks, SwiftFormat, and strict SwiftLint passed.
  • make test — all 46 sharded groups passed; one unrelated Claude deadline flake passed its automatic retry.
  • Exact-head autoreview — clean, no actionable findings, correctness confidence 0.83.
  • Current-main merge proof — clean after incorporating cec3d6dc2.

Live proof

  • Contributor authenticated proof: the exact app/CLI path rendered Weekly, Rate Limit, and a changing Monthly value from a real Kimi session; see the redacted output and explanation.
  • Maintainer exact-head check used the existing Chrome profile without exposing cookies. That profile was not logged into Kimi (Log in visible); both production POST routes responded with JSON 401, confirming endpoint reachability but blocking a second authenticated exact-head capture.
  • No Keychain access or credential output was used for maintainer validation.

Kimi Monthly proof

@clawsweeper

clawsweeper Bot commented Jul 2, 2026

Copy link
Copy Markdown

ClawSweeper review: did not complete due to Codex infrastructure failure. Reviewed July 4, 2026, 3:33 AM ET / 07:33 UTC.

Summary
Review failed before ClawSweeper could summarize the requested change.

Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

Review metrics: none identified.

Merge readiness
Not assessed.
Failure reason: codex execution failed.

This is a ClawSweeper/Codex infrastructure failure, not a PR readiness or patch-quality verdict.
Keep any merge decision on the normal maintainer review path until ClawSweeper can complete a fresh review.

Risk before merge

  • [P1] No close action taken because the review did not complete.

Maintainer options:

  1. Decide the mitigation before merge
    Retry the Codex review after fixing the execution failure.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • Review did not complete, so no work-lane recommendation was made.
Review details

Best possible solution:

Retry the Codex review after fixing the execution failure.

Do we have a high-confidence way to reproduce the issue?

Unclear. The review failed before ClawSweeper could establish a reproduction path.

Is this the best way to solve the issue?

Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model internal, reasoning high; reviewed against cec3d6dc2cc3.

Label changes

Label changes:

  • remove P2: Current review triage priority is none.
  • remove merge-risk: 🚨 auth-provider: Current PR review selected no merge-risk labels.
  • remove merge-risk: 🚨 availability: Current PR review selected no merge-risk labels.
Evidence reviewed

What I checked:

  • failure reason: codex execution failed.
  • codex failure detail: Codex review failed for this PR with exit 1.
  • codex stderr: No stderr captured.
  • codex stdout: {"type":"thread.started","thread_id":"019f2c0c-3b95-7ef2-a362-18ecd0d6f7c1"}.

Likely related people:

  • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)
How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (1 earlier review cycle)
  • reviewed 2026-07-02T13:23:32.064Z sha 1522d4d :: needs changes before merge. :: [P2] Bound the optional membership fetch latency

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 2, 2026
@zhiyue zhiyue marked this pull request as ready for review July 2, 2026 10:34
Copilot AI review requested due to automatic review settings July 2, 2026 10:34

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7dc512ce6

ℹ️ 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".

Comment thread Sources/CodexBarCore/Providers/Kimi/KimiUsageSnapshot.swift

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the Kimi provider’s browser/cookie-based usage fetch to also pull monthly subscription usage from Kimi’s membership endpoint and surface it as an additional “Monthly” window in the unified UsageSnapshot.

Changes:

  • Add models for Kimi’s subscription stat response (KimiSubscriptionStatResponse / KimiSubscriptionBalance).
  • Fetch subscription stats from GetSubscriptionStat during fetchUsage(authToken:) and carry subscriptionBalance into KimiUsageSnapshot.
  • Convert subscriptionBalance.amountUsedRatio into an extra “Monthly” NamedRateWindow, with new parsing/conversion tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
Tests/CodexBarTests/KimiProviderTests.swift Adds decoding + conversion tests for the new subscription stat response and monthly extra window.
Sources/CodexBarCore/Providers/Kimi/KimiUsageSnapshot.swift Stores subscription balance and maps it into a “Monthly” extra rate window.
Sources/CodexBarCore/Providers/Kimi/KimiUsageFetcher.swift Adds a second web endpoint call to fetch subscription stats alongside existing usage fetching.
Sources/CodexBarCore/Providers/Kimi/KimiModels.swift Introduces Codable models for the subscription stat payload subset that CodexBar uses.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/CodexBarCore/Providers/Kimi/KimiUsageSnapshot.swift
Comment thread Sources/CodexBarCore/Providers/Kimi/KimiUsageSnapshot.swift
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. label Jul 2, 2026

zhiyue commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 2, 2026
@zhiyue

zhiyue commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Live verification + review fixes

Pushed e533fddd to address the review, plus real end-to-end proof from a live Kimi web/cookie session.

✅ Live proof (addresses "needs real behavior proof")

Fetched through the exact code path the app uses (CodexBarCLI usage --provider kimi --json --source web). The snapshot carries no credentials — no token/email; identity is providerID only:

{
  "provider": "kimi",
  "source": "web",
  "usage": {
    "primary":   { "usedPercent": 20, "resetDescription": "20/100 requests",         "resetsAt": "2026-07-09T06:56:37Z" },
    "secondary": { "usedPercent": 1,  "resetDescription": "Rate: 1/100 per 5 hours",  "resetsAt": "2026-07-02T16:56:37Z", "windowMinutes": 300 },
    "extraRateWindows": [
      { "id": "kimi-monthly", "title": "Monthly", "window": { "usedPercent": 77.22, "resetsAt": "2026-07-23T00:00:00Z" } }
    ]
  }
}
  • The MembershipService/GetSubscriptionStat POST succeeds with the existing web token and the Monthly window renders.
  • An earlier fetch ~2.5h prior showed Monthly 77.16% (5h window at 98%); it now reads 77.22% (5h window reset to 1%) — confirming amountUsedRatio is a live, moving consumption ratio, not a constant/entitlement flag.
  • In the menu bar the Kimi card shows the Monthly row as “23% remaining” (= 77.2% used), resetting in ~20d, with no layout issues.

✅ Review fixes (e533fddd)

  • async let → sequential await (AGENTS.md Swift-concurrency red flag / merge-risk label): the best-effort subscription fetch is now a plain sequential await after the required usage response — no optional-sibling async let.
  • Clamp weekly & rate-limit percentages (Copilot ×2): both now go through clampedPercent, so they can no longer exceed 100% when used > limit, matching the monthly window and other providers.
  • Monthly uses amountUsedRatio — deliberate (Codex / ClawSweeper P2): Kimi’s subscription credit pool is shared across features (web chat etc. draw down the same pool), so amountUsedRatio is the real "how much of the month’s subscription remains". kimiCodeUsedRatio is only Code’s share of that shared pool and would understate remaining balance (it can read ~29% while the pool is 77% consumed). This is documented inline.

Re: overlap with #1762 — happy to defer landing order to the maintainers.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper

clawsweeper Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@clawsweeper clawsweeper Bot removed the proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. label Jul 2, 2026
@zhiyue zhiyue force-pushed the codex/kimi-monthly-subscription-usage branch from e533fdd to 1522d4d Compare July 2, 2026 13:19
zhiyue and others added 4 commits July 4, 2026 08:05
- Clamp weekly and rate-limit percentages via clampedPercent so they can't
  exceed 100% when used > limit, matching the monthly window and other providers.
- Document that Monthly tracks the shared subscription amountUsedRatio (the credit
  pool is shared across features) rather than the Code-only kimiCodeUsedRatio.
- Add a partially-used (0.7716 -> 77.16%) monthly-window test so the fully-exhausted
  1.0 fixture doesn't imply amountUsedRatio is a constant.

Claude-Session: https://claude.ai/code/session_01YW7G46VVTos9nDkx7hRcwn
@steipete steipete force-pushed the codex/kimi-monthly-subscription-usage branch from 1522d4d to ecc71d4 Compare July 4, 2026 07:31
@clawsweeper clawsweeper Bot removed the proof: sufficient Contributor real behavior proof is sufficient. label Jul 4, 2026
@clawsweeper clawsweeper Bot removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 4, 2026
@steipete steipete merged commit 2fa61d0 into steipete:main Jul 4, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal priority bug or improvement with limited blast radius.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants