Skip to content

fix: reduce standalone worker memory and startup cost - #183143

Merged
steipete merged 1 commit into
mainfrom
openclaw/aot-exp-TP-main
Oct 25, 2026
Merged

steipete merged 1 commit into
mainfrom
openclaw/aot-exp-TP-main

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Standalone Gateways pay unnecessary startup CPU and memory for large embedded routing maps in every worker.

User Impact

Workers allocate only the routing and metadata rows they use. Module aliases, direct embedded destinations, native dependency resolution, and file metadata retain their existing behavior. No configuration or migration is required.

Why This Change Was Made

Store sorted JSON-encoded rows as immutable embedded text, binary-search requested keys, and cache decoded values within each VM. This also removes the eager destination Set and the second eagerly materialized embedded-path dictionary.

Evidence

The same large routing map reproduced the penalty when compiled as JavaScript; 10,000 unused TypeScript interfaces did not. With a fixed compiler, the controlled memory slope fell from 104.66 to 9.11 MiB per worker. The full original-source desktop image retained all 145,971 aliases; its same-entry worker heap fell from 28.58 to 5.16 MiB (emitted-JS control: 4.96 MiB).

Eight interleaved samples per image on a loaded Mac, using the same frozen compiler:

Median Original TS Fixed TS Emitted JS
Gateway ready CPU 4.43 s 2.59 s 2.43 s
Gateway ready wall 7.08 s 6.18 s 5.32 s
First turn wall 1.93 s 1.35 s 1.08 s
Settled process-tree RSS 3,304 MiB 1,218 MiB 1,111 MiB

The full-image comparison uses the original-source integration build; this PR ports the identical lookup implementation to current main's standalone owners. The rebased six-file patch is byte-identical to the independently reviewed patch. Focused validation: 69 tests pass; four existing metadata-fixture failures reproduce on unchanged main with identical signatures. Targeted lint, script/tooling typechecks, formatting, and diff checks pass.

The fixed TS image and matched emitted-JS baseline passed the frozen core campaign (fresh/reused config, Doctor contributions, Gateway/agent behavior, clean shutdown, and crash audit). One real Codex turn reused the existing login and completed its native hook plus exact-file proof. No engine changes or cross-VM mutable sharing are involved.

The only failed CI test job is checks-node-compact-small-1: the two secret-resolver fixture cases read missing params.args, and the MXC/ACPX fixture cases lack the resolvePluginRuntimeProcessAssetUrl / resolvePackageRuntimeProcessEntrypointUrl bindings. These same four errors reproduce with unchanged main owners; the fixture and extracted owner inputs are unchanged by this PR. They remain failed and are being handled under the native inherited-failure landing policy. security-fast passed independently.

Keep embedded module routes and file metadata encoded until a worker queries them. Preserve every alias and direct destination, decode requested rows once, and cache values within their own realm.
@clawsweeper

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

@steipete
steipete marked this pull request as ready for review October 25, 2026 02:13
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T02:15:06.151629Z 1921a25 Draft marked ready
ℹ️ 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 scripts Repository scripts size: S labels Oct 25, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR decodes embedded routing and file metadata on demand instead of allocating complete lookup tables in every worker.

Example: A standalone worker resolves dist/main.js.

  • Before: The worker materializes the complete routing dictionary and destination Set before resolving the entry.
  • After: The worker searches embedded text and caches the requested row while preserving /$bunfs/root/runtime/dist/main.js.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch appears correct and worthwhile; inspectable evidence consists of source and unit contracts, supplemented by detailed reported production measurements.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports compiled Mac Gateway measurements and functional campaigns, while directly inspectable executable tests exercise generated lookup expressions.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Standalone Gateways spend unnecessary startup CPU and worker memory materializing routing data they never use.
Reason: The maintainer-authored direction has clear measured value, preserves routing behavior, and adds no user-facing setting or migration.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses measured standalone startup overhead that remains on main; no introduced correctness or security defect was found.

Priority: P2
Reviewed head: 1921a2520ba0f2c031f4021128b4f7c240d263c2

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Production campaign results are summarized in the body without linked raw traces or artifacts, and a red-on-base regression run is not shown.
Agent review details

How this fits together

The standalone builder converts packaged module paths and metadata into executable bootstrap code consumed independently by the Gateway and its workers.

flowchart LR
  A[Packaged runtime modules] --> B[Standalone builder]
  B --> C[Encoded routing and metadata]
  C --> D[Gateway or worker bootstrap]
  D --> E[Lookup and local cache]
  E --> F[Existing module and metadata owners]
Loading

Technical review

Best possible solution:

Retain the shared lazy lookup emitter and existing resolution owners, then handle inherited fixture failures through the repository’s CI policy.

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

Main visibly creates complete routing and metadata objects in each bootstrap; the PR reports controlled compiled-image measurements, but this read-only review did not reproduce the allocation measurements.

Is this the best way to solve the issue?

The patch addresses eager allocation at its build-time producer, preserves existing consumers and admission checks, and uses one shared emitter without introducing another runtime owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Standalone embedded routing and direct destinations keeps the original intent (7c6b8bc: The standalone builder embeds application modules and resolves them without a separate runtime installation.)
  • Image metadata and native dependency resolution keeps the original intent (9df2906: Minimal sidecars require immutable image metadata and preservation of original dependency-resolution aliases.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 7c6b8bc adds scripts/build-bun-standalone.mjs:2 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7c6b8bcfcc99; files: scripts/build-bun-standalone.mjs)

PR surface

Tests +63, Docs +5, Other +53. Total +121 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 63 0 +63
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 4 65 12 +53
Total 6 133 12 +121

Review metrics

Metric Value Why it matters
Production versus test changes Production +65/-12 lines; tests +63/-0 lines. The shared emitter adds necessary encoded lookup machinery used by three existing owners; the tests cover lazy decoding, key/value preservation, and alias/destination behavior.

Labels

Label changes:

  • add P2: Measured CPU and memory improvements affect standalone Gateways without establishing an urgent outage or functional regression.
  • 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: Measured CPU and memory improvements affect standalone Gateways without establishing an urgent outage or functional 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.

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 24, 2026, 10:29 PM ET / October 25, 2026, 02:29 UTC.

@steipete
steipete merged commit 8ae44f9 into main Oct 25, 2026
193 of 198 checks passed
@steipete
steipete deleted the openclaw/aot-exp-TP-main branch October 25, 2026 03:19
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
Keep embedded module routes and file metadata encoded until a worker queries them. Preserve every alias and direct destination, decode requested rows once, and cache values within their own realm.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: S 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