Skip to content

Fix native Codex encrypted replay recovery#85294

Closed
dredozubov wants to merge 2 commits into
openclaw:mainfrom
dredozubov:codex/native-codex-replay-fix
Closed

Fix native Codex encrypted replay recovery#85294
dredozubov wants to merge 2 commits into
openclaw:mainfrom
dredozubov:codex/native-codex-replay-fix

Conversation

@dredozubov

@dredozubov dredozubov commented May 22, 2026

Copy link
Copy Markdown

Summary

  • stop native openai-codex Responses requests from replaying prior reasoning items while preserving reasoning replay for non-native Responses backends
  • classify invalid_encrypted_content / encrypted-content parse failures as replay-invalid session state
  • route replay-invalid reply-agent recovery through the existing session reset helper so the new session id, session file, queued followups, transcript cleanup, and active session state stay consistent

Real behavior proof

Behavior addressed: Native Codex Responses follow-up turns can fail with invalid_encrypted_content when encrypted reasoning content from a prior response is replayed.

Real environment tested: Local OpenClaw source checkout on macOS against current origin/main after pnpm install refreshed workspace dependencies, using the real OpenClaw Responses payload builder with a redacted native Codex model/session shape and a prior assistant turn containing reasoning metadata.

Exact steps or command run after this patch:

node --import tsx --input-type=module <<'NODE'
import { buildOpenAIResponsesParams } from './src/agents/openai-transport-stream.ts';
// Built native openai-codex and standard openai-responses payloads from the same
// redacted transcript containing a prior assistant reasoning item.
// Printed whether each payload replays a `reasoning` input item.
NODE
git diff --check origin/main...HEAD
node scripts/run-vitest.mjs src/agents/openai-responses.reasoning-replay.test.ts src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts src/auto-reply/reply/agent-runner-execution.test.ts
node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts -t "rotates poisoned replay-invalid sessions"
pnpm check:test-types

Evidence after fix: Terminal capture from the local OpenClaw runtime payload-builder command:

{
  "nativeCodexReplayIncludesReasoning": false,
  "nativeCodexInputTypes": [
    null,
    "message",
    "message",
    null
  ],
  "standardResponsesReplayIncludesReasoning": true
}

Observed result after fix: Native openai-codex Responses payload construction no longer includes a replayed reasoning item for the redacted follow-up transcript, while standard OpenAI Responses still replays reasoning. git diff --check passed; the targeted regression command passed with 3 test files and 260 tests; the focused e2e replay-invalid session rotation test passed with 1 test and 50 skipped tests; pnpm check:test-types passed.

What was not tested: I have not attached a live Telegram/ChatGPT backend transcript from an actual networked native Codex follow-up after this branch. I also previously attempted the full agent-runner.runreplyagent.e2e.test.ts file; it did not complete green because two existing overflow fallback assertions expect conversation is too large while current output says Auto-compaction could not recover this turn. This PR does not touch those overflow assertions or fallback text.

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

clawsweeper Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close: the core native Codex encrypted replay recovery is already superseded by the merged provenance-bound replay fix on current main and shipped in v2026.5.20; this branch’s remaining changes would replace that safer contract with broader reasoning suppression and session-reset behavior.

Canonical path: Keep the shipped provenance-bound replay and encrypted-content retry implementation from the merged fix, and pursue any session-reset fallback only as a separate narrow follow-up that preserves that contract.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Keep the shipped provenance-bound replay and encrypted-content retry implementation from the merged fix, and pursue any session-reset fallback only as a separate narrow follow-up that preserves that contract.

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

Yes for the historical failure: the superseding merged PR includes before/after live Codex proof of invalid encrypted replay and recovery. I do not have a current-main failure path because the provenance-bound fix is now present and released.

Is this the best way to solve the issue?

No: this branch is not the best fix because it disables all native Codex reasoning replay instead of preserving safe replay and stripping/retrying only unsafe encrypted content. The shipped provenance-bound transport fix is narrower and already has stronger live proof.

Security review:

Security review cleared: The diff does not add dependencies, workflows, package metadata, downloaded code, permissions, or new credential-handling paths.

What I checked:

  • PR diff disables native Codex reasoning replay: The branch changes replayReasoningItems from always true to false for native Codex Responses, removing all replayed reasoning items rather than only unsafe encrypted payload fields. (src/agents/openai-transport-stream.ts:2022, 78c13ac5f85d)
  • Current main strips unsafe encrypted replay by provenance: Current main prepares Responses reasoning items for replay by checking provider/API/model/base URL/session/auth-profile metadata and stripping encrypted_content when that provenance does not match. (src/agents/openai-transport-stream.ts:897, 84329182a7c4)
  • Current main retries invalid encrypted-content failures: Current main catches invalid_encrypted_content, strips encrypted content from the outgoing Responses request, and retries once on the same model before surfacing failure. (src/agents/openai-transport-stream.ts:917, 84329182a7c4)
  • Current tests preserve safe native Codex replay: Current regression coverage asserts native Codex still keeps a reasoning item while omitting unsafe replay ids/encrypted content, and separate coverage preserves matching same-session encrypted replay. (src/agents/openai-transport-stream.test.ts:2263, 84329182a7c4)
  • Superseding merged PR: The same root problem was fixed by merged PR fix(agents): provenance-bound Codex reasoning replay #84367, whose body documents live Codex before/after proof and provenance-bound replay as the intended solution. (a54c73687f58)
  • Fix provenance: The merge commit for the superseding PR is fix(agents): provenance-bound Codex reasoning replay (#84367), committed at 2026-05-20T04:05:19Z. (a54c73687f58)

Likely related people:

  • joshavant: Authored and merged the shipped provenance-bound Codex reasoning replay fix that supersedes this branch, including transport, compaction auth forwarding, stream resolution, and regression coverage. (role: fix author and recent area contributor; confidence: high; commits: a54c73687f58, e8fe70e3b4bf, 1e18d6f65b22; files: src/agents/openai-transport-stream.ts, src/agents/openai-transport-stream.test.ts, src/agents/pi-embedded-runner/run/attempt.ts)
  • vincentkoc: Current-main blame in the local checkout attributes the active OpenAI transport replay/retry block to a recent commit under this author, so they are relevant for current-file routing even though the superseding fix provenance points to the merged PR above. (role: recent area contributor; confidence: medium; commits: 2b1c01f769a8; files: src/agents/openai-transport-stream.ts)
  • steipete: Recent git history shows OpenAI transport follow-up fixes in the same file shortly after the replay work, making this a useful adjacent routing signal. (role: recent adjacent contributor; confidence: medium; commits: 89c59a89fbf8, 0ddf51cf7106; files: src/agents/openai-transport-stream.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 84329182a7c4; fix evidence: release v2026.5.20, commit a54c73687f58.

@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. labels May 22, 2026
@clawsweeper

clawsweeper Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 22, 2026
@dredozubov

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 22, 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels May 22, 2026
@clawsweeper

clawsweeper Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M 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.

1 participant