Repository navigation
Description
Summary
On OpenClaw 2026.6.1, a native/OpenClaw-runtime openai-chatgpt-responses session can succeed on the first turn and then fail on the next turn with a provider-side 400 invalid_encrypted_content before any model output.
The user-visible error is sanitized to:
LLM request failed: provider rejected the request schema or tool payload.
The raw trajectory error is:
Codex error: {"type":"error","error":{"type":"invalid_request_error","code":"invalid_encrypted_content","message":"The encrypted content gAAA... could not be verified. Reason: Encrypted content could not be decrypted or parsed."},"status":400}
Environment
- OpenClaw:
2026.6.1(2e08f0f) - macOS:
26.4.1arm64 - Node:
25.9.0 - Runtime / harness: OpenClaw native (
agentRuntime.id = "openclaw") - Provider/model shape:
{
"provider": "openai",
"model": "gpt-5.5",
"api": "openai-chatgpt-responses",
"baseUrl": "https://chatgpt.com/backend-api/codex",
"agentRuntime": { "id": "openclaw" },
"params": { "thinking": "xhigh", "transport": "sse" }
}Reproduction observed
- Start a fresh session using
openai/gpt-5.5withapi=openai-chatgpt-responsesand native runtime. - Send a first turn that causes a normal model response and tool use. This succeeds.
- The successful assistant turn stores a
thinkingblock withthinkingSignaturecontaining a serialized Responses reasoning item withencrypted_content. - Send a second turn in the same session.
- OpenClaw replays the prior assistant reasoning item in the submitted history.
- The ChatGPT/Codex backend rejects the request before model output with
400 invalid_encrypted_content.
This explains why the previous turn succeeds but the next turn fails.
What I found in dist
openai-chatgpt-responses requests encrypted reasoning:
// openai-chatgpt-responses-*.js
include: ["reasoning.encrypted_content"]sanitizeSessionHistory only drops reasoning history when the provider replay policy says so:
const droppedReasoning = policy.dropReasoningFromHistory
? dropReasoningFromHistory(validatedThinkingSignatures)
: validatedThinkingSignatures;But buildOpenAIReplayPolicy(ctx) currently treats openai-chatgpt-responses as a Responses-family API with synthetic tool results, and does not set dropReasoningFromHistory for this API.
Local mitigation that fixed it
Adding this to buildOpenAIReplayPolicy(ctx) fixed the same session immediately:
...ctx.modelApi === "openai-chatgpt-responses" ? { dropReasoningFromHistory: true } : {},After restarting the gateway, the same session and same message completed successfully. The submitted history no longer contained thinkingSignature; only the old failed assistant turn's plain-text errorMessage still contained the string invalid_encrypted_content, which is harmless.
Expected behavior
For openai-chatgpt-responses against the ChatGPT/Codex backend, OpenClaw should not replay stale/unverifiable encrypted reasoning content, or should retry safely without it before surfacing an error.
Actual behavior
The next turn replays encrypted reasoning content and the backend rejects the whole request with 400 invalid_encrypted_content, resulting in an empty/non-deliverable assistant turn.
Related
- Related to fix(openai-codex): omit encrypted reasoning replay for native responses #87151 (
openai-codexnative Responses encrypted reasoning replay) - Related to fix: retry stale Responses reasoning replay safely #88917 (stale Responses reasoning replay retry)
- Related to openai-codex provider: multi-turn sessions permanently break with 400 invalid_encrypted_content after an OAuth token refresh #84511 (closed, OAuth refresh variant)
- Also observed while testing the native/Pi route discussed in Pi/native runtime routes openai-chatgpt-responses to boundary-aware transport and fails on ChatGPT Codex endpoint #90086, but this issue is specifically about encrypted reasoning replay.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jun 4, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 3, 2026, 9:16 PM ET / 01:16 UTC.
Summary
Keep open: current main still has a source-backed path where
openai-chatgpt-responsescan persist encrypted reasoning, preserve it when replay provenance matches, and send it on the next OpenClaw-runtime turn. The issue is valid, but several open PRs already touch this same Responses reasoning replay surface, so this should be coordinated rather than closed or duplicated.Reproducibility: yes. with source-level confidence rather than a live run: the issue's v2026.6.1 steps match current code that persists encrypted reasoning, preserves it when replay metadata matches, and sends it on the next
openai-chatgpt-responsesOpenClaw-runtime request.Next step
The bug is narrow and valid, but adjacent open PRs already target the same encrypted Responses replay surface, so a maintainer should choose or extend the canonical fix path before queuing another repair PR.
Review details
Best possible solution:
Fold this into one canonical Responses replay fix: native ChatGPT/Codex OpenClaw-runtime requests should drop or safely retry unverifiable encrypted reasoning while preserving custom/proxy replay contracts, with focused regression coverage.
Do we have a high-confidence way to reproduce the issue?
Yes, with source-level confidence rather than a live run: the issue's v2026.6.1 steps match current code that persists encrypted reasoning, preserves it when replay metadata matches, and sends it on the next
openai-chatgpt-responsesOpenClaw-runtime request.Is this the best way to solve the issue?
The local mitigation is plausible but probably too broad if applied only at generic transcript policy; the best fix should target the native ChatGPT/Codex request/retry path while preserving custom Responses backends that intentionally support encrypted replay.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 179ff9b4230c.
Label changes
Label changes:
P1: The report describes a released multi-turn OpenAI/Codex agent workflow failing before any model output on the next turn.impact:message-loss: The failed second turn produces no deliverable assistant output after the provider rejects the replay payload.impact:session-state: The break depends on replaying persisted prior assistant reasoning from the same session.impact:auth-provider: The failure is specific to the OpenAI ChatGPT/Codex Responses provider route and its encrypted reasoning contract.issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.clawsweeper:source-repro: Current issue advisory state selects this label.clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.clawsweeper:fix-shape-clear: Current issue advisory state selects this label.clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.Label justifications:
P1: The report describes a released multi-turn OpenAI/Codex agent workflow failing before any model output on the next turn.impact:message-loss: The failed second turn produces no deliverable assistant output after the provider rejects the replay payload.impact:session-state: The break depends on replaying persisted prior assistant reasoning from the same session.impact:auth-provider: The failure is specific to the OpenAI ChatGPT/Codex Responses provider route and its encrypted reasoning contract.Evidence reviewed
Acceptance criteria:
What I checked:
thinkingSignatureand attaches replay metadata whenencrypted_contentis present, which matches the reporter's stored-history observation. (src/agents/openai-transport-stream.ts:1601, 179ff9b4230c)prepareOpenAIResponsesReasoningItemForReplaystripsencrypted_contentonly when replay metadata does not match; matching metadata returns the reasoning item intact. (src/agents/openai-transport-stream.ts:936, 179ff9b4230c)buildOpenAIResponsesParamscallsconvertResponsesMessageswithreplayReasoningItems: true; native ChatGPT/Codex handling disables item id replay but does not disable reasoning item replay. (src/agents/openai-transport-stream.ts:2212, 179ff9b4230c)encrypted_contentfrom replayed reasoning input. (src/agents/openai-transport-stream.ts:2097, 179ff9b4230c)policy.dropReasoningFromHistoryis true, and the OpenAI-compatible replay helper only sets that flag foropenai-completions, notopenai-chatgpt-responses. (src/agents/embedded-agent-runner/replay-history.ts:744, 179ff9b4230c)src/agents/openai-transport-stream.test.ts:3193, 179ff9b4230c)Likely related people:
src/agents/openai-transport-stream.ts,src/plugins/provider-replay-helpers.ts,src/agents/embedded-agent-runner/replay-history.ts)store=falseitem-id replay fix in the same request-building path, which is closely related to this encrypted reasoning replay failure mode. (role: adjacent owner; confidence: medium; commits: 03dec8bb3a00; files:src/agents/openai-transport-stream.ts,src/agents/openai-transport-stream.test.ts)src/agents/openai-transport-stream.ts,src/agents/openai-transport-stream.test.ts)src/agents/openai-transport-stream.ts; less central to encrypted replay, but adjacent to the issue's native transport route. (role: recent adjacent contributor; confidence: low; commits: d07ba5f2656d; files:src/agents/openai-transport-stream.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.toruvieI commentedon Jun 4, 2026
I dug through the current
2026.6.1source path and I think the narrower bug is not runtime selection. The Pi/OpenClaw-native route is being used; the failure is in how the native ChatGPT subscription /openai-chatgpt-responsesrequest body reconstructs prior Responses reasoning items.Findings:
src/llm/providers/openai-chatgpt-responses.tsbuilds the ChatGPT/Codex request with:The same request body uses stateless Responses mode and asks the backend to return encrypted reasoning:
In
src/agents/openai-transport-stream.ts,convertResponsesMessages()callsprepareOpenAIResponsesReasoningItemForReplay(...). When replay provenance matches, that helper intentionally preserves the reasoning item'sencrypted_content.Immediately after that, the generic
replayResponsesItemIds: falsepolicy deletes the replay item id:So the next-turn payload can contain a malformed replay item like:
{ "type": "reasoning", "encrypted_content": "...", "summary": [] }instead of the full prior Responses output reasoning item containing both
id: "rs_..."andencrypted_content.That is the poisoned middle state: OpenClaw preserves
reasoning.encrypted_content, but strips the associated Responses reasoning item id on the nativeopenai-chatgpt-responses/ ChatGPT subscription path. This matches the observed second-turninvalid_encrypted_contentfailure better than a runtime-selection issue.There is also a source-level smoking-gun test in
src/llm/providers/openai-chatgpt-responses.test.tsnameddoes not replay Responses item ids for store-disabled ChatGPT requests; it currently expects a reasoning replay item withencrypted_contentand noid. That expectation looks wrong for encrypted reasoning replay.Likely fix shape:
idfortype: "reasoning"items that retainencrypted_content; oridandencrypted_contenttogether rather than sendingencrypted_contentwithout its item id;store=falseno-id behavior for ordinary message/function-call replay items.We will open a PR shortly with focused regression coverage for this path.
toruvieI commentedon Jun 4, 2026
Opened PR #90425 with the focused fix and regression coverage: #90425
toruvieI commentedon Jun 4, 2026
Update: I retracted PR #90425.
The proposed direction there — preserving
rs_*reasoning item ids withencrypted_content— was wrong for this route.Live validation showed that preserving the reasoning item id under
store:falsecauses the backend to reject the retry with:So that payload shape requires a stored Responses lineage (
store:true), which is a no-go foropenai-chatgpt-responses: the old pre-#88451openai-codex-responsespath already usedstore:falsewithinclude: ["reasoning.encrypted_content"], and the source noted ChatGPT Codex Responses rejectsstore:true/ requires store to remain false.Conclusion: #90425 does not solve this issue, and I closed it. The real fix needs to stay on the
store:falsestateless encrypted-reasoning path rather than preserving persisted item ids.toruvieI commentedon Jun 4, 2026
Additional analysis after retracting #90425:
Current
2026.6.1behavior onopenai-chatgpt-responsesis not usually a hard failure because OpenClaw catchesinvalid_encrypted_content, logs:and then retries with the encrypted reasoning content stripped.
That fallback is useful, but if it happens routinely it is still bad operational behavior:
reasoning.encrypted_content;So even if the user-visible turn eventually succeeds, this is a real efficiency/regression problem, not just cosmetic logging.
I do not have reliable local runtime logs proving whether these warnings fired in my 2026.5.x sessions. Source-wise, though, the retry mechanism already existed in
v2026.5.27:src/agents/openai-transport-stream.tshadisInvalidEncryptedContentError(...);stripResponsesRequestEncryptedContent(...);[responses] retrying without encrypted reasoning content ...warning;replayResponsesItemIds: !isNativeCodexResponses, so foropenai-codex-responsesitem ids were already stripped;include: ["reasoning.encrypted_content"]when reasoning was enabled.The architecture was different, though: 2026.5.x still had the
openai-codex-responsesroute/provider identity, while post-#88451 the native ChatGPT/Codex route is unified/renamed towardopenai-chatgpt-responses. That means the fallback warning existing in 2026.5.x does not prove the current frequency/trigger pattern was present then; it only proves the safety net was already in the code.This is why I would phrase this as: possible regression in behavior/frequency after the provider identity refactor, but not yet proven by historical logs.
Current upstream
openai/codexappears to follow the same high-level direction that OpenClaw should preserve for the ChatGPT/Codex route:store: false(store: provider.is_azure_responses_endpoint());include: ["reasoning.encrypted_content"];summaryandencrypted_contentserializable;ResponseItem::Reasoning.idis marked#[serde(default, skip_serializing)], so Codex may keep thers_*id internally but does not serialize that id back into the next request payload.That is why preserving
rs_*ids, as attempted in #90425, was the wrong fix for this route. Withstore:false, those ids are not persisted server-side; live validation returned:So the likely correct family of fixes must keep the
store:falsestateless encrypted-reasoning path, keepinclude: ["reasoning.encrypted_content"], keep reasoning summaries, and avoid relying on persistedrs_*item ids. The remaining question is why OpenClaw is producing encrypted-content replay that the backend rejects often enough to trigger the retry path.toruvieI commentedon Jun 4, 2026
Additional cross-PR/release note as of Thu 2026-06-04 21:26 GMT+2:
I checked the adjacent encrypted Responses replay PRs that ClawSweeper alluded to.
Release status relative to
v2026.6.1:Not included in
v2026.6.1, but already merged on main:fix: avoid replaying Responses item ids when store is disabled03dec8bb3a00209780d3140ec3f10ad0eb069030v2026.6.1fix(openai): avoid stale Responses message id replay6653193fdb90ac99f106b18040c0ef49cf97d285v2026.6.1Still open:
fix(openai-codex): omit encrypted reasoning replay for native responsesfix(agents): recover invalid OpenAI Responses reasoning replayfix: retry stale Responses reasoning replay safelyFix replay-invalid session recoveryMy current read is that #84904/#85277 are important prevention/payload-policy fixes, but they do not by themselves fully explain or close this specific
2026.6.1warning path, because they were not in that release and the warning is specifically about native encrypted reasoning replay being rejected and then retried without encrypted content.The PR that most directly matches this issue seems to be #87151, because it targets the native ChatGPT/Codex Responses path by omitting encrypted reasoning replay before the first request rather than relying on the
invalid_encrypted_contentretry fallback. If maintainers accept that tradeoff, #90093 should probably be closed by #87151.The other open PRs look more like adjacent recovery/fallback layers:
So my suggested closure mapping is: #90093 → probably #87151, with #84267/#88917/#85362 remaining as recovery/session-state follow-ups depending on which layering maintainers choose.
toruvieI commentedon Jun 4, 2026
@clawsweeper re-review
clthuang commentedon Jun 5, 2026
Adding a complementary finding from a 2026.6.1 reproduction yesterday — same user-visible symptom (
invalid_encrypted_contenton a multi-turnopenai/openai-chatgpt-responsesTelegram session) but a different root cause than the replay-reconstruction path discussed above.We sandbox-bisected the failure by extracting the persisted reasoning items from the affected session JSONL and replaying each one in isolation against
https://chatgpt.com/backend-api/codex/responses. Result: of 33 reasoning items persisted across the conversation, exactly 2 returned400 invalid_encrypted_content. The other 31 — including older ones, newer ones, and items adjacent to the failures — decrypted fine. So in our case the server is not categorically rejecting replay; it's rejecting two specific blobs whose ciphertext bytes are corrupted.The corruption pattern:
E2 80 A6(U+2026 HORIZONTAL ELLIPSIS) in the middle of a base64url Fernet blob. The byte pattern is byte-identical toredact-*.jsmaskToken()output:Tracing back:
transcript-*.js:494runsredactTranscriptMessage(message, params.config)on every assistant message before persisting it.redactTranscriptStructuredValuerecurses into every string leaf of the message — including the JSON-stringifiedthinkingSignaturefield, which embedsencrypted_content. Once inside the ciphertext,redactSensitiveText({mode:"tools"})runs the 31DEFAULT_REDACT_PATTERNS(redact-*.js:359-391). The low-specificity patterns (\b\d{6,}:…\b-shape, JWT-shape, etc.) can match incidental substrings of any sufficiently long random base64url string, andmaskTokenthen substitutes…into the matched window.The poisoned session JSONL is then written. Every subsequent turn rebuilds the request from disk, ships the corrupted
encrypted_contentto the backend, and the strip-retry middleware fires (createResponsesStreamWithEncryptedContentRetryinopenai-transport-stream-*.js:1705-1714) — which masks the underlying defect exactly as @toruvieI described, but burns 21 retry rounds over 5 minutes before the embedded run'stimeoutMs=300000finally surfaces the error to the user.Evidence this is independent of the replay-policy path discussed above:
…in theirencrypted_content(verified viagrep -c $'\xe2\x80\xa6'on the JSONL).redactSensitiveTexton the poisoned data is idempotent (…doesn't match any further patterns), so the corruption is exactly 1 redaction pass deep.We've shipped a local sentinel-guarded dist patch that adds an opaque-field exemption at the top of the walker:
Multi-turn smoke (3 turns × tool round-trip × reasoning enabled) passes with this patch; the new session JSONL contains 0 U+2026 bytes; old poisoned sessions remain unrecoverable on disk (we deleted the 2 corrupted thinking blocks from one such session by hand).
Worth considering whether the fix path here should be both:
openai-chatgpt-responses(the path @toruvieI is exploring — addresses the "encrypted_content is fragile across turns" surface, AND incidentally avoids replaying the redactor-corrupted blobs).redacted_thinking.datahas the same shape).Tightening
DEFAULT_REDACT_PATTERNS(line 390\b\d{6,}:…\b, line 382 JWT-shape) to require contextual anchors so they cannot match incidental substrings would be a third layer, useful even outside the encrypted-reasoning context.Logging the strip-retry decision at INFO instead of only when it terminates a run would also have caught this earlier — the 21 retry lines were only visible after the 300s timeout fired and the user noticed.
Full RCA with reproduction scripts, 7 hypotheses (4 rejected with evidence), and causal DAG is at the project I reproduced this on; happy to extract anything that would help.
fanyangCS commentedon Jun 6, 2026
Additional repro from OpenClaw
2026.6.1on a Discord channel session, likely the same encrypted-reasoning replay failure class.Environment:
2026.6.1(2e08f0f)github-copilot/gpt-5.5Gateway log excerpt (sanitized):
This happened twice in the same Discord discussion window:
2026-06-06T09:27:39.874Z2026-06-06T09:56:19.616ZUser-visible impact: the bot visibly acknowledged the mention (reaction), but no answer was generated/delivered because the provider rejected the replayed encrypted content before model output.
This looks related to the recovery direction in #84267 / #88917: classify this as stale/invalid encrypted Responses reasoning replay and retry once after stripping the replayed encrypted reasoning items, instead of surfacing it as a terminal generic LLM request failure.
fix(agents): preserve valid reasoning replay metadata (#90682)
fix(agents): preserve valid reasoning replay metadata (openclaw#90682)
fix(runtime): catch up openclaw upstream to d1b33a6 (openclaw#1733) (#99
fix(agents): preserve valid reasoning replay metadata (openclaw#90682)