Skip to content

feat(reset-credits): add banked rate-limit reset credits#1053

Open
huzky-v wants to merge 34 commits into
Soju06:mainfrom
huzky-v:feat/banked-reset
Open

feat(reset-credits): add banked rate-limit reset credits#1053
huzky-v wants to merge 34 commits into
Soju06:mainfrom
huzky-v:feat/banked-reset

Conversation

@huzky-v

@huzky-v huzky-v commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

UPDATE: tested redeeming a reset credit, and it is a success, so I am updating it to Ready to Review
May need a several pass of codex review to truly ready.

Summary

Adds banked rate-limit reset credit support across the backend and dashboard so operators can see per-account credit counts, expiry timing, and redeem the soonest-expiring credit without leaving codex-lb.

Type of change

  • fix: — bug fix (no behavior change beyond the bug)
  • feat: — new user-facing feature or capability
  • refactor: — internal refactor (no behavior change, no API change)
  • docs: — documentation only
  • chore: / ci: / build: — tooling, CI, packaging
  • test: — test-only change
  • Breaking change (also append ! after the type, e.g. feat!: or include BREAKING CHANGE: footer)

Linked issue: None specified.

OpenSpec

  • This PR includes / updates an OpenSpec change
  • Not applicable — bug fix that matches the existing spec
  • Not applicable — docs / CI / chore only
  • This PR touches a codex-faithful path (image pipeline, request/response
    shape, SSE framing, OAuth flow) and preserves upstream-equivalent behavior

Change directory: openspec/changes/add-rate-limit-reset-credits/

Changes

  • Backend: add a new upstream client, in-memory snapshot store, and lifespan-managed refresh scheduler for /wham/rate-limit-reset-credits, plus a dashboard consume endpoint that serializes per-account redemption and invalidates stale snapshots.
  • Backend: extend account summary responses with available_reset_credits and reset_credit_nearest_expires_at, and preserve account status on upstream reset-credit polling failures.
  • Frontend: add reset-credit badges, Reset (N) actions, expiry countdowns, and a confirmation dialog across the Accounts page, dashboard table/grid views, and the Accounts nav tab.
  • Frontend: add the reset-credit consume client, schema updates, formatter helpers, and a new default Accounts sort mode for Most reset credits.
  • Tests/OpenSpec: add targeted backend unit coverage for the client/store/scheduler/API/mapper, frontend coverage for badges/actions/dialog/sorting/formatting, and the new OpenSpec change/spec context for rate-limit reset credits.

Test plan

$ openspec validate add-rate-limit-reset-credits --strict
Change 'add-rate-limit-reset-credits' is valid

$ openspec validate --specs --strict
Totals: 30 passed, 0 failed (30 items)

$ uv run pytest -q tests/unit/test_rate_limit_reset_credits_api.py tests/unit/test_rate_limit_reset_credits_client.py tests/unit/test_rate_limit_reset_credits_mapper.py tests/unit/test_rate_limit_reset_credits_scheduler.py tests/unit/test_rate_limit_reset_credits_store.py
57 passed in 0.42s

$ bun run lint
$ bun run typecheck
$ bun run test
104 passed test files, 652 passed tests
螢幕截圖 2026-06-18 16 59 31 螢幕截圖 2026-06-18 16 59 46 螢幕截圖 2026-06-18 17 13 41

@ellentane

Copy link
Copy Markdown

