Skip to content

improve(plugins): speed up capture while preserving dependency resources - #166955

Merged
RomneyDa merged 5 commits into
openclaw:mainfrom
jjjhenriksen:improve/doctor-plugin-capture-scope
Oct 9, 2026
Merged

RomneyDa merged 5 commits into
openclaw:mainfrom
jjjhenriksen:improve/doctor-plugin-capture-scope

Conversation

@jjjhenriksen

@jjjhenriksen jjjhenriksen commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway and Doctor preparation can take minutes to capture external plugins with many small dependency files.

User Impact

Plugin preparation copies small ordinary POSIX files faster while retaining complete packages, dependency resources, independent snapshot bytes, and existing capture safeguards. Large files, native binaries, Windows, and aliased output directories retain guarded cloning. Capture remains synchronous.

Why This Change Was Made

Optimize the existing file-copy owner using pinned source descriptors, exclusive outputs, bounded transfers, identity checks, and receipt verification. Automatic dependency deferral was removed because Doctor callbacks can read dependency resources without importing their modules. No configuration, schema, receipt format, or stored-data contract changes.

Evidence

  • Conflict repair b757d63f841 integrates main 6eacab6c294, preserving the batched guarded-copy API and small-file descriptor path. Streaming tests now intercept the batch API; batching fixtures remain above the small-file threshold. Fresh AutoReview found no actionable P0–P2 findings, and the PR diff passes git diff --check. The earlier CI below applies to 45d4ef71c93; replacement-head CI passed. Fresh ClawSweeper review of b757d63f841 rates it platinum hermit with no findings.

  • Matched 60-package / 2,400-payload fixture: capture decreased from 13.435 s to 3.117 s, retaining all 9,830,400 payload bytes, independent files, modes, and the same artifact digest. These are isolated measurements on a loaded host.

  • Contributor proof covers compiled Gateway diagnostics, Doctor repair, repaired Gateway readiness, and a successful unchanged published 2026.9.5 updater against an existing npm lossless-claw installation. This does not prove steady-state throughput or LCM compaction.

  • Maintainer cleanup 45d4ef71c93: fixed all eight CI brace-style errors and made the disk-full retry assertion fail if no rejection occurs. Production source is unchanged. Fresh independent AutoReview found no actionable P0–P2 findings; git diff --check passed. Exact-head CI run passed: all selected test shards, formatting/lint, production/test types, architecture/source guards, and security checks. Fresh ClawSweeper review of this head rates it platinum hermit with no findings.

  • The prior head passed all test shards, type checks, guards, and security checks; its only failing job was check-lint-core-3 for the eight corrected errors. Isolated AWS validation could not allocate because the fleet active-lease limit was exceeded; final verification uses the attached secretless fork CI.

Original contributor proof and qualification details

What Problem This Solves

Gateway and Doctor preparation can spend minutes capturing large external plugin trees. Repeated guarded pathname admission during small-file cloning accounts for much of that cost.

User Impact

Capture still includes the complete plugin package and all declared dependency resources. Small ordinary POSIX files use a pinned source descriptor and an exclusively created output; native binaries, larger files, Windows, and aliased output directories retain the existing guarded clone path. This reduces capture work while preserving resource-only filesystem reads and immutable snapshots.

Why This Change Was Made

The earlier automatic dependency deferral broke Doctor callbacks that read dependency resources without importing their modules. That finding was reproduced and the deferral change is removed. The replacement optimizes the existing file-copy owner and retains source containment, source/output identity checks, exact byte bounds, independent copied bytes, receipt hashing, and final source verification.

The ownership contract introduced by #144252 remains: the managed instance keeps complete captured source and dependencies through admitted work and cleanup. The dependency sibling-resource availability protected by #153546 is retained. No manifest option, persistent schema, receipt format, or serialized data contract changes. Failed acquisitions remain unpublished and unavailable for alternate imports or recovery.

Evidence

  • On the same 60-package, 2,400-payload fixture, complete capture decreased from 13,435 ms to 3,117 ms and queued callback delay from 13,441 ms to 3,119 ms. Every payload file and all 9,830,400 payload bytes remain present, independently copied with the expected mode. The raw artifact digest exactly matches baseline and final source verification passes. These are isolated observations on a loaded host; capture still runs synchronously.
  • 63 focused tests passed on runtime revision 2ac9769; the three redundant helper-call-count cases were subsequently removed in test-only commit 1e4ea3463c0, leaving 60 retained tests. The affected copy/streaming subset was rerun: 24 passed, 12.04 s wrapper wall time; formatting passed. Combined Doctor/resource/copy/streaming/sibling/setup tests before that removal: 53 tests, 24.22 s wrapper wall time. Native-reference/layout tests: 10 tests, 17.92 s wrapper wall time. New copy safety cases cover source growth/shrink/replacement/symlinks, output substitutions/hardlinks, ENOSPC, exact bytes/mode/identity, and existing capture-boundary clone coverage. The resource-only callback regression fails on the prior deferred revision and passes with complete capture while retaining the captured bytes after the installed resource changes. The previous cache-size test and three redundant helper-call-count branch cases were removed.
  • Fresh independent AutoReview found no actionable P0–P2 issues in the revised diff with the actual installed filesystem API contracts supplied as evidence; this was static review, not a test run.
  • Full pnpm build passed at runtime revision 2ac9769 (3m 4.6s build phase time), and the canonical self-contained package passed tarball inventory/import-graph integrity checks. The build emitted a UI startup gzip size warning; no UI inputs changed and its baseline was not compared.
  • Fresh actual compiled Gateway proof at 2ac9769: the invalid-config diagnostic owner read the own-package asset, required dependency, and dependency 1 resource without importing dependency 1, with callback PID matching the Gateway. It correctly refused invalid config with exit 78. Supported Doctor repair exited 0 and persisted the repair; the repaired Gateway reached readiness and passed ten HTTP health/readiness checks and authenticated health/system.info calls. Private fixtures/listeners were cleaned. Test-only follow-up 1e4ea3463c0 leaves the runtime source byte-identical; SHA-256 3a67cd2bfbd36f943fe0d386df29be890fef6e6e83336343cc0c6d9b435479b2. This proves the resource path through actual Gateway/Doctor entry points, not steady-state performance or off-thread capture.
  • Changed-file guards, formatting, core type checking, and all 27 core-test type graphs passed (core-test graphs: 811.09 s). The overall check exits 1 for the pre-existing unused exported OpenAiCompatibleImageProviderOptions type in untouched image-generation code; the same finding reproduced on unmodified baseline 318c60f2. No guard was skipped.
  • Published-driver × candidate qualification passed: the unchanged npm OpenClaw 2026.9.5 CLI ran openclaw update --tag <candidate.tgz> --yes --json --no-restart against an existing genuine npm lossless-claw 0.12.0 install in a private canonical-account fixture. Driver exit 0 in 495.527 s; durable ledger finished/succeeded, reason null, run e3a8a2e3-ad57-4fdc-a9d2-0216b5e3ede7. Installed build matches 2ac9769 and tarball SHA-256 be39cd0128519fb0961c4b977dceac72d8ec523b7f35805d7da82f25cadb6165. All candidate gates passed, including actual Gateway canary startup (4.517 s), post-plugin Doctor lint (2.375 s), and final config validation. The authoritative install record still resolves the same LCM version; Doctor SHA-256 remains 494b9efbc1bae0dc2e0dc5a11e9f3623b3347440fb35580f012f54d895d9eecf. Five observed canary contract reads include the actual staged Doctor and Gateway process, with three observed repaired-policy publications/readbacks. No plugin source overlay or replaced product method. LCM runtime activation was disabled; this qualifies existing-install/Doctor/update behavior, not LCM compaction or live Gateway throughput.
  • Two earlier cells remain failed evidence: disabling bundled discovery hid mandatory memory Doctor metadata (the identical final selector passed after restoring discovery); the next cell's verified host suspension exceeded the unchanged five-minute lifecycle lease and caused lease-loss refusal. The successful fresh cell restores standard discovery and uses temporary task-owned sleep prevention; no product guard, timeout, lease, or source changes. Its approximately 596 MB managed-plugin snapshot makes these durations compatibility evidence, not a comparison with the smaller capture benchmark.

Sanitized terminal evidence (real compiled entry points and unchanged published driver; private paths/auth omitted):

Runtime revision / compiled candidate: 2ac9769ff4cb06528e6b34d8a58d1db7617dad4d
Current PR head: 1e4ea3463c00878dc17bceaf3ead99f2be2e957d (12 test lines removed only)
Gateway invalid-config Doctor: PID 96542; own asset + imported dependency + resource-only dependency read PASS
Gateway admission: exit 78 (expected invalid config)
Doctor --fix --non-interactive: exit 0; persisted repair and resource read PASS
Repaired Gateway: ready; 10 HTTP 200 responses; authenticated health/system.info exit 0
Published 2026.9.5 -> candidate update: exit 0; timedOut false; 495527 ms
Update ledger: phase finished; status succeeded; reason null
Candidate Gateway canary: exit 0; 4517 ms
Post-plugin Doctor lint: exit 0; 2375 ms
Final config validate: exit 0
Authoritative installed plugin: @martian-engineering/[email protected] (npm)
LCM Doctor bytes unchanged: true

Related drafts #161456 and #161827 provide asynchronous capture resource admission and native-worker catalog capture ownership. At inspected heads ecd429f1 and 35d1c1c7, neither offloads ordinary Gateway file/dependency copying, hashing, and source verification. They remain useful foundations for that separate runtime work; this PR reduces synchronous copy cost.

@clawsweeper

clawsweeper Bot commented Oct 8, 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 docs Improvements or additions to documentation size: M labels Oct 8, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Plugin preparation copies small ordinary POSIX files faster while preserving complete dependency resources, independent snapshots, and guarded copying for other files.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, bounded optimization with production-entry-point and upgrade evidence, meaningful integrity coverage, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Sanitized terminal evidence exercises compiled Gateway resource diagnostics, Doctor repair, repaired Gateway readiness, and the unchanged published updater against an existing npm plugin installation. Matched capture measurements show faster preparation with identical digest and complete independent payloads; current-head integration retains the tested runtime path and main’s batch API. Inspection confirms no persisted format or receipt-contract change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes
User problem: Preparing external plugins with many dependency files can delay Gateway startup and Doctor for minutes.
Reason: The measured improvement warrants a bounded change without adding configuration or a public API. Complete dependency resources and existing snapshot behavior remain intact.

Merge readiness

✅ Ready for maintainer review

This PR remains useful beyond main’s batching work and is not fully superseded by the overlapping proposal. No actionable correctness or security defect was found.

Priority: P2
Reviewed head: b757d63f841582eda39433d081e0b73e70918383

Before merge

None.

Findings

None.

Agent review details

How this fits together

Before running an external plugin, OpenClaw captures its package and dependencies into files owned by the plugin instance. Gateway and Doctor preparation consume these verified snapshots.

flowchart TD
 A[Plugin package and dependencies] --> B[Admit and pin source file]
 B --> C{Small ordinary POSIX file?}
 C -->|Yes| D[Bounded descriptor copy]
 C -->|No| E[Batched guarded copy]
 D --> F[Verify source and captured contents]
 E --> F
 F --> G[Gateway or Doctor uses snapshot]
Loading

Technical review

Best possible solution:

Keep the measured optimization in the existing capture owner while preserving complete resources and treating asynchronous scheduling as separate work.

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

Not applicable as a new bug report: supplied matched production-capture measurements establish the performance opportunity, and current-main source retains the targeted guarded-copy overhead.

Is this the best way to solve the issue?

Yes: it improves the measured cost in the existing copy owner while retaining snapshot and publication checks. It accurately leaves synchronous capture and broader scheduling work unresolved.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Introduced copy optimization: The pinned introduced delta selects descriptor copying for ordinary POSIX files up to 64 KiB with canonical destination parents. It preserves source admission, exclusive creation, bounded transfer, destination identity and hardlink checks, modes, and captured-content hashing. (src/plugins/plugin-source-file.ts:81, b757d63f8415)
  • Still distinct from main: Fetched main still sends ordinary files of every size through guarded copying. The merged batching optimization at perf(plugins): batch guarded copies in plugin capture #167516 amortizes directory admission but does not provide this small-file path; no subsequent difference in the inspected copy owner or traversal changes that conclusion. (src/plugins/plugin-source-file.ts:87, 05f7473e9ddb)
  • Independent publication checks remain: The traversal retains complete captured content facts. Receipt completion reopens and hashes ordinary destinations even on cached receipt hits, and source verification checks identity, containment, and content before publication. (src/plugins/plugin-generation-receipt.ts:84, b757d63f8415)
  • Verified dependency contract: The changed production owner imports the advanced filesystem API, establishing the dependency signal. The pinned 0.25.0 implementation performs positional, bounded descriptor transfers with complete writes and invokes the supplied assertion before writes; exclusive creation owns descriptor closure, while directory assertions verify identity and canonical location. (src/file-handle-transfer.ts:27, 50fd5171eecc)
  • Real behavior and upgrade evidence: The supplied complete body, captured source revision 78000d8ce3caaea107d8f01ce95ba6b76eed776f645fa7b9a5c7088d4800ed59, records matched capture improvement from 13.435 to 3.117 seconds with identical digest and all 9,830,400 payload bytes retained. Compiled Gateway diagnostics read dependency resources without importing their modules; Doctor repair succeeded and the repaired Gateway answered health checks. An unchanged published 2026.9.5 updater successfully installed the candidate over an existing npm plugin installation while preserving plugin version and Doctor bytes. The current runtime delta from that tested revision only integrates main’s existing batch callback. (src/plugins/plugin-source-file.ts:186, b757d63f8415)
  • Capture history and original intent: The guarded clone behavior dates to commit 2c8c66f. Its introducing PR, chore(deps): update fs-safe to 0.24.1 and clone plugin source captures #166189, sought independent copied inodes, APFS storage sharing, source-pin binding, byte bounds, restrictive modes, and later receipt verification. This PR explains its narrower small-file transfer choice and retains those integrity outcomes. (src/plugins/plugin-source-file.ts:188, 2c8c66f3fbd3)

Likely related people:

  • Peter Steinberger: Raw commit 2c8c66f adds src/plugins/plugin-source-file.ts:79 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2c8c66f3fbd3; files: src/plugins/plugin-source-file.ts)

PR surface

Source +97, Tests +228. Total +325 across 4 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 1 111 14 +97
Tests 3 243 15 +228
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 354 29 +325

Review metrics

Metric Value Why it matters
Production versus test growth Production +111/-14; tests +243/-15 Production growth is justified by the bounded transfer and explicit integrity checks within the existing copy owner.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded preparation-performance improvement with preserved behavior, rather than a complete remedy for broader Gateway stalls.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-08T04:25:56.101Z sha f83f047 :: needs real behavior proof before merge. :: [P1] Preserve dependency resources accessed without module imports
  • reviewed 2026-10-08T04:59:21.394Z sha 2ac9769 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-08T05:55:05.760Z sha 1e4ea34 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-08T06:13:35.004Z sha 1e4ea34 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T03:33:16.093Z sha 1e4ea34 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T07:19:03.546Z sha 45d4ef7 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T07:26:57.247Z sha 45d4ef7 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T22:09:15.725Z sha b757d63 :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 6:18 PM ET / 22:18 UTC (Revision 11).

@jjjhenriksen jjjhenriksen changed the title improve(doctor): avoid capturing unused plugin dependency trees perf(plugins): reduce copy admission while preserving dependency resources Oct 8, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the docs Improvements or additions to documentation label Oct 8, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 8, 2026
@jjjhenriksen
jjjhenriksen marked this pull request as ready for review October 9, 2026 03:28
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 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-09T03:35:20.342439Z 1e4ea34 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.

@RomneyDa RomneyDa changed the title perf(plugins): reduce copy admission while preserving dependency resources improve(plugins): speed up capture while preserving dependency resources Oct 9, 2026
@RomneyDa
RomneyDa merged commit 156412f into openclaw:main Oct 9, 2026
130 of 132 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…ces (openclaw#166955)

* improve(doctor): avoid capturing unused plugin dependency trees

* perf(plugins): preserve dependency resources while reducing copy admission

* test(plugins): remove redundant copy helper call assertions

* test(plugins): fix copy safety lint and assert failed retries

---------

Co-authored-by: Dallin Romney <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

2 participants