Skip to content

fix: keep encrypted reasoning replay stable after local session reloads - #167769

Closed
xyrolle wants to merge 1 commit into
openclaw:mainfrom
xyrolle:fix/local-reasoning-replay
Closed

xyrolle wants to merge 1 commit into
openclaw:mainfrom
xyrolle:fix/local-reasoning-replay

Conversation

@xyrolle

@xyrolle xyrolle commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #167768

What Problem This Solves

Fixes: a local Responses session changes the replayed bytes of an encrypted reasoning item when it is reopened after an in-turn tool continuation.

User Impact

User impact: encrypted reasoning items use the same signature bytes during the first tool continuation and after session reconstruction. Visible thinking, ciphertext, IDs, status, live tool arguments, and previously approved history retain their existing behavior. No configuration change or migration is required.

Risk: fresh signatures carrying non-empty encrypted_content now take the stored form on the in-turn continuation, as node turns and reopened sessions already do. Their summaries and plaintext content are dropped from the replay signature. Items without a non-empty string in encrypted_content retain today's in-turn behavior, including plaintext content; storage still canonicalizes them on reload. Provider acceptance and cache statistics were not measured on a real provider. Better prefix reuse is an expected consequence for caches sensitive to replayed input, not a measured result.

Why This Change Was Made

The local completion boundary now calls the existing transcript signature sanitizer before persistence for fresh signatures carrying non-empty encrypted_content. The sanitizer retains ownership of route eligibility, validation, and canonical bytes. Only blocks whose signatures change are copied.

This extends the byte-consistency approach in #164287 to local sessions, with a narrower entry condition to avoid newly dropping plaintext-only reasoning during a turn. It does not change the sanitizer or rewrite stored history.

Evidence

  • Synthetic local-session tests cover one Responses route with distinct encrypted and plaintext-only (encrypted_content: null) cases. On main f5e306d4fe0a1d2c2b844ea034c5341e7a97fb4e, the encrypted case fails on raw versus canonical signature bytes; the plaintext-only case passes. The fix passes both cases and checks visible thinking, ciphertext, IDs, status, live tool arguments, unchanged history, and reconstructed-session replay.
  • Focused command: pnpm test src/agents/sessions/agent-session-reasoning-replay.test.ts --maxWorkers=1. Baseline: 1 failed, 1 passed, 10.10 s wall. Fixed: 2 passed, 20.96 s wall, 0.371 s test time, including compiled-worker preparation. The plaintext-with-null case also fails with the prior presence-only guard and passes with the non-empty-string guard.
  • Affected suites: 77 tests pass across 6 files, 57.95 s command wall time: reasoning replay (2), loop correctness (27), Responses EOF (27), code-mode source (16), transcript worker (3), and reasoning redaction (2).
  • Touched-file formatting and typed lint, core types and all 27 core-test type graphs, docs MDX sanity, unused-export scans, and the remaining changed-file guards pass.
  • No provider requests were made.

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Oct 9, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The PR makes local sessions reuse the stored form of encrypted reasoning signatures, the provider’s serialized reasoning items, so replayed input stays consistent after session reload.

Example: A local Responses session runs lookup and is then reopened.

  • Before: The rs_fresh reasoning item includes fresh summary and fresh content during continuation, but reload removes that content and empties the summary.
  • After: Both continuations use summary: [] without plaintext content while preserving rs_fresh and gAAAA-synthetic==.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with meaningful regression coverage, but confidence remains limited to synthetic execution.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Reopening a local session changes the reasoning item replayed to the provider compared with the earlier tool continuation.
Reason: Encrypted replay consistency follows the existing transcript and worker contract. The repair is narrow and avoids claiming unmeasured provider or cache improvements.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR contains a distinct, useful consistency repair that current main still lacks. No actionable patch defect was identified, and the related merged worker fix does not cover local sessions.

Priority: P2
Reviewed head: 284f2f00a105dc92b6ab21d75258421993f9d6d3

Before merge

  • Add real behavior proof - The changed local completion boundary is exercised with an injected synthetic stream and in-memory storage, but no real provider request was made. Add redacted terminal output or logs from a local encrypted-reasoning tool continuation and reload showing matching replay bytes and successful continuation; omit API keys, private addresses, and non-public endpoints. Existing stored envelopes and readers remain unchanged, so no migration is required. 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.

Findings

None.

Tests

  • Missing end-to-end proof: A real local Responses tool continuation followed by session reload must show matching replayed encrypted signatures and successful subsequent provider output; only synthetic baseline/head results are supplied.
Agent review details

How this fits together

Local agent sessions receive assistant messages from model providers, execute tool calls, and save conversation history. Later provider requests replay reasoning items from either live messages or reconstructed history.

flowchart TD
  A[Provider assistant message] --> B[Local completion boundary]
  B --> C{Nonempty encrypted reasoning?}
  C -->|Yes| D[Existing signature sanitizer]
  C -->|No| E[Unchanged live signature]
  D --> F[Tool continuation]
  E --> F
  D --> G[Transcript storage]
  E --> G
  G --> H[Reloaded conversation]
