Skip to content

fix(openai-codex): omit encrypted reasoning replay for native responses#87151

Closed
baanish wants to merge 2 commits into
openclaw:mainfrom
baanish:codex/native-codex-encrypted-replay-pr
Closed

fix(openai-codex): omit encrypted reasoning replay for native responses#87151
baanish wants to merge 2 commits into
openclaw:mainfrom
baanish:codex/native-codex-encrypted-replay-pr

Conversation

@baanish

@baanish baanish commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: native openai-codex Responses turns can replay prior reasoning items with encrypted_content when replay provenance matches.
  • Result: the ChatGPT/Codex backend rejects that request shape, OpenClaw logs [responses] retrying without encrypted reasoning content ..., strips the field, and sends a second request.
  • Solution: strip encrypted_content during native openai-codex-responses request sanitization before the first request is sent.
  • What changed: native Codex Responses params now remove encrypted reasoning replay fields; custom/proxy Codex-compatible Responses models keep their existing replay behavior.
  • What did NOT change: canonical openai/gpt-5.5 auth/profile routing, model aliases, fallback behavior, prompt cache keys, or custom Responses backends.

Motivation

This removes an avoidable failed first request on openai-codex/gpt-5.5 Pi runs. The successful retry already runs without encrypted reasoning replay; this patch makes the first attempt use the same backend-compatible shape.

Related to #87099 and complementary to #87123. That PR addresses /model ...@profile session auth persistence; this PR addresses the separate transport retry churn.

Change Type

  • Bug fix
  • Test

Scope

  • Gateway / orchestration
  • API / contracts

Linked Issue/PR

Real behavior proof

  • Behavior or issue addressed: native openai-codex/gpt-5.5 Responses requests no longer send encrypted reasoning replay that the backend rejects.

  • Real environment tested: macOS arm64, OpenClaw 2026.5.22 local gateway patched with this transport change, Pi harness, openai-codex/gpt-5.5, Codex OAuth auth profile.

  • Exact steps or command run after this patch: rebuilt the local gateway from this branch, installed it as the local OpenClaw gateway, confirmed gateway status, ran two no-delivery agent turns in the same session with openai-codex/gpt-5.5 and thinking low, then scanned gateway logs after patched startup for encrypted-reasoning retry markers.

  • Evidence after fix (copied live output and redacted runtime log excerpt):

    openclaw gateway status
    gateway running from ~/clawdbot/dist/index.js; connectivity probe ok
    
    turn 1: provider=openai-codex model=gpt-5.5 harness=pi attempts=1 fallback=false output=proof-one
    session history after turn 1: reasoning thinkingSignature contained encrypted_content with matching openclawReasoningReplay metadata
    
    turn 2 same session: provider=openai-codex model=gpt-5.5 harness=pi attempts=1 fallback=false output=proof-two
    
    post-patch gateway log scan after startup:
    retrying without encrypted reasoning content: 0
    invalid_encrypted_content: 0
    openai-codex/gpt-5.5 retry lines for this proof session: 0
    
  • Observed result after fix: replayable encrypted reasoning material can exist in session history, but native Codex request sanitization removes it before dispatch, so the second same-session turn succeeds on the first request instead of hitting the encrypted-reasoning retry path.

  • What was not tested: maintainer-owned live production credentials or non-native proxy Codex-compatible backends.

  • Proof limitations or environment constraints: evidence is from Aanish's local macOS OpenClaw gateway with private paths/secrets redacted; no Discord delivery was used.

  • Before evidence (optional but encouraged): current main preserves matching native Codex encrypted replay in source-level reproduction, so the request can include encrypted_content before this sanitizer runs.

Root Cause

prepareOpenAIResponsesReasoningItemForReplay preserves encrypted_content when replay metadata matches provider, API, model, base URL, session, and auth profile. That is correct for compatible Responses backends, but native openai-codex-responses still rejects the encrypted replay field.

The retry wrapper already handled this after failure by stripping encrypted content and resending. The missing guardrail was that native Codex request sanitization stripped unsupported top-level/text fields but did not strip encrypted reasoning replay before the first send.

Regression Test Plan

  • Added strips native Codex encrypted reasoning replay even when provenance matches.
  • The test builds a native openai-codex-responses request with matching replay provenance and asserts the reasoning item keeps type: "reasoning" but drops both replay id and encrypted_content.
  • Existing custom Codex-compatible replay coverage remains unchanged, preserving proxy/custom backend behavior.

User-visible / Behavior Changes

Native openai-codex/gpt-5.5 Pi turns should stop paying the avoidable failed-request/retry tax caused by encrypted reasoning replay. The successful request content shape matches the existing retry fallback behavior.

