Repository navigation
improve(plugins): reduce JavaScript generation capture work - #146993
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 13, 2026, 8:08 AM ET / 12:08 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR parses ordinary JavaScript directly when collecting plugin dependencies, retains Jiti transformation for sensitive syntax, and adds capture-parity coverage. Merge readiness⛔ Blocked before merge - 4 items remain Keep open: this is a useful, measured optimization absent from current main, with no concrete introduced defect found. The maintainer-owned recovery PR remains a valid landing candidate. Priority: P2 Review scores
Verification
How this fits togetherPlugin generation capture preserves the source files and dependencies used by a plugin instance. Its reference scanner determines which inputs are captured before setup or runtime loading. flowchart TD
A[Plugin source files] --> B[Reference scanner]
B --> C{Safe to parse directly?}
C -->|Yes| D[Acorn parsing]
C -->|No| E[Jiti transformation]
D --> F[Ordered module and asset references]
E --> F
F --> G[Captured plugin inputs]
G --> H[Setup and runtime loading]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +141, Tests +82. Total +223 across 2 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the conservative parser fast path within the existing capture owner, with published-driver upgrade evidence confirming that installed plugins preserve their captured inputs and lifecycle behavior. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this is a performance optimization, supported by reported before/after runs of the actual capture owner; no runtime execution was performed during this review. Is this the best way to solve the issue? Yes: a conservative fast path reuses the existing parser and capture owner while retaining Jiti where its rewrites affect discovery, without adding configuration or another cache. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a67f4624c107. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
* temp/pr-145950: (101 commits) refactor(memory-wiki): share freshness result construction (#146935) improve(gateway): use metadata projection for presence (#146817) test(agents): reuse complete Responses model fixtures (#147015) fix(sessions): align the reclamation-memory test with the archive session owner (#147028) refactor(terminal): simplify copy-sensitive token checks (#146934) refactor(media): remove duplicate spaced path fallback (#146933) refactor(cli): reuse command-group names (#146893) improve(plugins): reduce JavaScript generation capture work (#146993) test: align plugin fixtures with current runtime contracts (#147000) refactor(browser): separate session tab tracking from cleanup (#146973) fix(tests): make systemd clock fixtures private (#146990) fix(linux): retire sleep guards when logind disconnects (#146046) refactor(matrix): share draft fallback delivery (#144840) fix(sessions): preserve cross-agent replies after reload (#146799) test(models): cover quota recovery during catalog discovery (#146708) fix(macos): recover browser sign-in when no browser opens (#146787) fix(process): prevent one-shot agents exiting while polling (#144268) fix(status): label the session inventory as stored (#146979) fix: avoid repeated background reads while loading chat (#146953) refactor(ui): narrow Skill Workshop proposal context (#146977) ...
* commit '060e856e5f9df245d63c98990fcb47e18108c6b9': (97 commits) refactor(memory-wiki): share freshness result construction (#146935) improve(gateway): use metadata projection for presence (#146817) test(agents): reuse complete Responses model fixtures (#147015) fix(sessions): align the reclamation-memory test with the archive session owner (#147028) refactor(terminal): simplify copy-sensitive token checks (#146934) refactor(media): remove duplicate spaced path fallback (#146933) refactor(cli): reuse command-group names (#146893) improve(plugins): reduce JavaScript generation capture work (#146993) test: align plugin fixtures with current runtime contracts (#147000) refactor(browser): separate session tab tracking from cleanup (#146973) fix(tests): make systemd clock fixtures private (#146990) fix(linux): retire sleep guards when logind disconnects (#146046) refactor(matrix): share draft fallback delivery (#144840) fix(sessions): preserve cross-agent replies after reload (#146799) test(models): cover quota recovery during catalog discovery (#146708) fix(macos): recover browser sign-in when no browser opens (#146787) fix(process): prevent one-shot agents exiting while polling (#144268) fix(status): label the session inventory as stored (#146979) fix: avoid repeated background reads while loading chat (#146953) refactor(ui): narrow Skill Workshop proposal context (#146977) ...
* temp/pr-137049: (110 commits) improve: reduce GitHub OAuth maintenance work for large agent rosters (#147021) fix(test): avoid settings lock writer startup timeouts (#147029) fix(update): correct backup guidance and cover incident regressions (#147023) refactor(gateway): share connection lifecycle across transports (#145950) refactor(telegram): share HTML text escaping (#146936) perf(build): reduce disk use in UI performance checks (#146687) refactor(memory-wiki): share freshness result construction (#146935) improve(gateway): use metadata projection for presence (#146817) test(agents): reuse complete Responses model fixtures (#147015) fix(sessions): align the reclamation-memory test with the archive session owner (#147028) refactor(terminal): simplify copy-sensitive token checks (#146934) refactor(media): remove duplicate spaced path fallback (#146933) refactor(cli): reuse command-group names (#146893) improve(plugins): reduce JavaScript generation capture work (#146993) test: align plugin fixtures with current runtime contracts (#147000) refactor(browser): separate session tab tracking from cleanup (#146973) fix(tests): make systemd clock fixtures private (#146990) fix(linux): retire sleep guards when logind disconnects (#146046) refactor(matrix): share draft fallback delivery (#144840) fix(sessions): preserve cross-agent replies after reload (#146799) ...
…#146993) * improve(plugins): reduce JavaScript generation capture work * chore(plugins): place assertion invariant beside the cast
….meta.url (#157862) ## What Problem This Solves Fixes: `openclaw update` stops with `Update state snapshot failed (exit): Assigning to rvalue (308:4)` when an installed plugin depends on valid JavaScript that assigns to `import.meta.url`. The error names no file, so the user cannot tell which dependency blocks the update. A real trigger is `@jsquash/[email protected]` (`codec/pkg/squoosh_png.js`), reached through a literal dynamic import: ```js if (import.meta.url === undefined) { import.meta.url = 'https://localhost'; } ``` Related: #146993 (added the native scan path), #155394 (earlier `import.meta` inspection fix). ## User Impact Updates no longer stop for plugins whose dependencies assign to `import.meta` properties, such as `@jsquash/png` and `@jsquash/avif`. If plugin source inspection still cannot parse a file, the updater error now names that file and says the failure happened after the source transform. Upgrade path: the installed updater runs the snapshot inspection itself. Installs that already run 2026.9.5 or 2026.9.6 keep the old inspection for the update that moves them to this fix, so that one update can still stop on such a plugin. The update troubleshooting page now documents the recovery for that one update: `openclaw plugins disable <id>`, `openclaw update`, then `openclaw plugins enable <id>`. Updates from releases before 2026.9.5 do not run this inspection in the snapshot. All later updates use the fixed inspection. ## Why This Change Was Made - Plugin source inspection sends JavaScript that uses `import.meta` through the Jiti transform, so Jiti can rewrite reference anchors such as `import.meta.dirname` and `import.meta.resolve(...)`. Jiti also replaces `import.meta.url` with a string literal on the left side of an assignment. The output is then not valid JavaScript, and the parser rejects it. - Before the transform, inspection now replaces an `import.meta.*` expression that receives a value (plain or compound assignment, update, destructuring, `for…in`/`for…of` target) with a plain identifier. The transform output is used only to find references and is never executed, so imports, `new URL(..., import.meta.url)` assets and `import.meta.dirname` anchors are still traced as before. The dependency is inspected, not skipped. - The fix is in the transform path and not in the native fast path. Other syntax can also select the transform (for example `for (key in object)` in the `@jsquash/avif` encoder), so a native-only fix would still fail on that sibling file. - If the transformed output still cannot be parsed, inspection now throws a `SyntaxError` that names the source file and the stage, and keeps the parser error as `cause`. Callers that already catch `SyntaxError` (candidate rehearsal warnings) keep their behavior. ## Evidence Real `openclaw update --tag <future tarball> --yes --no-restart --json`, run in a disposable container with a throwaway profile. The profile has one path-loaded plugin that lazily imports `@jsquash/[email protected]/encode.js` and `@jsquash/[email protected]/encode.js` (the published packages, unmodified). | Installed updater | Update target | Result | | --- | --- | --- | | `main` (base of this PR) | base + version bump | exit 1: `Update state snapshot failed (exit): Assigning to rvalue (308:4)` | | this PR | this PR + version bump | exit 0, updated, only the normal advisory for a `plugins.load.paths` plugin | | published 2026.9.6 | this PR + version bump | exit 1: same `Assigning to rvalue (308:4)` (the installed updater runs its own inspection; see User Impact) | | published 2026.7.35 | this PR + version bump | exit 0, updated | | published 2026.9.6, plugin disabled first (documented recovery) | this PR + version bump | exit 0, updated; `openclaw plugins enable` and `plugins inspect` then succeed | The scanner on the exact dependency files: | File | Before | After | | --- | --- | --- | | `@jsquash/png` `codec/pkg/squoosh_png.js` | `SyntaxError: Assigning to rvalue (308:4)` | ok, asset `squoosh_png_bg.wasm` traced | | `@jsquash/avif` `codec/enc/avif_enc.js` | `SyntaxError: Assigning to rvalue (8:900)` | ok, asset `avif_enc.wasm` traced | | `@jsquash/avif` `codec/enc/avif_enc_mt.js` | `SyntaxError: Assigning to rvalue (8:1752)` | ok, assets `avif_enc_mt.wasm` and `avif_enc_mt.worker.mjs` traced | Focused tests: - New `plugin-generation-source-inspection` cases fail on base (`Assigning to rvalue (4:2)`, and the parse error has no file name) and pass with the fix. The first case also checks that the dynamic import, the static import, `import.meta.resolve(...)`, the `new URL(..., import.meta.url)` asset and the `import.meta.dirname` asset are still traced. - `plugin-generation-source-inspection`, `plugin-generation-artifact`, `plugin-module-generation`, `plugin-module-generation.sibling-assets`, `update-candidate-plugin-repair`, `update-candidate-plugin-sources`: 205 tests pass. - Test cost: `pnpm test src/plugins/plugin-generation-source-inspection.test.ts --maxWorkers=1` runs in 2.2 s (5.0 s wall with startup); the two new cases take 30 ms and 7 ms. In CI (`checks-node-changed`) the file takes 3.1 s from shard begin to end (Vitest duration 1.98 s); the new cases take 33 ms and 6 ms. Co-authored-by: Ayaan Zaidi <[email protected]>
….meta.url (openclaw#157862) ## What Problem This Solves Fixes: `openclaw update` stops with `Update state snapshot failed (exit): Assigning to rvalue (308:4)` when an installed plugin depends on valid JavaScript that assigns to `import.meta.url`. The error names no file, so the user cannot tell which dependency blocks the update. A real trigger is `@jsquash/[email protected]` (`codec/pkg/squoosh_png.js`), reached through a literal dynamic import: ```js if (import.meta.url === undefined) { import.meta.url = 'https://localhost'; } ``` Related: openclaw#146993 (added the native scan path), openclaw#155394 (earlier `import.meta` inspection fix). ## User Impact Updates no longer stop for plugins whose dependencies assign to `import.meta` properties, such as `@jsquash/png` and `@jsquash/avif`. If plugin source inspection still cannot parse a file, the updater error now names that file and says the failure happened after the source transform. Upgrade path: the installed updater runs the snapshot inspection itself. Installs that already run 2026.9.5 or 2026.9.6 keep the old inspection for the update that moves them to this fix, so that one update can still stop on such a plugin. The update troubleshooting page now documents the recovery for that one update: `openclaw plugins disable <id>`, `openclaw update`, then `openclaw plugins enable <id>`. Updates from releases before 2026.9.5 do not run this inspection in the snapshot. All later updates use the fixed inspection. ## Why This Change Was Made - Plugin source inspection sends JavaScript that uses `import.meta` through the Jiti transform, so Jiti can rewrite reference anchors such as `import.meta.dirname` and `import.meta.resolve(...)`. Jiti also replaces `import.meta.url` with a string literal on the left side of an assignment. The output is then not valid JavaScript, and the parser rejects it. - Before the transform, inspection now replaces an `import.meta.*` expression that receives a value (plain or compound assignment, update, destructuring, `for…in`/`for…of` target) with a plain identifier. The transform output is used only to find references and is never executed, so imports, `new URL(..., import.meta.url)` assets and `import.meta.dirname` anchors are still traced as before. The dependency is inspected, not skipped. - The fix is in the transform path and not in the native fast path. Other syntax can also select the transform (for example `for (key in object)` in the `@jsquash/avif` encoder), so a native-only fix would still fail on that sibling file. - If the transformed output still cannot be parsed, inspection now throws a `SyntaxError` that names the source file and the stage, and keeps the parser error as `cause`. Callers that already catch `SyntaxError` (candidate rehearsal warnings) keep their behavior. ## Evidence Real `openclaw update --tag <future tarball> --yes --no-restart --json`, run in a disposable container with a throwaway profile. The profile has one path-loaded plugin that lazily imports `@jsquash/[email protected]/encode.js` and `@jsquash/[email protected]/encode.js` (the published packages, unmodified). | Installed updater | Update target | Result | | --- | --- | --- | | `main` (base of this PR) | base + version bump | exit 1: `Update state snapshot failed (exit): Assigning to rvalue (308:4)` | | this PR | this PR + version bump | exit 0, updated, only the normal advisory for a `plugins.load.paths` plugin | | published 2026.9.6 | this PR + version bump | exit 1: same `Assigning to rvalue (308:4)` (the installed updater runs its own inspection; see User Impact) | | published 2026.7.35 | this PR + version bump | exit 0, updated | | published 2026.9.6, plugin disabled first (documented recovery) | this PR + version bump | exit 0, updated; `openclaw plugins enable` and `plugins inspect` then succeed | The scanner on the exact dependency files: | File | Before | After | | --- | --- | --- | | `@jsquash/png` `codec/pkg/squoosh_png.js` | `SyntaxError: Assigning to rvalue (308:4)` | ok, asset `squoosh_png_bg.wasm` traced | | `@jsquash/avif` `codec/enc/avif_enc.js` | `SyntaxError: Assigning to rvalue (8:900)` | ok, asset `avif_enc.wasm` traced | | `@jsquash/avif` `codec/enc/avif_enc_mt.js` | `SyntaxError: Assigning to rvalue (8:1752)` | ok, assets `avif_enc_mt.wasm` and `avif_enc_mt.worker.mjs` traced | Focused tests: - New `plugin-generation-source-inspection` cases fail on base (`Assigning to rvalue (4:2)`, and the parse error has no file name) and pass with the fix. The first case also checks that the dynamic import, the static import, `import.meta.resolve(...)`, the `new URL(..., import.meta.url)` asset and the `import.meta.dirname` asset are still traced. - `plugin-generation-source-inspection`, `plugin-generation-artifact`, `plugin-module-generation`, `plugin-module-generation.sibling-assets`, `update-candidate-plugin-repair`, `update-candidate-plugin-sources`: 205 tests pass. - Test cost: `pnpm test src/plugins/plugin-generation-source-inspection.test.ts --maxWorkers=1` runs in 2.2 s (5.0 s wall with startup); the two new cases take 30 ms and 7 ms. In CI (`checks-node-changed`) the file takes 3.1 s from shard begin to end (Vitest duration 1.98 s); the new cases take 33 ms and 6 ms. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Cold plugin generation capture spends unnecessary time transforming ordinary compiled JavaScript before discovering its dependencies.
User Impact
Reduces capture work when loading plugins while preserving dependency and asset selection, ordered references, currentness, and cleanup. Installed-plugin update behavior is unchanged. This does not establish an overall Gateway startup percentage.
Why This Change Was Made
Use the existing Acorn parser directly for eligible JavaScript, retaining Jiti whenever its syntax or binding rewrites can change reference discovery. The fallback covers local bindings, dynamic-import options, resource management, exported loop targets, and reserved export names. No new cache or loading owner is introduced.
Evidence
Paired elapsed ratios are 0.393 and 0.461; mean elapsed time is 57.6% lower and CPU time 56.8% lower. This is two samples per variant on WSL/Linux Node 24.19, with substantial baseline variation and coordination of our known workloads rather than exclusive host use. The TypeScript control was also faster: originals 30.54/45.27 ms, candidates 26.59/18.82 ms. Initial RSS differed, so no retained-memory benefit is claimed.
The per-entry anthropic-vertex capture regressed from 12.10/17.45 ms to 110.05/96.15 ms. The full cohort includes that cost; shifting initial Jiti fallback work is a plausible but unproven explanation. Earlier prototype timings remain historical and are not used for the final-source claim.
Current-main source audits through 912685f confirm unchanged parser/capture/inspection/Jiti/module-loader owners and dependency manifests. Newer registry/cache/alias callers were inspected separately. The branch was replayed patch-identically onto that repaired base after the repository-wide test-shard headroom guard failed; both authored files remain identical. Replacement exact-head CI and CodeQL passed. A later normal native main capture at
4aff70f2confirms unchanged parser/capture/inspection/Jiti/module-loader source and unchanged Acorn/Jiti/import-meta-resolve versions; main separately upgrades fs-safe and jszip. Retained package proof remains tied to the exact reviewed candidate.Linked Recovery
Related: #146877. This replacement preserves that PR's exact reviewed source head
e96b9be253f6640d9e042d27d034017e78500c00and both existing commits; no source changes or rebase were made for recovery. The original was retained until this replacement merged, then closed with a backlink to the verified landing.GitHub's original PR API and branch identify
e96b9be, but its read-only pull head still identifies the earliera863dfb. One deliberate close/reopen regenerated the merge candidate and fresh checks without repairing that discrepancy. The native workflow correctly refuses the mismatched source ref. Original-PR CI and CodeQL both passed ate96b9be; replacement-specific native identity and exact-head hosted gates have now been verified.The accepted published-upgrade-survivor base cell passed in Package Acceptance 34755936611: published
[email protected]installed, updated to the exacte96b9becandidate tarball (SHA256506cba3f1c8827d37f909c4733cb8154d3285b129d9b02d39b5b2cdfeacedfb6), then passed migration/survival checks and Gateway health, readiness and status probes. One 287-second attempt completed without failure or timeout. Actual frozen admission records toolingdec9fe0aand the exact candidate/package identity. The uploaded proof includes the complete lane log and outer summary, not the container-internal per-assertion JSON; this establishes the agreed base cell, not special legacy/mobile scenarios, broad release coverage or a startup speed result.Three earlier Package Acceptance dispatch requests returned HTTP 500/502 and remain unresolved. A separately reviewed, single recovery request returned HTTP 204 and its actual inputs/admission identify the successful run above. Complete run reconciliation does not erase the older uncertainty; no further dispatch was sent.
After this linked replacement was published, #146950 landed a maintained immutable-head acquisition fix in
scripts/pr. Subsequent native operations will use that current owner. The earlier stale-ref refusal and one close/reopen recovery remain historical evidence; both PRs still contain the same reviewede96b9be253f6640d9e042d27d034017e78500c00commits.