Loading

Technical review

Best possible solution:

Keep signature canonicalization in the existing transcript owner and apply it to fresh encrypted local output before continuation.

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

Yes, source and the supplied baseline regression establish the local signature-byte mismatch between tool continuation and reconstructed history. This read-only review did not execute the reproduction.

Is this the best way to solve the issue?

Yes, the patch uses the existing canonicalization owner at the fresh-message boundary and preserves plaintext-only behavior, rather than changing storage or rewriting approved history.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0cf5e291a081.

Provenance checked

  • src/agents/sessions/agent-session-transcript.ts keeps the original intent (b6340c7: Reuse the existing SQLite writer for streamed completion persistence while preserving live custody, exact serialization, ordered receipts, and executable tool values.)
  • docs/reference/transcript-hygiene.md keeps the original intent (fix: node continuation signatures diverge from transcripts #164287: Fresh worker continuation and transcript persistence should use identical reasoning signature bytes while preserving ciphertext, tool arguments, and approved history.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced delta adds encrypted-signature normalization at local message persistence, two session regressions, and documentation. The verified test-merge comparison retains the same production change against its main parent. (src/agents/sessions/agent-session-transcript.ts:21, 284f2f00a105)
  • Still necessary on main: Fetched main persists completed local messages without first canonicalizing their live reasoning signatures. The latest stable tag also lacks that integration. (src/agents/sessions/agent-session-transcript.ts:17, 0cf5e291a081)
  • Existing canonicalization and compatibility: The unchanged sanitizer validates route, reasoning shape, identifiers, status, and ciphertext before emitting the existing stored envelope. Storage already invokes it; this PR changes fresh live output timing without changing stored formats or rewriting history. (src/agents/transcript-redact.ts:346, 284f2f00a105)
  • Actual replay consumer: Responses transport parses thinking signatures into reasoning input items, so differences in their summary and content can reach provider input rather than remaining a storage-only difference. (packages/ai/src/transports/openai-responses-replay-messages-internal.ts:450, 284f2f00a105)
  • Meaningful synthetic regressions: The tests drive the real local session loop with an injected stream and guarded in-memory storage. They independently specify encrypted replay bytes, preserve executable arguments and approved history, reconstruct a session, and protect plaintext-only continuation behavior. (src/agents/sessions/agent-session-reasoning-replay.test.ts:95, 284f2f00a105)
  • Contributor proof scope: The complete PR body explicitly reports synthetic tests and no provider requests. Its reported baseline failure supports byte divergence, but it supplies no after-fix real local provider continuation and reload evidence. Captured sourceRevision: b76fb6276c71767c6c00deddf4d7fd91dcc18ef1aad05256735db1f106f54ef3. (284f2f00a105)

Likely related people:

  • Peter Steinberger: Raw commit b6340c7 adds src/agents/sessions/agent-session-transcript.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b6340c7947bd; files: src/agents/sessions/agent-session-transcript.ts)

PR surface

Source +24, Tests +150, Docs +4. Total +178 across 3 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 24 0 +24
Tests 1 150 0 +150
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 178 0 +178

Review metrics

Metric Value Why it matters
Production versus test growth Production +24; tests +150 Production growth is justified by the bounded integration with the existing sanitizer, while the tests exercise continuation and reconstruction.

Labels

Label changes:

  • add P2: This repairs bounded replay consistency; provider rejection, cache loss, and urgent operational impact have not been established.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: This repairs bounded replay consistency; provider rejection, cache loss, and urgent operational impact have not been established.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 9, 2026, 6:36 AM ET / 10:36 UTC.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale after 7 days without qualifying human activity.
Without new human activity, Barnacle may close it as not planned 7 days after this message was posted. This is administrative inactivity cleanup, not a claim that the problem is fixed.
A human update restarts the inactivity clock; a new PR head also restarts it. A maintainer can add no-stale for a durable hold, or bad-barnacle to suppress Barnacle. Remove the hold when work can resume.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 26, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @xyrolle for diagnosing this and for the regression coverage. This is now covered on main by #169689 (438e06c), which normalizes SDK Responses replay to the stored privacy shape and field order, and #172455 (6b13edf), which preserves empty content containers and terminal reasoning ciphertext across cold reopen.

I verified both commits are on current main and ran the existing storage-replay and history-prefix suites: all 11 cases passed. Managed/package requests compare serialized reasoning before and after canonical storage preparation and reload; the four-turn, 12-request scenario checks prefix stability through cold transcript replay. This is offline boundary proof, not a new live-provider/cache measurement.

Closing as already fixed. The persistence/reload regression coverage is already present, so there is no remaining part to lift from this patch. Thank you for helping pin down the replay mismatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S stale Marked as stale due to inactivity 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.

[Bug]: Local Responses reasoning replay changes after session reload

2 participants