Repository navigation
fix(anthropic): forward round-2 stream with proper framing (vertical-text bug) - #126
Merged
Merged
Conversation
…text bug) Round-2 text after a proxy-tool re-request (e.g. acp_status) was emitted via emitText(ev.delta) per delta. For Anthropic, emitText/buildTextBlock wraps EACH call in a full content_block (start+delta+stop), so every ~2-char delta became its own block → clients rendered each chunk on its own line (vertical text). The adapter also gated content_block_start/stop behind 'round === 1', so round 2 had no framing at all. Fix: forward round-2 content_block_start/delta/stop with new client indices (remove the round===1 gate; firstRoundOnly: round===1), and have core.ts yield ev.raw in ALL rounds (not just round 1) when the adapter provides it. OpenAI/Responses round-2 (no raw) still falls back to emitText. textProtocol (marker) path unchanged. Regression test: round-2 deltas carry raw (pure delta, not a full block) + content_block_start/stop forwarded + message_start not re-emitted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In ZCode (and any Anthropic client), after a proxy-tool re-request (e.g.
acp_status), the model's round-2 answer rendered as vertical text — each ~2-char streaming chunk on its own line:Root cause
PR #122 made round-2 streaming call
emitText(ev.delta)per delta (core.ts:190). For the Anthropic adapter,emitText→buildTextBlockwraps each call in a full content block:So every tiny delta became its own complete block → the client rendered each block as a separate paragraph → vertical text. (OpenAI/Responses
emitTextonly emits a delta chunk, so they were unaffected.)The adapter also gated
content_block_start/content_block_stopbehindround === 1(adapter-anthropic.ts:166/178/212), so round 2 emitted zero framing.Fix
content_block_start/delta/stopwith new client indices (remove theround === 1gate; usefirstRoundOnly: round === 1). Round-2 text deltas now carryraw(the actual remappedcontent_block_deltaevent).ev.rawin all rounds when the adapter provides it (wasround === 1 && ev.raw). OpenAI/Responses round-2 (no raw) still falls back toemitText. textProtocol (marker) path unchanged.Result: round 2 now streams ONE
content_block_start+ many inlinecontent_block_delta+ ONEcontent_block_stop→ proper Anthropic framing → text renders inline.message_startstays round-1-only (one message per response).Tests
tests/anthropic-round2-stream.test.ts(2 tests): round-2 deltas carryraw(pure delta, not a full block) + content_block_start/stop forwarded + message_start not re-emitted.Verification
Captured round-2 raw HTTP shows the model answer is now a single text block with inline deltas (was N separate blocks).