Repository navigation
Description
Zen free-tier 429 FreeUsageLimitError: what we know, what we fixed, what is still unverified
Tracking issue for the anonymous-lane quota behaviour in this gateway. Written after several days of black-box probing plus a read of the Zen console source. Everything below is either measured on this deployment or quoted from source; guesses are marked as such.
Purpose: keep the confirmed model, the fixes already applied, and the open questions in one place so remaining work is verifiable rather than folklore.
1. Confirmed model (source + measurement agree)
Source: packages/console/app/src/routes/zen/util/ipRateLimiter.ts and handler.ts on the v2 branch. Note dev has no zen/util at all.
- Counter key:
${stage}:ratelimit:ip:<ip>[:<YYYYMMDD><modelId[0:2]>]. IPv6 is truncated to a/64:So the bucket is per egressconst ip = rawIp.includes(':') ? rawIp.split(':').slice(0, 4).join(':') : rawIp
/64(+ model prefix whenrateLimitis configured), not per session, project, account, or key. - Window: UTC calendar day (
buildYYYYMMDD(now)).getRetryAfterDayreturns seconds to next UTC midnight, sent asretry-afteron the 429. - New IPs get a doubled allowance while
lifetimeCount < dailyLimit * 7; the bonus decays over lifetime requests. - The 429 is thrown before
authenticate()and before the provider call, so no tokens are read or billed — matchesusage.in == 0on every 429 we see. track()runs on every 200 including prompt-cache hits, so a cache hit still spends a unit.- Numeric limits live in the secret
ZEN_LIMITS; per-modelrateLimitvalues are not public.
Measured on this deployment:
Retry-After: 18912and17076, both resolving to next UTC midnight.in: 0on every 429;in: ~5760on 200s.- Nine WARP exits map to nine distinct
/64s (verified via Cloudflare trace), i.e. nine independent buckets, plus onedirecthost exit.
Consequence for this gateway: retrying another exit is only useful because exits have separate buckets. Once every /64 is spent, no routing change helps until 00:00 UTC.
2. Bugs found and fixed here (all uncommitted at time of writing)
| location | bug | fix |
|---|---|---|
internal/gateway/pool.go MarkFailure |
Retry-After was clamped to cooldown * 8 (~4 min) instead of honoured in full (measured 5h15m) |
delay = retryAfter, unbounded |
internal/gateway/pool.go anonymousCursor.Next phase 2 |
the cooldown fallback handed back nodes still inside their cooldown, so a "hard" cooldown never stopped a walk | phase 2 only considers nodes whose cooldown has expired; a second, explicitly degenerate pass returns the soonest-expiring node only when every node is cooling |
internal/gateway/pool.go anonymousNodes.RestoreProxy |
a proxy returning any HTTP status (incl. 429) was treated as recovered, which cleared quota cooldowns for every node on it | added quotaCooldown atomic.Bool on anonymousNode; set when the delay came from Retry-After; RestoreProxy skips those nodes; MarkSuccess clears it |
internal/gateway/pool.go |
no way to start a retry pass on a different exit | added CursorForOffset; doAnonymousUpstream pass 1 now starts on the next exit |
Observed before/after on the same body:
- Before:
attempts=16(8 exits x 2 passes), 4.6-6.2 s, 429. - After: first request
attempts=10..11(inherited cooled exits), thenattempts=1, 0.7-2.4 s, 200.
Also relevant: isDiagnosticRequest makes observeAnonymousResult return before writing cooldowns, by design. Diagnostics therefore walk every exit (attempts=16) without ever learning from a 429. That is a deliberate contract, not a bug — but it means diagnostic latency and attempt counts are not representative of production.
3. Still unverified / possibly wrong
These are open. Several contradict the source, and we have not produced a clean reproduction of any of them.
-
Body-shape dependence. Holding headers, session id and egress constant,
helloreturned 429 whilehello.returned 200; other one-character edits flipped outcomes. We hypothesised a prompt-hash throttle and retracted it — the effect is better explained by per-/64bucket luck plus decaying new-IP bonus. No controlled reproduction exists either way. Open question: can anything other than the IP/day/model counter emitFreeUsageLimitError? -
Fresh vs warmed exits. Restarting a WARP container produced a brand-new
/64that immediately 429'd while untouched exits returned 200 in the same minute; conversely a spent/64sometimes passed well before UTC midnight. A pure/64+day counter does not explain either. Untested candidates: a separate per-/64reputation/abuse counter, or an interaction withlifetimeCount. -
Community disagreement on the key. One peer project reports metering per session+project pair rotated every 30 min; another reports per
/64. Our data and the source favour/64. We cannot rule out two counters existing with only one surfacing asFreeUsageLimitError. -
Reported runtime/TLS effect (most important). One project claims identical headers/session/body yield 429 under Node
fetchand 200 under Bunfetch. Not reproduced here. This gateway already uses a Bun-emulating TLS/HTTP1.1 transport (internal/httpx/bun.go). If the claim is real, at least one gate exists beyond header/session/tool-shape checks, and every header-only fix in the ecosystem is incomplete. Confirm or refute. -
Simultaneous 429s across independent
/64s. We have seen all exits 429 within the same second while a different request in the same minute succeeded. Consistent both with all buckets being spent and with an unseen shared component. -
upstreamNodes.RestoreProxyhas the same conflation as the anonymous fix above: it clears a key's cooldown when the key's preferred proxy recovers, even if the cooldown came from a 429 withRetry-After. Left unfixed deliberately — key-lane semantics differ and we have not observed the failure there. Needs a decision. -
Burned
directentry.directis the host IP, permanently 429 withRetry-After: 17076. It remains inconfig.jsonproxies, so a session whose cursor hashes onto it starts the walk on a dead exit. Removal was proposed and not applied.
4. Suggested next experiments
Each is cheap and answers one open item:
- Rotate only the
User-Agent/x-opencode-*headers on a single fixed exit against a body known to 429, and separately a body known to 200. Tests item 4 without touching routing. - Issue one request per exit, one body, sequential, logging
Retry-Aftereach time. Distinguishes "bucket spent" from "exit reputation" (items 1, 2). - Capture
Retry-Aftervalues across a UTC midnight boundary. Confirms the window is strictly daily for every exit, not rolling (item 5). - Repeat the Node-vs-Bun pair from the peer report on one exit with byte-identical requests (item 4).
5. Non-goals
We are not trying to defeat the quota. Nine /64 buckets plus a daily refill is the documented allowance; the goal of this issue is that the gateway spends each bucket at most once and fails predictably, not that it manufactures more.
Activity
unrayed commentedon Oct 28, 2026
Notes from a debugging session on the proxy: the criteria for a passing versus failing request were inconsistent at the time. Kept for reference; related fix in #182 (
95575c5).fix(identity): salt derived session ids per process (#160)