Skip to content

fix(gateway): keep presence deltas compact during activity - #175668

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

steipete merged 2 commits into
mainfrom
steipete/presence-modes

Conversation

@steipete

@steipete steipete commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Presence updates for capable Control UI clients often fell back to full resets during normal heartbeat and activity churn. Whole-row upserts resent unchanged metadata, making the candidate delta larger than a reset.

User Impact

Control UI presence keeps the same ordered rows and freshness timestamps with smaller updates. In the isolated real-Gateway reproduction, capable-client frames fell from an average 6,503 bytes to 2,120 bytes (67.4% smaller). Native and other non-capable clients keep full frames.

Why This Change Was Made

Existing rows now carry changed top-level fields and explicitly removed fields. New rows still carry full contents. Comparison uses the existing per-connection projected baseline; no hashes or additional cache state. The web presence owner applies patches before publishing complete lists. First delivery, recovery, backpressure, and size-based reset behavior remain intact.

The existing batched event metrics now expose openclaw_gateway_ws_presence_frames_total{mode} and openclaw_gateway_ws_presence_bytes_total{mode}, with delta, reset, and legacy modes. OpenTelemetry exports the corresponding counters. Classification and byte recording add constant work without parsing payloads or scanning rows.

Evidence

The regression starts an isolated real Gateway and eight signed WebSocket clients: six advertise the browser connect plan's capabilities and two are legacy readers. Three rounds exercise actual WebSocket pong renewals, activity RPCs, and watched-session changes with advanced owner wall time. Every publication reconstructs exactly the same roster as the legacy readers.

Measured capable frames Before After
Distribution 18 resets, 0 deltas 0 resets, 18 deltas
Round 1 6,354 B 1,937 B
Round 2 6,802 B 2,368 B
Round 3 6,354 B 2,056 B
Average 6,503 B 2,120 B

All nine rows changed, predominantly ts, lastActivityAt, connectionLastActivityAt, and watchedSessions. The before run fails on expected reset to be delta. The complete after trace has six initial resets and 30 deltas across capable sockets; the two legacy sockets receive seven full frames each. No backpressure, reconnect, or recovery RPC was needed to reproduce the reset-heavy steady state. Legacy frame sizes remain 5,949 / 6,397 / 5,949 bytes.

Focused proof covers field application/clearing, new rows and ordering, unknown-row recovery, transport drops/send errors, reconnect and snapshot recovery, and both metrics exporters. The new real-Gateway regression takes 9.894 seconds of test time (9.915 seconds before); its cold wrapper run takes 50.04 seconds. Exact-head CI has completed; see CI follow-up below.

Validation passed: the real-Gateway regression, UI presence tests, existing Gateway delta/recovery/backpressure tests, broadcaster and transport tests, both metrics exporters, pnpm tsgo:core, pnpm tsgo:core:test, pnpm tsgo:ui, type-aware oxlint and oxfmt on all touched files, assertion safety, line-cap ratchet, and git diff --check. Oxlint found one redundant return in the extracted recorder; it was removed and the affected lint and Prometheus tests passed. Isolated Codex autoreview at P0/P1 completed scoped-clean on the final candidate against the pinned merge base. A refresh against the moving origin/main also reported a Kimi change from main outside this PR; verified as out of scope, then reviewed the actual PR diff against its pinned merge base. The pr-simplify pass retains the existing baseline owner and full-row insertion path; small exporter/test extractions preserve line caps. Net change against the merge base: +111 production, +452 test, and +27 documentation lines. The required real-Gateway regression accounts for most of the new test code.

Related: #175508

CI follow-up

The initial exact-head CI run (39048071337) failed the hard chat-boot JavaScript budget at 1,490,053 bytes (limit 1,490,000). The browser presence owner now validates and applies each upsert in one pass on its private candidate map, reuses the validated key and patch fields, and retains atomic publication and snapshot recovery. Rebuilding the exact CI merge tree with this repair measures 1,489,994 bytes. The pre-existing startup-size diagnostic remains advisory under the repository's CI policy; no budgets or baselines changed.

The repair passed the five store-boundary presence tests, UI typecheck, targeted type-aware lint, formatting, and a fresh isolated P0/P1 review. Final-head CI passed in run 39049228343, attempt 2, with all 76 jobs complete and no failures. The first attempt stopped before Android Access tests because Maven Central returned HTTP 403 for unchanged build dependencies; one diagnosed infrastructure retry recovered it. Both required openclaw/ci-gate checks passed. No inherited-failure exception was used.

Release-note context

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.

Patch changed presence fields against each connection's delivered projection so heartbeat and activity churn retain compact deltas. Keep ordered full snapshots, insertion upserts, and recovery behavior intact. Add bounded delivery-mode counters and a real multi-client Gateway regression with equivalent rosters.

Related: #175508
@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 complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

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-17T16:26:39.371383Z 91140ea 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 extensions: diagnostics-otel Extension: diagnostics-otel extensions: diagnostics-prometheus size: L labels Oct 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c3712f784

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 17, 2026
@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:bug 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 sends changed presence fields instead of whole rows and adds traffic counters by delivery mode.

Example: The reported eight-client Gateway reproduction advances heartbeat, activity, and watched-session state.

  • Before: Capable-client frames average 6,503 bytes, with 18 measured resets.
  • After: Frames average 2,120 bytes, with 18 measured deltas and equivalent reconstructed rosters.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Coherent patch with meaningful production-boundary regression coverage; execution evidence remains harness-based and broad CI is pending.
Proof confidence 🦐 gold shrimp (3/6) The maintainer-authored exemption applies; inspected regression source covers Gateway heartbeat/activity delivery and UI field application, while the body reports after-fix results without a separate shipped-entry-point artifact.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Heartbeat and activity changes repeatedly resend presence metadata, increasing bandwidth while users keep the Control UI connected.
Reason: The maintainer-authored direction has concrete measured value and preserves the existing presence ownership and recovery contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR addresses a concrete bandwidth problem on current main, and no actionable correctness or security defects were found.

Priority: P2
Reviewed head: 91140ea01cc6d72b9cb54ef44235039226d172ad

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped CLI or browser run is supplied; the strongest supplied execution evidence is the reported real-Gateway WebSocket regression.
Agent review details

How this fits together

The Gateway projects its presence roster for each recipient, encodes updates against that connection's delivered baseline, and sends WebSocket frames that the Control UI reconstructs into complete ordered lists.

flowchart LR
  A[Presence owner] --> B[Recipient projection]
  B --> C[Connection baseline and encoder]
  C --> D[WebSocket transport]
  D --> E[Control UI presence store]
  D --> F[Traffic diagnostics]
Loading

Technical review

Best possible solution:

Land the field-patch encoder and matching UI decoder after the exact-head CI gate passes.

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

Current-main source exposes the whole-row size fallback, and the supplied regression exercises heartbeat and activity churn through real WebSockets; no target code was executed during this review.

Is this the best way to solve the issue?

Field patches address the repeated metadata at its existing encoder owner while the existing UI owner reconstructs complete rows without another cache or competing policy.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Presence wire encoding and UI reconstruction changes intended behavior with a stated reason (fa335db: Reduce full-roster traffic through negotiated whole-row deltas while preserving ordering, recipient visibility, and recovery.)
  • WebSocket metrics batching and aggregate counters keeps the original intent (27af6ba: Measure accepted outbound frames and encoded bytes per socket using bounded event labels and event-loop batching.)
  • Session traffic attribution keeps the original intent (ef26df9: Attribute session traffic by reason and delivery without changing aggregate counter labels or recipient selection.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit fa335db adds src/gateway/presence-delivery.ts:26 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fa335db99b7b; files: src/gateway/presence-delivery.ts)

PR surface

Source +111, Tests +452, Docs +27. Total +590 across 24 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 11 177 66 +111
Tests 8 569 117 +452
Docs 5 33 6 +27
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 779 189 +590

Review metrics

Metric Value Why it matters
Production versus test growth Production net +111 lines; tests net +452 lines Growth implements field patches and counters, with most new test code exercising multi-client Gateway behavior and retaining exporter contracts.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Reduces recurring presence bandwidth with limited blast radius; the existing behavior still delivers correct rosters.
  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-17T16:22:38.052Z sha 3c3712f :: needs maintainer review before merge. :: none

Reviewed October 17, 2026, 12:29 PM ET / 16:29 UTC (Revision 2).

@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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 17, 2026
@steipete
steipete enabled auto-merge (squash) October 17, 2026 16:31
@steipete
steipete merged commit 35dba3e into main Oct 17, 2026
213 of 217 checks passed
@steipete
steipete deleted the steipete/presence-modes branch October 17, 2026 17:00
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

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 extensions: diagnostics-otel Extension: diagnostics-otel extensions: diagnostics-prometheus 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