Commit Graph

14 Commits

Author SHA1 Message Date
kshitijk4poor
b076b5856c fix(codex): close a 400 whose body read fails; drop the raw body once answered
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.
2026-11-18 01:56:03 +05:30
kshitijk4poor
0513e714a5 fix(codex): keep zstd by default and resend a rejected body once as plain JSON
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.
2026-11-18 01:56:03 +05:30
kshitijk4poor
02cc4ea88d fix(codex): keep plain JSON when the config backend refuses the opt-in read
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.
2026-11-18 01:56:03 +05:30
kshitijk4poor
5dbf1039d0 fix(codex): keep the HTTP client when the compression opt-in read fails
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.
2026-11-18 01:56:03 +05:30
TheMethodicalJosh
d94d5e3d7a fix(codex): send plain JSON by default to avoid zstd rejections 2026-11-18 01:56:03 +05:30
Kevin Rajan
d6f73ca99a fix(codex): allow profile opt-out from zstd Responses requests
Refs NousResearch/hermes-agent#148898 (reported by enckequity).
Preserve default zstd parity from teknium1's #136916 while enabling
plain JSON for deterministic compressed-body HTTP 400 failures.
2026-11-18 01:56:03 +05:30
Teknium
aefffa077f feat(codex): zstd-compress Responses request bodies to the official Codex backend
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.
2026-10-11 20:10:06 -07:00
Maciej Lisiewski
d76cce4f11 ci: apply all automatic linter fixes available 2026-10-08 17:22:54 +02:00
ethernet
c13ea774e6 refactor: make install-stamp.json the single runtime version identity
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.
2026-09-23 11:41:01 -04:00
liuhao1024
0bbf7b7997 fix(agent): extract residency claims from Codex OAuth JWT for workspace auth
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
2026-09-19 09:28:13 -07:00
Teknium
e0693c4d3e refactor(agent/codex*,bedrock_adapter): drop intra-function blank lines (AST-identical, -117 LOC) 2026-09-02 18:47:54 -07:00
Teknium
4f5d9da6da refactor(agent/codex_runtime): fold agent-callback guard, dedupe change filtering, extract stream close; collapse signatures (-19 LOC) 2026-09-02 18:30:17 -07:00
Teknium
841d9ff4a8 refactor(agent/adapters): simplify codex responses adapter and runtime (-1080 LOC)
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.
2026-09-02 13:29:47 -07:00
fangliquanflq
fd1d8271db fix(cron): isolate lazy imports from stale modules 2026-08-31 09:58:51 -07:00