Skip to content

[WRONG BRANCH] codex: tolerate non-string account plan values in quota and routing - #230

Closed
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-non-string-codex-plan-handling
Closed

[WRONG BRANCH] codex: tolerate non-string account plan values in quota and routing#230
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-non-string-codex-plan-handling

Conversation

@luvs01

@luvs01 luvs01 commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Recent changes normalized plan with plan?.trim() which throws when plan is not a string, allowing malformed persisted or upstream plan values to crash quota projection and routing.
  • The intent is to make quota projection and routing robust to operator-controlled or upstream-malformed plan values without changing behavior for legitimate string plans like "go" and "free".

Description

  • Change isThirtyDayOnlyPlan to accept unknown and only normalize when typeof plan === "string", avoiding trim() on non-strings.
  • Change computeCodexUsageScore to accept plan?: unknown and apply the same runtime string guard before trimming and lower-casing.
  • Add regression tests: tests/codex-auth-api.test.ts now includes GET /api/codex-auth/accounts tolerates a non-string persisted plan, and tests/codex-routing.test.ts adds usage score tolerates a non-string persisted plan.
  • Preserve existing behavior for string plans ("go"/"free") and otherwise treat malformed plans conservatively (as unknown) so quota/routing falls back to existing safe paths.

Testing

  • Ran git diff --check and bun run typecheck with no new type errors observed.
  • Ran focused tests with bun run test tests/codex-auth-api.test.ts tests/codex-routing.test.ts and the modified test files passed.
  • Ran bun run privacy:scan which completed successfully.
  • Observed that a full bun run test execution in this environment progressed but hit unrelated timeouts in other large suites; the targeted tests for this change were executed and passed.

Codex Task

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of accounts with unexpected plan values.
    • Preserved account access and weekly/monthly quota information when plan data is not in the expected format.
    • Maintained standard quota scoring behavior across supported plan values.
  • Tests

    • Added coverage for numeric and object-based plan values to prevent regressions.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change makes plan normalization tolerate non-string persisted values. Account responses preserve quota data, and usage scoring falls back to weekly quota behavior. New regression tests cover object and numeric plan values.

Changes

Plan type tolerance

Layer / File(s) Summary
Guard plan normalization
src/codex/auth-api.ts, src/codex/routing.ts
isThirtyDayOnlyPlan and computeCodexUsageScore accept unknown plan values and normalize them only when they are strings.
Validate non-string plans
tests/codex-auth-api.test.ts, tests/codex-routing.test.ts
Regression tests verify that invalid persisted plan values do not break account responses or alter weekly quota scoring.

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

Suggested reviewers: lidge-jun, wibias, ingwannu

🚥 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 summarizes the main change: Codex now tolerates non-string account plan values in quota handling and routing.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-non-string-codex-plan-handling

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

@github-actions github-actions Bot added the bug Something isn't working label Aug 9, 2026
@github-actions github-actions Bot changed the title codex: tolerate non-string account plan values in quota and routing [WRONG BRANCH] codex: tolerate non-string account plan values in quota and routing Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions
github-actions Bot marked this pull request as draft August 9, 2026 09:58
@luvs01 luvs01 closed this Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant