Skip to content

Availability probes and the Playground bench both pin a deterministic session, so both 429 while live traffic succeeds #156

Closed

Description

@unrayed

Summary

Two code paths pin a deterministic upstream session, so they reuse a single project × egress quota bucket. Once burned, both report 429 Free usage limit reached permanently while live traffic to the same model, on the same process and egress, returns 200.

The two paths are independent — fixing one does not fix the other.

Path File Symptom
Availability probes internal/gateway/probe.go:100 every free model cached as http_429; /v1/models and Playground under-report availability for 1 hour
Playground bench internal/admin/debug.go handleDebugInference "Send diagnostic request" always 429

Background: how the upstream meters free quota

The Zen free tier meters usage per project × egress block (IPv4 /32, IPv6 /64), resetting daily at 00:00 UTC. Two consequences drive both bugs:

  1. A fixed project id is one shared bucket for the deployment's lifetime.
  2. A fixed session id appears to be treated as one continuous conversation, and reusing it keeps drawing from the same bucket.

The live request path already handles this: DeriveRequestIDs (internal/identity/request.go) mints projectSignal = RandomProjectID() per request when the client does not supply one, and the comment there documents exactly this failure mode:

// A fresh project id per request. The free tier ledges its quota per
// project id and egress, so one shared id is one shared bucket: the old
// per-caller default arrived pre-burned on popular exits.

Both buggy paths bypass that reasoning by hardcoding or deriving a stable value.

Bug 1 — availability probes

internal/gateway/probe.go:100

ids := identity.RequestIDs{Session: identity.CanonicalSessionID("availability:" + model), Project: "opencode2api:default-project"}

One literal project for the whole deployment, and one session per model, reused by every probe forever.

Result: probes are strictly more likely to 429 than real requests. The availability cache then stores reason: http_429 and skips the model for FreeModelCheckInterval (1 hour), so /v1/models and the Playground both under-report.

Bug 2 — Playground bench

handleDebugInference builds a synthetic request and forwards it to the gateway with no session header:

request.Header.Set("Authorization", "Bearer "+cfg.FirstEnabledServerKey())
request.Header.Set("Content-Type", "application/json")
request.Header.Set("Accept", "application/json")

With no session signal, DeriveRequestIDs falls back to conversationSeed(body) — system prompt plus first user turn.

That is correct for real traffic: it keeps a conversation on one session as its history grows. It is wrong for the Playground, which replays an identical prompt on every click. Same prompt → same seed → same session → same bucket, forever.

Every bench attempt produced the identical upstream session, across separate clicks and a process restart:

req_a3eff30dd7dc91c16c58f6821c571d08  session: ses_ef8e8304affe1KiVqKxJpx4wkE
req_204931ca94ceb14e4aa050c1a01cafb9  session: ses_ef8e8304affe1KiVqKxJpx4wkE

Reproduction

  1. Run the gateway where the free tier works (verified with direct plus distinct WARP IPv6 /64 exits).
  2. Confirm live traffic succeeds:
    curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:12808/v1/chat/completions \
      -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
      -d '{"model":"deepseek-v4.1-flash-free","messages":[{"role":"user","content":"hi"}],"max_tokens":8}'
    # => 200
  3. Delete config.json.<fp>.availability.json, restart, wait for the probe sweep:
    jq -r 'to_entries[] | .name + " " + (.value.reason // "OK")' config.json.*.availability.json
    # => every free model: http_429   while step 2 still returns 200
  4. Open the Playground, select the same model, press Send diagnostic request → HTTP 429.

Observed 2026-10-28: 0/8 probes succeeded, 8/8 live requests succeeded on the identical process and egress.

Fixes

Both are one-line identity changes; nothing else in the request shape needs to move.

Bug 1

--- a/internal/gateway/probe.go
+++ b/internal/gateway/probe.go
-ids := identity.RequestIDs{Session: identity.CanonicalSessionID("availability:" + model), Project: "opencode2api:default-project"}
+ids := identity.RequestIDs{Session: identity.CanonicalSessionID("availability:" + model + ":" + identity.RandomID("p", 8)), Project: identity.RandomProjectID()}

Note: randomizing Project alone was not sufficient (still 0/8). Randomizing the session signal as well recovered 8/8, so both should change.

Bug 2

--- a/internal/admin/debug.go
+++ b/internal/admin/debug.go
+	"opencode2api/internal/identity"
@@
+	// A Playground request is not a conversation: deriving identity from the
+	// prompt alone makes every click reuse one session and burn a single bucket.
+	request.Header.Set("x-opencode-session", identity.RandomID("playground", 24))
 	request.Header.Set("Content-Type", "application/json")

Verification after patching

Same binary, same config, same egress, stale cache cleared:

before after
availability probes 0/8 probe_succeeded 8/8
Playground bench 429 200
live traffic 200 200

Suggested tests

Both regressions are silent — nothing fails until a bucket is exhausted, and the resulting 429 is indistinguishable from genuine quota exhaustion. Worth asserting:

  1. Two consecutive probeAttempt calls for the same model do not produce equal ids.Project, and their ids.Session differ.
  2. Two handleDebugInference calls with an identical body do not produce equal ids.Session.

Environment

  • opencode2api v1.4.5 source, built from main
  • upstream https://opencode.ai/inference (v2 lane only; /zen retired for free models)
  • egress: host IPv6 /64 plus 8 distinct WARP /64 exits
  • anonymous: true, no zen_keys, no go_keys

Activity

  1. changed the title [-]Availability probes pin a fixed session+project, so they 429 while live traffic succeeds[/-] [+]Availability probes and the Playground bench both pin a deterministic session, so both 429 while live traffic succeeds[/+] on Oct 28, 2026
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