Skip to content

perf(infra): keep worker reference transitions local - #184282

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-worker-control-plane-messages-20261026
Oct 26, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-worker-control-plane-messages-20261026

Conversation

@steipete

@steipete steipete commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Retained workers send two unnecessary supervisor messages whenever a worker goes from idle to active and back to idle.

User Impact

No user-visible behavior change. Active work, pending CPU/heap samples, native cleanup, and process exit retain their existing host-owned liveness rules. Worker memory/GC sampling, retirement policy, and authority checks are unchanged.

Why This Change Was Made

The supervisor's control port stays referenced for its whole lifetime. Toggling its child Worker references therefore cannot change supervisor liveness. The host already references the supervisor and host control port from each handle's needsReference. Remove the private reference command end to end instead of maintaining two reference owners.

The prior same-state deduplication in #165230 is already in the measured deployment; these are the remaining actual idle/active transitions. Runtime production delta: −18 lines. The requested diff excluding tests/test-support/docs is +46 lines because the existing benchmark gains 64 net lines for the 42-worker workload and transport counters; runtime code itself is −18 lines. No new runtime state, configuration, or module is added.

Evidence

Acceptance: remove reference-only crossings, preserve local liveness/admission/cleanup, and reduce owner CPU/allocation without a material per-operation regression. Pure-deletion fast-path proof uses the real retained-worker owner; it does not claim a whole-Gateway latency improvement.

node --import ./scripts/tsx.mjs scripts/perf/native-control-port-measure.ts timing references

Repeat with allocation references for a separate allocation pass. Both revisions use the same script, 42 actual retained workers, three warmup passes, and five measured passes of 5,000 ref/unref cycles (25,000 cycles per arm). Each pass ends in 42 FIFO echo barriers, so base messages are processed before measurement ends. Startup/retirement are outside the measurement. The final proof-code revision was measured candidate then base, with separate allocation runs; the initial base-then-candidate run likewise reduced CPU/allocation and counted the same eliminated messages.

Metric Base Candidate Change
Lifecycle sends, including 210 barriers 50,210 210 50,000 eliminated
Lifecycle replies 210 210 unchanged
Main-thread CPU, 25,000 cycles 89.722 ms 14.298 ms −84.1%
Process CPU, 25,000 cycles 197.094 ms 32.601 ms −83.5%
Sampled allocated bytes, separate pass 46,770,952 23,223,408 −50.3%
Median 5,000-cycle elapsed time 22.703 ms 3.899 ms −82.8%
Total GC / maximum pause (one collection each) 0.427 / 0.427 ms 0.730 / 0.730 ms +0.304 ms total
End-of-run RSS 496.3 MiB 491.9 MiB −4.4 MiB
End-of-run main heap used 42.1 MiB 32.2 MiB −9.9 MiB
Host load, 1 / 5 / 15 min 29.4 / 29.6 / 41.1 27.1 / 29.5 / 41.6 context

Node 26.12.1, macOS arm64. GC has only one sample per timing arm (no meaningful percentile); its absolute rise is 0.000012 ms/cycle. RSS is an end-of-run snapshot, not a retained-memory improvement claim. Memory polling, handler latency, and event-loop tails were not changed or measured. No production load test or multi-pair Gateway campaign: this scoped deletion uses the requested fast-path exception.

  • Regression: worker-native-task-port.test.ts fails on base 0615124872cf because the two reference messages are present; passes with the deletion. It also preserves pending-sample retention, repeated fail-closed admission checks, and task-port-loss behavior.
  • Focused tests: node scripts/run-vitest.mjs src/infra/worker-native-task-port.test.ts src/infra/worker-native-handle.test.ts src/infra/worker-native-lifecycle.test.ts src/infra/worker-message-metrics.test.ts --maxWorkers=1 — 23 tests passed. Lifecycle file 21.07 s (includes existing 15.7 s late-attachment case); other three files 64.40 s including cold worker compilation, 107.81 s wrapper total.
  • New real subprocess proof: active work after unref/ref completes, an unreferenced worker's pending heap sample completes, and the process exits with the idle worker deliberately left open. Passed under the pinned Bun test runtime and separately under Node on both base and candidate.
  • Existing native termination, natural exit, generation shutdown, rejected resource attachment, and independent resource/execution receipt tests passed. After the proof-code correction, the 10-test lifecycle file passed again in 23.52 s (25.39 s wrapper total), and the Node liveness subprocess passed again.
  • Formatting and changed-file lint passed. Independent subagent review (autoreview route unavailable): clean through P2 with no actionable findings; the autoreview helper refused the operator/provider mismatch before inference, and no configuration was changed.
  • Broad validation: CI run 40279902847 succeeded on exact head 75208de5dc24975c4fb4b2b08e17e8e0a51ee715. Production, script, and test types; lint; Node shards; UI integration; guards; build artifacts; and docs passed. GitHub Codex review on this head also completed with no findings. No Testbox lease allocated. The first CI head exposed unsupported EventEmitter overloads in the new proof code; the fixtures now use the retained worker's documented on callbacks. pnpm tsgo:scripts passes locally; runtime code is unchanged by that repair.

@clawsweeper

clawsweeper Bot commented Oct 26, 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 26, 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-26T06:29:24.603700Z 75208de 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 gateway Gateway runtime scripts Repository scripts size: S labels Oct 26, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@steipete
steipete force-pushed the steipete/perf-worker-control-plane-messages-20261026 branch from 207e737 to 75208de Compare October 26, 2026 06:27
@steipete
steipete merged commit 20ffcf4 into main Oct 26, 2026
131 checks passed
@steipete
steipete deleted the steipete/perf-worker-control-plane-messages-20261026 branch October 26, 2026 06:42
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
* perf(infra): keep worker reference transitions local

* test(infra): use retained worker event contracts in proof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant