Skip to content

improve(plugins): reduce JavaScript generation capture work - #146993

Merged
steipete merged 2 commits into
mainfrom
codex/perf-plugin-source-parsing-recovery-7006
Sep 13, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf-plugin-source-parsing-recovery-7006

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 373-case exact original/candidate ordered-reference and error parity; 95 tests across artifact, ownership, native-module-loader, and setup-lifecycle suites passed. Eight public regressions also reproduce the earlier incorrect prototypes' failures.
  • Core and plugins-platform test types, focused lint, formatting and diff checks passed. Fresh independent P2 review has no findings.
  • CI exposed a misplaced existing assertion-safety comment. Moving it beside the cast changes no executable tokens or comment-free TypeScript AST; the maintained counter now reports zero uncommented assertions. The tests, timing, and build above used the code before this comment-only follow-up.
  • Ordinary full build and protocol check passed. Maintained built-entrypoint profiles for feishu and anthropic-vertex both passed.
  • Final-source generation-capture benchmark: four fresh processes in O,C,C,O order, same 19 built setup entries plus a TypeScript control. Every arm matched all 20 artifacts, 4474 inspected files, 2175 ordered references, and disposal results.
Compiled capture Original 1 Candidate 2 Candidate 3 Original 4
Elapsed, ms 4678.46 1838.24 1789.23 3877.07
Process CPU, ms 5004.37 2242.75 2175.89 5226.96

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 4aff70f2 confirms 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 e96b9be253f6640d9e042d27d034017e78500c00 and 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 earlier a863dfb. 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 at e96b9be; 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 exact e96b9be candidate tarball (SHA256 506cba3f1c8827d37f909c4733cb8154d3285b129d9b02d39b5b2cdfeacedfb6), 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 tooling dec9fe0a and 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 reviewed e96b9be253f6640d9e042d27d034017e78500c00 commits.

@clawsweeper

clawsweeper Bot commented Sep 13, 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.

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 13, 2026, 8:08 AM ET / 12:08 UTC (Revision 2).

ClawSweeper review

What this changes

The 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
Reviewed head: e96b9be253f6640d9e042d27d034017e78500c00

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, measured optimization with conservative fallback coverage and no concrete correctness finding; upgrade validation remains outstanding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied WSL/Linux runs exercise generation capture over built plugin setup entries and report faster capture with matching artifacts, ordered references, and disposal. This supports the changed behavior; the separately required installed-plugin upgrade cell remains pending.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied WSL/Linux runs exercise generation capture over built plugin setup entries and report faster capture with matching artifacts, ordered references, and disposal. This supports the changed behavior; the separately required installed-plugin upgrade cell remains pending.
Evidence reviewed 9 items Introduced change and current-main comparison: The complete host-pinned introduction contains only the reference scanner and artifact tests. Current main still transforms every scanned source through Jiti; the scanner, capture owner, and Jiti factory are unchanged between the pinned merge base and fetched main.
Capture and execution boundary: Selective capture invokes the scanner to acquire literal inputs. The existing artifact and module-loader owners continue to control resolution, source-current checks, admission, and disposal; the patch does not create another loading or authorization owner.
Behavioral coverage: The added cases protect local-binding exclusion, frozen dynamic imports, transformed reference ordering, and reserved-export behavior through artifact capture and dependency inspection. The complete artifact test module was read; tests were not executed during this read-only review.
Findings None None.
Security None None.

How this fits together

Plugin 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]
Loading

Before merge

  • Resolve merge risk (P1) - Installed-plugin upgrade compatibility remains unverified by the required published-driver × candidate cell; a reference-selection mismatch could leave an existing plugin without expected captured inputs.
  • Resolve merge risk (P1) - The benchmark covers two samples per variant on one host, and anthropic-vertex capture was slower; the aggregate improvement does not establish a universal startup benefit.
  • Complete next step (P2) - Record a successful published-driver × candidate Package Acceptance upgrade result before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +141, Tests +82. Total +223 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 193 52 +141
Tests 1 82 0 +82
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 275 52 +223

Review metrics

Metric Value Why it matters
Measured capture improvement 57.6% lower mean elapsed time across four processes The reported improvement measures the changed capture owner with complete artifact and reference parity, while remaining limited to one host and two samples per variant.
Production versus test growth Production net +141 lines; tests +82 lines The production growth implements conservative eligibility checks justified by the measured reduction in transformation work.

Stored data model

Persistent data-model change detected: serialized state: src/plugins/plugin-source-references.ts, unknown-data-model-change: src/plugins/plugin-source-references.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #146993
Summary: The author identifies this PR as the recovery landing candidate for identical source work; the tooling repair is separate.

