Skip to content

# zstd request compression: highly compressible content gets a bare 400 instead of the documented 413, and Codex never avoids it #61489

Open

Description

@Pengpengwanga

What version of Codex CLI is running?

codex-cli 0.167.0

What subscription do you have?

Pro 500

Which model were you using?

gpt-6.1-sol

What platform is your computer?

Linux x86_64(CentOS 8)

What terminal emulator and version are you using (if applicable)?

No response

Codex doctor report

What issue are you seeing?

Summary

With features.enable_request_compression on (the default for ChatGPT auth), Codex zstd-compresses HTTP request
bodies to chatgpt.com/backend-api/codex/responses. When part of the body decompresses to far more than its compressed
size, the backend answers 400 {"detail":"Bad Request"}. The same request sent uncompressed succeeds.

The API docs (production best practices → Compress request bodies)
say the decompressed body must be at most 100× the compressed size, that requests exceeding the limits return
HTTP 413
, and that 400 is for invalid or incomplete zstd data. A decompression-ratio limit is reasonable; the problems
are:

  1. The Codex backend returns a bare 400, not the documented 413, so a client can't tell "ratio limit" from corrupted
    data, and the user only sees "Bad Request".
  2. Codex compresses by default and never avoids or recovers from it: it does not check the ratio before sending and
    does not retry uncompressed. Once a thread's history contains such content, every later turn fails the same way.

The trigger is local expansion, not the whole-body ratio. In our sweep below, the image is uniform noise, so every
zstd block compresses about equally and the whole-body ratio is a fair proxy: ≤ ~106× passed, ≥ ~117× failed. With
repeated content, long-distance matches let a single block expand by orders of magnitude while the whole-body ratio
stays low. #60594 reports a 400 at a whole-body ratio of only 2.65×. So the limit is presumably checked per block or per
received piece, not on the whole frame; we have not pinned down the exact rule. An offline model that fails when one
~16 KiB input piece decodes to more than 100× matched most of our captured outcomes, but it misjudged one case near the
boundary. If the check is per received piece, the outcome could also depend on how the body is split in transit. That
might be why a repeated image failed in #60594 but passed for us (2/2); this is speculation.

Why it matters

  • It only happens over HTTP, which Codex uses after falling back from WebSockets. Long conversations with many images
    are the ones that fall back (a reloaded thread resends the whole history in one message), and then every later
    turn fails
    with the same 400, because each turn resends the same history.
  • Content that triggers it is ordinary, and nothing needs to be large or modified: a PNG stored without compression, a
    large blank or solid-colour image, or presumably content repeated within the zstd window (the same image twice,
    repetitive logs). A single 4.7 MB image (≈ 6 MB request) is enough. We only tested images.
  • The user only sees "Bad Request", with no hint that compression is involved.

Reproduction

Tested with codex-cli 0.167.0, ChatGPT login, Linux x86_64, direct TLS connection to chatgpt.com.

Files (attached below):

  • make_image.py OUT.png P — a valid 1254×1254 PNG stored without deflate; pixels are noise with probability P,
    otherwise one colour. P controls the zstd ratio. P=0 is a solid image.
  • ratio.sh IMAGE — zstd level-3 ratio of the image's base64 (what the request body mostly is).
  • repro.sh true|false IMAGE — codex exec with one image over plain HTTP (WebSockets off, no retries) and request
    compression on or off.
python3 make_image.py solid.png 0
./ratio.sh solid.png          # base64 6292308, zstd 2069, ratio 3041.2
./repro.sh true  solid.png    # ERROR: {"detail":"Bad Request"}
./repro.sh false solid.png    # OK

Results

Same image, compression on vs off (3 runs each):

image compression on compression off
solid.png (ratio ≈ 3041×) 400 ×3 OK ×3

Compression on, varying how well the image compresses (one run each; every image is 4,719,230 bytes, base64
6,292,308 bytes):

P zstd ratio of base64 result
0.02 28× OK
0.012 45× OK
0.008 64× OK
0.0055 89× OK
0.005 97× OK
0.0045 106× OK
0.004 117× 400
0.002 205× 400
0 3041× 400

Expected

Backend: return the documented 413 (or a specific error message) when a compressed body exceeds the ratio limit,
instead of a bare 400.

Codex client:

A smaller window (e.g. window_log 19) is not a general fix. Per the offline analysis in this thread, it removes
long-distance matches (a repeated image) but leaves short repetitions highly expandable: a run of one character still
reaches 32,768× in one block, and this issue's P=0 solid image 6,241×. Any mitigation should be tested against all
three cases: long-distance repeat, solid image, short repeat.

Workaround

[features]
enable_request_compression = false

With this, the same requests pass (verified with the images above and with real long conversations that had been
failing every turn).

make_image.py
#!/usr/bin/env python3
"""Write a valid 1254x1254 RGB PNG whose IDAT is stored without deflate (zlib level 0), so its bytes stay highly
compressible. Each pixel is random noise with probability P, otherwise one solid colour; P sets how well the image
(and its base64 data URL) compresses with zstd. P=0 gives a plain solid-colour image.

Usage: python3 make_image.py OUT.png P [SEED]
"""
import random, struct, sys, zlib

out, p = sys.argv[1], float(sys.argv[2])
rnd = random.Random(int(sys.argv[3]) if len(sys.argv) > 3 else 1)
n, solid = 1254, bytes([200, 30, 30])
rows = []
for _ in range(n):
    row = bytearray(b"\x00")  # filter type: none
    for _ in range(n):
        row += bytes(rnd.getrandbits(8) for _ in range(3)) if rnd.random() < p else solid
    rows.append(bytes(row))

def chunk(kind, data):
    return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data) & 0xFFFFFFFF)

png = (b"\x89PNG\r\n\x1a\n"
       + chunk(b"IHDR", struct.pack(">IIBBBBB", n, n, 8, 2, 0, 0, 0))
       + chunk(b"IDAT", zlib.compress(b"".join(rows), 0))
       + chunk(b"IEND", b""))
open(out, "wb").write(png)
print(out, len(png), "bytes")
repro.sh
#!/usr/bin/env bash
# Send one image to the ChatGPT Codex backend over plain HTTP (WebSockets off, no retries) with request compression
# on or off. Usage: ./repro.sh true|false IMAGE.png
set -u
codex exec --skip-git-repo-check --ephemeral \
  -c 'model_provider="chatgpt_http"' \
  -c 'model_providers.chatgpt_http.name="OpenAI"' \
  -c 'model_providers.chatgpt_http.base_url="https://chatgpt.com/backend-api/codex"' \
  -c 'model_providers.chatgpt_http.wire_api="responses"' \
  -c 'model_providers.chatgpt_http.requires_openai_auth=true' \
  -c 'model_providers.chatgpt_http.supports_websockets=false' \
  -c 'model_providers.chatgpt_http.request_max_retries=0' \
  -c 'model_providers.chatgpt_http.stream_max_retries=0' \
  -c "features.enable_request_compression=$1" \
  "Reply with the single word OK." -i "$2" < /dev/null
ratio.sh
#!/usr/bin/env bash
# zstd ratio of an image's base64 (what the request body mostly is), at Codex's default level 3.
b=$(base64 -w0 "$1" | wc -c); z=$(base64 -w0 "$1" | zstd -3 -q -c | wc -c)
python3 -c "print('$1', 'base64', $b, 'zstd', $z, 'ratio %.1f' % ($b / $z))"

What steps can reproduce the bug?

Tested with codex-cli 0.167.0, ChatGPT login, Linux x86_64, direct TLS connection to chatgpt.com.

