fix(copilot): consolidate chunk events in JSON log format#1057
Merged
Conversation
PR #1047 only consolidated chunks in summary mode, leaving JSON mode writing one line per agent_message_chunk. Users with log_format: json still saw fragmented output. Apply the same buffering logic to both formats so JSON logs emit a single assistant_message entry per turn. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Deploying agentv with
|
| Latest commit: |
c8484ec
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8550c589.agentv.pages.dev |
| Branch Preview URL: | https://fix-json-chunk-consolidation.agentv.pages.dev |
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.
Closes the remaining gap from #1047.
Problem
PR #1047 consolidated
agent_message_chunkevents into single[assistant_message]lines in summary log format, but left JSON mode unchanged — each chunk was still written as a separate JSON line. Users withlog_format: json(the default in many targets) still saw dozens of fragmented chunk entries per assistant response.Solution
Apply the same chunk buffering logic to both formats. When a
chunkExtractoris provided, chunk events are buffered regardless of format. On flush (next non-chunk event orclose()), JSON mode emits a single{"event": "assistant_message", "data": {"content": "..."}}entry instead of N individual chunk entries.Changes
copilot-utils.ts: Moved chunk extraction before the format branch so buffering applies to bothsummaryandjson.flushPendingText()now emits format-appropriate output.close()flushes unconditionally.copilot-stream-logger.test.ts: Updated the JSON format test to verify consolidation instead of asserting per-event passthrough.Test plan
bun test copilot-stream-logger)🤖 Generated with Claude Code