Skip to content

Port v0.60.4 OpenRouter credits fallback - #514

Merged
Finesssee merged 3 commits into
mainfrom
codex/port-upstream-0.60.4-accounting
Sep 18, 2026
Merged

Finesssee merged 3 commits into
mainfrom
codex/port-upstream-0.60.4-accounting

Conversation

@Finesssee

@Finesssee Finesssee commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve the selected OpenRouter API key's quota and spend windows when account-level /credits is unavailable.
  • Label the fallback as API key limit and keep the account balance explicitly unavailable.
  • Keep the original credits error when the key response has no usable limit, without fabricating a balance.

Upstream reference

  • CodexBar v0.60.4 commit 0cbaaea11 (OpenRouter credits fallback).

Validation

  • cargo fmt --all
  • cargo test --manifest-path rust/Cargo.toml providers::openrouter — 19 passed
  • cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings
  • cargo test --manifest-path rust/Cargo.toml --quiet — 1,822 passed, 1 ignored

This PR is intentionally left unmerged for review.

Summary by CodeRabbit

  • Bug Fixes
    • Usage information remains available when account-level credit data cannot be retrieved, provided API key quota data is usable.
    • API key limits now appear consistently as a separate quota indicator in normal, fallback, and recovered states.
    • Available daily, weekly, and monthly spending details are preserved in fallback views without duplicating quota information.
    • Improved handling for accounts without configured usage limits and restored the correct usage state after service recovery.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 23540547-5f9f-445f-a70b-a6d89f6855ed

📥 Commits

Reviewing files that changed from the base of the PR and between ec785f9 and e9c2f57.

📒 Files selected for processing (1)
  • rust/src/providers/openrouter/mod.rs

Included review availability: Your plan provides up to 4 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The OpenRouter provider concurrently fetches credits and key data. It resolves normal and fallback usage through stable primary and secondary lanes. Tests cover quota behavior across normal, fallback, and recovered states.

Changes

OpenRouter usage handling

Layer / File(s) Summary
Quota and spend helpers
rust/src/providers/openrouter/mod.rs
Fallback usage now uses an informational primary window. API key quota uses a secondary API key limit window. Spend windows are added through the shared lane helper. Tests verify normal, fallback, and recovered states.
Concurrent usage resolution
rust/src/providers/openrouter/mod.rs
fetch_usage_api concurrently fetches /credits and /key, then passes both results to resolve_usage. The resolver returns credits usage when available, or a key-quota fallback when credits fail and usable quota exists.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant fetch_usage_api
  participant OpenRouterCredits
  participant OpenRouterKey
  participant resolve_usage
  participant UsageSnapshot
  fetch_usage_api->>OpenRouterCredits: request account credits
  fetch_usage_api->>OpenRouterKey: request key quota
  OpenRouterCredits-->>fetch_usage_api: credits result
  OpenRouterKey-->>fetch_usage_api: key result
  fetch_usage_api->>resolve_usage: resolve both results
  alt credits succeed
    resolve_usage->>UsageSnapshot: build credits usage and add quota and spend windows
  else credits fail with usable quota
    resolve_usage->>UsageSnapshot: build fallback usage and add spend windows
  end
Loading

Merge Risk: ⚪ Minimal · up to e9c2f

The fallback preserves account-balance and API-key quota states without introducing an actionable current-head failure.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: porting the OpenRouter credits fallback from v0.60.4.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Thermo-nuclear code-quality review

Reviewed head ec785f9 against main using the full thermo-nuclear maintainability rubric.

P2 — API-key lane composition is duplicated across recovery paths

rust/src/providers/openrouter/mod.rs:309-315 builds the fallback secondary lane and label directly, while :419-426 builds the same lane and label again in add_key_quota; resolve_usage then separately appends spend windows at :297-300. Keep API-key lane composition in one helper with an explicit account-availability state, so labels and metadata cannot drift between healthy and degraded paths.

@Finesssee
Finesssee force-pushed the codex/port-upstream-0.60.4-accounting branch from e9c2f57 to 7dcb601 Compare September 18, 2026 15:10
@Finesssee
Finesssee merged commit 89b66f1 into main Sep 18, 2026
3 checks passed
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.

1 participant