Files (attached below):

  • make_image.py OUT.png P — a valid 1254×1254 PNG stored without deflate; pixels are noise with probability P,
    otherwise one colour. P controls the zstd ratio. P=0 is a solid image.
  • ratio.sh IMAGE — zstd level-3 ratio of the image's base64 (what the request body mostly is).
  • repro.sh true|false IMAGE — codex exec with one image over plain HTTP (WebSockets off, no retries) and request
    compression on or off.
python3 make_image.py solid.png 0
./ratio.sh solid.png          # base64 6292308, zstd 2069, ratio 3041.2
./repro.sh true  solid.png    # ERROR: {"detail":"Bad Request"}
./repro.sh false solid.png    # OK

What is the expected behavior?

No response

Additional information

No response

Activity

  1. added
    bug
    on Nov 14, 2026
  2. added
    CLI
    connectivity
    on Nov 14, 2026
  3. github-actions commented on Nov 14, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. glook9001 commented on Nov 14, 2026

    @glook9001

    Those are two types of compression you confuse the two

  5. Pengpengwanga commented on Nov 14, 2026

    @Pengpengwanga
    Author

    Those are two types of compression you confuse the two

    Thanks for taking a look! To clarify, this issue is only about one kind of compression: Codex's HTTP request-body compression (features.enable_request_compression, i.e. the whole JSON body sent with Content-Encoding: zstd). It isn't about image compression or about conversation compaction.

    The PNG in the repro is deliberately stored without deflate. That is only a convenient way to produce a request body that zstd can compress very well; the image format itself doesn't matter.

    The key point is that, in each pair of runs, the image bytes and the request are identical; the only thing that changes is features.enable_request_compression:

    enable_request_compression=true → 400 {"detail":"Bad Request"} (3/3)
    enable_request_compression=false → OK (3/3)
    And with compression on, whether it fails depends only on how well the body compresses (≤ ~106× passes, ≥ ~117× fails; table above). That points to the server's handling of the zstd-encoded body, e.g. a decompression-ratio limit that answers with a generic 400.

    If I've misunderstood which two types you mean, could you say a bit more? Happy to run any extra test that would help.

  6. glook9001 commented on Nov 14, 2026

    @glook9001
  7. glook9001 commented on Nov 14, 2026

    @glook9001

    enable_request_compression

    Hey I see you are a chinese user --- I assume you are using a VPN -- ( I mean you dont want to compress stuff for nothing)

    you are right , using "enable_request_compression" might be a very common issue -- you should not fail a reuqest due to having enable_request_compression - its a mechincal issue within Codex/ Codex-backend (i assume can be fixed in the client-side -- and the server side to document a better error for what happen )
    i mean you could be spending 4 days, and burnt 90 billion tokens on your coding agents , to understand why you have network connections issues

    aa. Whats your internet speed? https://speed.cloudflare.com/
    bb. what type of vpn tunneling you use ? something like Vmess or ?? (uses differents type of tunneling ), I know there some issues for chinese users deal with services using cloudflare stuff --- there is a lot of novel , interesting design

    image

    for example few months ago, this one end point was failing here under vpn users
    image

  8. r266-tech commented on Nov 14, 2026

    @r266-tech

    One caveat for a whole-body ratio cutoff: this same-JSON comparison in #60594 reports 400 at 131,601 / 49,636 = 2.65×, while level 1 and plain JSON succeeded. I have not independently replayed that request.

    An offline compression example helps reconcile a low overall ratio with highly compressible repeated content. Using the current encoder and its locked zstd 0.13.3 / libzstd 1.5.7, I compressed 2,097,170 bytes of synthetic JSON:

    import base64, json, random
    chunk = base64.b64encode(
        random.Random(20261114).randbytes(3 * 262144)
    ).decode()
    raw = json.dumps({"chunks": [chunk, chunk]}, separators=(",", ":")).encode()
    Level-3 streaming encoder Wire bytes Whole-body ratio
    Default 2 MiB window 787,005 2.665×
    window_log(19) (512 KiB) 1,573,773 1.333×

    In the default frame, a later compressed block contains 9 payload bytes plus its 3-byte block header and regenerates 131,072 bytes. Thus a 2.665× frame can contain a block expanding over 10,000×. With the smaller window, the peak block ratio in this fixture drops to about 1.333×. Both frames decode byte-for-byte to the original JSON.

    This supports inspecting per-block decoded output and cross-block references, alongside whole-body ratio. It also shows why lowering the window can change much more than the frame header. It does not establish that the backend enforces a block-level ratio limit, or that all these reports share one defect. A high-total-ratio cutoff alone would leave the reported 2.65× case untouched.

    AI-only offline source analysis on macOS arm64; no backend/model requests. The copied current encoder's three unit tests and all local roundtrips passed.

  9. Pengpengwanga commented on Nov 14, 2026

    @Pengpengwanga
    Author

    It actually make sense - to disable high compression types

    2 ways i thoerize of making this (my own creatievty I DONT USE AI I AM NOT FROM AUSTRLAIA I CANT SPEAK ENGLSIH)

    1. i thikn you can give a correct [your zstd ] pronouced ? [zs][tee][dee]
    2. Give a seprated queue if the a message is to overally compressed
    3. --> [ INCASE IF HIGH COMPRESSIONS DO HAPPEN ] -> Does your avage client happens to compress so much? is it something due to a user modified PARAMTERS / CONFIG . TOML setting ? [prioritise not giving corner doing a more heavy fix ]

    ""[Enrico Fermi] believed that a good scientist should be able to estimate any quantity in their head without needing a calculator or reference books ---"" For example but refrence books are important for developers (but they should also learn to also know how to extend the programming languages -- if they are low end kernel developers or deal with hardware or nanoelectronika)

    Is it a great deal of cost , allow 400x decompression? ```chatgpt.com/backend-api/codex/responses`` is cloudflare protected backend (which is fair whatever) how many users really do deal with it? (Does cloudflare - do another pass of compression or decompression, this sort of this khappen sometimes) **I think its an already a standartize fortmat the zstd - and actually cost a great deal of CPU TIME - and 400x compression time not being allow is well beyond whats consider even reasonable --- what if bad actors upload 200 images like this? **

    @Pengpengwanga I want to argue , its already docuemnted here https://developers.openai.com/api/docs/guides/production-best-practices I would like to know, how did you encounter this issue originally, is there a more lean way you could tacle the issue you attempt --- are you trying to "cheat"? uploading large amount of images or a large file to anlayze by the models? (Or maybe its the wrong tool or idea for the task you attempt --- bottom line is there is an already assesed reasoning on why this fails cloudflare/openai-backend/settings-on-cloudflare-/or actuall undocumented failgate ---> I think the very least it should an error [max decompression size is not allow] ) (--> if for example this randomally happen, **this is a P3 rca issue) atleast by my reasoning --> if its effect 10% of a certain type of heavy users - it should p2 even **

    Muchacs gracias, senor~!

    Thanks, that page is helpful. Under "Compress request bodies" it says the decompressed body must be at most 100× the compressed size, and that requests exceeding the limits return HTTP 413, while 400 is for invalid or incomplete zstd data.
    That fits our measurements: ≤ ~106× passes, ≥ ~117× fails. So I'm not asking to raise the limit; a decompression-ratio guard is reasonable, and it protects against exactly the abuse case you mention. The problem is what happens around it:

    1. The Codex backend returns a bare 400 {"detail":"Bad Request"} instead of the documented 413, so the client can't tell "ratio limit exceeded" apart from corrupted data.
    2. Codex compresses by default and never checks the ratio. It already measures it (RUST_LOG=codex_client::transport=info). It could skip compression above 100×, or retry once uncompressed on 413/400, instead of failing.
      To answer your questions:
      • Config: nothing was modified. Request compression is on by default with ChatGPT login. The repro forces HTTP only to make the failure deterministic.
      • How we hit it: ordinary long agent sessions with screenshots, run through the Codex app-server. When a turn falls back from WebSocket to HTTP, every later turn resends the whole history zstd-compressed. If anything in that history compresses extremely well (a blank or solid-colour screenshot, a PNG stored without compression, repetitive logs), every following turn fails with the same 400 and the session can't recover; the only way out is a new session.
      • Size: it isn't about large uploads. A single 4.7 MB image (≈ 6 MB request) is enough, as long as it compresses well.
      So the minimal fix I'd suggest is a clear 413 (or a specific error message) from the backend, plus the client-side guard above.
  10. Pengpengwanga commented on Nov 14, 2026

    @Pengpengwanga
    Author

    One caveat for a whole-body ratio cutoff: this same-JSON comparison in #60594 reports 400 at 131,601 / 49,636 = 2.65×, while level 1 and plain JSON succeeded. I have not independently replayed that request.

    An offline compression example helps reconcile a low overall ratio with highly compressible repeated content. Using the current encoder and its locked zstd 0.13.3 / libzstd 1.5.7, I compressed 2,097,170 bytes of synthetic JSON:

    import base64, json, random
    chunk = base64.b64encode(
    random.Random(20261114).randbytes(3 * 262144)
    ).decode()
    raw = json.dumps({"chunks": [chunk, chunk]}, separators=(",", ":")).encode()
    Level-3 streaming encoder Wire bytes Whole-body ratio
    Default 2 MiB window 787,005 2.665×
    window_log(19) (512 KiB) 1,573,773 1.333×
    In the default frame, a later compressed block contains 9 payload bytes plus its 3-byte block header and regenerates 131,072 bytes. Thus a 2.665× frame can contain a block expanding over 10,000×. With the smaller window, the peak block ratio in this fixture drops to about 1.333×. Both frames decode byte-for-byte to the original JSON.

    This supports inspecting per-block decoded output and cross-block references, alongside whole-body ratio. It also shows why lowering the window can change much more than the frame header. It does not establish that the backend enforces a block-level ratio limit, or that all these reports share one defect. A high-total-ratio cutoff alone would leave the reported 2.65× case untouched.

    AI-only offline source analysis on macOS arm64; no backend/model requests. The copied current encoder's three unit tests and all local roundtrips passed.

    Thanks, this is a great point, and I agree whole-body ratio is the wrong metric. Our sweep happens to use images with uniformly distributed noise, where every block compresses about equally, so whole-body ratio ≈ per-block ratio. That's why we saw a clean ~106–117× cut-off. With repeated content (like the 2.65× case in #60594), long-distance matches can make a single block expand by orders of magnitude while the whole-body ratio stays low.

    This is consistent with an offline model we tried earlier: decode the captured zstd bodies the way a streaming proxy might, feeding ~16 KiB input pieces and failing when one piece's decoded output exceeds 100× its size. That model matched 15/15 real outcomes in our first batch, and all 64 alignments of the solid-image body. But it misjudged one case right at the boundary (predicted failure at ~105×, which actually passed), so we don't know the exact piece size or rule.

    If the check is per input piece rather than per frame, the result could also depend on how the body is split in transit. That might explain why "same image twice" failed in #60594 but passed in our test (2/2). That part is speculation.

    Either way, the client-side options look the same, and your window result makes one of them cheap:

    compress with a smaller window (e.g. window_log 19) to cap per-block expansion;
    or compute the max per-block expansion before sending, and send uncompressed above ~100×;
    and retry once uncompressed when a compressed request gets 400/413.
    On the server side, the docs say ratio-limit violations should return 413, while the Codex backend returns a bare 400.

    I'll update the issue text so it doesn't present whole-body ratio as the trigger.

  11. changed the title [-]zstd request compression: backend returns 400 `{"detail":"Bad Request"}` when the body compresses more than ~110×[/-] [+]# zstd request compression: highly compressible content gets a bare 400 instead of the documented 413, and Codex never avoids it[/+] on Nov 14, 2026
  12. Pengpengwanga commented on Nov 14, 2026

    @Pengpengwanga
    Author

    Updated the description: cited the documented 100×/413 rule, and reframed the trigger as local (per-block) expansion rather than whole-body ratio, per the comments above. Thanks both.

  13. r266-tech commented on Nov 14, 2026

    @r266-tech

    A clarification on my window_log(19) result: it removes the long-distance matches in that fixture, but does not cap per-block expansion for arbitrary content. Short repetitions remain highly compressible within the smaller window.

    I tested two more offline fixtures using the same current encoder, locked zstd 0.13.3 / libzstd 1.5.7, level 3, changing only the window:

    Fixture JSON bytes Default wire bytes window_log(19) wire bytes
    {"text": "A" * 2097152} 2,097,163 101 101
    This issue's P=0 PNG in a single-image JSON body 6,292,407 2,483 2,725

    With window_log(19), the text fixture contains a legal RLE block whose 1 payload byte + 3 header bytes produce 131,072 decoded bytes (32,768×). The PNG's peak block produces 131,072 bytes from 18 payload bytes + 3 header bytes (6,241.5×).

    Thus reducing the window can help the long-distance-repeat fixture, while leaving the solid-image and short-repeat cases highly compressible. Those cases should remain in the test set for any proposed mitigation.

    All four frames decoded byte-for-byte to their inputs. AI-only offline analysis on macOS arm64; no backend/model requests, and no claim about the backend's exact block/piece rule.

  14. Pengpengwanga commented on Nov 14, 2026

    @Pengpengwanga
    Author

    A clarification on my window_log(19) result: it removes the long-distance matches in that fixture, but does not cap per-block expansion for arbitrary content. Short repetitions remain highly compressible within the smaller window.

    I tested two more offline fixtures using the same current encoder, locked zstd 0.13.3 / libzstd 1.5.7, level 3, changing only the window:

    Fixture JSON bytes Default wire bytes window_log(19) wire bytes
    {"text": "A" * 2097152} 2,097,163 101 101
    This issue's P=0 PNG in a single-image JSON body 6,292,407 2,483 2,725
    With window_log(19), the text fixture contains a legal RLE block whose 1 payload byte + 3 header bytes produce 131,072 decoded bytes (32,768×). The PNG's peak block produces 131,072 bytes from 18 payload bytes + 3 header bytes (6,241.5×).

    Thus reducing the window can help the long-distance-repeat fixture, while leaving the solid-image and short-repeat cases highly compressible. Those cases should remain in the test set for any proposed mitigation.

    All four frames decoded byte-for-byte to their inputs. AI-only offline analysis on macOS arm64; no backend/model requests, and no claim about the backend's exact block/piece rule.

    Thanks for the correction, that makes sense: a smaller window only removes long-distance matches, while RLE/short repeats can still expand thousands of times within one block. I've updated the description. The suggested client fixes are now (1) retry once uncompressed on 413/400, which holds whatever the server's exact rule is, and/or (2) check the per-block expansion before sending. The window change is noted as not a general fix, and all three fixtures (long-distance repeat, solid image, short repeat) are listed as cases any mitigation should be tested against.

  15. hso400021-hash commented on Nov 16, 2026

    @hso400021-hash

    Reproduced the bare HTTP 400 whenever zstd request compression is active in Codex CLI. Since the upstream endpoint is rejecting the compressed payload header before parsing, retrying the same command won't clear it—falling back to uncompressed requests / checking CLI payload flags is the only way around it right now. Full technical notes: https://debugradar.com/fix-codex-cli-zstd-compression-400-error/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugconnectivity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions