Skip to content

Zen free-tier 429: confirmed quota model, fixes applied, and open questions needing verification #158

Closed

Description

@unrayed

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:
    const ip = rawIp.includes(':') ? rawIp.split(':').slice(0, 4).join(':') : rawIp
    So the bucket is per egress /64 (+ model prefix when rateLimit is configured), not per session, project, account, or key.
  • Window: UTC calendar day (buildYYYYMMDD(now)). getRetryAfterDay returns seconds to next UTC midnight, sent as retry-after on 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 — matches usage.in == 0 on 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-model rateLimit values are not public.

Measured on this deployment:

  • Retry-After: 18912 and 17076, both resolving to next UTC midnight.
  • in: 0 on every 429; in: ~5760 on 200s.
  • Nine WARP exits map to nine distinct /64s (verified via Cloudflare trace), i.e. nine independent buckets, plus one direct host 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), then attempts=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.

  1. Body-shape dependence. Holding headers, session id and egress constant, hello returned 429 while hello. returned 200; other one-character edits flipped outcomes. We hypothesised a prompt-hash throttle and retracted it — the effect is better explained by per-/64 bucket luck plus decaying new-IP bonus. No controlled reproduction exists either way. Open question: can anything other than the IP/day/model counter emit FreeUsageLimitError?

  2. Fresh vs warmed exits. Restarting a WARP container produced a brand-new /64 that immediately 429'd while untouched exits returned 200 in the same minute; conversely a spent /64 sometimes passed well before UTC midnight. A pure /64+day counter does not explain either. Untested candidates: a separate per-/64 reputation/abuse counter, or an interaction with lifetimeCount.

  3. 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 as FreeUsageLimitError.

  4. Reported runtime/TLS effect (most important). One project claims identical headers/session/body yield 429 under Node fetch and 200 under Bun fetch. 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.

  5. 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.

  6. upstreamNodes.RestoreProxy has 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 with Retry-After. Left unfixed deliberately — key-lane semantics differ and we have not observed the failure there. Needs a decision.

  7. Burned direct entry. direct is the host IP, permanently 429 with Retry-After: 17076. It remains in config.json proxies, 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-After each time. Distinguishes "bucket spent" from "exit reputation" (items 1, 2).
  • Capture Retry-After values 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

  1. unrayed commented on Oct 28, 2026

    @unrayed
    ContributorAuthor

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions