Repository navigation
fix(core): pool-shaped quota pull-out and any-error-class escalating bench (#1014 PR3) - #1384
Conversation
…bench (#1014 PR3) - ModelRoute.poolQuotaExhausted: a leaf pool (deepest nested route / provider-route group) is pulled as a whole once two distinct leaves are quota-out (quota bench, credential gate, provider gate or balance hold); derived from live leaf state so it lifts at the stated reset, on balance-increase release, or on recovery - model-resolver: pool-exhausted leaves are excluded from candidacy and hard-excluded from the all-full last resort, so a proven-walled pool is never re-offered; the PR2 cascade looks elsewhere instead - session runner: terminal non-retryable failures (402/billing, 5xx, timeout, other classes outside retryable/Auth/QuotaExceeded) now record ModelRoute.failed health accounting without broadening same-request failover gates; context-overflow stays excluded - Tests: pool pull-out + reset restoration + re-entry (model-route), repeated non-retryable timeout and repeated 402 billing escalation (session-step)
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 36 minutes. View limit details
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. |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4794119cf5
ℹ️ 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".
| const quotaBench = (state: HealthState | undefined, now: number) => | ||
| state !== undefined && | ||
| state.cooldownUntil > now && | ||
| (state.benchReason === "quota" || state.benchReason === "quota retry-after") |
There was a problem hiding this comment.
Allow due quota probes through the pool exclusion
When two pool members have quota benches and a trusted reset is learned after those benches were created, armBenchProbe makes them probe-eligible at reset without shortening their cooldowns. This predicate still counts both as quota-out until their original cooldowns expire, so poolQuotaExhausted remains true and the resolver excludes every member, including the due probes, from both normal selection and last resort. This defeats the existing half-open recovery path and can leave a recovered pool unavailable until the escalated cooldown expires (up to 24 hours). Account for due probes when applying the pool exclusion.
Useful? React with 👍 / 👎.
| const out = new Set<number>() | ||
| for (const leaf of pool.leaves) { | ||
| const target = definition.targets[leaf] | ||
| if (target && quotaOut(target, credentialOf?.(leaf), now)) out.add(leaf) | ||
| } | ||
| return out.size >= POOL_QUOTA_LEAVES |
There was a problem hiding this comment.
Avoid counting one shared quota gate as multiple failure signals
For a nested route containing provider-a/model-1, provider-a/model-2, and a healthy provider-b/model-3, one quota failure on provider A's active credential gates both A leaves through credentialQuotaBlocked. This loop counts those leaves separately and declares the entire pool exhausted, so the resolver now hard-excludes the healthy B leaf even though neither it nor a second independent quota source has failed. The credential-less provider gate has the same issue. Deduplicate shared quota-gate evidence, or track distinct leaf failures, before using the threshold to remove unrelated healthy members.
Useful? React with 👍 / 👎.
|
Codex findings disposition (queue task 6188 verification, lane A 2026-11-02): this PR was merged with two Codex P2 findings unresolved. Both were re-verified against current main and filed as follow-up issues rather than left on this merged PR:
Task 6188 itself is completed as verified_merged: PR3 acceptance (pool-shaped benching + any-error-class escalating removal, with tests) confirmed on a tree containing this merge — packages/core model-route + session-step + model-resolver suites 205 pass. Issue #1014 stays open for its other routed packets, per the PR body. |
Part of #1014 (PR3 of the routing-resilience set; PR1 was #1190 and PR2 was #1364, both merged). Does not close #1014 — the runner-policy packet (issue #1379, task 6191) and the CodeRabbit follow-ups (issue #1380, task 6192) remain, and interim config mitigations stay in place.
Problem
Gap 4 of the analysis on #1014 (comment 6562786500), verified on main
52ac2c2852:ModelRoute.failedwas only reached behindrouteFailureinsession/runner/step.ts(retryable / Authentication / QuotaExceeded), so repeated errors of other classes — 402/billing answers that arrive unclassified, 5xx, timeouts — never escalated a target out of rotation.Change
Pool-shaped benching — dynamic pull-out (
model-route.ts,model-resolver.ts)ModelRoute.poolIDOf).ModelRoute.poolQuotaExhaustedderives the verdict from the leaves' live quota state: a leaf is quota-out when it carries a quota bench, its serving credential is quota-gated, or its provider is quota-gated (known-full snapshot, balance hold, or the reactive attempt-reported skip). Once two distinct leaves of a pool are quota-out, the pool is pulled as a whole — one leaf's answer can be leaf-specific; a second distinct leaf answering in turn is the pool-shaped signal.pool-quota-exhausted:<pool>in the decision's unavailable map) and hard-excludes them from the all-full last resort: a proven-walled pool is never re-offered; the route resolves nothing and the PR2 cascade looks elsewhere.Any-error-class escalating removal (
session/runner/step.ts)ModelRoute.failedfor the routed target even whenrouteFailureis false, so repeated 402/billing, 5xx, timeout and other repeated classes climb the same escalating, capped bench ladder (Retry-After / quota reset still govern duration when the error carries one).routeFailuregate for current-request failover and credential switching is unchanged — this does not broaden which failures move the current request — and context-overflow failures stay excluded from health accounting. Same-target retries still do not count against the target.Tests
UnknownProviderError, HTTP 402) do the same.bun run typecheckclean,git diff --checkclean.#1014 audit-table rows updated by this PR
ModelRoute.failedand climb the same doubling, capped ladderStill owed on #1014 (separate packets, unchanged): runner policy (issue #1379, task 6191) and the two CodeRabbit follow-ups (issue #1380, task 6192). This PR does not close #1014.
Need help on this PR? Tag
@codesmith-botwith what you need.