Skip to content

feat(oauth): report an explicit account plan field for OAuth providers - #4146

Merged
lidge-jun merged 1 commit into
devfrom
codex/anthropic-account-plan-3777
Sep 9, 2026
Merged

lidge-jun merged 1 commit into
devfrom
codex/anthropic-account-plan-3777

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Sep 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #3777.

The OpenAI/Codex provider reports a per-account plan string, so a consumer can weight each account's remaining quota by its seat size. The OAuth providers reported no such field at all, so a multi-account Anthropic pool had no meaningful aggregate capacity number and every account looked identical in tier terms. The reporter was maintaining a hand-written account-id to tier map that silently rots whenever a subscription changes.

plan is now reported on the OAuth account summary, the management route (GET /api/oauth/accounts) and the CLI DTO (ocx account list <provider> --json), using the same field name and placement as the Codex side so consumers need no per-provider branching.

The field is always present, and null when the tier is unknown. That distinction is the substance of the change, not a detail: an absent key means the proxy predates this field, while null means this version looked and the provider did not report a tier. Collapsing the two is what lets a consumer quietly assume a tier, which is the failure mode the issue describes. The CLI forwards the server's answer verbatim rather than normalizing null away.

For Anthropic the value is null, and that is upstream, not unfinished

Stating this plainly so a future reader does not read it as an oversight or a TODO.

GET https://api.anthropic.com/api/oauth/usage returns quota buckets only — five_hour, seven_day, the model-scoped weekly windows (seven_day_fable/_opus/_sonnet) and a limits array — and carries no subscription or tier field. The OAuth token response carries none either: src/oauth/anthropic.ts gets account.uuid and account.email_address and nothing else. There is no tier in anything this proxy receives, so nothing is mapped.

No tier is inferred from what is there, and the issue is explicit about why that would be wrong. Quota percentages are normalized per account, so a Max x5 seat at 50% is byte-identical to a Max x20 seat at 50%. The presence of a model-scoped weekly window tracks entitlement rather than seat size, so keying a tier off it would produce a confident wrong answer that is indistinguishable from data. A guess here is worse than null, because null is something a consumer can handle correctly and a wrong tier is not.

The reasoning is recorded in a comment at fetchAnthropicUsageQuota and in the providers guide, so the next person to look does not re-derive it. If upstream later returns the tier, populating this field is a one-line change at that call site with no contract change anywhere above it.

Issue item 4 (surfacing the tier in the dashboard Anthropic rows) is deliberately not included. There is nothing to display while every value is null, so it would be a GUI change with no user-visible effect; it belongs with the upstream field if it appears.

Verification

  • Local checks were NOT RUN, per maintainer instruction for this lane — no bun run test, test:changed, typecheck, build:gui, lint:gui or bun install. The exact-head remote CI on this PR is the gate, and the branch was pushed with --no-verify.
  • Added tests/oauth/oauth-accounts-api.test.ts -> "GET reports an explicit null plan for an Anthropic account", which asserts "plan" in account and plan === null. Asserting presence separately from the value is what pins the contract this change exists to create; a test that only checked the value would still pass if the key were dropped.
  • Documented in docs-site/src/content/docs/guides/providers.md under "Switching accounts from the terminal". English only; no translated locale is contradicted, since none of them describe this field.
  • No gui/ files are touched.

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. This touches src/oauth/index.ts, so specifically: the added field is a constant null and carries no credential-derived data; no token, refresh grant, account id or email reaches a new surface; the account summary's existing email masking is untouched; and the change is read-only with respect to the credential store.

Summary by CodeRabbit

  • New Features

    • Account listings now include a plan field for every OAuth account.
    • The field is explicitly null when the subscription tier is unknown, including for Anthropic accounts.
  • Documentation

    • Added guidance explaining the plan field, its possible values, and compatibility behavior across account-listing interfaces.
  • Tests

    • Added coverage verifying that Anthropic account listings include plan: null when no tier is available.

The OpenAI/Codex provider reports a per-account plan string, so a consumer can
weight each account's remaining quota by its seat size. The OAuth providers
reported no such field at all, so a multi-account Anthropic pool had no
meaningful aggregate capacity number and every account looked identical in tier
terms.

Add plan to the OAuth account summary, the management route response and the
CLI DTO, using the same name and placement as the Codex side so consumers need
no per-provider branching.

The field is always present and is null when the tier is unknown. That
distinction is the point: an ABSENT key means the proxy predates the field,
while null means this version looked and the provider did not report a tier.
Omitting it collapses the two and invites a consumer to assume a tier -- which
is exactly the workaround the reporter was maintaining by hand.

For Anthropic the value is null today, and that is an upstream gap rather than
an unfinished mapping. /api/oauth/usage returns quota buckets only (five_hour,
seven_day, the model-scoped weekly windows and limits[]) with no subscription
or tier field, and the OAuth token response yields only account.uuid and
account.email_address. No tier is inferred from what is there: quota
percentages are normalized per account, so a Max x5 seat at 50% is
indistinguishable from a Max x20 seat at 50%, and a model-scoped window tracks
entitlement rather than seat size. The reasoning is recorded at
fetchAnthropicUsageQuota so a future reader does not read null as an oversight.

Closes #3777
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner September 9, 2026 16:10
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the enhancement New feature or request label Sep 9, 2026
@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 634940ed-6980-461c-afea-875a84856461

📥 Commits

Reviewing files that changed from the base of the PR and between 71a0c30 and 2c4393b.

📒 Files selected for processing (5)
  • docs-site/src/content/docs/guides/providers.md
  • src/cli/account-api.ts
  • src/oauth/index.ts
  • src/providers/quota.ts
  • tests/oauth/oauth-accounts-api.test.ts

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


📝 Walkthrough

Walkthrough

The change adds a nullable plan field to OAuth account summaries, preserves explicit null values in account listings, documents Anthropic’s unknown tier, and adds API coverage for the response shape.

Changes

OAuth account plan field

Layer / File(s) Summary
OAuth summary plan contract
src/oauth/index.ts, src/providers/quota.ts
OAuthAccountSummary.plan is now required and nullable. getLoginStatus sets it to null. Anthropic quota documentation states that no tier is inferred from quota data.
Account API plan projection
src/cli/account-api.ts, tests/oauth/oauth-accounts-api.test.ts, docs-site/src/content/docs/guides/providers.md
Account row types accept nullable plans. OAuth row mapping preserves null. The Anthropic API test verifies that the plan key is present and null. Provider documentation describes the field contract.

Priority: ➖ Normal

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

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 2c439

The nullable OAuth plan behavior is implemented, but the added API test currently fails to compile because of a duplicate declaration. Fix this before merge.

