Cause: codex-cli's developer messages (permissions, writable roots under
the home, git email) contain things Settings → Privacy masks. A masked
request's reply goes through redact.Writer, which restores values one
SSE event at a time and buffered everything up to the next blank line.
holdWriter's ": keepalive\n" is a comment with no blank line after it, so
every one waited in that buffer for the vendor's first event: six came
together at 96.5s, and Cloudflare's 100s read timeout gave a 524. A plain
{"input": ...} body has nothing to mask, its reply isn't wrapped, and its
keepalives went out live, which is the bisection in the issue.
middleware's writer (a JS onEvent) had the same buffer.
Fix: both writers pass through whole comment lines and blank lines
at the head of the buffer as soon as they arrive. The head of the buffer
is always where an event starts, so these lines belong to no event. A
comment inside an event stays there. In redact, an event held for a
placeholder's tail stays held, so the placeholder still comes back whole.
Tests: TestQuietCodexStreamKeptAliveThroughReplyWriters (gateway, over
HTTP): the issue's Codex-shaped Responses body, masked / a middleware
only, a vendor that sends response.created and stays silent until the
client has read a keepalive (3s cap), keepaliveEvery 40ms injected. Unit
tests TestWriterStreamKeepaliveNotHeld (redact, with a placeholder split
around keepalives) and TestStreamKeepaliveNotHeld (middleware).
Broken by hand: disabled the pass-through in redact/writer.go and
the masked subtest went red after 4.7s, as did the redact unit test.
Disabled it in middleware/run.go and the middleware subtest went red,
as did the middleware unit test. Each one is green again with the fix.
Run (sandbox HOME, -tags nogui -p 1): go test ./internal/redact/
./internal/middleware/ (whole packages) ok; go test ./internal/gateway/
-run 'Keep|Quiet|Redact|Mask|Middleware|Codex|Held|Unredact|Placeholder|Silent'
ok (129s). gofmt -l clean; go vet -tags nogui for darwin, linux and
windows on the three packages ok. Not tried with a real Codex account
behind a real Cloudflare Tunnel.
Full suite: SUITE_LINE