Members:

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

Merge-risk options

Maintainer options:

  1. Complete the installed-plugin upgrade check (recommended)
    Record the published-driver × candidate Package Acceptance result before landing, verifying that existing plugins still load and retire correctly.

Technical review

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

Labels

Label changes:

  • add P2: This is a bounded plugin-loading performance improvement with measured benefit and no demonstrated urgent user regression.
  • add merge-risk: 🚨 compatibility: Dependency capture affects existing plugin loading, and the explicitly required published-driver upgrade result remains pending.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied WSL/Linux runs exercise generation capture over built plugin setup entries and report faster capture with matching artifacts, ordered references, and disposal. This supports the changed behavior; the separately required installed-plugin upgrade cell remains pending.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; 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. Sufficient (live_output): The supplied WSL/Linux runs exercise generation capture over built plugin setup entries and report faster capture with matching artifacts, ordered references, and disposal. This supports the changed behavior; the separately required installed-plugin upgrade cell remains pending.

Label justifications:

  • P2: This is a bounded plugin-loading performance improvement with measured benefit and no demonstrated urgent user regression.
  • merge-risk: 🚨 compatibility: Dependency capture affects existing plugin loading, and the explicitly required published-driver upgrade result remains pending.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; 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. Sufficient (live_output): The supplied WSL/Linux runs exercise generation capture over built plugin setup entries and report faster capture with matching artifacts, ordered references, and disposal. This supports the changed behavior; the separately required installed-plugin upgrade cell remains pending.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied WSL/Linux runs exercise generation capture over built plugin setup entries and report faster capture with matching artifacts, ordered references, and disposal. This supports the changed behavior; the separately required installed-plugin upgrade cell remains pending.

Evidence

What I checked:

  • Introduced change and current-main comparison: The complete host-pinned introduction contains only the reference scanner and artifact tests. Current main still transforms every scanned source through Jiti; the scanner, capture owner, and Jiti factory are unchanged between the pinned merge base and fetched main. (src/plugins/plugin-source-references.ts:249, e96b9be253f6)
  • Capture and execution boundary: Selective capture invokes the scanner to acquire literal inputs. The existing artifact and module-loader owners continue to control resolution, source-current checks, admission, and disposal; the patch does not create another loading or authorization owner. (src/plugins/plugin-generation-artifact.ts:552, e96b9be253f6)
  • Behavioral coverage: The added cases protect local-binding exclusion, frozen dynamic imports, transformed reference ordering, and reserved-export behavior through artifact capture and dependency inspection. The complete artifact test module was read; tests were not executed during this read-only review. (src/plugins/plugin-generation-artifact.test.ts:220, e96b9be253f6)
  • Dependency contract inspected: The patch directly calls Jiti transformation and claims reference parity, establishing the dependency signal. Jiti 2.7.0 source renames conflicting bindings, transforms dynamic imports, and hoists static module headers. Its package metadata identifies unjs/jiti, and the tag resolves to the recorded dependency SHA. (src/plugins/transform-module/index.ts, fd3bb289b75e)
  • Real capture measurements: The supplied complete PR body reports four fresh WSL/Linux Node 24.19 processes over 19 built setup entries and a TypeScript control. All arms matched 20 artifacts, 4,474 inspected files, 2,175 ordered references, and disposal results; mean compiled-capture elapsed time fell 57.6%. The body discloses baseline variation and the slower anthropic-vertex entry. A REST reread retained the same head and evidence. (e96b9be253f6)
  • Outstanding upgrade requirement: Root policy requires a published-driver × candidate cell for plugin-loading changes. The current PR body still explicitly records Package Acceptance upgrade proof as pending, matching the previous completed review's sole rank-up move. (AGENTS.md:69, e96b9be253f6)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record the already-required published-driver × candidate Package Acceptance upgrade result.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-13T11:54:11.010Z sha e96b9be :: blocked before merge. :: none

@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: 🐚 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. labels Sep 13, 2026
@steipete
steipete merged commit c2a7353 into main Sep 13, 2026
616 of 622 checks passed
@steipete
steipete deleted the codex/perf-plugin-source-parsing-recovery-7006 branch September 13, 2026 12:46
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 13, 2026
* 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)
  ...
vincentkoc added a commit that referenced this pull request Sep 13, 2026
* 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)
  ...
vincentkoc added a commit that referenced this pull request Sep 13, 2026
* 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)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
…#146993)

* improve(plugins): reduce JavaScript generation capture work

* chore(plugins): place assertion invariant beside the cast
obviyus added a commit that referenced this pull request Sep 25, 2026
….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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
….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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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.

1 participant