Security Impact

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS arm64
  • Runtime/container: local OpenClaw gateway LaunchAgent for live proof; clean PR worktree based on origin/main for tests
  • Model/provider: openai-codex/gpt-5.5
  • Harness: Pi
  • Delivery: no Discord delivery; --deliver omitted

Commands

node scripts/run-vitest.mjs run src/agents/openai-transport-stream.test.ts -t "strips native Codex encrypted reasoning replay even when provenance matches"
node scripts/run-vitest.mjs run src/agents/openai-transport-stream.test.ts
npx oxfmt --check src/agents/openai-transport-stream.ts src/agents/openai-transport-stream.test.ts
npx oxlint src/agents/openai-transport-stream.ts src/agents/openai-transport-stream.test.ts
node scripts/run-tsgo.mjs -p tsconfig.json

Results

  • Focused test: 2/2 passed, 392 skipped.
  • Full transport stream suite: 394/394 passed.
  • oxfmt: clean.
  • oxlint: clean.
  • tsgo: current origin/main fails in unrelated extensions/memory-core/src/dreaming.test.ts because a test mock is missing required getSession; this PR does not touch that file.

Human Verification

  • Verified the new test fails before the source fix and passes after it.
  • Verified the full affected test file passes on the clean PR branch.
  • Verified a rebuilt local gateway runs the patched code.
  • Verified a live two-turn Pi session where turn 1 stores encrypted reasoning replay and turn 2 succeeds in one attempt without encrypted-reasoning retry logs.
  • Did not verify maintainer production credentials or non-native proxy backends.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

  • Risk: accidentally stripping encrypted replay for custom Codex-compatible Responses backends that support it.
    • Mitigation: the sanitizer path is gated to the native ChatGPT/Codex backend, and existing custom-backend replay tests remain unchanged.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 27, 2026
@clawsweeper

clawsweeper Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed May 30, 2026, 9:44 PM ET / 01:44 UTC.

Summary
The branch adds native Codex Responses sanitization to remove encrypted_content from replayed reasoning input and adds a regression test for matching replay provenance.

PR surface: Source +8, Tests +73. Total +81 across 2 files.

Reproducibility: yes. for the request-shape bug from source: current main preserves matching encrypted_content before the first request and only strips it in the retry path. I did not independently reproduce the live backend rejection in this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Update the new regression test to openai / openai-chatgpt-responses or the current OpenClaw transport alias.
  • [P1] Refresh the PR body with after-fix live output for the latest branch; updating the PR body should trigger ClawSweeper re-review, or a maintainer can comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR includes useful redacted live output, but it demonstrates the older openai-codex identity rather than the current branch's native Codex provider path; refreshed logs or terminal output should redact private data before posting. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The PR changes native Codex Responses request shaping, but the current proof and new regression test still exercise the pre-refactor provider identity rather than the current native Codex path.
  • [P1] Until the fixture and real-environment proof are refreshed, maintainers cannot confirm that the latest branch removes the retry on the first request for current openai/gpt-5.5 native Codex Responses turns.

Maintainer options:

  1. Refresh current native Codex proof (recommended)
    Update the regression fixture and PR body proof to use the current openai / openai-chatgpt-responses native Codex path before landing.
  2. Accept stale live proof
    Maintainers could merge from source review alone, but they would own the risk that the current live provider path was not re-proven after the identity refactor.

Next step before merge

  • [P1] Contributor or maintainer action is needed to refresh the stale test and real-environment proof; ClawSweeper should not replace the contributor's live proof for them.

Security
Cleared: The diff does not add dependencies, CI changes, permissions, or secret-handling expansion; it narrows what is sent to the native Codex backend.

Review findings

  • [P2] Use the current native Codex model identity — src/agents/openai-transport-stream.test.ts:2783-2792
Review details

Best possible solution:

Refresh the regression test and real behavior proof to the current native Codex identity, then land the sanitizer if custom/proxy replay coverage still preserves encrypted replay.

Do we have a high-confidence way to reproduce the issue?

Yes for the request-shape bug from source: current main preserves matching encrypted_content before the first request and only strips it in the retry path. I did not independently reproduce the live backend rejection in this read-only review.

Is this the best way to solve the issue?

No as submitted: the production change is the right narrow shape, but the PR must update the stale test/proof identity to demonstrate the current native Codex path.

Full review comments:

  • [P2] Use the current native Codex model identity — src/agents/openai-transport-stream.test.ts:2783-2792
    This new regression test still builds the model as api: "openai-codex-responses" / provider: "openai-codex", but current main recognizes native Codex Responses through openai with openai-chatgpt-responses or the OpenClaw transport alias. With the retired identity, the sanitizer path under review is bypassed, so the test does not prove the current branch's live path. Please update the fixture, message metadata, auth profile, and proof to the current identity.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 26913e60a42e.

Label changes

Label justifications:

  • P2: This is a normal provider-runtime bug fix with limited blast radius, but it needs a current-head test/proof refresh before merge.
  • merge-risk: 🚨 auth-provider: The diff changes native Codex provider request shaping while the supplied proof still targets the retired provider/API identity.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR includes useful redacted live output, but it demonstrates the older openai-codex identity rather than the current branch's native Codex provider path; refreshed logs or terminal output should redact private data before posting. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +8, Tests +73. Total +81 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 8 0 +8
Tests 1 73 0 +73
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 81 0 +81

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs run src/agents/openai-transport-stream.test.ts -t "strips native Codex encrypted reasoning replay even when provenance matches".
  • [P1] node scripts/run-vitest.mjs run src/agents/openai-transport-stream.test.ts.

What I checked:

  • Current main still preserves matching encrypted replay before retry: prepareOpenAIResponsesReasoningItemForReplay returns the reasoning item unchanged when replay metadata matches, so matching encrypted_content can still reach the first request on current main. (src/agents/openai-transport-stream.ts:907, 26913e60a42e)
  • Current native Codex identity: Current main recognizes native Codex Responses only for provider openai with api openai-chatgpt-responses or the OpenClaw transport alias, so the old openai-codex-responses fixture does not exercise the sanitizer path. (src/agents/openai-transport-stream.ts:1939, 26913e60a42e)
  • PR test uses stale identity: The PR adds its new matching-provenance regression test with api: "openai-codex-responses" and provider: "openai-codex", which no longer matches the current native Codex path. (src/agents/openai-transport-stream.test.ts:2783, 65f92f2916c3)
  • Provider identity refactor provenance: Commit 4c33aaa86c1673924c9e15c41414ea8af253092f unified the OpenAI provider identity and updated the affected fixtures to openai-chatgpt-responses / openai. (src/agents/openai-transport-stream.test.ts:2678, 4c33aaa86c16)
  • Existing custom-backend coverage remains relevant: Current main has adjacent coverage preserving encrypted replay for custom Codex-compatible Responses backends, which is the sibling behavior this PR must keep intact. (src/agents/openai-transport-stream.test.ts:2779, 26913e60a42e)

Likely related people:

  • steipete: git blame and git log -S show Peter Steinberger authored the native Codex sanitizer/replay area and the provider-identity refactor that changed this surface to openai-chatgpt-responses. (role: recent area contributor; confidence: high; commits: 598e177e12a1, 4c33aaa86c16; files: src/agents/openai-transport-stream.ts, src/agents/openai-transport-stream.test.ts, packages/llm-core/src/types.ts)
  • Jerry-Xin: Recent merged work touched the same OpenAI transport stream source/test path for provider streaming behavior, making them a useful adjacent reviewer if Peter is unavailable. (role: recent adjacent contributor; confidence: medium; commits: f59fc0d477ff; files: src/agents/openai-transport-stream.ts, src/agents/openai-transport-stream.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels May 27, 2026
@clawsweeper

clawsweeper Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🥚 common Velvet Branchling

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 🥚 common.
Trait: polishes edge cases.
Image traits: location CI tidepool; accessory rollback rope; palette pearl, teal, and neon green; mood determined; pose sitting proudly on a smooth stone; shell paper lantern shell; lighting subtle sparkle highlights; background subtle branch markers.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Velvet Branchling in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 27, 2026
@baanish
baanish force-pushed the codex/native-codex-encrypted-replay-pr branch from 83c2ae0 to 697dce5 Compare May 27, 2026 04:15
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. proof: supplied External PR includes structured after-fix real behavior proof. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels May 27, 2026
@baanish

baanish commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 27, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels May 29, 2026
@baanish

baanish commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels May 31, 2026
@steipete

Copy link
Copy Markdown
Contributor

Superseded by #90682, merged as 66880a5d736c303691e5b439f3637f1bdb979b1c.

This PR proposed stripping native encrypted reasoning replay before dispatch. The landed fix addresses the underlying corruption instead: transcript redaction now preserves only validated, provenance-bound provider replay ciphertext and signatures while continuing to redact malformed, nested, unknown, and credential-shaped values.

That is the better current behavior because valid OpenAI reasoning replay remains available for continuity rather than being removed unconditionally. Exact-head live proof on #90682 ran openai/gpt-5.5 through prompt, tool read, tool execution, image input, and tool-only continuation; the post-run scan found zero invalid_encrypted_content markers and zero encrypted-reasoning retries. Focused OpenAI transport/replay tests and the full changed CI gate also passed.

The original fixture here also uses the retired openai-codex provider/API identity, while current runtime identity is folded into openai.

Thank you, @baanish, for isolating the first-request replay shape and supplying the original live evidence.

@steipete steipete closed this Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants