Skip to content

perf(plugins): batch guarded copies in plugin capture - #167516

Merged
steipete merged 4 commits into
mainfrom
build/fs-safe-0.25.0-batched-capture
Oct 9, 2026
Merged

steipete merged 4 commits into
mainfrom
build/fs-safe-0.25.0-batched-capture

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Related: #166526

What Problem This Solves

Plugin capture repeatedly resolves and admits the same directories when Doctor or Gateway startup copies many files from a package.

User Impact

Plugin capture performs less repeated filesystem work while preserving each file's source identity, path containment, hardlink policy, byte bound, permissions, content receipt, and cleanup guarantees.

Why This Change Was Made

Use createRootFileCopyBatchSync for each synchronous capture traversal. Recursive copies share one bound callback, and the traversal disposes its batch before returning. Later acquisitions and native namespace copies retain independent ownership.

The adoption preserves main’s capture-custody behavior: retained-source validation, native admission, retained content facts, and receipt checks. Both the batching and custody regressions exercise the combined implementation.

This PR contains only the two capture source files and the streaming test. It carries no dependency, lockfile, workspace, or Doctor-budget changes. Production LOC is +18/-5 (net +13) for the disposable batch lifetime and callback wiring; no integrity checks were removed to offset that growth.

Evidence

Validated head: 1927d181ddb876c92d3ad3aac200e0b5b91af35b, including main 18cade08699b24ecfd0be142cdf16d90b3af9fbd.

The streaming and Doctor custody suites passed together: 37 tests, 28.26 seconds wall. Core types, the covering plugin test-type graph, targeted lint/format, and the canonical package-preparation build passed. Fresh independent branch review found no actionable P0–P2 findings. ClawSweeper reviewed this exact head with no findings or required changes.

The regression exercises real captures: 16 sibling files require 802 directory metadata reads with batching versus 1,072 when only the two production files are reverted to integrated main, keeping fs-safe 0.25.0 installed. The negative control fails the intended 911.2-read bound (29.05 seconds wall). Candidate bytes were restored before publication.

Exact-head CI and CodeQL passed. The streaming CI file passed 28 tests with one APFS-only skip (3.26 seconds Vitest, 4.72 seconds wrapper, 5.09 seconds total; 42 ms for the batching regression). On the replacement AWS lease, all 18 module/Doctor files passed: 273 tests and one platform skip, 246.38 seconds wall. Core and the three covering test-type graphs passed, and the normal source build passed in 329.5 seconds.

The complete sqlite-volume published-upgrade survivor passed on this head, using baseline [email protected] and the candidate built from source on AWS. Repeat Doctor completed in 175 seconds against the computed 717-second budget. The budget came from the measured state: 4,803 sessions, 23,893 events, 2,203 cron jobs, and 9 enabled plugin roots; computed and applied budgets were equal, with no override.

The post-Doctor state assertion, Gateway restart and probes, restarted history checks, and final survival assertion all passed. Both real Gateway history probes verified eight conversations across two agents; all sampled message digests matched before and after restart. The final summary reports status: passed, failure: null, candidate 2026.9.9, and updateOutcome: success. The command and wrapper both exited 0; the scenario took 1,161 seconds.

Doctor measurement Seconds
Capture-custody reference 218
Current combined head with batching 175
Observed reduction 43 (19.7%)

This comparison is descriptive: the custody reference used c7a.8xlarge and fs-safe 0.24.2; this run used an explicitly pinned r7a.xlarge (4 vCPU, 30.6 GiB usable RAM) and fs-safe 0.25.0, with later main changes. Both used Node 24.21.0, pnpm 12.5.1, and Docker 29.8.2. The production-only negative control above separately isolates the batching change at fs-safe 0.25.0.

