Skip to content

perf(presence): enable compact updates for native clients - #177520

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-native-presence-deltas-20260919
Oct 19, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-native-presence-deltas-20260919

Conversation

@steipete

@steipete steipete commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Native operator connections keep receiving complete presence rosters when only a few fields change. This completes native adoption of the compact opaque-key presence protocol from #177471.

User Impact

Updated macOS, iOS, and Android apps receive smaller presence updates. macOS/iOS subscribers still receive the same complete, ordered rosters; old apps retain the server's legacy snapshots. This reaches users through native app releases and requires no Gateway restart or protocol bump.

Why This Change Was Made

The shared Swift channel owns capability negotiation and reconstructs keyed resets and field patches before bounded subscriber queues. It clears keyed state with the socket and reuses existing reconnect recovery on a missing presence baseline or transport gap. Full snapshots from released Gateways remain supported. Android ignores presence rosters, so it only advertises the capability; it needs no unused reducer or cache. Node-only connections have no read-scoped presence delivery. Ordinary TypeScript CLI calls remain legacy; Swift operator helpers inherit the shared channel support.

Handshake versions come from the Swift bundle, Android build version, and CLI package version. The replay uses synthetic dev metadata and aggregate client-kind counts; it does not claim an inventory of deployed app versions.

Evidence

Acceptance: identical synthetic presence workload and client identities, same ordered final rosters, no recovery or delivery failures, and fewer presence bytes per native socket. Two simultaneous A/B pairs under the sandbox quiet lock, with CPU halves swapped for the second pair. Bytes and frame counts are the decision metrics; host load is context.

Two concurrent pairs passed with identical byte results (16 CPUs per side, CPU halves swapped):

Pair Legacy bytes/native socket Delta bytes/native socket B − A Reduction Frames/socket A → B
1 1,353,944 106,532 −1,247,412 92.13% 37 → 37
2, CPUs swapped 1,353,944 106,532 −1,247,412 92.13% 37 → 37

Each replay lasted about 60.5 seconds with 96 RPCs. Legacy native frames averaged 36,593 bytes, close to the reported ~38 KB shape. All 42 admitted sockets matched their negotiated format and final authoritative roster; both candidate runs reconstructed 40 native rosters with zero recovery requests. The two unchanged CLI controls each received exactly 1,352,575 bytes on both sides. Admitted synthetic dev cohorts: 14 macOS, 13 iOS, 13 Android, and 2 CLI controls.

Ran scripts/perf/presence-churn-measure.ts --client-profile native --clients 42 --scenario traffic --rounds 12 --interval-ms 1000, with --legacy-clients 42 for A and --legacy-clients 2 for B. Each side had its own state directory and loopback port, a common --start-at, and the pair held the exclusive measurement lock. Source capsule: 69bef1a7611423fb9c8529fd4a3d757bbbd1fffa plus this PR's measurement script; measured server/reducer files were hash-matched to the rebased PR. Both sides audited 8,470 imports from that capsule with no foreign source. Outside load was recorded per pair; dirty pages stayed below 2 GiB.

These are UTF-8 presence-event JSON bytes, excluding WebSocket framing/compression, initial hello/reset, setup, and the final correctness flush. The live replay uses the web reducer as the decoder; native equivalence is proven by the shared-fixture tests below. No CPU/latency improvement or production installed-version census is claimed.

Independent Codex autoreview: scoped-clean, no actionable P0–P2 findings on the implementation and CI follow-ups. The simplification pass shares the existing stream-baseline reconnect branch; no new recovery coordinator. The synthetic native replay pairs its own fixture devices through the existing owner before signed connect.

  • Shared JSON stream: web store 6/6 tests passed (1.60 seconds); focused Swift projection package 2/2 passed (12.08-second compile, 0.010-second tests). Fixture covers opaque keys, nested-field replacement, clearing, insertion/removal, order, gaps, and reconnects.
  • Android ConnectionManagerTest: 37/37 passed (5.549-second tests; 1m47s including prerequisites), through scripts/run-android-gradle.mts --proof --no-daemon --max-workers=1 :app:testPlayDebugUnitTest --tests ai.openclaw.app.node.ConnectionManagerTest.
  • CI caught the obsolete iOS presence-event allowlist entry after the shared Swift handler was added. The obsolete entry is removed; the exact protocol-coverage guard now passes (iOS handles 29 events / allowlists 39).
  • CI also caught a missing JSON import attribute in the shared-fixture test under NodeNext. Added with { type: "json" }; the focused web test remains 6/6 passing.
  • Targeted pnpm tsgo:ui (tsrs), changed TypeScript lint/format, Swift source lint/format, and Android lint passed. Android's attempted lint filter was ineffective and scanned app source sets; it was not rerun. TypeScript lint prepared its normal plugin declarations.
  • PR CI covers Android and TypeScript gates. Dedicated macOS/iOS build-and-test lanes are deferred to scheduled CI; the separately selected iOS screenshot lane builds the simulator app, but does not run the full OpenClawKit unit suite. The focused Swift package compiles the production reducer and AnyCodable helpers with the unchanged generated EventFrame/StateVersion types. No physical-device proof or before-fix native execution is claimed. No Testbox/Crabbox lease was allocated under the lane's current validation rule.

Application production code grows by 88 lines; the measurement tool grows by 99 lines. The production increase is necessary to decode an existing wire contract before Swift subscribers; there is no duplicate roster owner or new configuration. Legacy server delivery remains for released clients and legacy decoding remains for released Gateways.

Current exact-head CI: a030ec55e899. Completed: Android tests/emulator checks, UI/Node tests, typechecks, lint, protocol coverage, iOS simulator build/screenshot capture, and screenshot evidence pass. Only the inherited baseline-ratchet failure and its aggregate CI gate are red. The current-head Codex review also completed without findings.

The remaining baseline-ratchet failure is inherited: check-test-mock-exports.mts asks to remove the stale extensions/acpx/register.runtime.test.ts / openclaw/plugin-sdk/acp-runtime-backend tuple from config/test-mock-exports-baseline.txt. This PR job and the scheduled main job on 4ec61b4ed2a8a5f05f041372726fe62f2706584c fail with the identical tuple/hash. None of those files is changed here. Both logs were inspected; no CI rerun was requested.

Landing uses the authorized inherited-failure exception. The native wrapper requires a separate PR review worktree; this lane explicitly prohibits extra worktrees, so the authorized exact-head REST squash-merge fallback is used. No native app release or Gateway restart is part of this PR.

@clawsweeper

clawsweeper Bot commented Oct 19, 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 19, 2026 17:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-19T17:41:34.374995Z a030ec5 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: android App: android app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts size: M labels Oct 19, 2026
Negotiate presence deltas in native operator sockets. Reconstruct ordered rosters at the shared Swift channel before bounded subscribers, reuse reconnect recovery for missing baselines, and retain released Gateway snapshots. Android ignores rosters and only needs capability negotiation. Add a shared web/native stream fixture and native cohort replay evidence.
@steipete
steipete force-pushed the steipete/perf-micro-native-presence-deltas-20260919 branch from 868121a to a030ec5 Compare October 19, 2026 17:22
@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 19, 2026
@steipete

steipete commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

The baseline-ratchet failure is inherited. On this PR head a030ec55e8994998262f085d88e7db7c888ed9c4, job 118201568139 reports a stale mock-baseline tuple for extensions/acpx/register.runtime.test.ts / openclaw/plugin-sdk/acp-runtime-backend.

The scheduled main job 118204795044, at 4ec61b4ed2a8a5f05f041372726fe62f2706584c, reports the identical tuple and hash. The affected test, baseline, and guard are unchanged by this PR. This supplies the baseline evidence for the authorized inherited-failure landing exception; all selected CI jobs are now complete, including successful iOS screenshot capture and evidence; only this inherited failure and its aggregate gate are red. No rerun was requested.

@steipete
steipete merged commit 78e0bb4 into main Oct 19, 2026
126 of 129 checks passed
@steipete
steipete deleted the steipete/perf-micro-native-presence-deltas-20260919 branch October 19, 2026 17:53
steipete added a commit that referenced this pull request Oct 19, 2026
The compact presence decoder from #177520 intentionally reconnects on an
invalid presence baseline. The sequence-gap test emitted an empty presence
payload and waited forever for it to be delivered, exhausting the native
CI job deadline.

Use ordinary synthetic events for both sequence numbers. Preserve the gap,
held callback, forced disconnect, reconnect, and dropped-event assertion.

Validation: all seven disconnect tests pass with Swift Testing parallelism
width 3 and coverage instrumentation. The original fixture hangs in the same
run. Native test build, formatting, CI-mode lint, and independent P2 review
pass; strict local lint retains the existing large_tuple finding.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 20, 2026
…77520)

* perf(presence): enable compact updates for native clients

Negotiate presence deltas in native operator sockets. Reconstruct ordered rosters at the shared Swift channel before bounded subscribers, reuse reconnect recovery for missing baselines, and retain released Gateway snapshots. Android ignores rosters and only needs capability negotiation. Add a shared web/native stream fixture and native cohort replay evidence.

* test(presence): pair native replay fixtures and refresh event coverage

* test(presence): mark shared fixture import as JSON
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 20, 2026
The compact presence decoder from openclaw#177520 intentionally reconnects on an
invalid presence baseline. The sequence-gap test emitted an empty presence
payload and waited forever for it to be delivered, exhausting the native
CI job deadline.

Use ordinary synthetic events for both sequence numbers. Preserve the gap,
held callback, forced disconnect, reconnect, and dropped-event assertion.

Validation: all seven disconnect tests pass with Swift Testing parallelism
width 3 and coverage instrumentation. The original fixture hangs in the same
run. Native test build, formatting, CI-mode lint, and independent P2 review
pass; strict local lint retains the existing large_tuple finding.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: android App: android 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 size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant