Skip to content

perf(gateway): shrink health and reconnect payloads - #178106

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-health-and-connect-payloads-20260919
Oct 20, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-health-and-connect-payloads-20260919

Conversation

@steipete

@steipete steipete commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Health notifications and reconnect handshakes repeatedly transfer diagnostics and presence rows that updated clients can obtain on demand or already receive through the presence stream.

User Impact

Updated Control UI and native operator clients receive smaller health payloads. Control UI reconnects retain their own profile row in hello and receive the full roster through the existing presence stream. Older clients keep their existing payloads; full health diagnostics remain available through the health RPC. No configuration, database, or protocol-version migration is required.

Why This Change Was Made

The Gateway now negotiates health-summary at the existing publication boundary, removing optional agent/heartbeat configuration and session activity from passive health and cached hello health. Control UI also negotiates hello-presence-self, removing the duplicate roster from hello while retaining the connecting client's profile bootstrap. The publication prepares each health representation once for interleaved compact and legacy recipients.

The current hello contains a method/event capability list, not model catalogs or configuration schemas. Existing plugin catalog revisions remain unchanged. This change removes redundant payloads without adding persistent client caches or another invalidation lifecycle.

Evidence

Acceptance recorded before measurement: 24 synthetic agents and 40 signed clients, cold attach and warm reconnects reported separately, concurrent A/B pairs under an exclusive lock with two swapped 16-core allocations. The requested 60% health and 70% warm-hello reductions are targets; landing also requires reduced work without a material paired readiness regression. Readiness ends after hello plus initial presence.

The baseline discovery run completed against b90b2cfb40ec77fde111297ee08d5617373282e0. Its warm hello was 39.9 KB: 24.2 KB of presence, 14.0 KB of method/event capabilities, and approximately 1.7 KB of other metadata. Health was 15.2 KB: 14.2 KB of agent details (including 8.8 KB of heartbeat configuration and 6.5 KB of repeated prompt text), 0.1 KB of top-level session diagnostics, and approximately 0.9 KB of remaining health. Field sizes overlap when reporting nested components. These are synthetic fixture measurements, not a capture of production payloads.

Both concurrent browser pairs passed (CPU halves swapped for pair 2), with one cold attach and two warm reconnect waves per side per pair: 80 cold and 160 warm client attaches per side.

Warm browser metric Capability off Capability on Result
Hello p50 39,877 B 16,239 B −59.3%
Hello p99 39,936–39,937 B 16,239 B −59.3%
Health frame 15,105–15,232 B 902–1,026 B −93.3% to −94.0%
Hello + health + presence / 40-client wave 3.42–3.46 MB 1.92–1.95 MB −43.7% / −44.0% paired aggregate
Socket through hello + initial presence p99 404–419 ms 406–420 ms Pair-average B−A: +5.7 ms / −1.9 ms

The health target is exceeded. The 70% warm-hello target is missed because the unchanged 14 KB method/event capability list is now the dominant floor; the measured reduction is 59.3%. Readiness is neutral within observed noise: individual warm p99 differences range from −6.4 to +11.0 ms, with no consistent directional regression after swapping CPUs. Cold hello p99 is 39,819 → 16,238 B; cold selected traffic is 2.75–2.76 → 1.71 MB. The native-profile pairs also passed (full hello presence retained):

Warm native-profile metric Capability off Capability on Result
Hello p50 55,420–55,546 B 41,139–41,264 B approximately −25.8%
Hello p99 55,477–55,603 B 41,196–41,321 B approximately −25.7%
Health frame p50 15,120–15,309 B 841–1,027 B −93.3% to −94.4%
Hello + health + presence / 40-client wave 3.82–3.84 MB 2.68–2.69 MB −29.8% paired aggregate
Socket through hello + initial presence p99 207–210 ms 206–210 ms Pair-average B−A: +0.8 ms / −2.3 ms

All eight runs completed successfully, with 960 measured attaches total (320 cold and 640 warm). Every wave verified all 40 reconstructed rosters and health deliveries, with zero presence-recovery RPCs. CPU load was recorded with mpstat for context; setup used a separate CPU allocation before both sides moved to their measured 16-core allocations at the common start time. No production configuration or services were changed. The fixed workload verifies each client's own hello row, complete reconstructed presence against system-presence, zero recovery RPCs, and changed health reaching every socket. Health changes use the real quarantine owner and public health collector after the first maintenance tick.

Focused validation: 105 tests passed across the six affected Gateway/UI files; the subsequent broadcaster/closure run passed 50 tests across three files. Core typecheck (tsrs), changed-file lint/format, Swift formatting, and the export-name collision guard passed. The original health regression failed on the baseline and passes with the change. Native compilation/tests and broad validation are delegated to PR CI; no Testbox lease was used. Independent review completed cleanly on the final production and fixture diff (no actionable P0–P2 findings).

Reproduce either side with node --import ./scripts/tsx.mjs scripts/perf/presence-churn-measure.ts --scenario payloads --clients 40 --agents 24 --rounds 2 --interval-ms 1000 --client-profile web --state-dir <new-synthetic-directory> --port <isolated-loopback-port> --start-at <shared-epoch-ms> --output <report.json>, adding --compact-payloads on B; repeat with --client-profile native and swap CPU halves.

Limitations: cold attaches use new devices against an already-ready, health-prewarmed Gateway. Plugins/channels/cron/heartbeat execution are disabled; no production databases are copied. Reported traffic totals cover hello, health, and presence application JSON, excluding WebSocket/TCP framing, compression, unrelated RPCs, and browser rendering. The fixture does not reproduce the reported production 120–125 KB hello tail. Necessary runtime growth is limited to capability negotiation and one shared projection so the shipped legacy protocol remains intact; benchmark instrumentation accounts for most added lines.

Diff size: runtime implementation +28 lines; tests +76; reproducible benchmark +294; documentation +33. The requested non-test/non-doc path filter totals +346 because it also includes the benchmark, its README, and native/inline test edits. Runtime growth is the small negotiated compatibility boundary; no parallel diagnostic collector or persistent cache is introduced.

The first CI run caught an inferred fixture type that omitted optional connect capabilities and a missing SAFETY marker on an already-explained internal health assertion. The fixture now uses the real ConnectParams contract; all 44 focused hello tests passed again, and the single-file assertion scan matches the existing baseline. Both touched files passed focused lint/format, and the fixture repair received a clean independent review. The unrelated UI E2E type error was fixed upstream in #178096 and is incorporated through rebase. Runtime behavior still matches the measured implementation. Final-head CI: https://github.com/openclaw/openclaw/actions/runs/39377702149.

@clawsweeper

clawsweeper Bot commented Oct 20, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: android App: android app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts app: linux size: L labels Oct 20, 2026
@steipete
steipete marked this pull request as ready for review October 20, 2026 05:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 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-20T06:04:47.896715Z 4403282 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.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 440328268f4029a45a0206ff0a473cdb62aa1334
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server/ws-connection/connect-hello.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 20, 2026
Negotiate compact passive health for updated operator clients and self-only hello presence for Control UI. Keep full health RPC diagnostics, profile bootstrap, roster delivery, and legacy payloads intact.
Use the protocol connect type for optional capabilities and mark the existing trusted health producer invariant for the assertion guard.
@clawsweeper

clawsweeper Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR negotiates smaller passive health payloads and self-only Control UI hello presence while preserving legacy delivery and full diagnostic RPCs.

Example: Forty signed web clients reconnect to a synthetic Gateway with 24 agents.

  • Before: Reported warm hello p50 is 39,877 bytes.
  • After: Reported warm hello p50 is 16,239 bytes, with complete presence reconstructed through the existing stream.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused production-boundary measurements support the optimization and no discrete defect was found; proof uses an in-process synthetic workload, and exact-head CI failures remain unattributed.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (live_output): The supplied real Gateway/WebSocket measurements exercise cold attaches and signed-device reconnects with 24 synthetic agents and 40 clients, verify complete reconstructed rosters and changed-health delivery, and report reduced application bytes without a consistent readiness regression; native profiles use synthetic transport clients rather than native app execution.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Health notifications and reconnects repeatedly transfer diagnostic fields and presence rows that updated clients do not need in those payloads.
Reason: The maintainer-authored direction has measured wire savings, preserves diagnostic access and roster delivery, and introduces little runtime machinery.

Merge readiness

✅ Ready for maintainer review

This PR provides a useful, maintainer-directed payload reduction with no actionable introduced defect found; failing exact-head CI still needs attribution before landing.

Priority: P2
Reviewed head: 08f2423088765fbf950cbdec63cb962a301b7db3

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway health and handshake owners collect diagnostic and presence snapshots, project them for negotiated client capabilities, and deliver them over authenticated WebSockets to browser and native clients.

flowchart LR
  A[Health collector] --> B[Health cache]
  B --> C[Capability projection]
  D[Presence owner] --> E[Hello snapshot]
  E --> C
  C --> F[Authenticated WebSocket]
  D --> F
  F --> G[Browser and native clients]
Loading

Technical review

Best possible solution:

Retain the small shared projection and capability negotiation, then land once the exact-head CI failures are resolved or demonstrably attributed outside this patch.

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

Current-main source sends the redundant diagnostic fields and hello roster; the submitted real-WebSocket measurements exercise that path, but this read-only review ran no target code.

Is this the best way to solve the issue?

The patch removes unused wire data at existing publication owners, shares one health projection, and preserves released-client contracts without adding another collector or cache.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced patch and current main: Reviewed the pinned merge-base-to-head patch; fetched main retains the original full-health and full-hello-presence behavior in the affected runtime files. (src/gateway/server/ws-connection/connect-hello.ts:139, 08f242308876)
  • Shared health projection: The shared projection removes only optional agents and sessions fields; the broadcaster prepares compact and legacy representations independently within one publication. (src/gateway/server-broadcast.ts:573, 08f242308876)
  • Presence filtering remains authoritative: Self-only selection still passes through createPresenceRecipientProjection, which retains operator-read and watched-session visibility checks; post-hello publication remains owned by the existing connection lifecycle. (src/gateway/server/health-state.ts:56, 08f242308876)
  • Measured behavior and accepted target shortfall: The maintainer-authored body reports eight real Gateway WebSocket runs with 960 attaches, complete reconstructed rosters, zero presence recovery RPCs, and approximately 93–94% smaller health frames; it explicitly accepts 59.3% warm-hello savings against the original 70% target because the unchanged capability catalog dominates the remainder. (scripts/perf/presence-churn-measure.ts:713, 08f242308876)
  • Workload checks the production boundary: The committed workload starts the real Gateway, connects signed WebSocket clients, changes health through the quarantine owner and public collector, and compares reconstructed presence with system-presence. (scripts/perf/presence-churn-measure.ts:727, 08f242308876)
  • Existing consumer contracts: Apple chat consumes health status, Android uses health as a refresh signal, and the caretaker consumes retained channel/config-reload fields; macOS detailed health continues through its RPC path. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatGatewayPayloadCodec.swift:335, 08f242308876)

PR surface

Source +33, Tests +68, Docs +33, Other +294. Total +428 across 20 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 9 42 9 +33
Tests 7 122 54 +68
Docs 3 34 1 +33
Config 0 0 0 0
Generated 0 0 0 0
Other 1 421 127 +294
Total 20 619 191 +428

Review metrics

Metric Value Why it matters
Negotiated wire capabilities 2 additions health-summary and hello-presence-self preserve default legacy delivery without a protocol-version bump or persisted setting.
Benchmark CLI options 2 additions --agents and --compact-payloads make the synthetic comparison reproducible without adding Gateway configuration.

Labels

Label changes:

  • add P2: This is a measurable bandwidth improvement for health delivery and reconnects without evidence of an urgent user-facing regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • 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: This is a measurable bandwidth improvement for health delivery and reconnects without evidence of an urgent user-facing regression.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 20, 2026, 1:55 AM ET / 05:55 UTC.

@steipete
steipete force-pushed the steipete/perf-micro-health-and-connect-payloads-20260919 branch from 08f2423 to 4403282 Compare October 20, 2026 05:57
@steipete
steipete merged commit f448475 into main Oct 20, 2026
164 of 166 checks passed
@steipete
steipete deleted the steipete/perf-micro-health-and-connect-payloads-20260919 branch October 20, 2026 06:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 21, 2026
* perf(gateway): shrink health and reconnect payloads

Negotiate compact passive health for updated operator clients and self-only hello presence for Control UI. Keep full health RPC diagnostics, profile bootstrap, roster delivery, and legacy payloads intact.

* test(gateway): type negotiated hello fixtures

Use the protocol connect type for optional capabilities and mark the existing trusted health producer invariant for the assertion guard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: android App: android app: linux app: web-ui App: web-ui clawsweeper:intake:feature Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts security-sensitive-changed size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant