Skip to content

fix(ai): keep sessions usable with malformed reasoning history - #123228

Merged
jalehman merged 1 commit into
openclaw:mainfrom
wanyongstar:fix/openai-responses-replay-thinking-signature-json
Aug 17, 2026
Merged

jalehman merged 1 commit into
openclaw:mainfrom
wanyongstar:fix/openai-responses-replay-thinking-signature-json

Conversation

@wanyongstar

@wanyongstar wanyongstar commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users continuing a Responses-provider session could have every later turn fail before the network request when persisted reasoning history contained malformed JSON or a non-reasoning JSON value.

Why This Change Was Made

The shared Responses replay converter now catches JSON parse failures and accepts only non-array records tagged as type: "reasoning". Invalid persisted signatures are skipped while valid reasoning items and later assistant content continue through the same provider- and transport-style replay paths.

User Impact

Sessions with truncated, imported, edited, or otherwise incompatible reasoning signatures remain usable. Valid reasoning history replays as before.

Evidence

Release-shaped OCM behavior proof

Built and ran isolated package runtimes for the exact pre-fix parent 57e862980be and PR head 1d15daec194. Each runtime used an OCM-managed loopback gateway and a strict local OpenAI Responses-compatible endpoint with no credentials or real provider calls.

The harness created sessions through the gateway so OpenClaw persisted authentic encrypted reasoning signatures in SQLite. It then stopped the gateways, changed copied session signatures transactionally, verified SQLite integrity, restarted the gateways, and continued the same sessions through gateway WebSockets.

Persisted signature Before 57e862980be After 1d15daec194
Truncated JSON Continuation failed before provider egress Continuation succeeded; malformed reasoning was omitted
Wrong-type object Invalid replay item reached the endpoint and received HTTP 400 Continuation succeeded; malformed reasoning was omitted
null Already omitted; continuation succeeded Continuation succeeded
Array Already omitted; continuation succeeded Continuation succeeded
Valid reasoning control Encrypted reasoning replayed normally Encrypted reasoning replayed normally

Both provider- and transport-style converters were exercised. Successful post-fix requests retained assistant text and valid history. The valid control confirms the change does not disable reasoning replay.

Protocol cross-check: openai/codex@97729885 defines Responses items as a type-tagged enum with a structured Reasoning variant in codex-rs/protocol/src/models.rs:814-860, and requests reasoning.encrypted_content in codex-rs/core/src/client.rs:907.

Automated checks

AI-assisted maintainer rewrite. The original contributor remains the commit author.

@clawsweeper

clawsweeper Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 13, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 13, 2026
@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 6:50 PM ET / 22:50 UTC.

ClawSweeper review

What this changes

The PR makes OpenAI Responses session replay skip malformed or non-reasoning persisted reasoning signatures while preserving valid reasoning replay.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open: it remains necessary, and the focused shared replay repair has no confirmed patch defect. The branch is behind current main, so exact-merge CI and replay validation should precede landing.

Priority: P2
Reviewed head: 1d15daec194ab6caac5d7e0826c79070f67202e8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused shared-owner repair with meaningful regression coverage and documented A/B gateway behavior proof.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The documented exact-head A/B gateway continuation run exercises persisted-session replay through a strict local Responses-compatible endpoint and reports successful after-fix recovery with a valid-reasoning control.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The documented exact-head A/B gateway continuation run exercises persisted-session replay through a strict local Responses-compatible endpoint and reports successful after-fix recovery with a valid-reasoning control.
Evidence reviewed 5 items Current-main behavior: Current main still parses every eligible persisted signature directly, so malformed JSON can throw before subsequent assistant text is replayed.
Shared-owner repair: The PR catches parse failures and rejects non-record or non-reasoning values before the existing replay preparation path, while leaving valid reasoning handling intact.
Both replay styles covered: The shared converter exposes transport and provider wrappers, and the new table-driven regression runs each invalid signature through both paths.
Findings None None.
Security None None.

How this fits together

OpenAI Responses replay converts stored assistant reasoning blocks into the next provider request for a continuing session. This shared converter feeds both provider-owned and transport-owned request paths.

