Skip to content

perf(gateway): publish health only when status changes - #175390

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-health-event-broadcast-20260919
Oct 17, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-health-event-broadcast-20260919

Conversation

@steipete

@steipete steipete commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A connected operator receives a complete health snapshot every minute even when only timestamps and diagnostic readings changed. At roughly 17.7 KB per snapshot, this repeats substantial idle WebSocket traffic across multiple viewers.

User Impact

Health changes still arrive on the next refresh, using the existing full event payload. Explicit health/probe RPC responses and native hello snapshots remain unchanged. Tick and transport ping/pong continue to provide liveness.

The caretaker reads initial health once per active connection/identity and retries failed initial reads on the existing tick, so a fault that predates its connection remains visible even when no new health event occurs.

Why This Change Was Made

The existing health-state owner now compares a normalized snapshot before publishing or advancing the health version. It still refreshes the diagnostic cache every time. The comparison ignores collection timing, ordinary channel/session activity, auth age, and event-loop sample noise while retaining lifecycle timestamps, failures, degraded states, and plugin-owned status. There is no new timer, subscription protocol, configuration, or schema.

The complete cutover requires a small production addition: the normalized comparison and the caretaker's scoped initial read. The full snapshot contract remains intact rather than introducing a second event shape. Production delta is +113 lines (118 added / 5 removed across the caretaker modules and health owner); this growth preserves initial-client state and the existing full-payload contract.

Evidence

Four concurrent, exclusively locked A/B pairs on a 128-core Linux host, with separate 16-core CPU halves swapped each pair. Eighteen synthetic operator sockets; roughly 17.7 KB full frames; session counts/recent keys and diagnostic readings change every refresh.

Health event traffic Before After
60 steady-state refreshes × 18 sockets 1,080 frames / 19,114,884 bytes 0 frames / 0 bytes
Initial publication plus 60 refreshes 19,424,412 bytes 309,528 bytes

Every paired B-minus-A difference was −19,114,884 bytes. Initial-plus-periodic traffic fell 98.41%. At the production 60-second cadence this is 19.1 MB/hour of avoided steady-state traffic. All six channel down/up, provider error/recovery, and event-loop degradation/recovery transitions reached all 18 peers on the next refresh; all 1,080 tick frames remained. Prometheus event/byte counters exactly matched the received WebSocket frames.

Measurement limits: an accelerated 60-refresh replay through the actual health owner, broadcaster, WebSocket sender, and Prometheus exporter with synthetic collector/admission adapters. This is a publication-boundary measurement, not an hour-long observation, full Gateway boot, real provider test, or CPU speedup claim. Ambient CPU load was recorded per pair. No production state or multi-GB fixtures were used; the small benchmark sandbox was removed.

Validation: baseline regression failed as intended (duplicate broadcasts); final health-state and caretaker tests passed 67 tests across 3 files, plus the maintenance sibling file passed 22 tests. Changed-file formatting/lint, export-name collision guard, and both required import/PR-wrapper closure files passed (22 closure tests; 75.62 s wall time). Independent Codex autoreview: scoped-clean through P2. Final focused command wall time: 104.63 s (health file 77.05 s including worker preparation, two UI files 7.60 s). Full typecheck/build/suites are delegated to PR CI; no Testbox/Crabbox leases used.

Consumer audit: the web caretaker consumes health errors; Debug uses health RPC. Apple chat consumes health status and already polls health from tick; macOS HealthStore polls RPC. Android treats health as a refresh nudge and already has tick plus dedicated question/progress events. CLI/TUI have no periodic-health liveness dependency. No rendering or layout changes.

PR CI found two test-fixture omissions: the credential-rotation mock needed the shared health route, and the shared request input needed the callable Vitest Mock type instead of generic ReturnType<typeof vi.fn> (which also includes constructors). Both are repaired without production changes. The four affected UI files passed 74 tests in 5.95 s. Local file-scoped lint reports only the pre-existing 1,013-line limit in custodian-page.test.ts; this repair preserves its line count, and hosted CI treats size limits as advisory. Production repair lint/format and independent Codex autoreview through P2 passed; exact-head PR CI passed, including all previously failing UI/typecheck jobs.

Review follow-up: a failed initial caretaker health RPC now retries on the next existing tick. Successful and in-flight reads remain deduplicated; newer events and connections supersede old failures. The focused recovery regression failed before the repair and passed afterward. This does not change Gateway publication or the measured payload result.

Final CI: run 39022461089 on 18d68363dbd19e768b2ccb7a3933ab19cc352ce4; all required gates passed, no failing or pending checks.

Keep cached diagnostics fresh while suppressing unchanged health events. Preserve full hello and RPC snapshots, and seed caretaker health once per connection so pre-existing faults remain visible.
@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.

@steipete
steipete marked this pull request as ready for review October 17, 2026 09:34
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime labels Oct 17, 2026
@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-17T09:50:32.987230Z 18d6836 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.

@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: 289362b1a7

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

Comment thread ui/src/pages/custodian/event-nudge.ts Resolved
@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 17, 2026
@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 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Suppress unchanged health broadcasts while retaining fresh diagnostic snapshots and initializing caretaker health per connection.

Example: Eighteen connected viewers receive 60 refreshes with unchanged health status.

  • Before: The reported benchmark received 1,080 repeated health frames totaling 19,114,884 bytes.
  • After: The reported benchmark received no repeated health frames, while status transitions still reached every viewer.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation appears correct, with useful regression coverage and bounded publication measurements, but supplied evidence stops short of the shipped caretaker flow.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; its reported Linux publication replay exercises production sending with synthetic collection adapters, while caretaker hydration and recovery have unit-test evidence only.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Connected viewers repeatedly receive complete health snapshots when only diagnostic readings and ordinary activity have changed.
Reason: The maintainer-authored direction reduces avoidable traffic without adding configuration or another payload contract.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored PR open: it provides a useful traffic reduction, and source review found no actionable introduced defect.

Priority: P2
Reviewed head: 18d68363dbd19e768b2ccb7a3933ab19cc352ce4

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No browser-entry-point recording or logs demonstrate caretaker initial hydration and tick recovery; the PR reports before/after owner-test regressions.
Agent review details

How this fits together

The Gateway health owner collects channel and system diagnostics, caches complete snapshots for RPC consumers, and publishes health events to connected clients.

flowchart TD
  A[Health collector] --> B[Health state owner]
  B --> C[Fresh diagnostic cache]
  B --> D[Normalized status comparison]
  D --> E[Full health event]
  C --> F[Health RPC]
  E --> G[Connected clients]
  F --> H[Caretaker initial read]
Loading

Technical review

Best possible solution:

Publish full health events for material changes while keeping diagnostic RPCs fresh and seeding caretaker health per connection.

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

Current main unconditionally advances the health version and broadcasts each completed public collection; this path was verified in source without executing target code.

Is this the best way to solve the issue?

The existing health owner is the appropriate comparison boundary, and the caretaker initialization closes the initial-state gap created by suppressing unchanged events.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Health publication cadence changes intended behavior with a stated reason (unknown: Unconditional publication was already present in the health-owner extraction bcbfb35; the pre-extraction git log -S search failed on unavailable historical blob 886af68ccc02b0901757f786818f510cb41451f9. Later collection and refresh-admission work preserves full diagnostic access.)
  • Caretaker health reconciliation keeps the original intent (feat(ui): add reactive OpenClaw health nudges #110708: Consequential health snapshots produce restrained diagnostic nudges; later safety work prevents stale incidents and inappropriate wizard submissions. This PR retains those rules while adding a scoped initial read.)
  • Public versus sensitive health and probe strength keeps the original intent (fix(gateway): preserve runtime-backed health state #72417: Runtime-backed health fields must survive collection; subsequent probe-strength work keeps explicit probes separate from passive refreshes. The introduced comparison leaves these collection boundaries intact.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced publication change: The pinned diff refreshes the complete public cache before conditionally advancing the health version and broadcasting; sensitive collections remain excluded. (src/gateway/server/health-state.ts:203, 18d68363dbd1)
  • Earlier retry finding addressed: The existing review discussion identified failed initial reads becoming permanently deduplicated; the follow-up clears only the current pending source, and the store retries from tick while rejecting superseded results. (ui/src/pages/custodian/event-nudge.ts:58, 18d68363dbd1)
  • Consumer contracts: Health RPC responses retain complete diagnostics; Android and shared Apple chat retain tick-based polling, and macOS HealthStore retains polling independently of health events. (src/gateway/server-methods/health.ts:54, 18d68363dbd1)
  • Owner-approved direction and reported measurement: The maintainer-authored body explicitly accepts change-only publication and reports a Linux replay through the production health owner, broadcaster, WebSocket sender, and metrics exporter with synthetic collection adapters. (18d68363dbd1)
  • Current main still publishes every collection: The reviewed main implementation retains unconditional health publication; the optimization remains distinct work on this PR. (src/gateway/server/health-state.ts:163, a1c134d1f91e)
  • Policy and history inspection: Root, Gateway, UI, and docs instructions were applied; no maintainer-notes directory exists here. History reaches the health-owner extraction and earlier docs name; searching pre-extraction server contents encountered an unavailable historical blob, leaving the original broadcast introduction unknown. (AGENTS.md:1, 18d68363dbd1)

Likely related people:

  • Peter Steinberger: Raw commit a115af2 adds ui/src/pages/custodian/event-nudge.ts:2 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a115af277410; files: ui/src/pages/custodian/event-nudge.ts)

PR surface

Source +113, Tests +238, Docs +6. Total +357 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 118 5 +113
Tests 6 246 8 +238
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 370 13 +357

Review metrics

Metric Value Why it matters
Production versus test growth Production +118/-5 lines; tests and test support +246/-8 lines Production growth implements status normalization and initial-client reconciliation; added tests cover suppressed traffic, retained transitions, retry, and stale-result rejection.

Labels

Label changes:

  • add P2: This reduces recurring idle traffic across connected viewers without addressing an urgent runtime 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: This reduces recurring idle traffic across connected viewers without addressing an urgent runtime 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.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Show caretaker activation with a pre-existing fault and recovery after an initial health RPC failure through the browser entry point.

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, 5:52 AM ET / 09:52 UTC.

@steipete
steipete merged commit b4ced69 into main Oct 17, 2026
132 of 134 checks passed
@steipete
steipete deleted the steipete/perf-micro-health-event-broadcast-20260919 branch October 17, 2026 09:57
steipete added a commit that referenced this pull request Oct 17, 2026
The health digest introduced by #175390 requires the complete collector
contract. The shared Gateway fixture returned only ok/stub, making public
health requests throw and reddening auth, reconnect and probe tests.

Return a fresh HealthSummary constrained by the real collector signature.
Preserve every authorization assertion and the production health digest.
Explain fixture isolation and remove its obsolete exact mock-baseline row.

Before: trusted-proxy scope test fails at health RPC (165.46s wall).
After: all seven reported files plus health-state and mock tests pass,
123 tests in 264.99s wall with --maxWorkers=1. Gateway server/root type
checks, focused lint, format and mock-export ratchet pass. P2 review clean.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
* perf(gateway): publish health only when status changes

Keep cached diagnostics fresh while suppressing unchanged health events. Preserve full hello and RPC snapshots, and seed caretaker health once per connection so pre-existing faults remain visible.

* fix(ui): recover initial caretaker health reads and align fixtures
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…#175460)

The health digest introduced by openclaw#175390 requires the complete collector
contract. The shared Gateway fixture returned only ok/stub, making public
health requests throw and reddening auth, reconnect and probe tests.

Return a fresh HealthSummary constrained by the real collector signature.
Preserve every authorization assertion and the production health digest.
Explain fixture isolation and remove its obsolete exact mock-baseline row.

Before: trusted-proxy scope test fails at health RPC (165.46s wall).
After: all seven reported files plus health-state and mock tests pass,
123 tests in 264.99s wall with --maxWorkers=1. Gateway server/root type
checks, focused lint, format and mock-export ratchet pass. P2 review clean.
steipete added a commit that referenced this pull request Oct 19, 2026
…176726)

Follow-up to #175390. Exclude channel busy/run diagnostics from material health changes and require one minute of sampler-observed event-loop degradation before independent publication. Preserve complete diagnostic snapshots and immediate material channel/recovery events.

Proof: two regressions fail on the base; all 18 focused tests pass with the fix. Changed-file formatting/lint, core typecheck, independent review, and exact-head PR CI pass. Two concurrent CPU-swapped synthetic publication replays reduce routine health traffic from 60 to 0 frames per socket per simulated hour, preserving every expected material transition. This is publication-boundary proof, not a full live-provider Gateway observation.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 19, 2026
…penclaw#176726)

Follow-up to openclaw#175390. Exclude channel busy/run diagnostics from material health changes and require one minute of sampler-observed event-loop degradation before independent publication. Preserve complete diagnostic snapshots and immediate material channel/recovery events.

Proof: two regressions fail on the base; all 18 focused tests pass with the fix. Changed-file formatting/lint, core typecheck, independent review, and exact-head PR CI pass. Two concurrent CPU-swapped synthetic publication replays reduce routine health traffic from 60 to 0 frames per socket per simulated hour, preserving every expected material transition. This is publication-boundary proof, not a full live-provider Gateway observation.
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 clawsweeper:intake:feature Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant