Skip to content

feat(diagnostics): pin a Playground request to one relay - #167

Closed
unrayed wants to merge 1 commit into
jasonxu114514:mainfrom
unrayed:feature/relay-pin-diagnostics
Closed

unrayed wants to merge 1 commit into
jasonxu114514:mainfrom
unrayed:feature/relay-pin-diagnostics

Conversation

@unrayed

@unrayed unrayed commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Why

The Playground can already name the key a diagnostic request uses, but not the relay (proxy) it leaves through. When one relay is suspected of throttling or breaking, the only way to tell was to read the request log and hope routing landed on the relay in question.

This adds an explicit relay pin, so one relay can be exercised in isolation.

Design

gateway.RelaySelection names a relay by index, by name, or both:

{"relay": {"index": 3, "name": "socks5h://127.0.0.1:10804"}}
  • index is the position in the configured proxy list, name is the proxy URL. Either alone is enough; supplying both requires them to agree.
  • The selection is resolved against Gateway.transports, the shared proxy list, so the pin applies on every tier — not just the anonymous lane.
  • An unknown relay is a 400 unknown_relay, never a silent fallback: a typo would otherwise read as a relay verdict.

The pin is applied as a context value (gateway.WithRelayOverride), so the request stays on the production path — session minting, system prompt, tool shaping and the transport are unchanged. Only the exit is forced.

Both lanes are capped at one attempt while pinned:

  • anonymous: the cursor is built from the pinned proxy and limit = 1
  • key: attemptLimit = 1, and the key's proxy binding is replaced by the pinned relay

Rotating keys or exits would no longer describe the relay that was asked for.

The request is still marked diagnostic, so a pinned attempt writes no cooldown, proxy health or IP-block state — it cannot poison the relays it is meant to measure.

API

POST /api/debug/inference gains an optional relay field:

{
  "protocol": "openai",
  "key": {"mode": "auto"},
  "relay": {"index": 3},
  "request": {"model": "...", "messages": [...]}
}

GET /api/debug/models now returns relays, the configured proxy names in configuration order.

DebugInferenceResult gains relay_test, the relay that actually served the request.

UI

The Playground (Diagnostics → request test) renders a Relay selector under Upstream Key, populated from relays, defaulting to Any relay (normal routing). The result panel gains a Relay tested row. Strings added for en/vi/it.

Per-attempt legs on the anonymous lane now append the redacted relay (anon:200:412ms@socks5h://…), so the request log shows which exit each attempt used.

Testing

go build ./cmd/opencode2api && go vet ./internal/gateway ./internal/admin

Then, with the gateway running:

# list relays
curl -s -b cookies -H "x-csrf-token: $CSRF" http://127.0.0.1:12881/api/debug/models | jq .relays

# pin by index
curl -s -b cookies -H "x-csrf-token: $CSRF" -H 'content-type: application/json' \
  -d '{"protocol":"openai","relay":{"index":3},"request":{"model":"...","messages":[{"role":"user","content":"hi"}]}}' \
  http://127.0.0.1:12881/api/debug/inference | jq '{ok, http_status, relay_test, route}'

# pin by name only, mismatched pair, out-of-range index
# → 200 with relay_test set, 400 unknown_relay, 400 unknown_relay

Verified live: index 0/3/5/7 resolved to the expected relays, name-only resolution worked, a mismatched index+name pair and an out-of-range index both returned 400.

The Playground could already name a key, but not the relay (proxy) a
request leaves through. When a relay is suspected of throttling or
breaking, the only way to tell was to read the request log and hope the
routing landed on the relay in question.

Add an optional `relay` to POST /api/debug/inference:

    {"relay": {"index": 3, "name": "socks5h://127.0.0.1:10804"}}

Index is the position in the configured proxy list, name is the proxy
URL; either alone is enough and supplying both requires them to agree.
An unknown relay is a 400 rather than a silent fallback, because a typo
would otherwise read as a relay verdict.

The pin is resolved against Gateway.transports, the shared proxy list, so
it applies on every tier: the anonymous lane walks exactly that exit and
a key request is sent through that proxy. Both lanes are capped at a
single attempt, since rotating keys or exits would no longer describe the
relay that was asked for.

The request stays marked diagnostic, so a pinned attempt writes no
cooldown, proxy health or IP-block state and cannot poison the relays it
is meant to measure. Session minting, system prompt, tool shaping and the
transport remain the production path, so the answer is comparable to real
traffic.

GET /api/debug/models now returns `relays` in configuration order, and
the result carries `relay_test` with the relay that actually served the
request. The Playground renders a relay selector from that list and shows
the tested relay in the result facts. Per-attempt legs on the anonymous
lane now append the redacted relay, so the request log shows which exit
each attempt used.
jasonxu114514 pushed a commit that referenced this pull request Nov 5, 2026
Resolved against #170 so a relay pin clears the per-attempt WARP choice
(attemptUseWARP). The relay list is now credential-redacted, and a pin may
name a relay by its redacted URL.
@jasonxu114514

Copy link
Copy Markdown
Owner

Merged to main as b296a61. I resolved the conflict with #170 by hand and made the relay list return credential-redacted proxy URLs. Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants