Skip to content

fix(core): pool-shaped quota pull-out and any-error-class escalating bench (#1014 PR3) - #1384

Merged
dezren39 merged 1 commit into
mainfrom
queue/6188-1014-dynamic-pull-out
Nov 2, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/6188-1014-dynamic-pull-out

Conversation

@dezren39

@dezren39 dezren39 commented Nov 2, 2026 •

Copy link
Copy Markdown

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:

  1. Quota gating was per provider/credential only: when a pool's leaves answered quota errors in turn, each leaf was spent and benched separately, and the resolver's all-full last resort could re-offer the remaining leaves of a pool already proven walled.
  2. ModelRoute.failed was only reached behind routeFailure in session/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)

  • A leaf's pool is its deepest nested group (a provider-route group or nested route node); a leaf on the route root belongs to no pool (ModelRoute.poolIDOf).
  • ModelRoute.poolQuotaExhausted derives 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.
  • The resolver excludes pool-exhausted leaves from candidacy (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.
  • Restoration needs no second producer: the verdict lifts by itself when the leaves' benches reach their stated reset, when a balance hold is released by a fresh balance increase (no timer-based re-admission for balance pools), or when a benched leaf recovers — the recovered pool re-enters rotation automatically.

Any-error-class escalating removal (session/runner/step.ts)

  • Health accounting is now broader than same-request failover: a terminal non-retryable failure records ModelRoute.failed for the routed target even when routeFailure is 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).
  • The routeFailure gate 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

  • New (model-route): two distinct leaves answering quota in turn pull the whole pool, an outside leaf is never pulled, and bench expiry re-admits the pool; reactive quota gates on two leaves' providers exhaust the pool until the stated reset and lift at the reset.
  • New (session-step): repeated non-retryable timeout failures bench the routed target with an escalating cooldown; repeated non-retryable 402 billing failures (UnknownProviderError, HTTP 402) do the same.
  • Existing quota-reset restoration / probed re-entry coverage (fix(core): quota bench escalates to 24h decoupled from the provider window reset — benched credential can never earn the success that clears it #1123 bench-probe tests) passes unchanged and now also governs the pool verdict, which is derived from that same leaf state.
  • Laptop runs: model-route 98/98, session-step + model-resolver 105/105, model-route-credential + session-runner-model + model-routes-expand 98/98, bun run typecheck clean, git diff --check clean.

#1014 audit-table rows updated by this PR

#1014 item Status after PR3
1. Repeated errors remove target, not fixed-interval retry forever COVERED for the core router — any-class health accounting (this PR) on top of the ordinary bench and PR1 balance/quota gates
2. Removal escalates with recurrence, capped COVERED — non-quota, non-retryable classes now reach ModelRoute.failed and climb the same doubling, capped ladder
3. Expected resolution (reset / Retry-After) governs removal; auto-restore at reset COVERED — the ladder already honours Retry-After / quota reset; the pool verdict is derived from that leaf state, so a pool restores at its leaves' stated resets and balance-held pools only on a fresh balance increase
4. Automatic, probed restoration COVERED — pool re-entry is automatic on bench/gate expiry; #1123 half-open probe behaviour is unchanged and pinned by its existing tests
5. Consistent core + OpenChamber surfaces Unchanged by this PR — core remainder only; the OpenChamber read-only surface remainder was recorded on #1014 on 2026-10-30
Tests: repeated 402 escalating; quota-reset restoration; recovered re-entry COVERED — new session-step 402 test; new model-route pool reset/re-entry tests; #1123 probe tests for leaf-level reset restoration

Still 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.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…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)
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b74b3ce5-ca84-4b55-8ae8-50394b744154
Commits

Reviewing files that changed from the base of the PR and between 52ac2c2 and 4794119.

Files selected for processing: 5
  • packages/core/src/model-resolver.ts
  • packages/core/src/model-route.ts
  • packages/core/src/session/runner/step.ts
  • packages/core/test/model-route.test.ts
  • packages/core/test/session-step.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@dezren39 dezren39 added work/assigned An agent holds this item via the queue (claimed task) queue/claimed A queue worker has claimed the task for this item status/in-progress Actively being worked labels Nov 2, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T11:28:13.606837Z 4794119 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 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".

Comment on lines +538 to +541
const quotaBench = (state: HealthState | undefined, now: number) =>
state !== undefined &&
state.cooldownUntil > now &&
(state.benchReason === "quota" || state.benchReason === "quota retry-after")

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 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 👍 / 👎.

Comment on lines +617 to +622
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

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 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 👍 / 👎.

@dezren39

dezren39 commented Nov 2, 2026

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

queue/claimed A queue worker has claimed the task for this item status/in-progress Actively being worked work/assigned An agent holds this item via the queue (claimed task)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ensure(core+openchamber): repeated errors of ANY class remove a model from rotation for escalating time, or until its expected resolution

1 participant