Repository navigation
feat(kiro): per-account concurrency cap and least-loaded selection - #5994
Conversation
maxConcurrentPerAccount bounds in-flight requests per Kiro account with a process-local lease ledger. A request admitted to a full account waits up to a bounded interval and then gets a retryable 503 account_capacity; capacity never moves a request or writes the stored selection. A reactive rotation takes a no-wait lease on its target before committing the selection, so a full target returns the original refusal with state unchanged. The opt-in least-loaded strategy picks the eligible account with the fewest requests in flight, skipping accounts at their cap, under the existing proactive-preference switch. Leases release on body end, error, cancel and request abort, and a 15-minute reclaim bounds any leak.
…count A slot released while a request is queued now goes straight to the first live waiter instead of back to the pool, so a new arrival cannot take it and leave the waiter to time out. A 401 replay that resolves a different account takes that account's lease before sending, or stops with the formatted 401.
|
✅ Deterministic PR hygiene checks passed. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository: lidge-jun/opencodex/.coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (29)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 08aa38572d
ℹ️ 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".
| if (kiroLoadEnabled) { | ||
| const lease = await acquireAccountLease("kiro", admitted.accountId, { | ||
| maxConcurrentPerAccount: kiroCap, waitMs: KIRO_ACCOUNT_WAIT_MS, signal: options.abortSignal ?? req.signal, | ||
| }); |
There was a problem hiding this comment.
Reserve the least-loaded account before asynchronous resolution
When two Kiro requests arrive concurrently with least-loaded and a per-account cap, both can observe the same zero-load tie before either reaches this post-resolution lease acquisition. They therefore select the same account; one acquires its lease while the other waits and returns 503 account_capacity, even though another eligible account remains idle. Make selection and reservation atomic, or retry least-loaded selection against the current ledger when this acquisition cannot obtain a slot.
Useful? React with 👍 / 👎.
|
Verification follow-up for head |
리뷰 · 우선순위 63 / 80Kiro는 계정 하나에 요청이 몇 개까지 동시에 붙는지 정하지 못했습니다. 멀쩡한 계정이 더 있어도, 지금 계정으로 계속 보냈습니다. 이 PR은 그 한도와, 덜 바쁜 계정을 고르는 방법을 넣습니다. 라인 - 라인 - 라인 - 메인테이너의 판단이 필요한 지점 한도만 켜면 요청은 지금 계정에 남고, 넘치면 503입니다. 옆 계정으로 퍼뜨리려면 너의 추천 고른 계정이 가득 차 있으면 503 전에 여유가 있는 계정을 한 번 더 고르면 됩니다. 고르는 순간에 자리를 같이 맡기면 같은 결과가 납니다. 15분 정리는 두되, 응답 본문이 아직 열려 있는 자리는 빼지 않으면 됩니다. 401 재시도에서 자리가 없으면 503 이 댓글은 grok-bot이 작성했습니다 |
Summary
Kiro had no way to limit how many requests hit one account at once, and no way to spread load across healthy accounts: the pool kept every healthy request on the active account until it was refused.
After this change:
oauthAccountFailover.maxConcurrentPerAccount(Kiro only, 1–100) bounds in-flight requests per account with a process-local lease ledger. A request admitted to a full account waits up to 250 ms for a slot, then gets a retryable503 account_capacitywithRetry-After: 1. Capacity never moves a request and never writes the stored selection.least-loadedis a new opt-in Kiro pool strategy: among eligible accounts it skips those at their cap and picks the fewest in flight, with stable ties. It runs only under the existing proactive-preference switch andpool.kernel; with it off, rotation keeps today's headroom ranking. When a cap is configured, reactive rotation prefers a sibling with room./api/oauth/accounts/poolresponse shape. The unified/api/pool/settingsDTO gainsmaxConcurrentPerAccountas a declarednullfor every kind, per its same-keys contract.Layer 040 of
devlog/_plan/260926_kiro_lb_parity2/.Stack (manual chain, merge bottom-up):
Verification
bun run typecheck— passtests/providers/kiro/, the three server Kiro e2e suites,credential-redirect-guard,web-search-sidecar-429,generic-oauth-failover,oauth-store-multi,images/loop, the 429 docs guard,cli-account-pool-verbs, layout, ratchet and core–Lab boundary — 923 pass, 0 failaccount-pool-management-api, run in a clean worktree outside~/.codex— 1162 pass, 0 failprivacy:scan,structure:check— pass. Hosted CI: see the follow-up comment.Checklist
structure/providers/kiro.md,structure/transports/responses-failover.mdand related structure docs)Summary by CodeRabbit
least-loadedaccount selection when proactive selection is enabled.