flowchart LR
  A[Stored session history] --> B[Responses replay]
  B --> C[Parse reasoning signature]
  C --> D{Reasoning record?}
  D -->|Yes| E[Replay valid reasoning]
  D -->|No| F[Skip invalid block]
  E --> G[Provider request]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - The PR is behind current main after its force-push; rerun the focused replay test and required CI on the exact merge result before landing.
  • Resolve merge risk (P1) - This changes interpretation of persisted provider reasoning signatures, so the valid encrypted-reasoning control must remain part of merge-result validation.
  • Complete next step (P2) - No repair lane is needed because no concrete defect was found in the proposed patch; rebased exact-head validation is normal maintainer merge work.
Agent review details

Security

None.

PR surface

Source +6, Tests +24. Total +30 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 12 6 +6
Tests 1 24 0 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 36 6 +30

Review metrics

Metric Value Why it matters
Production versus regression coverage production +12/-6; tests +24 The net six production lines add a parse-failure boundary and type discriminator in the shared owner; the test addition exercises both converter styles.

Stored data model

Persistent data-model change detected: serialized state: packages/ai/src/transports/openai-responses-replay-messages-internal.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Validate the exact merge result (recommended)
    Rebase or test GitHub’s merge result against current main, confirming malformed signatures are skipped and valid encrypted reasoning still replays in both converter styles.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Rebase or validate the exact merge result, rerun the focused Responses replay regression and required CI, and preserve the valid encrypted-reasoning control.

Technical review

Best possible solution:

Land the shared parse-and-discriminate repair only after validating the rebased merge result, retaining coverage for malformed values and valid encrypted reasoning across both replay styles.

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

Yes, from source: current main directly parses persisted signatures at the replay boundary, so malformed JSON can abort conversion before the later assistant content is emitted. The PR also supplies a documented before/after gateway continuation run.

Is this the best way to solve the issue?

