Skip to content

fix(xai): restore encrypted reasoning replay across turns - #29672

Merged
teknium1 merged 1 commit into
mainfrom
fix/xai-restore-encrypted-reasoning-replay
May 21, 2026
Merged

fix(xai): restore encrypted reasoning replay across turns#29672
teknium1 merged 1 commit into
mainfrom
fix/xai-restore-encrypted-reasoning-replay

Conversation

@teknium1

@teknium1 teknium1 commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary

xAI partner integration requires Hermes to thread encrypted_content reasoning items back to the Responses API on every turn so Grok can maintain cross-turn reasoning coherence — the whole point of the partnership. PR #26644 (May 15) suppressed that replay for is_xai_responses on the theory that xAI's OAuth/SuperGrok surface rejected replayed encrypted blobs. That diagnosis was wrong: the prelude-SSE fallback added in the same PR is what actually fixed the multi-turn failure mode, and the replay gate was unnecessary collateral that broke the partnership integration.

Changes

  • agent/codex_responses_adapter.py — drop the is_xai_responses gate in _chat_messages_to_responses_input. Kwarg stays in the signature for transport compatibility; docstring documents the May 2026 reversal.
  • agent/transports/codex.py — restore kwargs["include"] = ["reasoning.encrypted_content"] on the xAI Responses path so xAI echoes encrypted reasoning back to us.
  • tests/run_agent/test_codex_xai_oauth_recovery.py — flip the three xAI assertions (xAI now MUST receive replayed reasoning AND we MUST request encrypted_content back).
  • tests/agent/transports/test_codex_transport.py — flip the include assertions on test_xai_reasoning_effort_passed and test_xai_grok_4_omits_reasoning_effort; update the allowlist block comment.

The prelude-SSE fallback and the entitlement-403 surfacing fixes from #26644 are untouched — they were independent fixes that happened to ride along with the reasoning-replay gate.

Validation

Result
Targeted (test_codex_xai_oauth_recovery + test_codex_transport) 65/65 pass
Broader (tests/agent/transports/ + tests/run_agent/) 1674 passed, 3 skipped, 0 failures
E2E (real imports, isolated HERMES_HOME, ResponsesApiTransport.build_kwargs) turn-1 request carries include: ["reasoning.encrypted_content"]; turn-2 input replays the encrypted_content blob from turn-1's codex_reasoning_items; native Codex unchanged

Infographic

xAI encrypted reasoning replay restored

xAI partner integration requires Hermes to thread `encrypted_content`
reasoning items back to the Responses API on every turn so Grok can
maintain cross-turn reasoning coherence. PR #26644 (May 15) gated this
off for `is_xai_responses` on the theory that the OAuth/SuperGrok
surface rejected replayed encrypted blobs and produced the multi-turn
"Expected to have received \`response.created\` before \`error\`"
failure. That diagnosis was wrong — the prelude-SSE fallback added in
the same PR is what actually fixed that failure mode. Suppressing the
replay was an unnecessary side-effect that broke the whole point of
xAI's partnership integration.

Changes:
- agent/codex_responses_adapter.py — drop the `is_xai_responses` gate
  in `_chat_messages_to_responses_input`. Keep the kwarg in the
  signature for transport compatibility; update the docstring to
  document the May 2026 reversal.
- agent/transports/codex.py — restore
  `kwargs["include"] = ["reasoning.encrypted_content"]` on the xAI
  Responses path so xAI echoes encrypted reasoning back to us.
- tests/run_agent/test_codex_xai_oauth_recovery.py — flip the three
  xAI assertions (now: xAI MUST receive replayed reasoning AND we MUST
  include encrypted_content in the request).
- tests/agent/transports/test_codex_transport.py — flip the
  `include` assertions on `test_xai_reasoning_effort_passed` and
  `test_xai_grok_4_omits_reasoning_effort`; update the allowlist
  block comment.

The prelude-SSE fallback and the entitlement-403 surfacing fixes from
#26644 are untouched — they were independent fixes that happened to
ride along with the reasoning-replay gate.

Validation:
- Targeted: tests/run_agent/test_codex_xai_oauth_recovery.py +
  tests/agent/transports/test_codex_transport.py → 65/65 pass
- Broader: tests/agent/transports/ + tests/run_agent/ →
  1674 passed, 3 skipped, 0 failures
- E2E (real imports, isolated HERMES_HOME, ResponsesApiTransport
  build_kwargs): turn-1 request carries
  `include: ["reasoning.encrypted_content"]`; turn-2 input replays
  the encrypted_content blob from turn-1's
  `codex_reasoning_items`; native Codex unchanged.
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: fix/xai-restore-encrypted-reasoning-replay vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8984 on HEAD, 8984 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4741 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@teknium1
teknium1 merged commit b4afc65 into main May 21, 2026
20 of 21 checks passed
@teknium1
teknium1 deleted the fix/xai-restore-encrypted-reasoning-replay branch May 21, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant