Folds the review wave and second-model review of b5974d1eba (#148898).
- A read error or cancellation while inspecting a streamed 400 left that
response open (and its pool connection held). Close it on every
exceptional exit, sync and async.
- The raw JSON stored for a possible resend stayed on the request a
successful response points at, so a long SSE stream kept a second,
uncompressed copy of the conversation alive. Pop it as soon as the
response arrives.
- Docstring: the budget is one resend per send(); an SDK-level retry
builds a fresh request (Hermes' agent client runs max_retries=0).
Tests: the failed-read close (sync, async) and the raw-body drop, both
red with their fix removed. The resend test now checks the plain body is
byte-identical to the decompressed zstd body with a matching
Content-Length, and the builder test covers the async client too.
The previous commits made plain JSON the default to dodge #148898. That
departs from OpenAI's own guidance: the API production guide recommends
zstd request bodies on POST /responses, and the official Codex client
ships `features.enable_request_compression` stable and on by default for
ChatGPT auth, the route Hermes uses (parity added in #136916). The
backend bug is real but narrow: it answers some valid zstd frames with a
bare 400 {"detail":"Bad Request"} and accepts the identical JSON.
So compression stays on, and the client handles the bug where it shows:
- codex_request_compression_hooks records the raw JSON on each body it
compresses (request extension), and codex_zstd_replay_client_cls wraps
httpx.Client / AsyncClient.send(): on exactly that bare 400 for a body
the hook compressed, it resends the same request once as plain JSON,
marked so the hook leaves it alone. Any other status or body, and a
second rejection of the plain resend, is returned untouched and
classified as before. One extra round trip only on a rejected frame;
no change to retries, fallback or the error classifier.
- agent.codex_request_compression flips back to default true, as an
opt-out. An unreadable config (including ConfigBackendUnavailable)
still means plain JSON with the HTTP client kept;
--ignore-user-config now means the built-in default.
Live (official endpoint, gpt-6-luna): 131073/131243/200000-byte bodies
that main sends as zstd and gets a bare 400 for now log one resend and
complete 200 as plain JSON; 131072 stays zstd 200.
Folds the gate wave on 4fa6710118 (#148898 salvage).
- ConfigBackendUnavailable is a SystemExit. Letting it out of
_codex_compression_opted_in() escaped build_keepalive_http_client's
`except Exception` and could end a gateway turn worker during a
client rebuild, a failure main never had (main read no config here).
Catch it alongside Exception, as agent/redact_phone_policy.py does:
plain JSON is the safe default, so nothing is served from the wrong
config.
- Drop the process-global warn-once latch: it hid a later profile's
read failure behind an earlier one. Client builds are per agent or
cache miss, not per request, so one warning per failed build is fine.
- Docs: a running gateway must restart too, since cached clients keep
the encoding they were built with.
- Trim comments that narrated the code.
Follow-up to the #149579 salvage (#148898).
- A failing read of agent.codex_request_compression (import error,
loader exception) used to propagate out of build_keepalive_http_client,
whose blanket except then returned None. The agent fell back to the
SDK default client and lost Hermes' proxy and keepalive policy. The
read now lives in _codex_compression_opted_in(), warns once, and
answers "plain JSON". ConfigBackendUnavailable (a SystemExit) still
propagates, keeping the config backend's fail-closed contract.
- HERMES_IGNORE_USER_CONFIG=1 (--ignore-user-config) now ignores a
stored opt-in, like every other user setting.
- Restore the meaning of the api_max_retries comment the salvaged commit
reworded (two lines, so config_defaults.py does not grow past its cap);
the new key keeps its own one-line comment.
- Docs: "never used for proxies" -> "never applies to custom endpoint
URLs" (an official URL behind an HTTP proxy is still official).
- Opt-in lossless test now covers async as well as sync; new tests for
the ignore-config and failed-read cases (both red on the PR head) and
for ConfigBackendUnavailable still propagating.
The official Codex client has sent zstd request bodies to
chatgpt.com/backend-api/codex/responses under ChatGPT auth by default since
openai/codex#10102. Hermes sent raw JSON, so large-context sessions uploaded
~3.6x more bytes than the client OpenAI's edge is tuned for.
The keepalive httpx client now installs a request hook for the official Codex
base URL only: POST .../responses bodies are compressed with the stdlib
compression.zstd codec (Python 3.14, the installer default) and sent with
Content-Encoding: zstd. Custom proxies, other providers, other endpoints, and
interpreters without the codec keep sending raw JSON. Lossless transport
encoding: input tokens and prompt caching are unchanged.
Runtime identity resolved through hermes_cli.__version__ (a static 0.0.0
on source installs, rewritten by release stamping) leaked v0.0.0 into
About, /api/health, User-Agents, and plugin compat, and source updates
showed "couldn't reach update server" because identity and channel
authority disagreed with the checkout.
Now: get_version_info() resolves install stamp -> live git -> unknown,
never pyproject metadata, never a package constant. Source checkouts
derive identity from their reachable release tag; the completion tail of
every successful install/update/historical takeover atomically rewrites
install-stamp.json with that identity; a stale source stamp whose commit
no longer matches HEAD defers to live git. ACP/TUI use derived_version
for display and base_version for protocol fields; all ~44 runtime
__version__ consumers migrated; hermes_cli.__version__ and generated
_version.py are gone; release stamping only touches the native manifests
external builders consume (nix/tauri/cargo) and passes release identity
straight into write_install_stamp.py; pyproject.toml stays inert 0.0.0.
Desktop no longer synthesizes a competing install-stamp.json: the
checkout owns its stamp, and desktop-bootstrap classification keys on
the bootstrap-complete marker. verify-bootstrap-version-stamp.py now
cross-checks the checkout's stamp (baseVersion + commit == HEAD).
Validation: 31-file focused suite green (version identity, stamping,
adoption, providers, gateway, acp/tui runtime identity, api server via
extras env, release graph); desktop tsc + 25 vitest green; real-repo
probe: base=unknown derived=git.0635606.dirty source=git on this
checkout; clean-env imports resolve entirely from this tree; windows
footgun + compat-pointer scans clean.
Extract chatgpt_data_residency (fallback: chatgpt_compute_residency) from
the OAuth JWT and send as x-openai-internal-codex-residency header on
requests to chatgpt.com/backend-api/codex. Residency-enforced workspaces
return 401 without this header.
Fixes#23896
Split _preflight_codex_input_items into per-item-type helpers over a
_PreflightCtx; streaming assembly moves into _CodexResponseAssembler with a
per-event dispatch table; run_codex_app_server_turn loses its session/usage/
interrupt regions to _ensure_codex_session/_finish_codex_turn/
_consume_user_interrupt/_queue_token_counts (counts built lazily so stub agents
without a session DB are never touched). Responses input/normalization and
stream callback order verified byte-identical against merge-base.