Skip to content

fix(quota): report unlimited A6API keys - #1171

Closed
byongshintv wants to merge 2 commits into
lidge-jun:devfrom
byongshintv:fix/a6api-unlimited-quota-v2
Closed

fix(quota): report unlimited A6API keys#1171
byongshintv wants to merge 2 commits into
lidge-jun:devfrom
byongshintv:fix/a6api-unlimited-quota-v2

Conversation

@byongshintv

@byongshintv byongshintv commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • keep unlimited A6API API-key quota visible when finite credit totals are zero
  • expose structured USD credit values and optional expiry for finite and unlimited quota rows
  • cover unlimited keys and structured finite-credit data with focused regression tests

Verification

  • bun run typecheck
  • bun test tests/provider-quota.test.ts (86 pass, 0 fail)
  • bun run privacy:scan
  • git diff --check upstream/dev...HEAD

The earlier full-suite run had one unrelated tests/codex-sync-api.test.ts failure, reproduced unchanged on a clean upstream/dev worktree. The focused quota suite and all static/privacy checks pass after rebasing onto the latest dev.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • New Features
    • Added USD credit quota tracking, including used, limit, remaining, and utilization details.
    • Added support for unlimited credit accounts.
    • Added expiration information for metered credit quotas.
    • Quota information now accurately reflects unlimited keys and finite credit balances.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (2/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 2/4).

Review readiness checklist

  • ⬜ All CI tests are green on my local testing.
  • ✅ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

2/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@github-actions
github-actions Bot marked this pull request as draft August 7, 2026 03:40
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d8908c33-e617-4aae-941e-eb38f42df1dc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The quota model now supports structured USD credits. A6API parsing reports metered usage, unlimited status, expiration timestamps, and custom quota windows. Tests cover metered and unlimited accounts.

Changes

A6API credit quota reporting

Layer / File(s) Summary
Quota contract and visibility
src/providers/quota.ts
Lines 67–84 add ProviderQuotaCreditsUsd and the optional ProviderQuota.creditsUsd field. Lines 216–217 keep unlimited and percentage-based credit quotas visible.
A6API quota parsing and validation
src/providers/quota.ts, tests/provider-quota.test.ts
Lines 355–375 parse unlimited flags and expiration timestamps. Lines 398–404 report metered USD credit values. Tests at lines 285–291 and 300–328 verify metered and unlimited reports.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: wibias, ingwannu, lidge-jun

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: reporting unlimited A6API keys in quota results.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/provider-quota.test.ts`:
- Around line 300-327: Update the test around fetchProviderQuotaReports to use a
valid nonzero expires_at timestamp in the mocked unlimited-quota response, then
assert that the returned creditsUsd object includes the same expiresAt value
alongside its existing fields. Keep the test focused on propagating expiry for
unlimited accounts.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1f1dc15e-b69d-4902-9f2a-c5377732ec6c

📥 Commits

Reviewing files that changed from the base of the PR and between 1fc24f0 and 63d1c8d.

📒 Files selected for processing (2)
  • src/providers/quota.ts
  • tests/provider-quota.test.ts

Comment on lines +300 to +327
test("A6API unlimited keys remain visible even when all finite credit totals are zero", async () => {
globalThis.fetch = (async (input: RequestInfo | URL) => new Response(JSON.stringify(
String(input).includes("subscription")
? { data: { hard_limit_usd: 100_000_000 } }
: { data: {
total_granted: 0,
total_used: 0,
total_available: 0,
unlimited_quota: true,
expires_at: 0,
} },
), { status: 200 })) as typeof fetch;

const result = await fetchProviderQuotaReports(a6apiOnlyConfig(), true);

expect(result.reports).toHaveLength(1);
expect(result.reports[0]?.quota.creditsUsd).toEqual({
used: 0,
limit: 0,
remaining: 0,
percent: 0,
unlimited: true,
});
expect(result.reports[0]?.quota.customWindows).toEqual([{
label: "Unlimited API credits",
percent: 0,
}]);
});

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Test expiry propagation for unlimited accounts.

Line 309 sets expires_at to 0. The test cannot detect a regression that drops expiresAt from the unlimited creditsUsd branch.

Set a valid timestamp and assert expiresAt in the expected quota object.

Proposed test update
-          expires_at: 0,
+          expires_at: "2027-01-01T00:00:00Z",
...
       percent: 0,
       unlimited: true,
+      expiresAt: Date.parse("2027-01-01T00:00:00Z"),

As per path instructions, a src/ behavior change must have a focused regression test under tests/.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test("A6API unlimited keys remain visible even when all finite credit totals are zero", async () => {
globalThis.fetch = (async (input: RequestInfo | URL) => new Response(JSON.stringify(
String(input).includes("subscription")
? { data: { hard_limit_usd: 100_000_000 } }
: { data: {
total_granted: 0,
total_used: 0,
total_available: 0,
unlimited_quota: true,
expires_at: 0,
} },
), { status: 200 })) as typeof fetch;
const result = await fetchProviderQuotaReports(a6apiOnlyConfig(), true);
expect(result.reports).toHaveLength(1);
expect(result.reports[0]?.quota.creditsUsd).toEqual({
used: 0,
limit: 0,
remaining: 0,
percent: 0,
unlimited: true,
});
expect(result.reports[0]?.quota.customWindows).toEqual([{
label: "Unlimited API credits",
percent: 0,
}]);
});
test("A6API unlimited keys remain visible even when all finite credit totals are zero", async () => {
globalThis.fetch = (async (input: RequestInfo | URL) => new Response(JSON.stringify(
String(input).includes("subscription")
? { data: { hard_limit_usd: 100_000_000 } }
: { data: {
total_granted: 0,
total_used: 0,
total_available: 0,
unlimited_quota: true,
expires_at: "2027-01-01T00:00:00Z",
} },
), { status: 200 })) as typeof fetch;
const result = await fetchProviderQuotaReports(a6apiOnlyConfig(), true);
expect(result.reports).toHaveLength(1);
expect(result.reports[0]?.quota.creditsUsd).toEqual({
used: 0,
limit: 0,
remaining: 0,
percent: 0,
unlimited: true,
expiresAt: Date.parse("2027-01-01T00:00:00Z"),
});
expect(result.reports[0]?.quota.customWindows).toEqual([{
label: "Unlimited API credits",
percent: 0,
}]);
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/provider-quota.test.ts` around lines 300 - 327, Update the test around
fetchProviderQuotaReports to use a valid nonzero expires_at timestamp in the
mocked unlimited-quota response, then assert that the returned creditsUsd object
includes the same expiresAt value alongside its existing fields. Keep the test
focused on propagating expiry for unlimited accounts.

Source: Path instructions

@byongshintv
byongshintv force-pushed the fix/a6api-unlimited-quota-v2 branch from e646862 to d2f4991 Compare August 7, 2026 04:50
@lidge-jun

Copy link
Copy Markdown
Owner

Closing in favor of #1208, which adopts this change as-is.

This PR needed no changes. It was independently re-audited against current dev and confirmed correct — the unlimited branch is properly ordered ahead of finite-total validation, expiry is preserved, and the generic customWindows row is what the GUI and CLI already consume. We are rebuilding it on our stack per the sequential-PR convention. You are credited in the commit.

Why it sat: 524 workflow runs were queued awaiting maintainer approval, 39 on open-PR branches including this one. The readiness gate verifies the ci check, and a run that never started has no result to verify — so this could not leave draft no matter what you did. Our backlog, not your PR.

Two observations recorded in #1208, neither blocking: creditsUsd and its expiry are not yet surfaced by the GUI (visibility comes from customWindows), and the unlimited flag accepts true/1/\"true\".

Thanks for catching this — a working key showing as dead is exactly the kind of bug that erodes trust in the dashboard.

@lidge-jun lidge-jun closed this Aug 7, 2026
lidge-jun added a commit that referenced this pull request Aug 7, 2026
Adopted from PR #1171 by @byongshintv, rebuilt on the current stack. Original
closed in favor of this commit.

An unlimited A6API key reports zero finite credit totals. Finite-total
validation then treated that as a terminal failure and returned before the key
could be represented at all, so a perfectly working key looked dead in the
dashboard.

The unlimited branch now runs ahead of that validation and emits the generic
`customWindows` row the GUI and CLI already consume, preserving expiry. It
accepts `true`, `1`, and `"true"` for the upstream flag.

Two known limitations, stated rather than discovered later: `creditsUsd` and
its expiry are not yet surfaced by the GUI — visibility comes from
`customWindows` — and neither changes existing behavior for finite keys.

Confirmed to fail with the unlimited branch disabled.
iF2007 pushed a commit to iF2007/opencodex that referenced this pull request Aug 7, 2026
…-jun#1171)

Adopted from PR lidge-jun#1171 by @byongshintv, rebuilt on the current stack. Original
closed in favor of this commit.

An unlimited A6API key reports zero finite credit totals. Finite-total
validation then treated that as a terminal failure and returned before the key
could be represented at all, so a perfectly working key looked dead in the
dashboard.

The unlimited branch now runs ahead of that validation and emits the generic
`customWindows` row the GUI and CLI already consume, preserving expiry. It
accepts `true`, `1`, and `"true"` for the upstream flag.

Two known limitations, stated rather than discovered later: `creditsUsd` and
its expiry are not yet surfaced by the GUI — visibility comes from
`customWindows` — and neither changes existing behavior for finite keys.

Confirmed to fail with the unlimited branch disabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants