CodexBar icon indicating copy to clipboard operation
CodexBar copied to clipboard

Codex (OAuth): team-account monthly credit limit dropped — wham/usage nests it under spend_control.individual_limit

Open guhyun9454 opened this issue 3 months ago • 1 comments

Summary

On a Codex Team account, the monthly credit limit never reaches the UI/CLI via --source oauth. codexbar usage --provider codex --source oauth --format json emits no credits key at all, even though the account has a 1000 credit monthly pool with 36.79 used.

Root cause is a payload-shape gap, not a missing feature: chatgpt.com/backend-api/wham/usage returns the limit nested under spend_control.individual_limit, while the OAuth decoder only looks at the response root (individual_limit) or rate_limit.individual_limit. The string spend_control does not appear anywhere in the repository.

Environment

CodexBar CLI 0.48.0 (CodexBarCLI-v0.48.0-linux-musl-aarch64)
Codex CLI 0.147.0
OS Linux aarch64 (Ubuntu, Jetson Xavier)
Plan plan_type: team (workspace spend controls)
Source --source oauth (--source web is macOS-only)

Reproduce

codexbar usage --provider codex --source oauth --format json --pretty --no-color

Text output shows no Credits line:

== Codex 0.147.0 (oauth) ==
Weekly: 0% left [------------]
Resets in 14h 40m
Limit Reset Credits: 1 available
Next reset credit expires in 5d 4h
Account: [email protected]
Plan: Team
JSON output (redacted) — no credits key
[
  {
    "provider": "codex",
    "source": "oauth",
    "usage": {
      "accountEmail": "[email protected]",
      "codexResetCredits": {
        "availableCount": 1,
        "credits": [
          {
            "description": "Thanks for using Codex! You've been granted one free rate limit reset.",
            "expires_at": "2026-08-12T17:44:41Z",
            "granted_at": "2026-07-13T17:44:41Z",
            "id": "REDACTED",
            "reset_type": "codex_rate_limits",
            "status": "available",
            "title": "Full reset"
          }
        ],
        "updatedAt": "2026-08-07T15:07:35Z"
      },
      "dataConfidence": "exact",
      "identity": {
        "accountEmail": "[email protected]",
        "loginMethod": "team",
        "providerID": "codex"
      },
      "loginMethod": "team",
      "primary": null,
      "secondary": {
        "resetDescription": "12:53 PM",
        "resetsAt": "2026-08-08T03:53:24Z",
        "usedPercent": 100,
        "windowMinutes": 10080
      },
      "tertiary": null,
      "updatedAt": "2026-08-07T15:07:35Z"
    },
    "version": "0.147.0"
  }
]

Actual upstream payload (redacted)

Same account, same moment, GET https://chatgpt.com/backend-api/wham/usage with the OAuth access token from ~/.codex/auth.json:

wham/usage response (redacted)
{
  "user_id": "user-REDACTED",
  "account_id": "REDACTED",
  "email": "[email protected]",
  "plan_type": "team",
  "rate_limit": {
    "allowed": false,
    "limit_reached": true,
    "primary_window": {
      "used_percent": 100,
      "limit_window_seconds": 604800,
      "reset_after_seconds": 45962,
      "reset_at": 1786161204
    },
    "secondary_window": null
  },
  "code_review_rate_limit": null,
  "additional_rate_limits": null,
  "credits": {
    "has_credits": true,
    "unlimited": false,
    "overage_limit_reached": false,
    "balance": null,
    "approx_local_messages": null,
    "approx_cloud_messages": null
  },
  "spend_control": {
    "reached": false,
    "individual_limit": {
      "source": "workspace_spend_controls",
      "limit": "1000",
      "used": "36.79748725891113",
      "remaining": "963.2025127410889",
      "used_percent": 4,
      "remaining_percent": 96,
      "reset_after_seconds": 2105558,
      "reset_at": 1788220800
    }
  },
  "rate_limit_reached_type": null,
  "promo": null,
  "rate_limit_reset_credits": {
    "available_count": 1,
    "applicable_available_count": 1
  }
}

Note rate_limit.individual_limit is absent and credits.balance is null, so mapCredits sees balance == nil && creditLimit == nil and returns nil — which is why the whole credits object disappears from the payload rather than showing a zero.

Where it breaks

  1. CodexOAuthUsageFetcher.CodexUsageResponse.init(from:) decodes individual_limit / individualLimit from the response root only; there is no spend_control coding key.
  2. CodexProviderDescriptor.mapCredits then evaluates (response.individualLimit ?? response.rateLimit?.individualLimit)?.codexCreditLimitSnapshot(updatedAt:) → nil.
  3. guard balance != nil || creditLimit != nil else { return nil } drops the CreditsSnapshot, so CLIRenderer.appendCreditsLine prints nothing and the JSON payload omits credits.

Everything downstream (CodexSpendControlLimitMapping, CodexCreditLimitSnapshot, the Credits renderer line) already works — it just never receives a value.

Secondary: reset_at vs resets_at

SpendControlLimitSnapshot accepts resetsAt / resets_at, but this payload spells it reset_at (matching WindowSnapshot.resetAt). So even after the nesting is handled, the reset timestamp decodes as nil unless that spelling is accepted too.

Proposed fix

Decode spend_control.individual_limit as an additional fallback in the existing resolution chain, and accept reset_at in SpendControlLimitSnapshot. Both are additive and cannot disturb payloads that already work.

Happy to send a PR with tests — will follow up shortly.

Note on verification

I do not have a macOS or Swift toolchain on the machine that reproduced this (Linux aarch64), so the evidence above is from the released 0.48.0 musl CLI plus direct API reads. Repro fixtures for the new shape are included in the PR as decoder tests.

guhyun9454 avatar Aug 07 '26 15:08 guhyun9454

Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed August 7, 2026, 6:19 PM ET / 22:19 UTC.

Summary Keep this issue open: current main still omits the nested Team spend-control limit, and the explicitly linked open PR is a focused, clean, proof-backed fix candidate. Likely related people: steipete (medium confidence, current OAuth-decoder history).

Reproducibility: yes. The released v0.48.0 output and redacted upstream Team payload are consistent with the current decoder and mapping path, which source inspection shows cannot handle the nested key.

Root-cause cluster Relationship: canonical Canonical: https://github.com/steipete/codexbar/issues/2736 Summary: This issue is the canonical report; the linked pull request is the focused candidate repair for the same decoder gap.

Members:

  • fixed_by_candidate: https://github.com/steipete/codexbar/pull/2737 - The open PR explicitly links this issue and implements the reported nested spend-control decoding and reset timestamp support.

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Next step The explicitly linked open PR already owns this focused repair, so another fix branch would duplicate the contributor’s work.

Review details

Best possible solution:

Review and land the linked PR with its additive fallback order and decoder fixtures, then ship the correction in the next release.

Do we have a high-confidence way to reproduce the issue?

Yes. The released v0.48.0 output and redacted upstream Team payload are consistent with the current decoder and mapping path, which source inspection shows cannot handle the nested key.

Is this the best way to solve the issue?

Yes. The linked PR uses the narrowest compatible repair: add the missing nested fallback and reset spelling while retaining existing root and rate-limit precedence with regression coverage.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 22b24b885693.

Label changes

Label justifications:

  • P2: This is a bounded provider-decoding defect that suppresses monthly credit visibility for affected Codex Team accounts without disrupting core runtime availability.
  • impact:auth-provider: The affected OAuth usage-response decoder and provider credit mapping determine which Codex account-limit data reaches users.
Evidence reviewed

What I checked:

Likely related people:

  • steipete: Current decoder lines and adjacent credit-limit support trace to Peter Steinberger's release-baseline commit; the available history identifies this as the strongest current-main ownership signal. (role: recent OAuth decoder contributor; confidence: medium; commits: 5bd587850611; files: Sources/CodexBarCore/Providers/Codex/CodexOAuth/CodexOAuthUsageFetcher.swift, Sources/CodexBarCore/Providers/Codex/CodexProviderDescriptor.swift)
How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

clawsweeper[bot] avatar Aug 07 '26 15:08 clawsweeper[bot]