Skip to content

fix(quota): isolate thrown vendor quota probe errors in /api/provider-quotas - #8948

Merged
lidge-jun merged 2 commits into
lidge-jun:devfrom
EnesKartal:fix/provider-quotas-isolate-probe-errors
Nov 20, 2026
Merged

lidge-jun merged 2 commits into
lidge-jun:devfrom
EnesKartal:fix/provider-quotas-isolate-probe-errors

Conversation

@EnesKartal

@EnesKartal EnesKartal commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Root cause: In src/providers/quota.ts, maybeFetchProviderQuota() wraps provider quota probes in ry { ... } catch { return null; }, but four async branches ( etchChatGptForwardQuota, etchAnthropicQuota, etchKiroQuota, and
    eader(...) for key-based vendor probes such as OpenRouter and DeepSeek) returned their promises without ^Gwait. When any of those probes threw a network error (e.g. ECONNRESET or ENOTFOUND), the rejected promise bypassed the catch block and rejected the Promise.all in etchProviderQuotaReports(), failing the entire GET /api/provider-quotas response.
  • Fix: Add ^Gwait to all four
    eturn statements inside maybeFetchProviderQuota() so per-provider probe rejections are caught and normalized to
    ull (preserving bounded last-good cached rows on transient failures and returning healthy providers' reports).
  • Tests: Added ests/providers/provider-quota-probe-isolation.test.ts (and registered it in scripts/test-layout/layout-providers.json and ests/fixtures/test-layout-expected.json) covering OpenRouter ECONNRESET, DeepSeek ENOTFOUND, last-good cache preservation on transient throws, all-failing probes, and etchProviderApiKeyQuotas isolation.

Fixes #8939

Verification

  • bun test tests/providers/provider-quota-probe-isolation.test.ts tests/providers/deepseek-quota-currency.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts — 40 pass, 0 fail
  • bun test tests/providers/provider-quota.test.ts — 171 pass, 0 fail
  • bun run typecheck — no type errors in 2,645 files
  • bun run structure:check — passed

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Summary by CodeRabbit

  • Bug Fixes
    • Provider quota results now wait for quota checks to finish before being returned. A failed check for one provider no longer prevents other providers’ quota results from being reported.
    • When a provider check fails temporarily, its most recent successful quota report is retained while results from other providers can still update. API-key quota fetch failures are reported as unavailable rather than interrupting the results.

Maintainer completion (lidge-jun)

I finished this draft for the fb-contrib-queue lane. d7fbf4cb45 merges current dev into the branch with a merge commit; there is no force push and no source change beyond the merge. Validation on d7fbf4cb45: provider-quota-probe-isolation, provider-quota and the layout/size guards: 214 pass, 0 fail. Fail-before (independent terra review): with the merge-base src/providers/quota.ts, the OpenRouter ECONNRESET and DeepSeek ENOTFOUND cases throw out of /api/provider-quotas. Security: the catch discards the thrown value without logging it; a synthetic error URL containing a key does not reach the response or the console. Full local suite: NOT RUN (resource exception); CI covers it.

Review readiness checklist

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

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The quota reader now awaits selected vendor and API-key quota calls. Added tests cover transport failures, retained reports, all-probe failures, and API-key failure rows. The new test is registered in the provider layout mapping and expected fixture.

Changes: Provider quota probe handling

Layer / File(s) Summary
Await quota reader calls
src/providers/quota.ts
The ChatGPT-forward, configured Anthropic, Kiro, and key-quota reader calls are awaited before their results are returned.
Test probe failure outcomes
tests/providers/provider-quota-probe-isolation.test.ts, scripts/test-layout/layout-providers.json, tests/fixtures/test-layout-expected.json
Tests cover OpenRouter and DeepSeek transport failures, retention of the last-good OpenRouter report while DeepSeek updates, an empty report list when all vendor probes fail, and an unavailable API-key row with a null quota. The test is added to the provider layout mapping and expected fixture.

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

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to d7fbf

This change prevents one vendor's network error from failing the whole provider quota report. Reports from healthy providers are returned, and tests cover the failure cases. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: thrown vendor quota probe errors are isolated so that /api/provider-quotas does not fail as a whole. The raw summary confirms the change to maybeFetchProviderQuota in …
Linked Issues check Passed [#8939] requires that one failing vendor quota probe does not fail GET /api/provider-quotas. The whole-PR diff (merge base 3bc34e6 to head d7fbf4c) changes only src/providers/quota.ts in source code. …
Out of Scope Changes check Passed The whole-PR source diff for src/providers/quota.ts contains only the four added await keywords inside maybeFetchProviderQuota(). These directly implement [#8939]. No other hunk exists in that file.…
Full details: Title check

Explanation

The title names the main change: thrown vendor quota probe errors are isolated so that /api/provider-quotas does not fail as a whole. The raw summary confirms the change to maybeFetchProviderQuota in src/providers/quota.ts, where four promise-returning branches now await their fetches so that rejections are caught per provider. The PR objectives describe the same goal, tied to issue #8939. The title is specific, uses the conventional fix(scope) form, and stays under typical length limits.

Full details: Linked Issues check

Explanation

[#8939] requires that one failing vendor quota probe does not fail GET /api/provider-quotas. The whole-PR diff (merge base 3bc34e6 to head d7fbf4c) changes only src/providers/quota.ts in source code. In maybeFetchProviderQuota(), four promise-returning branches now use return await: fetchChatGptForwardQuota (hunk @@ -123,12 +123,12 @@), fetchAnthropicQuota for configured Anthropic instances, fetchKiroQuota for kiro, and reader(name, { ...provider }) (hunk @@ -138,7 +138,7 @@). Before the change these returned unawaited promises, so a rejection bypassed the enclosing try/catch, which returns null. With the awaits, a thrown ECONNRESET or ENOTFOUND from a key-based probe becomes null for that provider only. Promise.all in fetchProviderQuotaReports therefore resolves with the healthy providers' reports. The issue accepts omission or an error/unknown marker for the failing provider, and null yields omission. The fetchProviderApiKeyQuotas path also goes through maybeFetchProviderQuota. The new test file tests/providers/provider-quota-probe-isolation.test.ts exists at head. I read it. It asserts OpenRouter ECONNRESET isolation, DeepSeek ENOTFOUND isolation, last-good cache preservation with a transient OpenRouter throw, all-probes-failing returning an empty list, and fetchProviderApiKeyQuotas returning one unavailable row with null quota. I did not run these tests. The reader-to-collectOwnedReport call path shown in the issue stack trace (src/providers/quota/report-cache.ts) was not re-read in this review. Confidence in the mechanism rests on the awaited return inside the try block and on the test assertions.

Full details: Out of Scope Changes check

Explanation

The whole-PR source diff for src/providers/quota.ts contains only the four added await keywords inside maybeFetchProviderQuota(). These directly implement [#8939]. No other hunk exists in that file. The supporting changes are scripts/test-layout/layout-providers.json and tests/fixtures/test-layout-expected.json, which register the new test file for the repository layout checks, and tests/providers/provider-quota-probe-isolation.test.ts, which covers the fix. The test file contents match the isolation objectives and contain no unrelated behavior. The merge with dev (head d7fbf4c, per the maintainer note) adds no source change beyond the merge in the reviewed diff. I did not read the two layout JSON files in this review. Their scope is inferred from the raw summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 30fd494 and d7fbf4c.

Files selected for processing: 1

  • tests/fixtures/test-layout-expected.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ✅ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

✅ 4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers: @lidge-jun @Ingwannu

Hygiene

✅ Deterministic PR hygiene checks passed.

@github-actions
github-actions Bot marked this pull request as draft November 19, 2026 08:36
@lidge-jun
lidge-jun marked this pull request as ready for review November 20, 2026 18:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T18:41:12.588460Z d7fbf4c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer integration (lidge-jun, dev) on exact head d7fbf4cb4544083a4fcbb9f0493a7c85cf69fffb.

  • Independent review: terra reviewer (gpt-6.1-terra) APPROVE across rounds 1–3. Round 3 confirmed that the dev merge commit equals the automatic merge tree (no conflict-resolution edits). Fail-before: with the merge-base src/providers/quota.ts, the OpenRouter ECONNRESET and DeepSeek ENOTFOUND probes throw out of /api/provider-quotas. Security: the catch discards the thrown value without logging it; a synthetic secret-bearing error URL reaches neither the response nor the console.
  • Required checks, all successful on this head: gates, test changed, Catalog async contracts, enforce-target, hygiene, label, CodeRabbit (runs: PR gates 44794787152, PR gates 44794434435, Catalog async contracts 44794324724, ocx-ci-v1 lane=all sha=87b0a118d3667b1198d7e0691754465d416e4c96 44794324857, PR gates 44794321080).
  • Union check against current dev (git merge-tree --write-tree origin/dev d7fbf4cb45): clean. No touched file exceeds its file-size cap in the merged tree.
  • Fork CI approval: the diff changes no .github/**, workflow-executed scripts or install hooks. Approval-gated workflows run on pull_request with read-only permissions and no secrets.

Verification

  • Focused: provider-quota-probe-isolation, provider-quota, DeepSeek quota and the layout/size guards: 220 pass, 0 fail. Typecheck and structure:check pass. This lane finished the draft (dev merge, readiness checklist).
  • Overlap: draft Discover Antigravity CLI models and display account quota windows #8990 also edits src/providers/quota.ts and is outside this lane; whichever lands second re-verifies.
  • Full local suite: NOT RUN (resource exception; parallel lane worktrees on one host). CI test changed covers import-connected tests, and the batched dev dispatch covers the full and cross-platform suites.

@lidge-jun
lidge-jun merged commit d9120df into lidge-jun:dev Nov 20, 2026
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /api/provider-quotas fails as a whole when a single vendor quota probe throws (OpenRouter ECONNRESET, DeepSeek ENOTFOUND)

2 participants