Skip to content

feat(gateway): send presence deltas to capable operator clients - #175508

Merged
steipete merged 2 commits into
mainfrom
steipete/presence-deltas
Oct 17, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/presence-deltas

Conversation

@steipete

@steipete steipete commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A reported production roster of 24 presence rows produces ~23 KB full snapshots for each change, fanned out to ~20 sockets at 1–2 changes per minute: roughly 0.5 MB/minute and ~50 MiB over two hours, usually for one changed row.

User Impact

The web Control UI opts into presence-deltas and receives changed rows instead of repeated full rosters. Native clients retain the existing full presence payload byte-for-byte, and ordinary system-presence calls still return an array. There is no protocol-version bump or configuration change.

Why This Change Was Made

Presence delivery compares each connection's last sent projected roster with its current recipient projection, using opaque keys from the presence owner and the existing presence version. Deltas carry whole-row upserts, removals, and the complete roster order. A reset replaces the roster when there is no base or a delta would not save bytes. The hello snapshot stays unchanged; the first post-hello event establishes an explicit reset baseline.

Only a frame accepted by the socket advances the baseline. Backpressure drops invalidate it; synchronous/asynchronous send failures and disconnects clear it. The next send after a drop is a full reset. Per-recipient watched-session visibility remains authoritative before diffing. Retained connection state holds row references, not copies or serialized rosters.

The Gateway store reconstructs ordinary full presence events for all downstream web consumers. A base mismatch requests system-presence with {snapshot:true}, available only to opted-in readers; the response replaces the list and retires the server event base. Recovery is deduplicated and cannot overwrite a newer event or another hello.

Recipient policy stays in the existing projection, and delivery state stays on the connection. The tests exercise the actual WebSocket lifecycle without production test hooks.

Evidence

  • Real Gateway with capable and legacy WebSocket clients: connect, watched-session update, and disconnect reconstruct identical ordered rosters; actual deltas arrive. Forced backpressure drops the capable frame, the next event resets, and reconnect starts with hello followed by a reset. Ordinary/recovery RPC shapes are covered. 1 test, 6.806 seconds test time / 39.55 seconds wall time.
  • Gateway delivery/infra proof: 28 tests pass, including synchronous rejected send, asynchronous callback failure, recipient projection change, full-reset size fallback, stable keys, and existing presence lifecycle behavior. 109.35 seconds cold wall time, mostly compiler preparation.
  • UI owner/self-profile/app-host proof: 36 tests pass (0.72 seconds test time / 19.27 seconds wall); another 7 connect-plan tests pass. The four new UI owner tests failed against the original implementation for the intended missing delta/recovery behavior.
  • Synthetic 24-row roster, one changed projected row, complete uncompressed JSON event: 19,624 B full → 1,451 B delta (92.6% smaller). Key lengths and the number of changed rows determine actual savings.
  • Gates pass: pnpm tsgo:core, all pnpm tsgo:core:test shards, pnpm tsgo:ui, type-aware oxlint and oxfmt on all touched files, pnpm -s check:assertion-safety, pnpm -s check:line-cap-ratchet, docs MDX sanity, and git diff --check. The UI owner tests and UI typecheck also pass after lint cleanup.
  • Isolated Codex review through P2 completed. Its sole finding requested older-Gateway web fallback; rejected under ui/AGENTS.md's explicit Gateway Coupling contract. Native compatibility is retained and proven. No accepted actionable findings remain.

The real-path test releases simulated pressure before its RPC barrier because RPC replies also enforce backpressure. It compares fresh recovery snapshots at a fixed clock instant because snapshot reads refresh the Gateway self timestamp. No production gates were bypassed. PR CI supplies the broad test proof.

Related: #175352

CI follow-up

The first PR run exposed a static type-import cycle and browser fixtures still emitting legacy presence events after the UI negotiated deltas. The connection snapshot type now lives with the connection contract, and the existing mock presence owner encodes negotiated reset frames using recorded handshake capabilities.

After the repairs, all 11 selected test files pass: 15 Gateway tests, 33 UI/fixture tests, and 59 browser E2E tests (154.92 seconds total wall time). Core/UI typechecks, touched-file lint and formatting, the import-cycle check, and the line-growth guard pass. A fresh isolated Codex review through P2 found no actionable findings in the corrections.

Release note: The Control UI now receives presence changes as deltas instead of full rosters, cutting a typical presence update from ~20 KB to ~1.5 KB; native apps keep full snapshots.

The original checks-node-changed-3 failure is inherited: the focused agent-terminal-delivery.e2e.test.ts reproduces the same line-409 assertion (['no_reply'] expected, [] received) on the exact CI main baseline 04ed62b9c8718be572cf83615d316846e13c6c7c. The test and terminal-reply/token owners are byte-identical in the baseline and this PR. Main's #170972 made whole-reply NO_REPLY matching case-insensitive, while that E2E still expects lowercase delivery. No unrelated terminal-reply behavior was changed.

An additional full-tree max-lines check reports existing suppressions in three unchanged files (chat-message.test.tsx, config-page-state.ts, and sessions-page-state.ts). The diff-scoped line-growth guard passes; those unrelated baseline entries were left untouched.

