Three gaps Jichao reported, each reproduced on origin/main 4a6bf80f4
with fake upstreams before the change:
1. An HTTP error or stream error event whose message is, whole, "The
request was rejected because it was considered high risk" with no
policy code was any failure, not a refusal: no refusal fallback.
policyRefusal now takes that exact message (trimmed) as a refusal
(highRiskRefusal). It reads only an error's own message field, so an
answer that quotes the sentence stays an answer. The vendor that sends
it isn't known (no wire capture; none of our code or docs has it); it
says the request was turned away, so it rests nobody and goes to the
next candidate under RefusalRetries, like every refusal.
2. A policy error event before any content (content_filter, coded) left
the held try waiting for the upstream's EOF: with the connection kept
open the request hung until the client gave up. Such an event is now
eventRefusalError and stops the try as eventError does; a refusal's
stop/finish marker (eventRefusal) is still read to the end for its
trailing usage and terminator.
3. After content, refusalAfter skipped a write that didn't look like a
refusal, so an "event: error" whose name and data came in separate
writes was never noted (a coded content_filter too). Every write is now
read; only an unfinished event's bytes are kept, so a reply's content
isn't copied. refusalSays matches the bare word error for the named
event. Nothing already sent is replayed.
Reference patch by Jichao (585836c on Jichao/magpie
fix/provider-refusal-errors), reviewed line by line and taken with
changes: refusalAfter no longer appends every write to a buffer, the
message is a named const with why, the doc line is rewritten, and the
split test gains a coded named error (red on main without the message
match). No new retries or fallbacks: everything goes through the
existing refusal path.
Run (darwin, sandbox HOME, -tags nogui -p 1):
- New tests on main without the fix: TestHighRiskErrorMessage,
TestHighRiskErrorFallsBack, TestRefusalErrorDoesNotWaitForEOF (hung to
the 10s guard), TestHighRiskErrorWhenRetryStops,
TestHighRiskTextAndStartedReplyAreNotReplayed,
TestHighRiskNamedErrorAfterContentRestsNobody,
TestHighRiskErrorSplitAfterContent all red. With it, ok.
- Broken by hand, each red: no stop on eventRefusalError
(TestRefusalErrorDoesNotWaitForEOF), the per-write prefilter back
(TestHighRiskErrorSplitAfterContent), the message case off (the
TestHighRisk* set).
- -run 'Refus|Refuse|Hold|Fallback|StreamEvent|Late|Policy|Safety' ok;
-race on 'TestHighRisk|TestRefusalErrorDoesNotWaitForEOF|Refus|
StreamEvent|Hold' ok.
- gofmt -l clean; go vet -tags nogui for darwin, linux, windows ok.
Not run: the full suite, any real vendor.
Full suite: SUITE_LINE