Yes: the shared converter owns both provider and transport replay paths, and rejecting malformed or unrelated parsed values there avoids downstream compensation while retaining valid reasoning replay.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2fc85bdc1bd2.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The documented exact-head A/B gateway continuation run exercises persisted-session replay through a strict local Responses-compatible endpoint and reports successful after-fix recovery with a valid-reasoning control.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The documented exact-head A/B gateway continuation run exercises persisted-session replay through a strict local Responses-compatible endpoint and reports successful after-fix recovery with a valid-reasoning control.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This repairs a bounded persisted-session continuation failure without adding product surface.
  • merge-risk: 🚨 compatibility: The converter changes how existing persisted provider signatures are interpreted during later session turns.
  • merge-risk: 🚨 availability: The altered replay boundary determines whether a continuing session reaches the provider request.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The documented exact-head A/B gateway continuation run exercises persisted-session replay through a strict local Responses-compatible endpoint and reports successful after-fix recovery with a valid-reasoning control.
  • proof: sufficient: Contributor real behavior proof is sufficient. The documented exact-head A/B gateway continuation run exercises persisted-session replay through a strict local Responses-compatible endpoint and reports successful after-fix recovery with a valid-reasoning control.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Git blame assigns the current unguarded replay block to this commit. (role: current replay implementation author; confidence: medium; commits: 11ebdfc9c32a; files: packages/ai/src/transports/openai-responses-replay-messages-internal.ts)
  • jalehman: The supplied PR timeline records assignment and force-push of the reviewed head by this contributor. (role: recent PR committer and assignee; confidence: medium; commits: 1d15daec194a; files: packages/ai/src/transports/openai-responses-replay-messages-internal.ts, packages/ai/src/transports/openai-responses-compaction-replay.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Validate the exact rebased or GitHub merge result against current main before landing.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (7 earlier review cycles)
  • reviewed 2026-08-13T20:03:53.653Z sha fb2f5b1e8e3ccbbb265fafbc3597feb5eff705f8 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T13:01:26.841Z sha fb2f5b1e8e3ccbbb265fafbc3597feb5eff705f8 :: needs changes before merge. :: [P1] Validate parsed reasoning items before replaying them
  • reviewed August 15, 2026, 1:55 AM ET / 05:55 UTC sha unknown :: needs changes before merge. :: [P1] Validate parsed reasoning records before replaying
  • reviewed 2026-08-15T09:41:24.648Z sha fb2f5b1e8e3ccbbb265fafbc3597feb5eff705f8 :: needs changes before merge. :: [P1] Validate parsed reasoning records before replaying
  • reviewed 2026-08-15T09:56:47.426Z sha fb2f5b1e8e3ccbbb265fafbc3597feb5eff705f8 :: needs changes before merge. :: [P1] Reject non-reasoning JSON values before replaying
  • reviewed 2026-08-16T16:46:31.468Z sha fb2f5b1e8e3ccbbb265fafbc3597feb5eff705f8 :: needs changes before merge. :: [P1] Validate parsed signatures before replaying
  • reviewed 2026-08-17T21:50:11.021Z sha 1d15dae :: needs real behavior proof before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 14, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
@jalehman jalehman self-assigned this Aug 17, 2026
Responses replay parsed persisted thinking signatures without validating their JSON shape, so corrupt or unrelated values could prevent every later turn in a session.

Parse signatures in the shared replay owner and accept only reasoning records. Cover malformed syntax, null, arrays, and wrong item types through both provider- and transport-style converters.
@jalehman
jalehman force-pushed the fix/openai-responses-replay-thinking-signature-json branch from fb2f5b1 to 1d15dae Compare August 17, 2026 21:43
@jalehman jalehman changed the title fix(ai): skip malformed thinkingSignature JSON instead of bricking the session fix(ai): keep sessions usable with malformed reasoning history Aug 17, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 17, 2026
@jalehman

Copy link
Copy Markdown
Contributor

Added release-shaped OCM A/B behavior proof to the PR body for exact head 1d15daec194.

The proof used package runtimes for the pre-fix parent and PR head, OCM-managed loopback gateways, a strict local Responses-compatible endpoint, authentic gateway-created sessions, persisted SQLite history, a stop/mutate/integrity-check/restart boundary, and continuation of the same sessions through gateway WebSockets.

Observed result:

  • truncated JSON: failed before provider egress before the fix; continued successfully after the fix
  • wrong-type object: produced an invalid provider request and HTTP 400 before the fix; was omitted and continued successfully after the fix
  • valid encrypted reasoning: replayed normally before and after
  • assistant text and valid history remained in successful post-fix requests

null and arrays were already omitted in the full pre-fix replay path, so I have recorded that observed behavior rather than claiming they were user-visible failures.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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 Aug 17, 2026
@jalehman

Copy link
Copy Markdown
Contributor

Land-ready verification for head 1d15daec194ab6caac5d7e0826c79070f67202e8:

  • Focused replay test: pre-fix 2 failures; fixed head 40/40 passing.
  • pnpm check:changed: passed on Blacksmith Testbox.
  • Release-shaped OCM A/B: parent 57e862980be failed persisted truncated JSON before provider egress and sent wrong-type replay input that received HTTP 400; this head omitted both invalid signatures and continued the sessions. Valid encrypted reasoning replayed in both packages.
  • Fresh bundled .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main: exit 0, TruffleHog clean, no actionable findings.
  • Exact-head CI run 32072556461: openclaw/ci-gate and all selected lanes passed.
  • Native scripts/pr review-validate-artifacts 123228: READY FOR /prepare-pr, zero findings.
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 123228: passed with hosted_exact_or_recent_parent.

No remaining proof gaps. The local provider was strict and credential-free; no real provider call was needed to prove the persisted replay boundary.

@jalehman
jalehman merged commit 438c55c into openclaw:main Aug 17, 2026
186 of 188 checks passed
@jalehman

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 18, 2026
…23228)

Responses replay parsed persisted thinking signatures without validating their JSON shape, so corrupt or unrelated values could prevent every later turn in a session.

Parse signatures in the shared replay owner and accept only reasoning records. Cover malformed syntax, null, arrays, and wrong item types through both provider- and transport-style converters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants