Skip to content

perf(gateway): per-transcript broadcast lanes - #121104

Merged
steipete merged 2 commits into
mainfrom
perf/session-sync-broadcast-lanes
Aug 9, 2026
Merged

steipete merged 2 commits into
mainfrom
perf/session-sync-broadcast-lanes

Conversation

@steipete

@steipete steipete commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

createTranscriptUpdateBroadcastHandler serialized every transcript-update broadcast behind one process-wide promise queue. Ordering only matters within a transcript, but the single queue made it global: one session's pending async seq read (readSessionMessageCountAsync, taken whenever an update arrives without a committed messageSeq) head-of-line blocked session.message and sessions.changed delivery for every other session. Each queued update also does a full gateway session-row build, so a busy session's per-message broadcasts stalled unrelated sessions on multi-agent installs and subagent swarms.

Why This Change Was Made

Ordering is a per-transcript contract — subscribers merge each session's updates independently and no consumer depends on cross-session broadcast order. The queue is now a Map of lanes keyed by the update's transcript identity (target.sessionKey → sessionKey → sessionFile), so independent sessions proceed concurrently while order within one transcript is preserved. Drained lanes are deleted so idle sessions do not accumulate map entries.

Scope note: an earlier revision of this PR also skipped the per-message transcript-usage re-derivation. CI caught that as a regression — session.message payloads carry live totalTokens / estimatedCostUsd derived from the transcript as a dashboard API contract (#50101), proven by src/gateway/session-message-events.test.ts. That part is reverted; per-message usage stays derived under its existing bounded 64KB cap. Reducing that remaining per-message read needs a different fix (recording usage at its producer rather than re-deriving it downstream) and is left as a follow-up.

User Impact

A busy session can no longer stall transcript and message updates for other connected sessions. No payload or ordering contract changes.

Evidence

  • New boundary tests: one session's broadcast completes while another session's lane is parked on a pending seq read; message order within one lane is preserved when the first update blocks.
  • node scripts/run-vitest.mjs run src/gateway/server-session-events.test.ts src/gateway/session-message-events.test.ts — 52 passed (includes the usage-metadata contract test that caught the reverted change).
  • node scripts/run-vitest.mjs run src/gateway/server-runtime-subscriptions.test.ts — 10 passed; earlier full run with session-utils.test.ts — 169 passed.
  • tsgo core test lane clean; oxfmt/oxlint clean.
  • Codex autoreview (gpt-5.6-sol, xhigh) clean on the change bundle.

Production LOC delta: +21 (lane map). Tests +88. Growth justification: the per-transcript ordering fact is now recorded at the boundary that enforces it.

Found by a full syncing-logic audit; separate follow-ups tracked for cloud-worker workspace-sync repeated full-tree hashing and its 25ms directory-walk poll, auth-profile throwaway SQLite handles, per-turn sandbox skill wipe/recopy, and sessions.patch key scoping.

Unrelated main breakage fixed here

main is red on checks-node-compact-large-6 independently of this PR (its own run on 5b6c19d9 fails the same job). Cause: ui/src/pages/labs/labs-page.test.ts gives the "Cloud Worker Desktop" case index: 6, which is the "Message audit metadata" row — the row added in #120727 reused the previous index instead of taking the next one. Labs rows render in LAB_FEATURES registry order and workerDesktop is the eighth entry, so the case toggled the audit row and asserted the audit patch. Reproduced locally on an unmodified UI tree before the fix and green after (node scripts/run-vitest.mjs run ui/src/pages/labs/labs-page.test.ts — 44 passed). Per repo policy the merge gate is not bypassed; the smallest correct fix rides in this landing PR as a separate commit.

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 9, 2026 15:48
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 9, 2026
@steipete steipete changed the title perf(gateway): per-transcript broadcast lanes and lighter message frames perf(gateway): per-transcript broadcast lanes Aug 9, 2026
@steipete
steipete force-pushed the perf/session-sync-broadcast-lanes branch from fa71bb6 to b6c24cf Compare August 9, 2026 16:03
Transcript-update broadcasts were serialized behind one global promise queue,
so one session's pending async seq read head-of-line blocked every other
session's session.message and sessions.changed delivery. Ordering is a
per-transcript contract, so key the queue by transcript identity and drop
drained lanes.

Per-message transcript usage stays derived: session.message payloads carry
live totalTokens/estimatedCostUsd as a dashboard API contract (#50101).
@steipete
steipete force-pushed the perf/session-sync-broadcast-lanes branch from b6c24cf to a645fad Compare August 9, 2026 16:46
The row added in #120727 reused index 6, which belongs to Message audit
metadata, so the case toggled the audit row and asserted its patch. Labs
features render in registry order, and workerDesktop is the eighth entry.
@vincentkoc

Copy link
Copy Markdown
Member

I opened #121161 as the narrow Labs test-owner repair. It removes all positional/index-based toggle selection by resolving each named .settings-row and its wa-switch, rather than changing only Cloud Worker Desktop from index 6 to 7.

Please drop this PR's one-line labs-page.test.ts overlap when rebasing so the gateway performance change can stay independent.

@steipete
steipete merged commit ad1a2cd into main Aug 9, 2026
131 checks passed
@steipete
steipete deleted the perf/session-sync-broadcast-lanes branch August 9, 2026 17:17
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
* perf(gateway): per-transcript broadcast lanes

Transcript-update broadcasts were serialized behind one global promise queue,
so one session's pending async seq read head-of-line blocked every other
session's session.message and sessions.changed delivery. Ordering is a
per-transcript contract, so key the queue by transcript identity and drop
drained lanes.

Per-message transcript usage stays derived: session.message payloads carry
live totalTokens/estimatedCostUsd as a dashboard API contract (openclaw#50101).

* fix(ui): target the Cloud Worker Desktop labs row in its toggle test

The row added in openclaw#120727 reused index 6, which belongs to Message audit
metadata, so the case toggled the audit row and asserted its patch. Labs
features render in registry order, and workerDesktop is the eighth entry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui gateway Gateway runtime maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants