perf(acp): coalesce streamed text snapshots #19626
main fromrefs/pull/19626/head·merged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHubProblem#
The shared ACP adapter emits three events for every root text chunk, with two carrying the entire reply so far. A 5,000-chunk reply produces about 262.5 million characters of serialized event JSON before downstream filtering.
Change#
Emit the first text immediately, coalesce subsequent assistant, reasoning and user text into scheduled 50 ms snapshots, and flush the complete text before a segment closes or a turn ends. Emit text nodes only when they open and close. Each emission captures one text snapshot, and a serialized flush cannot restore a completed item to running.
Scope and approval#
Fixes #19461. This reduces event production within the established shared ACP text-streaming path used by Grok, Antigravity and registry agents. Existing segment identities, ordinals and final text are preserved. Child-thread streams remain unchanged. An identified message can update after an intervening tool event within the coalescing window; its item position stays fixed. No new client flow or contract is introduced.
Verification#
The new public adapter test fails on the original per-chunk implementation and passes with coalescing. The primary validator and author each passed all 119 adapter tests. Two independent reviews covered the full change, followed by a fresh review of the final text-snapshot correction. Scoped provider typecheck and targeted lint passed.
A primary comparison through the real adapter and mock ACP subprocess reduced a 5,000-chunk burst from 15,006 events and 262,504,192 JSON characters to 17 events and 293,866 characters. Both runs delivered the first chunk immediately and the complete final text before the terminal event. A paced 100-chunk run reduced 306 events to 39. Scheduling adds latency to intermediate snapshots; the 50 ms window is not a wall-clock deadline under host load.
These measurements cover adapter events. SQLite and socket savings were not measured; downstream persistence already throttles snapshots. No product browser or authenticated provider session was run.
Prepared for Wout byclaude-opus-5-5 in T3 Code's Claude harness. Validated by gpt-6.1-sol in Codex.- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
7ca86b1c-db34-4ce8-9c5d-6045011a5937
📥 Commits
-
Reviewing files that changed from the base of the PR and between 348f217a853dd4a23d7fa4834dedb05f545c2075 and daa035cbe5df4ffa2ce405ebacbb48df0b911107.
📒 Files selected for processing: 2
-
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tspackages/provider-acp/src/server/adapter.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
-
📝 Walkthrough
-
The ACP adapter now emits the first text snapshot immediately, coalesces subsequent text changes into snapshots at 50 ms intervals, and emits a final snapshot when a segment closes. A test checks the emitted text snapshots and statuses.
Changes: ACP text streaming
Layer / File(s) Summary Capture and publish coalesced text snapshots
packages/provider-acp/src/server/adapter.ts,apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tsThe adapter captures text for each snapshot and coalesces later segment changes at 50 ms intervals. It emits text nodes only for the first and completing non-user segment updates. The test checks assistant message and turn-item snapshots, streaming status, and node status updates. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Other
Sequence Diagram(s)#
sequenceDiagram participant ACP as ACP session updates participant Adapter as ACP adapter participant Events as Runtime events ACP->>Adapter: Send assistant text chunks Adapter->>Events: Emit initial text snapshot Adapter->>Adapter: Coalesce later text changes for 50 ms Adapter->>Events: Emit captured text snapshot ACP->>Adapter: Close assistant segment Adapter->>Events: Emit final text snapshotSuggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
daa03-
Streamed ACP text is now coalesced into fewer snapshots. The first chunk is still delivered immediately and the final text is flushed before the segment closes. No actionable merge-blocking risk was found.
Security architecture risk: 🔵 Low · up to
daa03-
The change reduces repeated text updates without adding permissions or access paths. No security defect was established. Remaining uncertainty concerns completion and cancellation interleavings rather than a demonstrated boundary bypass.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The changed path processes provider-controlled text within existing root-thread and run ownership. It is shared adapter behavior, but the inspected comparison does not add another tenant, asset, credential, filesystem, network, or tool-authority transition.
Trust Boundaries and Controls
- observed — Runtime notifications pass through the existing callback semaphore, teardown-state check, and runtime-generation check before projection. Prompt completion uses the same wrapper. Delayed text emissions additionally use a separate semaphore and validate that their captured segment remains current and dirty.
Resilience and Maintainability Implications
- inferred — Normal completion and prompt failure explicitly close text before terminal publication, and scheduled flushes belong to the session scope. Complete transition atomicity remains uncertain: text mutation and detachment are outside the emission semaphore, while background and interrupt-timeout finalization can run outside the notification callback permit. This leaves a bounded concurrency proof gap, not an established security vulnerability or cross-owner exposure.
-
Pre-merge checks:
4-
Passed checks: 4 passed-
Check name Status Explanation Title check The title clearly and concisely describes the main change: coalescing streamed text snapshots in the ACP adapter. Description check The description includes all required sections. It explains the problem, implementation, scope and issue reference, approval rationale, verification results, limitations, and the agent and harness use… Linked Issues check Issue #19461requires lower event and serialized-JSON volume in the shared ACP adapter, coalescing streamed text, flushing at segment and turn boundaries, and preserving final text with a burst test. …Out of Scope Changes check The diff changes only the shared ACP adapter and its adapter test. The implementation changes text snapshot scheduling and node emission behavior that directly support issue #19461. The test provides …
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Yash-Singh1(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This changes shared production ACP streaming semantics by delaying and suppressing intermediate snapshots through new asynchronous scheduling, while preserving only the initial and final emissions. The scope is focused and tested, but the shared runtime impact and concurrency coordination merit human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).