Final landing evidence for 8ae224f1b7fac698b27cd9bf8a075ca458a3bbef: CI run 39032881506 completed with 77 successful jobs and 20 intentionally skipped jobs. The only root failure is checks-node-changed-3 (the stale lowercase no_reply assertion above), plus its downstream openclaw/ci-gate. CI labels it unknown because the scheduled-main comparison has no matching job; independent exact-main reproduction supplies the attribution. The current tested merge is fea03a0b1aeef603bdc913c911e8d579d78857d6, with main parent 9ee09dbaba4a5c56bda57c909c9f76dbb74e12f7; the four relevant test/terminal-reply/token source blobs also match that baseline. The scoped land order authorizes the native inherited-failure exception, subject to its live authority, policy, security, and review checks. CI is not being represented as green.

ClawSweeper and GitHub Codex completed review of the final head with no findings. No unresolved review threads remain.

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T12:35:10.955393Z 8ae224f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: L labels Oct 17, 2026
@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 17, 2026
Keep connection snapshot types with the connection contract to avoid a static import cycle. Encode full-roster mock inputs as resets for opted-in browser clients, reusing the recorded handshake capabilities.
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds negotiated presence deltas and snapshot recovery for the Control UI while preserving legacy clients’ full rosters.

Example: One projected row changes in the supplied synthetic 24-row roster.

  • Before: The complete presence event is 19,624 bytes.
  • After: The delta event is 1,451 bytes and reconstructs the same ordered roster.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and focused, with no actionable findings and meaningful transport coverage; confidence rests on supplied in-process evidence while the exact-head CI gate is unresolved.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence reports real in-process Gateway/WebSocket delivery, fault recovery, legacy equivalence, and UI owner tests rather than a separately captured shipped-app run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Concurrent operator clients repeatedly download full presence rosters when only one row changes.
Reason: The maintainer-authored direction addresses measured traffic amplification with an opt-in wire format and preserves existing downstream roster contracts.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it provides a useful, maintainer-approved bandwidth improvement absent from current main, with no actionable patch findings; the CI gate remains pending with an inherited failure.

Priority: P2
Reviewed head: 8ae224f1b7fac698b27cd9bf8a075ca458a3bbef

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway’s in-memory presence owner feeds recipient-filtered WebSocket events and RPC snapshots; the Control UI reconstructs delta events before publishing full rosters to existing consumers.

flowchart LR
  A[Presence mutations] --> B[Presence owner]
  B --> C[Recipient projection]
  C --> D[Connection delivery baseline]
  D --> E[WebSocket reset or delta]
  E --> F[UI presence observer]
  F --> G[Existing roster consumers]
  F --> H[Snapshot recovery RPC]
  H --> C
Loading

Technical review

Best possible solution:

Land negotiated deltas through the existing presence projection and connection lifecycle after the CI gate is resolved through the native landing workflow.

Do we have a high-confidence way to reproduce the issue?

Current main visibly serializes full projected rosters for each publication, and the supplied synthetic measurement demonstrates the bandwidth opportunity; this review ran no target code.

Is this the best way to solve the issue?

The implementation fits the existing owners, preserves recipient filtering and legacy payloads, and handles dropped-frame recovery without introducing persistent state or another authorization policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1a6e911e32b8.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +284, Tests +559, Docs +65. Total +908 across 25 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 12 296 12 +284
Tests 10 565 6 +559
Docs 3 66 1 +65
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 25 927 19 +908

Labels

Label changes:

  • add P2: Reduces repeated roster traffic for concurrent operator clients without evidence of an urgent availability or delivery failure.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Reduces repeated roster traffic for concurrent operator clients without evidence of an urgent availability or delivery failure.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 17, 2026, 8:41 AM ET / 12:41 UTC.

@steipete
steipete merged commit fa335db into main Oct 17, 2026
177 of 182 checks passed
@steipete
steipete deleted the steipete/presence-deltas branch October 17, 2026 13:08
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

steipete added a commit that referenced this pull request Oct 17, 2026
Presence deltas now send only changed fields per row, so heartbeat and activity updates stay compact instead of falling back to full rosters; new metrics count presence frames by delta, reset and legacy.

Keep browser reconstruction atomic, retain snapshot recovery and legacy delivery, and apply validated upserts in one pass within the existing chat-boot bundle budget.

Related: #175508
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…claw#175508)

* feat(gateway): send presence deltas to capable operator clients

* fix(test): honor negotiated presence in browser fixtures

Keep connection snapshot types with the connection contract to avoid a static import cycle. Encode full-roster mock inputs as resets for opted-in browser clients, reusing the recorded handshake capabilities.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…175668)

Presence deltas now send only changed fields per row, so heartbeat and activity updates stay compact instead of falling back to full rosters; new metrics count presence frames by delta, reset and legacy.

Keep browser reconstruction atomic, retain snapshot recovery and legacy delivery, and apply validated upserts in one pass within the existing chat-boot bundle budget.

Related: openclaw#175508
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 docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant