Skip to content

improve: reduce broker memory when loading plugin and SQLite resources - #206142

Merged
vincentkoc merged 2 commits into
mainfrom
perf/group-native-resource-attachments-20261127
Nov 26, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
perf/group-native-resource-attachments-20261127

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

The Gateway’s broker loads part of the Gateway bundle when it first captures a plugin source or opens a read-only SQLite resource. In the stock package, those attachments have 132 and 193 statically imported files respectively. The broker pays that cost in its own process.

User Impact

In three paired runs with the normal Linux x64 packages, median broker PSS after a real plugin source capture fell from 70,386 to 67,428 KiB (−2.89 MiB). Median time from startup through source release and broker shutdown fell from 288.9 to 260.9 ms. Operators get the change on update.

Why This Change Was Made

Both attachments run in the same isolate. Building them together gives their error classes and lifecycle helpers one private module graph. It preserves both public entry URLs, ordinary runtime code generation and retained-generation lookup. The unified build still produces the plugin ownership manifest.

Evidence

Normal package Stock With this change
Compressed tarball 123,251,871 B 123,612,247 B
Unpacked regular-file bytes 330,407,673 B 331,853,641 B
Packaged regular files 22,105 22,136
Static files for plugin capture / SQLite 132 / 193 8 / 14

The private group ships 36 chunks. The complete package adds 360,376 compressed bytes (0.29%). All 933 ownership records matched the shipped files on both sides, with the same first-party module authorizations. The sealed worker archive was byte-identical.

  • Six fresh brokers on Node 24.22.1, one CPU, 2 GiB and zero swap. Each acquired the real owner and execution resources, captured and released a source, sealed the host and joined. A separate check on each package retained a SQLite sentinel and the plugin resource across a dist rename, then retired the staging session and removed the snapshot.
  • A separate earlier Linux ARM64 diagnostic build with 40 private chunks measured a 4.60 MiB reduction in source PSS. The source request took 12.76 → 14.60 ms and total lifecycle time fell by about 75 ms. The full ARM64 Gateway trial on the normal package at c3b484b3 still failed at agent.wait. The Gateway became ready at 33.601 s and accepted chat.send, then the service hit 768.00 MiB and recorded three local OOM kills before any provider request or reply. The outer group peaked at 819.477 MiB and recorded zero local kills. The picker, UI and 60-second soak were never reached.
  • The full package builds and tarball checks, runtime config and package suites, SQLite and plugin retirement tests, focused build-graph cases and tooling typecheck passed. The lease used the broker head 0122e917 and the byte-identical packaging diff in 2c724b8d. The original measured patch was rebased onto broker squash 0971864e as c3b484b3. CI found that older TypeScript targets lack the Map.groupBy declaration. The final head 77a0e4fe uses the existing build helper. All 79 ordering and subset checks over the 38 standalone entries produced byte-identical groups and output options on the two heads. Verification run

Related: #192547

@vincentkoc vincentkoc self-assigned this Nov 26, 2026
@clawsweeper

clawsweeper Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@vincentkoc
vincentkoc marked this pull request as ready for review November 26, 2026 19:56
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S labels Nov 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. labels Nov 26, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 26, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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:feature Preliminary submission classification; full source review pending. labels Nov 26, 2026
@clawsweeper

clawsweeper Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

Builds plugin-capture and read-only SQLite broker attachments together in a private graph to reduce loaded code.

Example: A packaged Linux x64 broker captures and releases a real plugin source.

  • Before: Reported median broker PSS is 70,386 KiB.
  • After: Reported median broker PSS is 67,428 KiB.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, supported optimization with no discrete defect found; the overall rating reflects its partial contribution to the linked memory issue.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The public report exercises packaged production brokers on Node 24.22.1 with real plugin owner/execution resources, source capture/release, shutdown, and retained SQLite/plugin resources across a dist rename; the final helper substitution preserves those build groups, while raw linked workflow logs were inaccessible to this review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Partial
User problem: The broker retains unnecessary Gateway code when plugin capture or SQLite resources first attach.
Reason: The maintainer-authored direction reports a measurable broker saving and openly accepts modest package growth without claiming to solve the linked Gateway OOM issue.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR provides a focused broker memory improvement that current main lacks; no actionable correctness or security defect was found.

Reviewed head: 77a0e4fefa776fc8de15194ab6a2cc6e9858f7c5

Before merge

None.

Findings

None.

Agent review details

How this fits together

The build registry supplies attachment entrypoints and chunks that the native-resource broker imports to serve plugin capture and SQLite snapshot requests.

flowchart LR
  A[Runtime entry registry] --> B[Build group planner]
  B --> C[Private attachment graph]
  C --> D[Native resource broker]
  E[Plugin capture requests] --> D
  F[SQLite snapshot requests] --> D
  D --> G[Results and resource cleanup]
Loading

Technical review

Best possible solution:

Use the existing build-group owner for both attachments while keeping the broader ARM64 memory acceptance work open.

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

Current main places both attachments in the shared runtime graph, and the broker dynamically imports them; the PR supplies matched packaged measurements of the resulting memory cost.

Is this the best way to solve the issue?

The change removes unnecessary shared-graph loading through the existing planner, preserves attachment entrypoints and code generation, and introduces no competing runtime owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Shared worker build grouping keeps the original intent (d38fed5: Emit common hosted-worker modules once to reduce installed package entries while preserving shared module identity.)
  • Standalone versus ordinary runtime minification keeps the original intent (eaa8aeb: Reduce retained source while preserving names and module-origin information required by runtime and update compatibility.)
  • Broker startup isolation keeps the original intent (0971864: Keep unavailable file-operation readers out of the native-resource broker's startup graph.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit 0971864 adds scripts/lib/runtime-process-core-build-entries.mts:62 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0971864e9351; files: scripts/lib/runtime-process-core-build-entries.mts)
  • Ayaan Zaidi: Raw commit d38fed5 adds tsdown.config.ts:1039 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d38fed580398; files: tsdown.config.ts)
  • Peter Steinberger: Raw commit 7b230ef adds scripts/lib/runtime-process-core-build-entries.mts:25 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7b230efeac32; files: scripts/lib/runtime-process-core-build-entries.mts)

PR surface

Tests +17, Other +26. Total +43 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 17 0 +17
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 53 27 +26
Total 4 70 27 +43

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: partial_overlap
Canonical: #192547
Summary: This PR addresses attachment-loading overhead within the broader constrained-host memory investigation.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit 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:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 November 26, 2026, 3:14 PM ET / 20:14 UTC.

@vincentkoc
vincentkoc merged commit ee4061c into main Nov 26, 2026
131 checks passed
@vincentkoc
vincentkoc deleted the perf/group-native-resource-attachments-20261127 branch November 26, 2026 20:21
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 27, 2026
openclaw#206142)

* improve(build): load less code when the broker attaches native resources

* fix(build): group broker resources with the compatible helper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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