Repository navigation
Avoid Account Pooler usage 429 bursts and keep current cached quotas visible - #8556
Open
salemsayed wants to merge 1 commit into
Open
salemsayed wants to merge 1 commit into
salemsayed wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
In a multi-account OAuth pool, three behaviors in
plugins/account-poolcombined to trigger/api/oauth/usageHTTP 429s and hide valid cached quotas in Provider usage (#8555):forward()calledrefreshExhaustedUsage()wheneverselect()returnednullor an account pastswitchThreshold, polling every past-threshold/exhausted account every 30 seconds in parallel (Promise.all) even when its blockingresetAtwas hours or days in the future, despiteisRefusedWindow/isWindowPastThresholdalready auto-clearing atresetAt.registerUsageSource()returned{ status: "error" }wheneverhub.usageCheckFailure(account.id)was set, even on passiverefresh: falsereads whenaccount-poolalready had current un-resetlimitWindowspersisted in SQLite. Whenprovider-usagehad a cold in-memory cache (for example after a server restart whose startup burst 429'd), it had no cached reading to fall back to and showed only the rate-limit message with no bars, plan badge, or reset times.refreshUsage()firedPromise.allacross all enabled OAuth accounts simultaneously on hub startup and every 5 minutes; 429 responses withoutRetry-Afterfell back to 1 second with no exponential backoff; andrefreshAccountUsage()stampedlastUsageRefreshAtbefore the fetch, locking out passive retries for 5 minutes even afterretryAtexpired.What changed
plugins/account-pool/src/quota.ts: AddedhasUnknownPastThresholdReset()(true only when an account is past threshold or usage-restricted with no known futureresetAt) andparseRetryAfterMilliseconds()(returningnullwhenRetry-Afteris absent/unparseable, withretryAfterMilliseconds()keeping its 1s fallback for existing callers).plugins/account-pool/src/provider-adapter.ts,claude-adapter.ts,codex-adapter.ts: NarrowedUsageRefreshResultto{ kind: "done" } | { kind: "rate-limited"; retryAfterMs: number | null } | { kind: "failed" }.plugins/account-pool/src/hub.ts:refreshExhaustedUsage()now only rechecks accounts matchinghasUnknownPastThresholdReset()and returnsboolean, soforward()skips the extra selection loop when nothing was refreshed. Known future resets rely on the 5-minute background loop and manual refresh, and auto-clear atresetAt.Promise.allbursts across same-provider accounts withrefreshAccountsSequentiallyByProvider(), propagating the service abortsignalfromstart().lastUsageRefreshAt(updated only on success) fromusageFailures({ kind, retryAt, attempts }) with exponential backoff from 30s to 5m (takingMath.max(retryAfterMs, backoffMs)on 429). Passive checks retry as soon asretryAtpasses instead of waiting 5 minutes; non-429 failures back off on passive checks while remaining immediately retryable on forced refresh (minIntervalMs === 0).plugins/account-pool/src/usage-source.ts,server.ts: WirednowintoregisterUsageSource(). Passiverefresh: falsereads return{ status: "ok", windows }whenaccount.error === null,observedAt !== null, and at least one window is still current (resetAt === null || resetAt > now). Explicitrefresh: truereads, unobserved accounts, and accounts whose cached windows have all reset still returnstatus: "error"(preserving Show stale and rate-limited usage honestly in the usage panel #8455 andprovider-usage's"Showing last update."behavior).plugins/account-pool/skills/account-pool/references/accounts-and-routing.md: Documented per-provider serialized refreshes and that the 30-second recheck applies when the blocking reset time is unknown.plugins/account-pool/src/server.test.ts: Updated the 30s exhausted-recheck and paid-pin recovery tests to match the reset-time policy, and added 4 tests covering future-reset skip + auto-recovery, passive vs forced/post-reset usage errors, exponential 429/500 backoff + passive retry afterretryAt, and serialized per-provider startup refreshes.No wire, host-daemon protocol, CLI, or Plugin SDK changes.
How you verified
plugins/account-pool/src/server.test.ts:skips 30-second exhausted-usage rechecks while a blocking reset time is in the future and recovers at resetreturns current cached usage on passive reads during a 429, but surfaces the error on forced refresh or after resetbacks off 429 usage checks exponentially without Retry-After and retries passively once backoff expiresserializes multi-account usage refreshes per provider on hub startuppnpm exec turbo run typecheck lint test --filter=bb-plugin-account-pool --filter=bb-plugin-bb--provider-usagepasses (13/13 tasks; 410/410 tests inbb-plugin-account-pool, 0 lint errors).pnpm exec turbo run lint:type-aware --filter=bb-plugin-account-poolpasses (0 warnings, 0 errors).pnpm exec oxfmt --checkon all 8 modified.tsfiles passes.Fixes #8555