Repository navigation
perf(presence): compact repeated roster identities - #177471
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR assigns compact, stable presence row IDs and extends the existing Gateway traffic benchmark. Example: A 24-row roster sends a delta for one changed field with long connection identities.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR makes a focused, useful optimization absent from current main; no concrete introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe presence owner receives connection and activity updates, maintains ephemeral rows, and supplies opaque identities to recipient-projected Gateway deltas consumed by the Control UI. flowchart LR
A[Connection and activity updates] --> B[Presence owner]
B --> C[Recipient projection]
C --> D[Presence delivery]
D --> E[WebSocket clients]
E --> F[Control UI presence reducer]
Technical reviewBest possible solution: Retain compact IDs in the existing presence owner and evaluate the recorded traffic acceptance rule before landing. Do we have a high-confidence way to reproduce the issue? Current main embeds full internal identities in keys repeated by every delta's order array; the PR supplies a focused size comparison, but this review executed no target code. Is this the best way to solve the issue? The smallest complete change is to allocate short IDs in setPresence, preserve them while rows exist, and allocate fresh IDs after deletion; the patch follows that boundary without adding a competing owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ac6c8b97ea83. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests +10, Docs +2, Other +289. Total +305 across 5 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 19, 2026, 12:36 PM ET / 16:36 UTC. |
Keep opaque wire identities short and stable across live row updates, assigning new IDs after removal. Retain existing field patches, ordering, coalescing, and legacy snapshots. Extend the real WebSocket replay with traffic breakdown and UI reducer correctness checks.
791fb93 to
6dd8e17
Compare
|
The completed real-Gateway evidence is now in the PR body: two concurrent A/B pairs with swapped core halves produced identical byte counts, 49.9% fewer delta bytes and 38.6% fewer total presence bytes. All 42 rosters matched in every accepted run, with zero recovery requests and unchanged frame counts. This closes the pending replay-proof gap noted in the advisory review. The 60% total target was missed; legacy snapshots remain unchanged. Landed as |
* perf(presence): compact repeated roster identities Keep opaque wire identities short and stable across live row updates, assigning new IDs after removal. Retain existing field patches, ordering, coalescing, and legacy snapshots. Extend the real WebSocket replay with traffic breakdown and UI reducer correctness checks. * test(perf): bind presence observers before handshake delivery
What Problem This Solves
Presence deltas already send changed fields and coalesce publications for 200 ms, but each delta repeats the complete roster order using long connection/device identities. The same identities also prefix every changed row. Activity updates can affect multiple connections belonging to the same person, multiplying that overhead.
User Impact
Presence keeps its existing timing, ordering, recipient filtering, field-patch semantics, and client protocol while sending smaller deltas. The presence owner now assigns compact opaque row keys, preserves them through updates, and assigns fresh keys after removal or expiry. No new capability, cache, configuration, or protocol version is introduced.
Evidence and Measurement
A real Gateway WebSocket replay uses 42 synthetic operator connections (40 delta readers, two legacy readers), four node beacons, and five phases: viewer switches/leaves, activity, typing, node heartbeat, and mixed bursts. A and B run concurrently under the exclusive measurement lock on separate 16-core halves, with identical workloads and separate synthetic state. The next pair swaps the halves. Each measurement window is about 200 seconds; byte counts include the serialized event envelope, excluding WebSocket/TLS framing. The baseline loads the old presence owner into the same source/dependency environment; the hook asserts that it was used.
The predeclared target was at least 60% fewer total presence bytes. Both concurrent pairs, including the swapped-core pair, produced identical event-byte counts: 49.9% fewer delta bytes and 38.6% fewer total presence bytes (1.63× smaller), with identical frame counts. The total target is not met, principally because legacy snapshots remain unchanged. The current change delivers a meaningful reduction with four additional runtime lines; native-client delta support remains the next opportunity.
CPU over each 200-second window was 4,632 → 4,467 ms (paired −165 ms) and 4,870 → 4,937 ms (paired +67 ms); there is no consistent CPU improvement or regression. Final RSS was 2,571,730,944 → 2,627,780,608 B (paired +56,049,664 B) and 2,553,868,288 → 2,554,572,800 B (paired +704,512 B). These short runs do not establish a steady-state memory change. Host CPU busy averages on the two halves were 6.11%/5.98% in pair 1 and 9.56%/8.76% in the swapped pair, recorded with
mpstatfor context.Replay command on each side:
node --import ./scripts/tsx.mjs scripts/perf/presence-churn-measure.ts --scenario traffic --clients 42 --rounds 4 --interval-ms 10000 --state-dir <fresh-isolated-state> --port <isolated-loopback-port> --start-at <shared-deadline-ms> --output <report.json>. A additionally uses--presence-owner src/infra/system-presence.baseline.ts, containing the owner from8b78b230a1c109fe6456964e59cb0eeefe63b7e5; B uses this PR's owner. Pair 1 assigns A/B to CPUs 96–111/112–127, then swaps them, with the shared exclusive lock held around each pair.The focused 24-row, single-field size regression is red on the old owner: 2,334 B → 295 B (full snapshot: 19,624 B).
Cause breakdown
Both pairs have identical changed fields on both sides and identical per-phase byte counts. Per-delta means by replay phase:
The roster-order component falls from 1,118,320 B to 112,560 B; upserts fall from 2,455,720 B to 1,623,560 B. The changed values are timestamps/activity, watched sessions, and node text/input age. Profiles, avatars, and static device fields are already omitted from updates. Typing has its own event; presence emitted during that phase reflects activity publication, not retransmitted typing data. Shared-person activity fans out to connections, explaining why this synthetic cohort's baseline deltas are larger than the observed production average.
Legacy clients and resets
Handshake metadata in the reported 15-minute window contains exactly 39 Control UI connections, matching the 39 reported resets. This supports first-post-hello initialization as the cause, rather than periodic reset churn. The replay excludes setup and final verification from measured traffic and requires zero recovery; it does not claim to eliminate initial resets.
Native macOS 2026.10.3 is present in the legacy cohort.
ChatSessionSidebarPeople.receivePresencedecodes a fullpresencearray and has no delta reducer, so advertisingpresence-deltasalone would break it. Generic backend/CLI clients also lack that capability. The legacy wire format is unchanged. A slower legacy cap would add latency without demonstrated benefit at the observed cadence; reducing that traffic requires a native-client delta implementation. Node host statistics use a separate event and are outside this presence replay.Change Size and Tradeoffs
Runtime production code is +5/−1 lines (net +4). The counter and existing-row key lookup preserve the public opaque-key stability contract while preventing identity reuse after removal; there is no parallel owner or identity cache. The larger diff extends the existing benchmark driver, adds regression coverage to existing test files, and documents the existing opaque-key contract. The requested production stat excluding tests/docs is
scripts/perf/presence-churn-measure.ts: +387/−92; src/infra/system-presence.ts: +5/−1(the benchmark is not runtime code).Proof and Limitations
src/infra/system-presence.test.ts,src/gateway/presence-delivery.test.ts, andsrc/gateway/server.auth.presence-deltas.test.ts. The transport file covers reconnect and backpressure recovery. CI also passed the related client-presence, activity, publication-window, session-viewer-presence, and presence-audience tests (job 118180226319, job 118180226406).git diff --check, and one targetedpnpm tsgo:core(tsrs) passed. Broad proof is PR CI; no Testbox lease was allocated.Exact-head CI run 39287586311 has one substantive failure:
checks-fast-baseline-ratchets, plus its downstream aggregate gate. Its error issrc/infra/openclaw-process-census.missing-command.test.ts:12: ./container-environment.jsunderFirst-party mock factories must preserve real exports or explain isolation;mock-exports failed (exit 1). The identical signature fails on unchanged main in run 39282913747. The automatic table labels this "new" against older scheduled-main run 39278710829; the newer main-push run above reproduces the exact signature. Both source files are identical between that failing main baseline and this PR. All other scheduled checks, including dependency/security review, passed or were skipped by CI. No unrelated source was changed and no CI rerun was requested. This qualifies for the explicitly authorized inherited-failure landing exception; CI is not being reported green.