GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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
|
|
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 45 seconds. 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. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: c9aeff9c57
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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.
There was an error while loading. Please reload this page.
| const rows = yield* ModelRouteLog.targetUsage(db, since) | ||
| const totals = ModelUsage.sum(rows.filter((row) => row.providerID === plan.providerID)) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
| now: number, | ||
| ) => | ||
| Effect.gen(function* () { | ||
| if (!ModelRoute.shouldFeedQuota(now)) return |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
| return | ||
| } | ||
| const targetProviders = new Set<string>(targets.map((target) => target.providerID)) | ||
| const relevantPlans = plans.filter((plan) => targetProviders.has(plan.providerID)) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
| const fullSnapshot = providerSnapshots | ||
| .filter((s) => QuotaSnapshot.isKnownFull(s, now)) | ||
| .sort((a, b) => (b.resetAt ?? 0) - (a.resetAt ?? 0))[0] | ||
| const snapshot = fullSnapshot ?? providerSnapshots[0] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
| if (!full && previous?.gated) { | ||
| removeAdjustment(`quota:${target.providerID}`) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
| const since = now - window.windowHours * 3_600_000 | ||
| const rows = yield* ModelRouteLog.targetUsage(db, since) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
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)
There was an error while loading. Please reload this page.