Repository navigation
Conversation
unrayed
force-pushed
the
feat/free-quota-estimate
branch
from
November 19, 2026 20:28
5779864 to
dd40016
Compare
The upstream exposes no remaining-quota endpoint and no rate-limit headers, so count what the gateway already sends: accepted free-model client requests per egress for the current UTC day. Only a free-limit 429 that follows real usage on that egress teaches a floor, and only when its Retry-After points near the next UTC midnight. Shape refusals, short throttles, and refusals on a fresh exit teach nothing. The floor stays with that egress across midnight; free_quota.assumed_daily_limit is the prior for an egress that has not taught its own, and 0 shows unknown. Availability probes are not counted. State persists beside the config in config.json.freequota.json, survives runtime rebuilds, and is served by GET /api/free-quotas. The WebUI shows it in the existing free-models tab of Model & quotas.
A midnight-Retry-After refusal can be scoped to one conversation rather than to the egress: the same exit serves another session moments later. Learning a limit from such a refusal recorded counts as low as 2-19 and marked healthy egresses exhausted, so the page under-reported the pool. Now a refusal proves egress exhaustion only once that egress has already accepted at least free_quota.assumed_daily_limit requests. Below that it teaches nothing and the configured prior stays in place.
unrayed
force-pushed
the
feat/free-quota-estimate
branch
from
November 20, 2026 17:32
dd40016 to
e915e2b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The gateway serves free models through rotating egresses (proxies,
direct, WARP), but gives no visibility into how much of the free daily allowance each egress has consumed. Users only find out when a request is answered withFreeUsageLimitError.This adds a passive per-egress estimate for the current UTC day. It never probes or generates traffic to measure quota, and it never touches the upstream request path beyond observation.
Design
direct, orwarp:<block>— resolved exactly as the request was routed.FreeUsageLimitError,Retry-Afterof at least 1 minute,midnightSkew),free_quota.assumed_daily_limitaccepted free requests today: a refusal below the prior can be scoped to one conversation rather than the egress, so it teaches nothing.Used > 0.Limit = max(limit, used),Remaining = 0once exhausted, source islearned,assumed, orunknown.Config and state
free_quota.assumed_daily_limit(default200,0= unknown) is the fallback for egresses that have not learned a floor. It is config-file only; admin config saves preserve it.<config>.freequota.json; a missing or corrupt file only clears estimates.GET /api/free-quotasreturns the snapshot; the WebUI "Free models" tab renders it with used/remaining and a countdown to UTC midnight.Evidence
Real run on a side instance built from this branch (main gateway untouched):
beam-freerequest returned HTTP 200;total_usedmoved2 → 3and a new egress rowsocks5h://127.0.0.1:10802appeared.total_used=3and all rows inoc2-side.json.freequota.json.Used 3,Remaining ≈597, three rows, countdown ticking (1h 35m 27s → 1h 35m 24s).gofmt -l .clean,go vet ./...clean,go test -race ./internal/freequota/passes, Linux and Windowsgo build ./...pass,node --checkon changed JS,git diff --checkclean.Known limits
midnightSkewlogic tests, not a live clock test.