GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): count distinct quota gates, not leaves, for pool exhaustion · developing-today-forks/opencode@eb8eac9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/core
    • src
      • model-resolver.ts
      • model-route.ts
    • test
      • model-route.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/src/model-resolver.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/model-resolver.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ export const layer = Layer.effect(
739739
const unavailable = new Map<number, string>()
740740
const overLimit = new Set<number>()
741741
// Pool-shaped pull-out (#1014 PR3): a leaf whose nested group (pool) has had two
742-
// distinct leaves answer quota in turn is out with its pool, derived from the
742+
// distinct quota evidence sources answer quota in turn is out with its pool, derived from the
743743
// leaves' live quota benches/gates at this moment.
744744
const poolExhausted = new Map<number, boolean>()
745745
for (const index of indexes)
Collapse file

‎packages/core/src/model-route.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/model-route.ts
+40-22Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ export const activeBenches = (now = Date.now()): ActiveBench[] => {
559559
return benches.toSorted((left, right) => left.until - right.until)
560560
}
561561

562-
/** How many distinct leaves of one pool must be quota-out before the pool itself is pulled:
563-
* one leaf's quota answer can be leaf-specific, but a second distinct leaf of the same pool
562+
/** How many distinct quota evidence sources of one pool must be out before the pool itself is pulled:
563+
* one leaf's quota answer can be leaf-specific, but a second distinct evidence source of the same pool
564564
* answering quota in turn is the pool-shaped signal (#1014 PR3). */
565565
const POOL_QUOTA_LEAVES = 2
566566

@@ -569,25 +569,37 @@ const quotaBench = (state: HealthState | undefined, now: number) =>
569569
state.cooldownUntil > now &&
570570
(state.benchReason === "quota" || state.benchReason === "quota retry-after")
571571

572-
/** Whether one leaf is currently out for a quota-class reason: a quota bench on the leaf (or
573-
* on the credential that serves it), a quota gate on its credential, or a quota gate on its
574-
* provider (a known-full snapshot, a balance hold, or the reactive attempt-reported skip).
575-
* Balance holds count until a fresh balance increase releases them, so a pool held by a
576-
* balance gate stays out with no timer-based re-admission (#1014). */
577-
const quotaOut = (target: Model.Ref, credentialID: string | undefined, now: number, location?: string): boolean => {
572+
/** One leaf's quota-out evidence, or undefined when the leaf is not quota-out: a quota
573+
* bench on the leaf (or on the credential that serves it) counts per leaf, a quota gate
574+
* on the credential counts once per credential, and a quota gate on the provider (a
575+
* known-full snapshot, a balance hold, or the reactive attempt-reported skip) counts
576+
* once per provider. Bench evidence takes priority over a shared gate on the same
577+
* leaf, so two genuinely independent benches under one gate still count separately.
578+
* Balance holds count until a fresh balance increase releases them, so a pool held by
579+
* a balance gate stays out with no timer-based re-admission (#1014). */
580+
const quotaEvidence = (
581+
target: Model.Ref,
582+
credentialID: string | undefined,
583+
now: number,
584+
location?: string,
585+
): string | undefined => {
578586
if (credentialID) {
579-
if (quotaBench(credentialHealth.get(credentialKey(target, credentialID)), now)) return true
580-
return credentialQuotaBlocked(credentialID, now, location) !== undefined
587+
if (quotaBench(credentialHealth.get(credentialKey(target, credentialID)), now))
588+
return `bench:${credentialKey(target, credentialID)}`
589+
if (credentialQuotaBlocked(credentialID, now, location) !== undefined) return `cred-gate:${credentialID}`
590+
return undefined
581591
}
582-
if (quotaBench(health.get(key(target)), now)) return true
592+
if (quotaBench(health.get(key(target)), now)) return `bench:${key(target)}`
583593
const provider = providerQuota.get(target.providerID)
584594
if (
585595
provider &&
586596
(provider.balanceHold !== undefined ||
587597
QuotaSnapshot.isKnownFull(provider.snapshot, now, currentConstants(location).quotaGate.balanceDeadThreshold))
588598
)
589-
return true
590-
return activeAdjustments(now).some((item) => item.id === `quota:${target.providerID}` && item.action === "skip")
599+
return `prov:${target.providerID}`
600+
if (activeAdjustments(now).some((item) => item.id === `quota:${target.providerID}` && item.action === "skip"))
601+
return `prov:${target.providerID}`
602+
return undefined
591603
}
592604

593605
interface PoolMembership {
@@ -629,12 +641,16 @@ const poolOf = (definition: Definition, index: number): PoolMembership | undefin
629641
/** The id of the pool (nested group) a leaf belongs to, or undefined when it sits on the root. */
630642
export const poolIDOf = (definition: Definition, index: number) => poolOf(definition, index)?.id
631643

632-
/** Whether a leaf's pool is quota-exhausted: at least two distinct leaves of the pool are
633-
* currently quota-out, so the pool is pulled as a whole instead of spending attempts on its
634-
* remaining leaves one by one (#1014 PR3 dynamic pull-out). The verdict is derived from the
635-
* leaves' live quota state, so it lifts by itself when the benches reach their stated reset,
636-
* when a balance hold is released by a fresh increase, or when a benched leaf recovers — a
637-
* recovered pool re-enters rotation with no second producer. */
644+
/** Whether a leaf's pool is quota-exhausted: at least two distinct quota evidence
645+
* sources across the pool's leaves are currently out, so the pool is pulled as a whole
646+
* instead of spending attempts on its remaining leaves one by one (#1014 PR3 dynamic
647+
* pull-out). Evidence is deduplicated by identity — two leaves out only through one
648+
* shared credential or provider gate count as one signal, so a single provider's quota
649+
* wall cannot hard-exclude a healthy leaf from another provider (#1389) — while a
650+
* leaf's own quota bench always counts per leaf. The verdict is derived from the
651+
* leaves' live quota state, so it lifts by itself when the benches reach their stated
652+
* reset, when a balance hold is released by a fresh increase, or when a benched leaf
653+
* recovers — a recovered pool re-enters rotation with no second producer. */
638654
export const poolQuotaExhausted = (
639655
definition: Definition,
640656
index: number,
@@ -644,12 +660,14 @@ export const poolQuotaExhausted = (
644660
): boolean => {
645661
const pool = poolOf(definition, index)
646662
if (!pool || pool.leaves.length < POOL_QUOTA_LEAVES) return false
647-
const out = new Set<number>()
663+
const evidence = new Set<string>()
648664
for (const leaf of pool.leaves) {
649665
const target = definition.targets[leaf]
650-
if (target && quotaOut(target, credentialOf?.(leaf), now, location)) out.add(leaf)
666+
if (!target) continue
667+
const source = quotaEvidence(target, credentialOf?.(leaf), now, location)
668+
if (source) evidence.add(source)
651669
}
652-
return out.size >= POOL_QUOTA_LEAVES
670+
return evidence.size >= POOL_QUOTA_LEAVES
653671
}
654672

655673
export const failed = (
Collapse file

‎packages/core/test/model-route.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/model-route.test.ts
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,4 +2226,50 @@ describe("ModelRoute pool-shaped quota pull-out (#1014 PR3)", () => {
22262226
expect(ModelRoute.poolQuotaExhausted(definition, 2, resetAt + 1)).toBe(false)
22272227
ModelRoute.resetHealth()
22282228
})
2229+
2230+
test("one shared credential or provider gate counts once, so a healthy leaf keeps the pool open (#1389)", () => {
2231+
const shared = [0, 1].map((index) => ModelRoute.ref({ providerID: "pool-shared", model: `s${index}` }))
2232+
const healthy = ModelRoute.ref({ providerID: "pool-healthy", model: "m2" })
2233+
const sharedDefinition = {
2234+
id: "pool-shared-route",
2235+
targets: [...shared, healthy],
2236+
targetVariants: [],
2237+
health: policy,
2238+
nodes: [
2239+
{ selection: "ordered" as const, weights: [1], children: [{ node: 1 }] },
2240+
{ routeID: "pool-shared-plan", selection: "ordered" as const, weights: [1, 1, 1], children: [{ leaf: 0 }, { leaf: 1 }, { leaf: 2 }] },
2241+
],
2242+
} as unknown as ModelRoute.Definition
2243+
const now = Date.now()
2244+
const resetAt = now + 30 * 60_000
2245+
2246+
// Two leaves behind one gated credential are one quota signal, not two.
2247+
ModelRoute.resetHealth()
2248+
const sharedCredential = (index: number) =>
2249+
sharedDefinition.targets[index].providerID === "pool-shared" ? "cred-shared" : undefined
2250+
ModelRoute.observeQuotaFailure(shared[0], "cred-shared", resetAt, now)
2251+
expect(ModelRoute.poolQuotaExhausted(sharedDefinition, 0, now, sharedCredential)).toBe(false)
2252+
expect(ModelRoute.poolQuotaExhausted(sharedDefinition, 1, now, sharedCredential)).toBe(false)
2253+
expect(ModelRoute.poolQuotaExhausted(sharedDefinition, 2, now, sharedCredential)).toBe(false)
2254+
// A second, genuinely distinct gate on the healthy leaf's provider still exhausts the pool.
2255+
ModelRoute.observeQuotaFailure(healthy, undefined, resetAt, now)
2256+
expect(ModelRoute.poolQuotaExhausted(sharedDefinition, 2, now, sharedCredential)).toBe(true)
2257+
2258+
// Two credential-less leaves behind one gated provider are one quota signal, not two.
2259+
ModelRoute.resetHealth()
2260+
ModelRoute.observeQuotaFailure(shared[0], undefined, resetAt, now)
2261+
expect(ModelRoute.poolQuotaExhausted(sharedDefinition, 2, now)).toBe(false)
2262+
ModelRoute.observeQuotaFailure(healthy, undefined, resetAt, now)
2263+
expect(ModelRoute.poolQuotaExhausted(sharedDefinition, 2, now)).toBe(true)
2264+
2265+
// Two independent quota benches on distinct credentials still exhaust the pool.
2266+
ModelRoute.resetHealth()
2267+
const distinctCredential = (index: number) =>
2268+
sharedDefinition.targets[index].providerID === "pool-shared" ? `cred-${index}` : undefined
2269+
ModelRoute.failed(shared[0], policy, now, { quota: true }, "cred-0")
2270+
expect(ModelRoute.poolQuotaExhausted(sharedDefinition, 2, now, distinctCredential)).toBe(false)
2271+
ModelRoute.failed(shared[1], policy, now, { quota: true }, "cred-1")
2272+
expect(ModelRoute.poolQuotaExhausted(sharedDefinition, 2, now, distinctCredential)).toBe(true)
2273+
ModelRoute.resetHealth()
2274+
})
22292275
})

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.