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): feed current quota reads into route candidacy gate (#984) by dezren39 · Pull Request #1028 · developing-today-forks/opencode

Conversation

@dezren39

@dezren39 dezren39 commented Oct 30, 2026 •
edited by blacksmith-sh Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Fixes #984 (proactive half).

The reactive half (#991) gates a credential after one quota-exhaustion answer. The proactive gate (observeCredentialQuota) and its read side existed but had no production producer, and credential-less providers had no proactive path at all.

This wires current reads into the existing gate at route candidacy:

  • resolveRoute feeds QuotaSnapshot.deriveAll (plans store + windowed route_attempt usage, route-usage.ts pattern) through observeCredentialQuota per active credential, TTL-guarded at 60s so fallback recursion pays no extra DB read.
  • New ModelRoute.observeProviderQuota gives credential-less providers the same treatment via the existing skip-adjustment store (last-resort preserved, reset capping mirrors observeQuotaFailure).
  • No second gate, no config edits. Gated providers surface per providerID (opencode-go workspaces already distinct).

Tests: 4 new ModelRoute proactive provider gate tests (arm/skip, re-admit, out-of-order, capping); existing model-route, model-route-credential, model-resolver, quota-snapshot suites pass (163 tests). Typecheck clean.


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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
repo-worker-opencode
fix(core): feed current quota reads into route candidacy gate (#984)
c9aeff9
@coderabbitai

coderabbitai Bot commented Oct 30, 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 45 seconds.

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: dc4dce8f-40ff-48c6-9be6-5094ba1ecbfe
Commits

Reviewing files that changed from the base of the PR and between 40d2edf and c9aeff9.

Files selected for processing: 3
  • packages/core/src/model-resolver.ts
  • packages/core/src/model-route.ts
  • packages/core/test/model-route-credential.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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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-10-31T00:00:42.232988Z c9aeff9 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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dezren39
dezren39 merged commit 18e33f8 into main Oct 30, 2026
1 check passed

Uh oh!

There was an error while loading. Please reload this page.

@dezren39 dezren39 mentioned this pull request Oct 30, 2026
router: auto-disable providers at 100% quota until a fresh read shows headroom (cline-pass, commandcode, go) #984
Closed
chatgpt-codex-connector[bot]
chatgpt-codex-connector Bot reviewed Oct 31, 2026
View reviewed changes

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

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: c9aeff9c57

ℹ️ 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".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/core/src/model-resolver.ts
Comment on lines +454 to +455
const rows = yield* ModelRouteLog.targetUsage(db, since)
const totals = ModelUsage.sum(rows.filter((row) => row.providerID === plan.providerID))

@chatgpt-codex-connector chatgpt-codex-connector Bot Oct 31, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve credential scope when deriving quota usage

When a provider has multiple account credentials, ModelRouteLog.targetUsage() groups history only by provider and model, so these totals include usage from every credential. The resulting provider-wide snapshot is then assigned to whichever credential is currently active by observeCredentialQuota(). After an exhausted account switches to a healthy account, the next refresh therefore marks the healthy account full using the previous account's usage; the ready filter and credentialFallback subsequently exclude it. Use credential-attributed usage for credential gates, or leave the credential quota unknown when that attribution is unavailable.

Useful? React with 👍 / 👎.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@dezren39 dezren39 Oct 31, 2026

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by PR #1113 (fix(core): scope quota usage to the serving credential), which implements issue #1106 filed for this finding: route_attempt now records the serving credential, ModelRouteLog.targetUsage groups by it, and refreshQuotaGate sums a credential's quota snapshot from that credential's rows only — provider-wide totals are no longer assigned to the active credential, and unattributed (null-credential) rows feed no credential. A two-credential regression test pins the behavior.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/core/src/model-resolver.ts
now: number,
) =>
Effect.gen(function* () {
if (!ModelRoute.shouldFeedQuota(now)) return

@chatgpt-codex-connector chatgpt-codex-connector Bot Oct 31, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scope the quota refresh throttle to the refreshed targets

When different routes resolve within the same minute, the first call consumes the process-global shouldFeedQuota() allowance, but this function reads and feeds only that route's providers. Subsequent routes cannot refresh their own providers, even if the first route had no relevant plans and returned immediately. A regularly requested route can consequently keep other routes' exhausted providers ungated indefinitely. Cache snapshots globally and apply them to every call, or key the refresh allowance by the providers and credentials actually refreshed.

Useful? React with 👍 / 👎.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/core/src/model-resolver.ts
return
}
const targetProviders = new Set<string>(targets.map((target) => target.providerID))
const relevantPlans = plans.filter((plan) => targetProviders.has(plan.providerID))

@chatgpt-codex-connector chatgpt-codex-connector Bot Oct 31, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude inactive historical plans from quota gating

When a provider has an expired or cancelled plan alongside its current plan, this filter includes both. ModelPlan deliberately retains ended plans, and the loop attributes the provider's current usage to every matching plan, so an old plan with a smaller quota can produce the selected full snapshot and gate a provider whose current plan still has capacity. Restrict candidacy-gate derivation to applicable active plans rather than treating retained historical records as current limits.

Useful? React with 👍 / 👎.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/core/src/model-resolver.ts
const fullSnapshot = providerSnapshots
.filter((s) => QuotaSnapshot.isKnownFull(s, now))
.sort((a, b) => (b.resetAt ?? 0) - (a.resetAt ?? 0))[0]
const snapshot = fullSnapshot ?? providerSnapshots[0]

@chatgpt-codex-connector chatgpt-codex-connector Bot Oct 31, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Choose a known snapshot when clearing a multi-window gate

If a provider's first quota window has no windowHours or limit, its snapshot is unknown. A later known window can still arm the gate through fullSnapshot, but once that window drops below its limit, this fallback selects the first unknown snapshot instead of the fresh known reading. Both observation functions reject unknown updates when previous state exists, so the gate is not cleared; for a credential with a rolling window and null reset, it can remain blocked indefinitely. Prefer a known non-full snapshot before falling back to an unknown one.

Useful? React with 👍 / 👎.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/core/src/model-route.ts
Comment on lines +539 to +540
if (!full && previous?.gated) {
removeAdjustment(`quota:${target.providerID}`)

@chatgpt-codex-connector chatgpt-codex-connector Bot Oct 31, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear restored provider gates on a fresh below-limit reading

After a restart, ModelRouteLog.restoreNotes() restores the persisted quota:<providerID> skip adjustment, but the process-local providerQuota map is empty. If usage has fallen below the quota before the adjustment expires, the first fresh known reading sets gated: false without removing that adjustment because previous?.gated is undefined. Subsequent below-limit readings also leave it intact, so the recovered provider remains skipped until the old hold expires, potentially for 30 days. Reconcile a fresh known non-full reading with the existing quota adjustment even when there is no prior in-memory snapshot.

Useful? React with 👍 / 👎.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/core/src/model-resolver.ts
Comment on lines +453 to +454
const since = now - window.windowHours * 3_600_000
const rows = yield* ModelRouteLog.targetUsage(db, since)

@chatgpt-codex-connector chatgpt-codex-connector Bot Oct 31, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Align fixed-reset usage reads with the current quota period

For a 24-hour quota with resetRule: "daily 00:00 UTC", this rolling lookback includes usage from the previous quota period after midnight, while QuotaSnapshot.deriveAll() advances resetAt to the following midnight. For example, 100 requests at 23:55 against a 100-request daily limit still produce a known-full snapshot at 00:05, even though the provider has reset and the new period has no usage. This re-arms the gate and can exclude the recovered provider for almost another day. Bound fixed-reset usage reads to the current period's start rather than always subtracting windowHours from now.

Useful? React with 👍 / 👎.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
This was referenced Oct 31, 2026
model-resolver: quota usage is summed provider-wide and assigned to the active credential — multi-credential providers misattribute usage (PR #1028 Codex P1 unaddressed) #1106
Closed
fix(core): scope quota usage to the serving credential #1113
Merged
fix(core): quota gate feed throttle is process-global — the first route resolved in a 60s window starves every other route's providers (PR #1028 Codex P2 unaddressed) #1339
Closed
fix(core): quota gate derivation includes expired/cancelled plans — a retained historical plan's smaller window can gate a provider whose current plan has capacity (PR #1028 Codex P2 unaddressed) #1340
Closed
fix(core): gatingSnapshot fallback returns the first (possibly unknown) snapshot, so a multi-window gate armed by a later window never clears (PR #1028 Codex P2 unaddressed) #1341
Closed
fix(core): fixed-reset (daily) quota windows are read on a rolling windowHours lookback — usage from the previous period re-gates the provider after its reset (PR #1028 Codex P2 unaddressed) #1342
Closed
fix(core): #1014 follow-ups — stale balance holds on deleted/reclassified plans + balance-exhaustion classification breadth #1380
Closed
@dezren39
dezren39 deleted the queue/4028-984-proactive-quota-gate branch November 2, 2026 13:17
@dezren39 dezren39 added the audit:complete PR fully implemented spawning issue label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@chatgpt-codex-connector chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

audit:complete PR fully implemented spawning issue

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

router: auto-disable providers at 100% quota until a fresh read shows headroom (cline-pass, commandcode, go)

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@dezren39
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.
You are visitor 01402775 — 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.