Skip to content

[codex] add FIFO account wait queue#4085

Open
xtyooo wants to merge 1 commit into
Wei-Shaw:mainfrom
xtyooo:codex/fifo-account-wait-queue
Open

[codex] add FIFO account wait queue#4085
xtyooo wants to merge 1 commit into
Wei-Shaw:mainfrom
xtyooo:codex/fifo-account-wait-queue

Conversation

@xtyooo

@xtyooo xtyooo commented Jul 12, 2026

Copy link
Copy Markdown

What changed

  • Add an optional Redis-backed FIFO wait queue for account slots
  • Only the queue head can acquire the next account slot
  • Encode wait deadlines in tickets and remove expired or cancelled heads
  • Keep the legacy counter and polling path for non-queue cache implementations
  • Use the configured WaitPlan max waiting and timeout across Claude, Gemini, and OpenAI account paths
  • Include integration coverage for FIFO ordering, capacity limits, and cancelled waiters

Why

The previous account wait path only counted waiters and let every request compete to acquire a slot. That allowed later requests to overtake earlier requests and caused avoidable slot-acquisition pressure during bursts.

This first slice makes admission order deterministic and bounds stale waiters. Waiters still use the existing exponential-backoff polling loop, but only the FIFO head performs the account-slot acquisition attempt; event-driven wakeups can be added in a follow-up without changing the queue contract.

Validation

  • go test ./internal/handler ./internal/service ./internal/repository -count=1
  • go test -tags integration ./internal/repository -run TestConcurrencyCacheSuite/TestAccountWaitQueue -count=1
  • git diff --check

The queue is optional so existing cache implementations and test doubles retain the legacy behavior.

@github-actions

github-actions Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@xtyooo
xtyooo force-pushed the codex/fifo-account-wait-queue branch from 54fe0d3 to 8d6892a Compare July 12, 2026 05:23
@xtyooo

xtyooo commented Jul 12, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jul 12, 2026
@xtyooo
xtyooo marked this pull request as ready for review July 12, 2026 16:31
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