Repository navigation
fix(ai): prevent truncated Anthropic streamed replies - #140820
Conversation
Preserve text, thinking, and signatures supplied in Anthropic block-start events through the canonical stream reducer. Reuse the completed-signature path so streamed signatures replace initial seeds. SDK-oracle regressions and local HTTP proof cover seeded, seed-only, and empty-start sequences.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 1:06 AM ET / 05:06 UTC. ClawSweeper reviewWhat this changesPreserves initial Anthropic text, thinking, and completed signatures in standalone streamed replies, with SDK comparison tests covering seeded and empty starts. Merge readiness✅ Ready for maintainer review This remains a useful, focused repair: current main still discards seeded content for standalone Anthropic consumers. No actionable introduced defect was found, and the maintainer-protected PR should remain open for normal landing. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s AI package converts Anthropic streaming responses into assistant events and completed messages. Its shared reducer serves both standalone consumers and OpenClaw’s managed transport. flowchart TD
A[Anthropic response events] --> B[Standalone adapter]
A --> C[Managed transport]
B --> D[Shared stream reducer]
C --> D
D --> E[Preserve initial content and append deltas]
E --> F[Publish completed signatures]
F --> G[Assistant events and final reply]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -4, Tests +80. Total +76 across 3 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep initial-content handling in the shared reducer so both adapters preserve complete replies and publish replacement signatures only when their blocks finish. Do we have a high-confidence way to reproduce the issue? Yes, from source: send a text block starting with Hello followed by a world delta through the standalone adapter; current main drops the initial text. This review did not execute the scenario. Is this the best way to solve the issue? Yes. Removing the profile restriction repairs the shared owner, and reusing its completed-signature path avoids a second implementation while retaining existing interrupted-stream safeguards. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fd5c985d50a3. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
Preserve text, thinking, and signatures supplied in Anthropic block-start events through the canonical stream reducer. Reuse the completed-signature path so streamed signatures replace initial seeds. SDK-oracle regressions and local HTTP proof cover seeded, seed-only, and empty-start sequences.
Additional instructions
Keep Allow edits from maintainers enabled so maintainers can help update the branch.
What Problem This Solves
Fixes an issue where developers consuming Anthropic streams through the standalone adapter received truncated or empty replies when the response included text or thinking in its initial stream events. A response starting with
Helloand continuing withworldreturned onlyworld.Why This Change Was Made
Both Anthropic adapters now preserve initial content through their shared stream reducer. They also share the completed-signature accumulation path: an initial signature survives when no replacement arrives, and streamed signature data replaces that initial value. Production code shrinks by four lines.
User Impact
Standalone Anthropic consumers retain the complete streamed reply and thinking content, matching the managed adapter and native SDK. The usual empty-start sequence continues to work.
Evidence
The two seeded regression cases failed before production changes; the empty-start control passed. After repair, both adapters matched the pinned Anthropic SDK 0.120.0 across three event sequences and nine real local HTTP requests. All 278 related tests passed, followed by a final 18-test parity run. The full package test typecheck, full-file lint, formatting, max-lines ratchet, and independent P2 review passed. Regression tests add 70 lines, and the corrected snapshot adds 10 net lines.
The HTTP proof uses synthetic local SSE responses. Current first-party frequency of nonempty block starts was not measured: request parameters cannot force whether Anthropic places content in a start event or a later delta, so a live smoke would not reliably exercise this case. The regression compares the actual native SDK parser and both adapters against seeded, seed-only, and empty-start sequences.