fix(partial-json): merge consecutive string tokens in generate#971
Open
ysnows wants to merge 1 commit intoanthropics:mainfrom
Open
fix(partial-json): merge consecutive string tokens in generate#971ysnows wants to merge 1 commit intoanthropics:mainfrom
ysnows wants to merge 1 commit intoanthropics:mainfrom
Conversation
When the tokenizer produces consecutive string tokens (e.g., from strings containing escaped quotes that get split across token boundaries), the generate function now merges them with an escaped quote instead of producing invalid JSON with adjacent quoted strings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
rbwsam
added a commit
to rbwsam/pi-mono
that referenced
this pull request
Apr 6, 2026
Switch from client.messages.stream() to client.messages.create() to avoid the Anthropic SDK's unguarded partialParse() call in MessageStream, which crashes with 'Expected , or } after property value in JSON' or 'Bad control character in string literal' when tool input JSON contains control characters or triggers the vendored partial-json tokenizer's consecutive string token bug. Pi already accumulates tool arguments with its own parseStreamingJson() which handles all these cases gracefully. The SDK's MessageStream accumulation was redundant and its partialParse crash killed the entire stream before pi ever saw the event. The raw Stream from .create() yields identical SSE events without the buggy accumulation layer. Upstream: anthropics/anthropic-sdk-typescript#971 (open, unmerged) Related: anthropics/anthropic-sdk-typescript#882 Related: anthropics/anthropic-sdk-python#1265
rbwsam
added a commit
to rbwsam/pi-mono
that referenced
this pull request
Apr 9, 2026
Switch from client.messages.stream() to client.messages.create() to avoid the Anthropic SDK's unguarded partialParse() call in MessageStream, which crashes with 'Expected , or } after property value in JSON' or 'Bad control character in string literal' when tool input JSON contains control characters or triggers the vendored partial-json tokenizer's consecutive string token bug. Pi already accumulates tool arguments with its own parseStreamingJson() which handles all these cases gracefully. The SDK's MessageStream accumulation was redundant and its partialParse crash killed the entire stream before pi ever saw the event. The raw Stream from .create() yields identical SSE events without the buggy accumulation layer. Upstream: anthropics/anthropic-sdk-typescript#971 (open, unmerged) Related: anthropics/anthropic-sdk-typescript#882 Related: anthropics/anthropic-sdk-python#1265
rbwsam
added a commit
to rbwsam/pi-mono
that referenced
this pull request
Apr 15, 2026
Switch from client.messages.stream() to client.messages.create() to avoid the Anthropic SDK's unguarded partialParse() call in MessageStream, which crashes with 'Expected , or } after property value in JSON' or 'Bad control character in string literal' when tool input JSON contains control characters or triggers the vendored partial-json tokenizer's consecutive string token bug. Pi already accumulates tool arguments with its own parseStreamingJson() which handles all these cases gracefully. The SDK's MessageStream accumulation was redundant and its partialParse crash killed the entire stream before pi ever saw the event. The raw Stream from .create() yields identical SSE events without the buggy accumulation layer. Upstream: anthropics/anthropic-sdk-typescript#971 (open, unmerged) Related: anthropics/anthropic-sdk-typescript#882 Related: anthropics/anthropic-sdk-python#1265
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.
Summary
stringtokens (e.g., from strings containing escaped quotes that get split across token boundaries), thegeneratefunction now merges them with an escaped quote instead of producing invalid JSON with adjacent quoted strings like"hello""world".Test plan
partialParse('{"key": "hello"}')still works correctly🤖 Generated with Claude Code