Files
magpie/internal/gateway/stream_refused.go
T
yetone 1f99f6f0b5 provider, gateway: a backend that only streams is tested and served (Cyrus_4433 on X: claude-relay-service "400 · Stream must be set to true")
A CRS Responses endpoint, like Codex's own backend, turns away a request that
doesn't ask for stream:true. The editor's Test models and protocol detection
send one small body, so every model of such a relay was red; an agent that sent
stream:false got the same 400 through the gateway.

Probe: probeAt asks once more with stream:true when a 400/422 says the stream
must be set (provider.StreamRequired, WithStream). Chosen over streaming every
probe so a vendor that takes one body keeps being asked for one; every probe
(model test, per-model check, detect, key check) goes through probeAt.
Gateway: passthrough marks the model stream-only on that 400 for a request
asking one body and returns done=false; attempt then translates on the same
API (always streamed upstream, whole reply to the client), and asks so at once
from then on, as a refused custom tool is.

Run (mote): new tests built from the reporter's literal error, red on the old
code (TestProbeStreamsWhereTheBackendOnlyStreams, TestDetectFindsAStreamOnlyBackend,
TestWholeReplyFromAStreamOnlyBackend), green on the new; go vet darwin, windows,
linux nogui; go test ./internal/provider ./internal/gateway ok. Each fix broken
by hand (probe retry stashed, gateway hook stashed): red. Not tried: a real CRS
relay; the rest of ./... (started after the tag).
2026-11-11 10:37:13 +08:00

24 lines
1.0 KiB
Go

package gateway
import (
"github.com/yetone/magpie/internal/provider"
)
// A backend that only streams (claude-relay-service's Responses endpoint,
// like Codex's own ChatGPT backend) turns a request that asks for one body
// away: "Stream must be set to true" (Cyrus_4433 on X). An agent that sent
// stream:false got that 400. The request is then translated on the same
// API, which always asks the upstream streamed and gives the client its
// whole reply (translate), and so from then on, as a custom tool turned
// away is (custom_tool.go).
// streamOnlyRefused is how unfit remembers model's backend answering only
// streamed requests.
func streamOnlyRefused(model string) string { return "stream only\x00" + model }
// refusesWhole is whether a 400's body says the request must ask for a
// stream, while the client's body asked for one whole reply.
func refusesWhole(proto provider.Protocol, body, reply []byte) bool {
return (proto == provider.Chat || proto == provider.Responses) && !streamOf(body) && provider.StreamRequired(wordsOf(reply))
}