nice work on this — the ui and openspec coverage are way ahead of my overlapping pr (#1056).

while implementing and testing the same feature against real upstream accounts, i ran into a few gaps that might be worth folding in here:

1. refresh usage after consume

#1014 asks for an immediate /wham/usage refresh so quota bars and account status update right after apply. consume currently invalidates the credits cache and react queries, but doesn't force a usage refresh. suggest calling the existing force_refresh path on success (same idea as force probe).

2. block paused / reauth / deactivated on consume

the scheduler correctly skips paused accounts for polling, but the dashboard still shows redeem on paused accounts and the consume endpoint doesn't check account status. i'd return 409 for paused, reauth_required, and deactivated before hitting upstream.

3. proxy-aware upstream

accounts with per-account upstream routes need the codex transport path for credits fetch and consume, not only direct lease_retry_client.

4. visibility without extra polling

/wham/usage already returns rate_limit_reset_credits.available_count on the normal refresh loop. persisting that (or using it as a fallback) avoids showing 0 credits for ~60s after restart and cuts duplicate upstream load. the dedicated credits endpoint is still useful for expiry/title in the confirm dialog.

5. live fetch at consume time

cache-first is fast but can go stale. fetching credits once at click time (then consume) is closer to what the desktop client does and avoids 409s when the cache lags behind upstream.

6. audit

a small account_usage_reset_applied event with before/after counts would help operators trace what happened.


happy to help with a follow-up pr on this branch for any of the above. planning to close my duplicate #1056 in favor of this one.

@Soju06

Soju06 commented Jun 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10f685b67c

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/core/clients/rate_limit_reset_credits.py
Comment thread app/modules/proxy/api.py Outdated
Comment thread frontend/src/features/accounts/schemas.ts Outdated
@Soju06

Soju06 commented Jun 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 433b956ddd

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/core/usage/reset_credits_refresh_scheduler.py
@Soju06 Soju06 added 🤖 codex: needs work [@codex review] raised an issue and removed 🤖 codex: needs work [@codex review] raised an issue labels Jun 19, 2026
@Soju06

Soju06 commented Jun 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 7bf987c1e1

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Soju06 Soju06 added the 🤖 codex: ok [@codex review] says no issues found. label Jun 19, 2026
@notengoideanise

notengoideanise commented Jun 20, 2026

Copy link
Copy Markdown

when will this be added @Soju06 ? :) I want to be able to check bank reset and reset accounts via codex-lb

@buzaslan129

Copy link
Copy Markdown

+1

@huzky-v

huzky-v commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

I am not converting to ready to merge as

  • I don't test the actual reset (I don't have the need to use the reset credit ATM), thus I could not confirm the redeem logic is actually working
  • There is a hardening and tweaks WIP

Once these items are resolved, I will convert the status to "Ready to Merge"
If you are going to try that out, you can clone my branch and test that (Best if you can report if the redeem logic works)

@TanasitISTG

Copy link
Copy Markdown

reset works for me

image image image image

@notengoideanise

Copy link
Copy Markdown

also tried, reset worked for me in 2 accounts

@huzky-v

huzky-v commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed5f5de1f8

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/proxy/api.py Outdated
@huzky-v

huzky-v commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd35115f6f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/proxy/api.py Outdated
@huzky-v

huzky-v commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 67b0a32022

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/proxy/api.py Outdated
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label Jun 22, 2026
@Soju06 Soju06 removed the 🤖 codex: needs work [@codex review] raised an issue label Jun 22, 2026
@huzky-v

huzky-v commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 80be8a6766

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/rate_limit_reset_credits/api.py
Comment thread app/core/usage/reset_credits_refresh_scheduler.py
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label Jun 22, 2026
@huzky-v huzky-v marked this pull request as ready for review June 22, 2026 12:13
@Soju06 Soju06 removed the 🤖 codex: needs work [@codex review] raised an issue label Jun 22, 2026
@Soju06

Soju06 commented Jun 22, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6832cdc905

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread frontend/src/components/confirm-dialog.tsx Outdated
Comment thread app/modules/proxy/api.py
@Soju06

Soju06 commented Jun 22, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ffd51023f4

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +122 to +128
await _refresh_account_reset_credits(
account,
encryptor=TokenEncryptor(),
store=store,
fetch_fn=fetch_reset_credits,
resolve_route=_resolve_reset_credit_route,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep reset-credit GET cache-only

When an eligible account has no local snapshot (after restart, invalidate, or a failed poll), this dashboard GET now calls _refresh_account_reset_credits, even though the change artifacts describe the endpoint as returning the cached snapshot or null and relying on the scheduler cadence. Because this route only requires a dashboard session, read-only users can trigger outbound ChatGPT calls and cache writes on cache misses, and repeated misses can bypass the intended 60s background polling cadence; return null on misses or move this refresh behind an explicit write/refresh path.

Useful? React with 👍 / 👎.

@Soju06

Soju06 commented Jun 22, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6bf30df864

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/rate_limit_reset_credits/api.py
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.

6 participants