perf(server): coalesce thread WS events into batched frames - #191
Merged
Conversation
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.
Problem
After cadence pull 6 (PR #190) the upstream transfer-budget regression test
(
apps/server/src/server.test.ts→reports thread HTTP and WebSocket transfer budgets) failed on loom: 52 WebSocket messages per measured turn against abudget of 21, and 8024/8045 wire bytes against 8000, for both the codex and
claudeAgent variants.
The pull-6 review gate diagnosed it: same events as upstream, all unique
sequences, no double-publish. Loom emitted singleton frames where upstream
batches several events per frame — same data, ~50 envelopes instead of a dozen.
The cause is historical: upstream's pull-5 burst-coalescing perf work was
deferred on loom because it arrived entangled with loom's #115 fail-loud shell
catch-up ownership of
apps/server/src/ws.ts.Fix
Re-home the batching onto
subscribeThread's live leg only:coalesceThreadStreamgroups the buffered live stream withStream.groupedWithin(512, 50 millis)and re-emits each group whole, in order,as a single chunk — one RPC frame carrying several items. This is the same
groupedWithinshape upstream applies on its shell leg (SHELL_COALESCE_*),minus the per-aggregate collapsing: the thread client applies every activity
item, so nothing may be dropped.
Loom's owned semantics on this seam are untouched — the #115 fail-loud mapper
lives on the shell leg, and pingdotgg#4079's ordering holds because the completion marker
still rides the same FIFO queue as the events it must follow.
Two thread-subscription tests move to
TestClock.withLive— the flush window isa real sleep that virtual time never advances past. Upstream's own coalescing
tests do exactly this.
apps/server/src/server.test.tsis 129/129 green; therest of the server suite matches the recorded known-failure set on
origin/mainexactly (verified by re-running the same files on a stashed baseline).
Model: claude-opus-4-8 · Harness: T3 Code (pi coder sub-thread)