Skip to content

perf(server): coalesce thread WS events into batched frames - #191

Merged
QuinRiva merged 1 commit into
mainfrom
t3code/ws-burst-coalescing
Aug 29, 2026
Merged

perf(server): coalesce thread WS events into batched frames#191
QuinRiva merged 1 commit into
mainfrom
t3code/ws-burst-coalescing

Conversation

@QuinRiva

Copy link
Copy Markdown
Owner

Problem

After cadence pull 6 (PR #190) the upstream transfer-budget regression test
(apps/server/src/server.test.tsreports thread HTTP and WebSocket transfer budgets) failed on loom: 52 WebSocket messages per measured turn against a
budget 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:
coalesceThreadStream groups the buffered live stream with
Stream.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
groupedWithin shape 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.

measured turn before after budget
WS messages (codex) 52 18 21
WS messages (claudeAgent) 52 17 21
WS wire bytes (codex) 8024 6898 8000
WS wire bytes (claudeAgent) 8045 6849 8000

Two thread-subscription tests move to TestClock.withLive — the flush window is
a real sleep that virtual time never advances past. Upstream's own coalescing
tests do exactly this. apps/server/src/server.test.ts is 129/129 green; the
rest of the server suite matches the recorded known-failure set on origin/main
exactly (verified by re-running the same files on a stashed baseline).

Model: claude-opus-4-8 · Harness: T3 Code (pi coder sub-thread)

@QuinRiva
QuinRiva merged commit 6f3404a into main Aug 29, 2026
@QuinRiva
QuinRiva deleted the t3code/ws-burst-coalescing branch August 29, 2026 12:21
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M labels Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant