Repository navigation
Conversation
Each tool-input delta was appended to the raw text and the whole text re-parsed, so large arguments (a big write) cost quadratic CPU and memory: 500 KB took about 36 s. An incremental, tolerant JSON parser now reads each delta once and hands out immutable snapshots, about 4 ms for the same input. The raw text no longer rides on partial messages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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
On every
tool-input-delta, aikit appended the delta to the raw text and re-parsed the whole thing, so streaming large arguments (a bigwriteoredit) cost quadratic CPU and memory. The raw text also rode on every partial message aspartialJson.utils/streamjson.ts: an incremental, tolerant JSON parser. It reads each delta once and returns snapshots that are never mutated after being handed out; finished strings and containers are shared, and only the open path is copied. Copy credit keeps total work linear even for a huge open container.stream.ts: a per-runMap<callID, ToolCallArgumentsStream>replacespartialJson; each delta setsblock.arguments = args.append(delta). Final arguments still come from the AI SDK's parsedtool-callinput.transform.ts:StreamingToolCallBlock,updateToolCallFromInputand theparseStreamingJsoncall are removed.jsonparse.tsis kept.No wire or persisted format change.
Partial snapshots differ from the old parser only on edge cases: a trailing lone backslash is held back until its escape completes,
__proto__stays an own key, a missing comma is tolerated, and an array root shows as{}.Test
test/e2e/streaming.tool.args.e2e.test.tsreplays an Anthropic Messages SSE stream from a local server (no API key): about 600 KB ofwritearguments in 9,220 deltas. It asserts the final arguments, the delta and snapshot counts, that no snapshot is mutated, nopartialJsonon parts, and a 2 s bound (about 170 ms locally), then writes__artifacts__/streaming-tool-args.json.vp checkandvp run typecheckpass.🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.