fix(agents): concatenate signature_delta chunks in transport stream#87582
Conversation
|
Codex review: needs maintainer review before merge. Reviewed May 28, 2026, 11:24 AM ET / 15:24 UTC. Summary PR surface: Source +6, Tests +666. Total +672 across 3 files. Reproducibility: yes. Current main overwrites repeated Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the narrow parser and regression-test change after required checks finish and maintainers accept the persisted Anthropic thinking-signature replay contract; keep broader recovery or sanitization work in the linked follow-up issues. Do we have a high-confidence way to reproduce the issue? Yes. Current main overwrites repeated Is this the best way to solve the issue? Yes, with maintainer acceptance of the replay contract. The change is narrow, aligns the embedded transport with the sibling Anthropic provider's append semantics, and adds focused seeded-signature and multi-delta coverage. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 5216841a9e59. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +6, Tests +666. Total +672 across 3 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
|
4d7f5ad to
2136e52
Compare
|
ClawSweeper PR egg: ✨ hatched 🌱 uncommon Tiny Clawlet. Rarity: 🌱 uncommon. Trait: hums during re-review. DetailsShare on X: post this hatch
About:
|
2136e52 to
cb39899
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
cb39899 to
39ba28e
Compare
ce20c59 to
4046173
Compare
b0bac55 to
5162834
Compare
The anthropic-transport-stream was overwriting thinkingSignature on each signature_delta event instead of appending. Since Anthropic sends the thinking block signature across multiple streaming chunks, only the last chunk survived. The truncated signature was persisted to session JSONL, causing all subsequent replay attempts to fail with HTTP 400: thinking or redacted_thinking blocks in the latest assistant message cannot be modified This permanently bricked sessions with no user recovery path. Fix: accumulate signature_delta values by concatenating instead of overwriting, matching the correct implementation in the LLM provider layer (src/llm/providers/anthropic.ts:629-634). Includes real-scenario proof against live Anthropic API validating that correct signatures replay successfully while truncated signatures are rejected. Fixes openclaw#87574 Refs openclaw#80625, openclaw#85781, openclaw#87475
6a13ca1 to
ffdb947
Compare
|
Landed via rebase onto main.
Thanks @Jerry-Xin! |
Summary
Fixes the root cause of permanent session corruption when using Anthropic models with extended thinking enabled.
The
anthropic-transport-stream.ts(used by the embedded agent runner) was overwritingthinkingSignatureon eachsignature_deltaevent instead of appending. Since Anthropic sends the thinking block signature across multiple streaming chunks, only the last chunk survived. The truncated signature was persisted to session JSONL, and all subsequent replay attempts failed with HTTP 400.Root Cause
The correct implementation already existed in the same repo at
src/llm/providers/anthropic.ts:629-634— this fix aligns the transport stream with that reference.Changes
src/agents/anthropic-transport-stream.ts— One-line fix: append signature deltas instead of overwritingsrc/agents/anthropic-transport-stream.test.ts— Updated 2 existing assertions + added dedicated multi-chunk concatenation testtest/proof/thinking-signature-real-proof.ts— Real-scenario proof exercising the patched code path + live API replay validationReal behavior proof
Behavior or issue addressed: When OpenClaw stores assistant messages with Anthropic thinking blocks, the
signaturefield is truncated (only lastsignature_deltachunk kept). On replay, Anthropic rejects the invalid signature with HTTP 400, permanently bricking the session. Fixes Bug: anthropic-transport-stream overwrites signature_delta instead of appending, causing permanent session corruption #87574.Real environment tested: macOS arm64, OpenClaw 0.6.0-dev gateway, Claude Sonnet 4 via Anthropic API proxy, Node.js v22.22.1. The patched code path section exercises
createAnthropicMessagesTransportStreamFndirectly with crafted multi-chunk SSE events. The live API section uses real Anthropic streaming withthinking.type: "enabled".Exact steps or command run after this patch:
Terminal output from the real proof script:
Observed result after fix: The proof demonstrates three critical behaviors:
createAnthropicMessagesTransportStreamFnfunction is called with 5 craftedsignature_deltaSSE events. The outputthinkingSignatureequals the concatenation of all 5 chunks (75 chars), not just the last chunk (15 chars). This would FAIL without the patch (old behavior would produce only "rX4uVnB9oI6mKpL").What was not tested: Multi-chunk
signature_deltadelivery was not observed from the live API endpoint (AWS Bedrock proxy coalesces chunks). Multi-chunk concatenation through the actual patched function is verified by the patched code path section which feeds 5 separatesignature_deltaevents directly intocreateAnthropicMessagesTransportStreamFn.Related Issues