Suggested reviewers: luvs01

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. (1 skipped: 1… 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: adding an explicit account plan field for OAuth providers.
Linked Issues check ✅ Passed The changes satisfy issue #3777 by adding a consistently named plan field to OAuth account summaries, the API response, and CLI DTOs. The field is always present and preserves null when Anthropic prov…
Out of Scope Changes check ✅ Passed The changes in docs-site/src/content/docs/guides/providers.md, src/cli/account-api.ts, src/oauth/index.ts, src/providers/quota.ts, and tests/oauth/oauth-accounts-api.test.ts directly support the plan-…
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/anthropic-account-plan-3777

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.

@lidge-jun

Copy link
Copy Markdown
Owner Author

리뷰 · 우선순위 58 / 80

설명

이 PR은 이슈 #3777을 닫으려는 계약(contract) 작업이다. 지금 dev 팁은 aff8a222b이고, 직전에 랜딩한 #4142 패스스루 web-search 브리지와는 다른 축이다. 여기는 OAuth 계정 목록 쪽이다.

문제의 핵심은 이렇다. OpenAI/Codex 쪽은 이미 계정마다 plan 문자열을 준다. 그래서 여러 계정을 묶을 때 좌석 크기(프로/플러스 등)로 남은 쿼터를 가중할 수 있다. 그런데 Anthropic 같은 OAuth 계정 목록에는 plan 키 자체가 없다. 키가 없으면 소비자는 “옛 프록시라서 아직 필드가 없다”와 “이번 버전이 찾아봤는데 티어를 모른다”를 구별하지 못한다. 그 틈으로 사람들이 계정 id→티어 손지도를 만들고, 구독이 바뀌면 그 지도가 조용히 썩는다. 이슈가 정확히 그걸 말하고 있다.

이 PR이 하는 일은 단순하다. src/oauth/index.ts의 OAuthAccountSummary에 plan: string | null을 넣고, getLoginStatus가 계정마다 항상 plan: null을 붙인다. 관리 API GET /api/oauth/accounts는 src/server/management/oauth-account-routes.ts에서 getLoginStatus의 summary를 그대로 펼치므로, 서버 JSON에도 키가 생긴다. CLI src/cli/account-api.ts의 AccountRow / OAuthAccountDto도 string | null을 받게 바꾸고, ocx account list <provider> --json이 그 값을 넘긴다. Codex와 같은 필드 이름·위치를 맞춰서 소비자 쪽 분기 코드를 줄이려는 설계다.

Anthropic 값이 오늘 null인 이유는 미완성이 아니라 업스트림 공백이다. src/providers/quota.ts의 fetchAnthropicUsageQuota 주석과 providers 가이드에 적힌 대로, /api/oauth/usage는 five_hour / seven_day / 모델별 주간 창과 limits[]만 주고 구독·티어 필드는 없다. 토큰 응답도 account.uuid와 이메일뿐이다. 퍼센트는 계정마다 0–100으로 정규화되므로 Max×5의 50%와 Max×20의 50%가 바이트 단위로 같다. 그래서 추측 매핑을 넣지 않은 판단은 맞다. 대시보드 Anthropic 행에 티어를 그리는 이슈 항목 4도, 전부 null인 지금은 GUI 변경 효과가 없어서 일부러 빼 둔 것도 타당하다.

현재 dev 방향(계정 건강/쿼터/패스스루 도구)과 겹치지 않는 독립 레인이다. types.ts/config.ts 대형 분리 캠페인에도 걸리지 않는다. 로컬 테스트는 메인테이너 지시로 안 돌렸고, tests/oauth/oauth-accounts-api.test.ts에 “키가 있고 값이 null”을 따로 고정한 테스트가 있다. 원격 CI가 게이트다. 우선순위 58은 “계약은 열리지만, 이슈가 원한 가중 용량 숫자 자체는 아직 안 나온다”는 점수다. 소비자는 여전히 외부 티어 지도가 필요하다. 다만 absent vs null 구분과 Codex 정렬은 지금 심어 두는 게 맞고, 업스트림이 티어를 주면 그 위에 채우면 된다.

라인 src/cli/account-api.ts fetchOAuthRows - plan: a.plan ?? null 은 서버가 키를 아예 안 보낸 옛 프록시(undefined)까지 CLI에서 null로 바꿔 버린다. PR 본문은 “서버 답을 그대로 전달”이라고 하는데, absent→null 정규화는 그 구분(옛 프록시 vs 이번 버전이 찾아봄)을 CLI 출력에서 다시 무너뜨린다. 새 서버와 짝이면 서버가 이미 null을 주니 실해는 작지만, 새 CLI + 옛 프록시 조합에서는 거짓으로 “찾아봤다”가 된다. ("plan" in a ? a.plan : undefined) 또는 키가 있을 때만 넣는 편이 계약 설명과 일치한다.
라인 src/oauth/index.ts getLoginStatus - 모든 OAuth 제공자에 plan: null을 하드코드한다. 지금은 맞다. 그런데 PR/주석은 업스트림이 티어를 주면 fetchAnthropicUsageQuota 한 줄이면 된다고 한다. 실제 목록 경로는 쿼터 프로브와 분리되어 있다. 티어가 usage 응답에만 생기면 oauth-account-routes의 쿼터 enrichment나 자격 증명 저장 시점에 plan을 심는 배선이 한 줄 이상 필요하다. “한 줄” 주석은 과대광고에 가깝다.
경로 OAuthAccountSummary.plan - 서버 타입은 필수 plan: string | null인데 CLI DTO는 선택 plan?: string | null이다. 의도된 버전 스큐 허용이면 괜찮지만, “항상 존재” 계약을 CLI 타입만 보면 덜 단단하다. 문서와 테스트를 서버 JSON 기준으로 읽는 한 실해는 작다.
경로 이슈 #3777 항목 2 - “Anthropic이 이미 노출하는 구독 정보로 채운다”는 항목은 업스트림에 필드가 없어 충족 불가이고, PR이 그걸 명시했다. 항목 1·3(필드 추가 + 명시적 null)은 충족, 항목 4(대시보드)는 의도적 제외. 이슈를 closes로 닫으면 “가중 용량이 된다”로 읽힐 수 있으니, 닫을 때 댓글로 “계약만 열림 / 가중은 업스트림 이후”를 남기는 편이 안전하다.
경로 gui/ - GUI를 안 건드린 선택은 맞다. 전부 null이면 표시할 값이 없다. 나중에 업스트림 티어가 오면 그때 Anthropic 행에 붙이면 된다.

메인테이너의 판단이 필요한 지점

  • 이슈 #3777을 이 PR만으로 closes 할지, 아니면 “계약 절반 / 업스트림 대기”로 남기고 대시보드·실티어 채움을 후속 이슈로 쪼갤지.
  • 새 CLI가 옛 프록시를 말할 때 absent→null 정규화를 허용할지, 아니면 키 존재 여부를 그대로 보존할지.
  • 업스트림 티어가 생겼을 때 plan을 자격 증명 저장 시점에 심을지, 쿼터 probe enrichment에 심을지(지금 summary 경로는 하드코드 null).

너의 추천
CI 통과하면 병합해도 좋다. 범위가 작고, absent/null 계약과 Codex 정렬은 지금 심는 게 맞다. 다만 머지 전에 fetchOAuthRows의 a.plan ?? null을 키 존재 보존 형태로 고치거나, “CLI는 항상 null을 노출한다(서버 버전과 무관)”고 문서/주석을 솔직히 고치는 쪽 중 하나를 고르라. 머지 후 #3777 닫을 때 “가중 용량은 아직 외부 지도 또는 업스트림 티어 필요” 한 줄을 남기라. GUI/실티어 채움은 후속.

이 댓글은 grok-bot이 작성했습니다

@lidge-jun
lidge-jun merged commit 6d99a18 into dev Sep 9, 2026
31 checks passed
@lidge-jun
lidge-jun deleted the codex/anthropic-account-plan-3777 branch September 9, 2026 20:43
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
…unt-plan-3777

Closes lidge-jun#3777. Adds an explicit plan field to the OAuth account summary, the management route, the CLI DTO and the Anthropic dashboard rows, matching how the OpenAI provider already exposes plan.\n\nThe Anthropic usage endpoint carries no subscription tier field, so Anthropic accounts land plan: null rather than a tier inferred from usage percentages. That is recorded at the source and in the docs so a future reader does not read null as an oversight, and a test pins the present-versus-null distinction.\n\nExact-head CI at dae5d14: Cross-platform CI success, enforce-target success x2, PR hygiene success x2, PR Labeler success x2, React Doctor success.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant