CartethyiaQwQ (#3274): Codex's "safety filter: cyber_policy" refusal
(the Daybreak note) set healthy accounts aside; two such turns benched a
five-account pool for about 17 minutes.
Cause: the HTTP 400 cyber_policy is already a refusal (policyRefusal reads
its code: next account asked, nobody rests), and so is one said in a
stream relayed as a stream. A Codex account is always streamed upstream,
so a stream:false Responses, Chat or Messages request is answered from
that stream whole. There, a response.failed or error event whose error
has a code (cyber_policy) but no invalid_request_error type got no status
from the decoder, and the whole path answered it 502 api_error: retried
on the same account, then every account asked, each one but the last
resting by backoff. A refusal after a few words went to the client as a
finished 200 turn, and the failure after it rested the account.
Fix, at the decoders and the whole path:
- filterRefused (fallback.go): a stream error event refusedCode reads as
the safety filter's gets status 400 and Said {"error":{type
invalid_request_error, code}}. Used by every decoder that set
Code: refusedCode -- Responses (both error sites, after requestRefused),
Chat, Anthropic and carriedError.
- The whole path (gateway.go) answers a reply the filter cut part way as
the refusal, not its words so far, and notes it in refusedHeader, since
Anthropic's error shape drops the code that settle reads.
- restAfterMarked: a 400 whose error object policyRefusal reads as a
refusal rests nobody and counts no failure (By "off", Why refused), as
the ZDR refusal does, for any route that reaches it.
- docs/subsystems/gateway-routing.md says so.
Review of the submitted patch (dc6c695db, not taken as is): it matched
`safety filter|cyber_policy|Daybreak access` anywhere in a 400's words,
so a 400 that echoes the user's prompt in its message skipped the rest
too; its fixture was magpie's own refusedError text, which restAfter is
never handed for a 400; and it gated on status 400, while the path that
rested (above) answered 502, so it would not have stopped the rests.
Its restAfter unit tests' shape is kept in TestRestAfterPolicyRefusal.
Run at 21f7f9df2 (origin/main then) plus this change, unless said:
- New TestStreamRefusalAnsweredWholeRestsNobody: {response.failed, error
event, refusal after text} x {Responses, Chat, Messages answered whole}
x {next answers, nobody left}; fixture is the reporter's quoted message
without magpie's 300-char cut. Asserts the client gets 200 from the
next account or a 400 naming cyber_policy, every try failRefused with
no Rest, nothing resting.
- New TestRestAfterPolicyRefusal: cyber_policy 400 rests nobody and
counts 0 failures; a plain 400, and two 400s echoing the reporter's
words in the message (code string_above_max_length / code null) still
rest by backoff.
- Red on the old code: all 18 TestStreamRefusalAnsweredWholeRestsNobody
subtests and TestRestAfterPolicyRefusal/cyber_policy. Broken by hand,
each went red: filterRefused returning no status (all 18); the
part-way clause dropped (6 "after some text"); refusedHeader not set
(6 Messages subtests).
- A scratch matrix before the fix (also streamed Responses/Chat/Messages
and Codex's own path, HTTP 400 and response.failed): only the whole
routes rested; the streamed ones and the HTTP 400 already passed.
- gofmt -l clean; go vet ./... (darwin), GOOS=linux and GOOS=windows
go vet -tags nogui ./... clean.
- go test -race -timeout 45m ./internal/gateway/: FAIL on two tests
this change doesn't reach, each ok alone with -race -count=3 and
filed: TestPluginStreamLongActiveReader (client deadline after 36MB,
#3286) and TestQuietKeptAliveOnlySoLong (0 keepalives in a 3s pause,
#3287). Load was 180-280 from other sessions' GUI runs.
- Rebased on ba1dc7f97: gofmt, go vet ./internal/gateway/ and the two
new tests again: ok.
- go test -timeout 45m ./... at ba1dc7f97 plus this change: ok, 69
packages, no FAIL (internal/gateway 783s).
Not tried: a real Codex account. Whether the ChatGPT backend sends
cyber_policy as an HTTP 400 or inside a 200 stream, and with or without
an error type, isn't known from the issue; every shape is covered by
tests, not by a live refusal.
Co-authored-by: 卡提希娅可爱捏 <134358478+CartethyiaQwQ@users.noreply.github.com>