AWS lease: cbx_48da0cc83d58; run: run_679e106c17a85bfc3b1f00cbf6a12547. The fresh PR checkout verified the exact source SHA/tree, the trusted bootstrap verified the secretless instance boundary and pinned toolchain, and the normal source build/package integrity checks ran on the lease. No heap, resource, or Doctor-budget override was used. The earlier quota-downgraded 2 GiB allocation was OOM-killed during candidate installation; the explicitly pinned replacement completed successfully.

Excerpts:

idempotenceSeconds: 175
idempotenceBudgetSeconds: 717
assert-volume-idempotence: passed
gateway-restart: passed
gateway-restart-probes: passed
gateway-restart-volume-history: passed
assert-restarted-survival: passed
SURVIVOR_EXIT=0

Validation commands:

node scripts/run-vitest.mjs src/plugins/plugin-generation-artifact.streaming.test.ts src/plugins/doctor-contract-registry.custody.test.ts --maxWorkers=1
pnpm tsgo:core
pnpm tsgo:core:test --ci-graphs-json '["core-test-plugins-platform","core-test-commands-doctor","core-test-infra"]'
GITHUB_ACTIONS=false \
[email protected] \
OPENCLAW_UPGRADE_SURVIVOR_SCENARIOS=sqlite-volume \
pnpm test:docker:published-upgrade-survivor

The source build emitted the existing advisory Control UI startup-size overage (364.8 KiB versus 364.7 KiB); the build passed and no budget was changed. This PR remains partial work toward the broader Doctor issue.

Reuse guarded directory admission within each synchronous plugin capture while retaining per-file integrity checks and disposable ownership. Related: #166526.
@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.

@steipete
steipete marked this pull request as ready for review October 8, 2026 23:18
@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph guard cleared

This PR no longer has dependency changes awaiting review. A future dependency graph change from an external contributor requires a maintainer's /allow-dependencies-change comment after the guard notice identifies that revision.

  • Current SHA: 1927d181ddb876c92d3ad3aac200e0b5b91af35b

@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. 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. 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

The branch shares guarded directory admission across each synchronous plugin capture traversal while preserving individual file verification and cleanup.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The bounded optimization is sound and supported by scoped runtime evidence, while remaining a partial response to the broader performance problem.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Earlier AWS runs exercised batched capture through real Doctor and observed 471-second versus 257-second execution, supporting the scoped performance improvement. Integrated capture negative controls support the unchanged batching implementation; the combined-head upgrade run is unfinished and establishes no restart or history-survival result. Stored settings and receipt formats are unchanged.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Partial
User problem: Users with large installations wait several minutes while Doctor and startup repeatedly capture plugin files.
Reason: Measured savings justify a small optimization authored by an established contributor to this capture area. The PR appropriately uses Related because batching does not resolve the entire Doctor latency report.

Merge readiness

✅ Ready for maintainer review

This PR retains a useful, bounded optimization absent from current main. No actionable defect was found, and the introduced files are unchanged since the previous reviewed head.

Priority: P2
Reviewed head: 1927d181ddb876c92d3ad3aac200e0b5b91af35b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The combined-head published-updater, Doctor, restart, and preserved-history run remains unfinished; the completed scoped runtime measurements come from the earlier batching head.
Agent review details

How this fits together

OpenClaw captures plugin files into private snapshots for Doctor and Gateway loading. Source identity checks and content receipts verify those snapshots before plugin code uses them.

flowchart TD
  A[Doctor or Gateway startup] --> B[Plugin capture owner]
  C[Plugin source files] --> B
  B --> D[Traversal-scoped copy batch]
  D --> E[Fresh directory and file checks]
  E --> F[Private copied files]
  F --> G[Content receipt verification]
  G --> H[Plugin loading]
Loading

Technical review

Best possible solution:

Keep disposable traversal batching within the existing capture owner, preserving fresh file checks and independent instance cleanup while broader Doctor latency remains tracked separately.

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

Yes: current source repeats single-file directory admission, and the recorded capture negative control isolates that overhead. This read-only review did not execute the scenario.

Is this the best way to solve the issue?

Yes for the scoped overhead: the dependency's existing disposable batch removes repeated admission work without introducing a competing cache owner or relaxing file checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Introduced changes: The pinned delta adds traversal-scoped batching and an optional internal copy callback, with adapted capture regressions. Dependency updates, Doctor budgets, and retained-source custody are already in the base. (src/plugins/plugin-generation-file-capture.ts:240, 1927d181ddb8)
  • Still necessary on current main: Fetched main retains individual guarded copies without traversal batching. The three touched files have no changes between the pinned base and fetched main; merged dependency and custody improvements do not supersede this optimization. (src/plugins/plugin-source-file.ts:83, e6ca676b02b6)
  • Re-review continuity: All three introduced files are byte-identical to the previous reviewed head. The previous structured review contains no findings or applicable rank-up moves. (1927d181ddb8)
  • Integrity and upgrade compatibility: Copies retain the open source pin, expected inode identity, admitted byte bound, restrictive modes, destination-descriptor hashing, and later pathname receipt verification. Each traversal disposes its batch; native namespace copies retain the single-file default. No persisted format, config, schema, or receipt framing changes. (src/plugins/plugin-source-file.ts:84, 1927d181ddb8)
  • Dependency contract: The introduced advanced API import establishes the dependency signal. The verified v0.25.0 tag resolves to this commit; its batch reuses directory admission, clears the cache on disposal, and retains source and destination checks around copying. (src/copy-root-file-sync.ts:62, 50fd5171eecc)
  • Cached directory validation: Cached admission rechecks root, ancestor, and parent identities; file observations are never cached. Windows and noncanonical paths retain the existing resolver. The dependency's applicable filesystem-boundary policy was read. (src/copy-path-admission.ts:56, 50fd5171eecc)

Likely related people:

  • Peter Steinberger: Raw commit 2c8c66f adds src/plugins/plugin-source-file.ts:74 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 +13, Tests +44. Total +57 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 18 5 +13
Tests 1 54 10 +44
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 72 15 +57

Review metrics

Metric Value Why it matters
Production versus test LOC Production +18/-5; tests +54/-10 The small production increase provides explicit batch disposal and callback wiring while retaining existing integrity checks.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #166526
Summary: This PR addresses per-traversal guarded-copy overhead within the broader Doctor performance report.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Measured redundant capture work slows maintenance and startup on large installations without evidence of an urgent introduced regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; 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 (4 earlier review cycles)
  • reviewed 2026-10-08T23:26:43.753Z sha baecca3 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-08T23:33:07.748Z sha baecca3 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T05:14:18.261Z sha 4ffdf4f :: needs changes before merge. :: none
  • reviewed 2026-10-09T05:39:15.221Z sha 6506ebe :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 2:38 AM ET / 06:38 UTC (Revision 5).

@github-actions github-actions Bot removed the dependencies-changed PR changes dependency-related files label Oct 9, 2026
@steipete steipete changed the title fix: reduce Doctor plugin capture overhead perf(plugins): batch guarded copies in plugin capture Oct 9, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 9, 2026
@steipete
steipete merged commit f8e594e into main Oct 9, 2026
118 checks passed
@steipete
steipete deleted the build/fs-safe-0.25.0-batched-capture branch October 9, 2026 07:28
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Oct 9, 2026
Align ENOSPC injection and native-copy observation with f8e594e (#167516), which moved plugin generation capture to the fs-safe batch API. Keep the real loader, error guidance, Doctor outcomes, and copy-budget assertions.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
Reuse guarded directory admission within each synchronous plugin capture while retaining per-file integrity checks and disposable ownership. Related: openclaw#166526.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
Align ENOSPC injection and native-copy observation with d1e15b4 (openclaw#167516), which moved plugin generation capture to the fs-safe batch API. Keep the real loader, error guidance, Doctor outcomes, and copy-budget assertions.
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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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