Skip to content

fix(vscode): deduplicate sync event delivery - #13410

Merged
marius-kilocode merged 1 commit into
mainfrom
fix-kilo-high-cpu-usage
Aug 25, 2026
Merged

fix(vscode): deduplicate sync event delivery#13410
marius-kilocode merged 1 commit into
mainfrom
fix-kilo-high-cpu-usage

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

When multiple sessions stream concurrently, the shared VS Code connection receives two representations of several events: the normal live event and a compatibility sync envelope with the same event ID. Both representations currently reach every registered provider. This duplicates session resolution, event mapping, stream scheduling, and webview update work across the Kilo sidebar, editor tabs, and Agent Manager.

The duplication is especially costly during high-rate message.part.updated streaming. It increases extension-host and webview work even though the second representation carries no new information for those event types.

Why This Change Was Made

The connection now records the IDs of recently delivered live events and drops only a matching compatibility envelope that follows the live event. The filter is bounded to 1,024 IDs. It does not use time-based cleanup or scan the set on every event.

The filter intentionally preserves compatibility events that may contain information not present in the normal event path:

Event category Behavior
message.updated, message.removed Drop matching later sync envelope
message.part.updated, message.part.removed Drop matching later sync envelope
session.created, session.deleted Drop matching later sync envelope
session.updated Preserve sync envelope for reconciliation sequence metadata
Replay-only sync events Preserve

This is a VS Code client optimization only. It does not change the CLI server, database persistence, network delivery, or replay APIs.

User Impact

Users running multiple concurrent sessions should see less duplicate processing in the VS Code extension. Normal live updates, replay-only events, session reconciliation, and existing UI behavior remain available. The change applies to all VS Code clients using the shared connection service, including the sidebar, editor tabs, and Agent Manager.

Evidence

The same synthetic workload was run through the real SdkSSEAdapter path with 5,000,000 wire events, 11 sessions, and 8 downstream listeners.

Metric Before After Change
Wire events received 5,000,000 5,000,000 No change
Events forwarded downstream 5,000,000 2,500,000 50% fewer
Downstream listener calls 40,000,000 20,000,000 50% fewer
CPU time 1,149 ms 1,113 ms 3.1% lower
Wall time 1,040 ms 993 ms 4.5% lower

The full SSE path is dominated by parsing and heartbeat timer work, so the end-to-end CPU reduction is smaller than the downstream reduction. The measurement proves that duplicate downstream dispatch is removed; it does not claim a reduction in CLI server CPU or total device CPU.

Validation Result
Event-path unit tests 85 passed
VS Code typecheck Passed
Formatting and diff checks Passed
Replay-only sync behavior Covered
session.updated reconciliation behavior Covered

@kilo-code-bot

kilo-code-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • .changeset/calm-agent-manager-streams.md
  • packages/kilo-vscode/src/services/cli-backend/connection-service.ts
  • packages/kilo-vscode/src/services/cli-backend/connection-utils.ts
  • packages/kilo-vscode/tests/unit/connection-utils.test.ts

Reviewed by grok-4.6 · Input: 78.8K · Output: 13.3K · Cached: 588.4K

Review guidance: REVIEW.md from base branch main

@iscekic iscekic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, bot remarks below, feel free to ignore

Comment thread packages/kilo-vscode/src/services/cli-backend/connection-utils.ts
Comment thread packages/kilo-vscode/src/services/cli-backend/connection-service.ts
Comment thread packages/kilo-vscode/tests/unit/connection-utils.test.ts
@marius-kilocode
marius-kilocode merged commit e540e5a into main Aug 25, 2026
24 checks passed
@marius-kilocode
marius-kilocode deleted the fix-kilo-high-cpu-usage branch August 25, 2026 12:07
@marius-kilocode

Copy link
Copy Markdown
Collaborator Author

Following up in 12417 @iscekic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants