codexZstd (internal/provider/codex_zstd.go) set no window, so klauspost's
encoder declared its default 8 MiB (and, single-segment, up to the body
size below that) on every turn magpie re-compresses for the ChatGPT
backend: the accounts loop (forwardOnce), the native relay
(codexUpstreamOn) and warm-up all go through CodexCompressed. Codex's own
client never sends that: openai/codex ce0323f2
codex-rs/http-client/src/request.rs compresses with
zstd::stream::encode_all(Cursor, 3); zstd 0.13.3 (Codex's Cargo.lock)
copy_encode streams through Encoder::new(dest, 3) with the size unknown,
which libzstd 1.5.7 gives level 3's windowLog 21 (2 MiB). pc418's
15,173,526-byte image-heavy turn got 400 in the 8 MiB frame and 200 at
2 MiB; a later replay of the 8 MiB bytes was taken, so this matches the
client's envelope rather than proving a backend limit. Level and checksum
are unchanged. Cost: a large turn is bigger on the wire at 2 MiB with
SpeedDefault (pc418's turn 7.59 MB -> 12.44 MB; libzstd -3 gives 9.78 MB).
Reviewed and run (reviewer, at this commit on 89521b03d):
- Source checked: request.rs on openai/codex main ce0323f2 (encode_all,
level 3), Cargo.lock zstd 0.13.3, zstd-rs v0.13.3 copy_encode.
- libzstd check: a 9.4 MB fixture with a 3 MiB random block repeated
~4 MiB apart. `zstd -3` from stdin: Window Size 2.00 MiB, 6,293,668 B.
The old encoder's frame: 8.00 MiB window, 4,297,564 B, and
`zstd -d --memory=2MB` refuses it ("Window size larger than maximum:
8388608 > 2097152"). This commit's frame: 2.00 MiB window, 8,377,219 B,
and `zstd -d --memory=2MB` decodes it to the same bytes. (For the record,
SpeedBetterCompression at 2 MiB gave 6,293,661 B, libzstd's size; not
changed here.)
- TestCodexCompressedLargeImageTurn fails with the option removed:
"zstd frame window = 8388608 bytes, want at most 2 MiB"; passes with it.
- The gateway zstd tests in gateway-routing.md's commands pass;
-race -count=3 on the new test passes.
- gofmt -l clean; go vet ./... and -tags nogui (darwin), GOOS=linux and
GOOS=windows go vet -tags nogui ./...: clean; go build, GOOS=linux go
build -tags nogui, GOOS=windows go build: ok.
- Full suite: see the #2727 commit after this one, run at that head with
both changes.
- Not run: a real ChatGPT account through magpie (pc418 ran real native
relay and account-pool image turns at 2 MiB: 200 each).
Co-authored-by: pc418 <271863285+pc418@users.noreply.github.com>