Skip to content

perf(code-mode): share prepared catalog bytes with Node workers - #169045

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-code-mode-worker-input-20260919
Oct 11, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-code-mode-worker-input-20260919

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Node Code Mode serialized the entire tool catalog, namespace descriptors, and API declaration files on the Gateway thread for every exec, including repeated cells in the same catalog generation.

User Impact

Less Gateway main-thread work for repeated Code Mode calls. Tool visibility, execution permissions, fresh guest contexts, and per-call time/output/concurrency limits retain their existing behavior. No config or stored-data migration.

Why This Change Was Made

Prepare metadata and its UTF-8 shared buffer at the core-owned catalog snapshot boundary. Carry that snapshot through execution and send the shared buffer with each small execution payload. The worker decodes it into a fresh guest context. Catalog replacement/restriction produces a new snapshot; swarm availability still resolves per call.

The Node worker no longer stringifies initialization metadata per cell. Public executor inputs retain their mutable-input contract and are encoded anew when no core-prepared snapshot is supplied. This contract requires an explicit distinction between immutable core snapshots and public inputs; production LOC is +72: the immutable byte representation and the preserved mutable public-input contract require explicit preparation and transport typing. Repeated per-cell metadata preparation and worker stringify are removed.

Evidence

  • Synthetic 109-tool workload in an isolated, loopback-only Gateway process on the Linux rig. Calls use the production Code Mode exec path; model/provider and HTTP latency are excluded. Main-thread CPU uses process.threadCpuUsage, excluding worker CPU. After 1,000 warmup calls, the median of three 1,000-execution batches dropped from 1,787 ms to 1,015 ms main-thread CPU (1.76×, 43% less). Median worker-post time dropped from 401 ms to 221 ms. Median wall time was 6.62 s → 6.07 s. End-process RSS was 2.53 GB → 2.76 GB; no memory reduction is claimed. The shared rig had background startup work: CPU samples were 1,992/1,787/1,694 ms before and 2,792/1,015/995 ms after. These are comparative medians, not isolated latency promises.
  • JSON-measured per-call inline payload: 103,444 → 372 bytes; a 103,133-byte immutable buffer is shared by reference per catalog snapshot.
  • Payload regression fails on the original executor: no shared initialization buffer. Covers shared bytes, bounded per-call shape, new metadata, and current limits. Additional regression covers mutable public inputs, catalog replacement, and catalog restriction.
  • Focused regression/sibling validation passed: 12 files, 161 tests, in 91.73 s with --maxWorkers=1; export-name collision guard and both closure suites passed (20 tests). The initial broad gate included a temporary baseline fixture and was canceled; it is not counted as a passing gate. The clean staged gate on the rebased tree hits an inherited max-lines ratchet failure in untouched src/web-search/runtime.test.ts; node --import ./scripts/tsx.mjs scripts/check-max-lines-ratchet.mts --staged --base HEAD reproduces the same failure on pristine main fd1fd2ce0ef8. The remaining native gate commands were continued without hiding that failure, then the duplicate typecheck run was stopped once exact-head CI passed the corresponding production/test types, lint, architecture guards, and behavioral checks. The local gate is not claimed green. Blacksmith Testbox tbx_01m4mwzmp9djbyrc8pswgspxb9 admission remained queued; the authorized AWS fallback is cbx_ad17bbd3133e (c7a.4xlarge). A fresh AWS lease fell back to an unusable 2 GB instance; Hetzner cbx_eb4ba0d26af3 then stalled during sync. Final validation uses the authorized Linux rig fallback with its index tree verified identical to d38d2b2798df. All leases were stopped.
  • Exact-head CI passed on d38d2b2798df74b88a411f320ac5730d62d02580; all required checks and security review are green.
  • Independent review identified the mutable-input issue in the first candidate; the cache moved to the core snapshot owner. Follow-up independent review is clean through P2.

@clawsweeper

clawsweeper Bot commented Oct 11, 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 agents Agent runtime and tooling size: M labels Oct 11, 2026
@steipete
steipete marked this pull request as ready for review October 11, 2026 09:44
@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. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR prepares catalog metadata once per snapshot and shares its encoded bytes with Node Code Mode workers.

Example: Repeated Code Mode executions with the reported 109-tool catalog.

  • Before: Each execution sends 103,444 bytes of inline metadata.
  • After: Each execution sends a 372-byte inline payload referencing a shared 103,133-byte catalog buffer.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and correct on inspection; the reported benchmark and regressions support it, with strongest execution evidence coming from an in-process scenario.
Proof confidence 🦐 gold shrimp (3/6) The supplied host facts identify maintainer authorship, exempting this PR from the ordinary contributor-proof gate; its body records the changed production exec path running in an isolated Linux Gateway process.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Repeated Code Mode cells spend Gateway main-thread CPU preparing and transferring unchanged tool metadata.
Reason: Maintainer direction and the scoped CPU measurements support the optimization, with unchanged tool visibility, authority, configuration, and persisted state.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-directed optimization removes repeated catalog preparation that remains on main, and the introduced diff has no actionable correctness finding.

Priority: P2
Reviewed head: d38d2b2798df74b88a411f320ac5730d62d02580

Before merge

None.

Findings

None.

Agent review details

How this fits together

Code Mode receives a policy-filtered tool catalog and JavaScript cell, prepares guest metadata, executes it in a worker, and routes tool requests through the existing host authority.

flowchart LR
  A[Policy filtered catalog] --> B[Prepared catalog snapshot]
  B --> C[Shared metadata bytes]
  C --> D[Node worker]
  E[Cell source and current limits] --> D
  D --> F[Fresh guest context]
  F --> G[Host tool dispatch]
  G --> F
Loading

Technical review

Best possible solution:

Land the catalog-owned shared-byte optimization after the existing required gates pass.

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

Current-main source establishes repeated metadata preparation and serialization; the PR reports comparative production-path measurements, which were not rerun during this read-only review.

Is this the best way to solve the issue?

The snapshot owner is the appropriate reuse boundary, and retaining per-call limits plus fresh encoding for public inputs avoids stale mutable-input behavior.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The reviewed changes are limited to the verified merge-base-to-head diff; base movement was inspected separately. (d38d2b2798df)
  • Snapshot ownership and invalidation: Preparation is keyed by the catalog entries array; registration, appended client tools, restriction, and changed executor bindings publish replacement arrays. Swarm availability remains resolved per call. (src/agents/code-mode-execution.ts:110, d38d2b2798df)
  • Mutable public inputs remain supported: The Node adapter reuses bytes only when supplied with the core preparation symbol; ordinary executor inputs are encoded anew, and current execution limits remain outside the cached metadata. (src/agents/code-mode-node.ts:51, d38d2b2798df)
  • Current main still performs repeated preparation: Fetched main constructs namespace metadata and catalog projections for each execution and stringifies initialization in the worker; this optimization is not already implemented. (src/agents/code-mode-node.worker.ts:294, 48a348028fb0)
  • Reported production-path measurement: The full PR body records an isolated Linux Gateway process exercising production Code Mode exec: median main-thread CPU decreased from 1,787 to 1,015 ms per 1,000 executions. Reported RSS increased from 2.53 to 2.76 GB, and the author explicitly claims no memory reduction. (d38d2b2798df)
  • Existing performance work is distinct: perf(tool-search): reuse catalog tokens across Code Mode cells #160811 caches lexical search tokens, while refactor(code-mode): speed up repeated type checks #147252 optimized TypeScript preparation; neither owns Node worker initialization-byte sharing.

PR surface

Source +72, Tests +81. Total +153 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 103 31 +72
Tests 3 90 9 +81
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 193 40 +153

Review metrics

Metric Value Why it matters
Production versus test changes Production +103/-31; tests +90/-9 The production growth supplies snapshot preparation and explicit transport typing while preserving mutable public inputs; tests cover transport reuse and catalog invalidation.

Labels

Label changes:

  • add P2: A bounded performance improvement reduces repeated Gateway main-thread work without changing configuration or user-facing execution semantics.
  • 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: A bounded performance improvement reduces repeated Gateway main-thread work without changing configuration or user-facing execution semantics.
  • 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 11, 2026, 5:51 AM ET / 09:51 UTC.

@steipete
steipete merged commit acd955a into main Oct 11, 2026
206 of 207 checks passed
@steipete
steipete deleted the steipete/perf-micro-code-mode-worker-input-20260919 branch October 11, 2026 10:06
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 18, 2026
First-parent upstream fd0fc62..f4f4868 (8 commits: openclaw#169033
collaboration/workshop SQLite bookkeeping, 952c102, openclaw#155464 active
turns during worker dispatch, openclaw#168995 approval/placement queries,
openclaw#154286 telegram polling workers, 194a08e, openclaw#169045 code-mode catalog
bytes, openclaw#159697 talk voice permissions).

Conflicts:
- session-sharing-store.native.ts: upstream folded the member lookup and
  delete into one DELETE ... RETURNING with a no-row early return; our
  recipient-authority advance now follows that return, so only an actual
  removal revokes access (same order as before the merge).
- worker-access inventory: took upstream, regenerated (632 files, 2442
  calls).

sharing-store receipt/worker auto-merged: upstream's category plan
(keys only) is disjoint from our authority.capture command.

Refs #1475

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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