Skip to content

fix(copilot): consolidate chunk events in JSON log format#1057

Merged
christso merged 1 commit intomainfrom
fix/json-chunk-consolidation
Apr 12, 2026
Merged

fix(copilot): consolidate chunk events in JSON log format#1057
christso merged 1 commit intomainfrom
fix/json-chunk-consolidation

Conversation

@christso
Copy link
Copy Markdown
Collaborator

Closes the remaining gap from #1047.

Problem

PR #1047 consolidated agent_message_chunk events 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 with log_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 chunkExtractor is provided, chunk events are buffered regardless of format. On flush (next non-chunk event or close()), 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 both summary and json. 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

  • 6 unit tests pass (bun test copilot-stream-logger)
  • All 1506 core tests pass
  • Biome lint + typecheck pass
  • Pre-push hooks pass (build, typecheck, lint, test, validate:examples)

🤖 Generated with Claude Code

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>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying agentv with  Cloudflare Pages  Cloudflare Pages

Latest commit: c8484ec
Status: ✅  Deploy successful!
Preview URL: https://8550c589.agentv.pages.dev
Branch Preview URL: https://fix-json-chunk-consolidation.agentv.pages.dev

View logs

@christso christso merged commit 7c3cd24 into main Apr 12, 2026
4 checks passed
@christso christso deleted the fix/json-chunk-consolidation branch April 12, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant