OpenCode's gateway answers some of s-leeq's turn-start requests with a
400 whose body is {"model":"deepseek-v4.1-flash"} and nothing else: no
error, message, code, type or param, nothing in or out, no reply id.
retryable() read it as the request's own fault, so a group stopped there
and a lone provider's turn ended on it, with a 400 nothing retries. Their
log ties it to the request, not the key: 30 of 214 requests carrying
~246K tokens of tools failed so, none of 420 under 1K, and the same
request was answered 200 some 13s to 25s after the first refusal.
openCodeBareRefusal (ported from ggbdpq's patch on the issue) reads a
400 from an OpenCode host whose body is a JSON object naming no error
field as the 502 it stands for (asBadGateway). A group asks its next
member; a lone provider is asked again within its patience (60s, with
replan pauses), which outlasts the reporter's window. Any 400 that names
something, a body that isn't a JSON object, and every other vendor's
400 go on as they came.
Changed from the patch:
- restAfterMarked rests nobody for this 502. The patch rested the key
for fallbackCooldown in a group (a scratch test showed ocgo resting
60s), over a refusal tied to request content: one heavy prompt would
have set aside a key that serves every other request.
- The body is read through a 64KB limit and put back with a
MultiReader, so nothing is cut; a body at the limit is left alone.
The patch read it whole.
- TestOpenCodeGoBare400ToldAs502 asserts at least 3 asks, not exactly
3: on current main the lone provider's patience asks 15 times.
Run on mote:
- At the pushed head (on c272e5582): gofmt -l clean; go vet
./internal/gateway for darwin, linux and windows; go test
./internal/gateway -run 'OpenCode|Rest|Fallback|Patience|Retry' ok (83s).
- On 576b5dcbc, before main took four more gateway commits
(82ff88933..c272e5582): go test ./internal/gateway -count=1
-timeout 45m ok (615.8s).
- TestOpenCodeGoBare400AskedAgain, ToldAs502, RestsNobody (new: a group
of OpenCode Go and another provider; the first request's bare 400 is
served by the other, the next request still reaches OpenCode) and
TestOpenCodeGoError400Untouched pass.
- Before the rebase, the package was red only in
TestClaudeCallerEnvironmentInAMessageIsTheLastGiven, which 576b5dcbc
fixed on main since.
Broken by hand:
- rest exemption off (`if false &&`): RestsNobody red, "OpenCode asked
1, the other 2".
- openCodeBareRefusal taken out of forwardOnce: AskedAgain, ToldAs502
and RestsNobody red; AskedAgain shows the issue's exact 400.
- A real-time scratch test (refusals for 25s, 2.5s each, the real
retryPause, lone provider) got its 200 after 32s, asked 6 times.
Deleted after.
Not tried: a real OpenCode Go key or the reporter's DeepSeek Harness; the
bodies are the issue's bytes. A turn whose refusals outlast 60s still
ends, now as a 502 the client can retry.
Co-authored-by: ggbdpq <ggbdpq@gmail.com>