Skip to content

feat(javascript): recover code-split bundles from multiple inputs - #1686

Merged
morluto merged 2 commits into
morluto:mainfrom
JingHao-Leon:feat/recover-javascript-multi-input
Oct 11, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
JingHao-Leon:feat/recover-javascript-multi-input

Conversation

@JingHao-Leon

@JingHao-Leon JingHao-Leon commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Related code-split scripts previously required separate recovery calls, leaving cross-chunk module IDs unresolved. additional_paths now recovers up to 16 additional files with the primary path in one native Wakaru invocation. The CLI exposes the same choice through repeatable --additional-path options.

Each input has a separate snapshot, digest and published copy. The manifest retains source for the primary file and adds additional_sources for the rest; module provenance binds to its producer-reported snapshot and retains that file's extraction/context byte ranges. Relative input layout is preserved, aggregate input is limited to 64 MiB before allocation, and every original file is independently rechecked before commit. Single-file recovery retains its existing result shape. This also fixes the strict-schema failure that broke recovery in CI.

Validation:

  • npm run check and npm run docs:check pass.
  • 65 focused Linux tests pass, covering CLI/MCP contracts, per-file mutation, invalid provenance/ranges, malformed UTF-8, input capacity, publication rollback and cleanup.
  • The official Wakaru 1.14.0 Linux x64 binary passes all 12 real CLI/stdio-MCP fixture workflows in a Linux container. The webpack 5.101.3 runtime/shared/entry/lazy-chunk fixture produces four modules, four source maps and four resolved cross-chunk import edges on each surface.
  • Original variable names and arbitrary runtime equivalence remain unknown. Unsupported multi-input filename layouts fail before engine execution when they cannot be published without renaming.

Fixes #1605.

recover_javascript_sources accepted a single path, and
validateModuleSet bound every module's provenance to that one snapshot.
A code-split app (runtime + chunks, or an Electron main/preload/renderer
set) had to be recovered one file per call, and modules recovered alone
could not resolve imports across chunks: cross-chunk require(id)
references stayed as numeric ids with property reads.

Add an optional additional_paths input. The listed files are
concatenated, in order after path, into the single engine snapshot, so
one Wakaru run sees every module and cross-chunk imports resolve.
validateModuleSet's single-snapshot binding is unchanged. Module
provenance is attributed back to the input file its first extraction
range starts in, with byte ranges rebased to that file's own offsets;
a module whose ranges cross an input boundary keeps the concatenated
snapshot identity and offsets, recorded as an explicit limitation.
Single-path behavior is byte-for-byte unchanged (one segment,
offset 0).

Fixes morluto#1605
@JingHao-Leon
JingHao-Leon marked this pull request as ready for review October 11, 2026 03:56
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: On 5ddf876, every recovery call fails, even with one file. A small local fix makes it work, and then cross-chunk imports resolve on real code. But the files are joined with no newline, so one chunk can hide the next without any warning.

Results

I tested 5ddf876 (parent e5bc4e8) with a real Wakaru 1.14.0 (Apache-2.0). Main was 693ed33.

Check Node 22 Node 24 Node 26
The PR's three changed test files (18 tests) pass pass pass
Recovery boundary tests, fake Wakaru (29 tests) 5 fail 5 fail 5 fail
Same boundary tests on e5bc4e8 not run 29 pass not run
Real Wakaru check script (verify:javascript:recovery), 5ddf876 not run fail not run
Same script on e5bc4e8 and on main 693ed33 not run pass not run
One-file MCP call, 5ddf876 fail fail fail
Two-file MCP call, 5ddf876 plus my local fix pass pass pass

Why it fails. The new segments list ends up in the result's source field. That schema is strict and rejects it: Unrecognized key: "segments" at source. The PR's own tests miss this. The boundary tests catch it, but npm run test:local does not run them. They need Linux x64, which the PR says its author did not have.

With my local fix (it keeps segments out of source; see the fold below), I ran real code-split builds. The count is require(id) calls with a number still in them. An import across files is an import ... from "./module-N.js" line whose target came from another input file.

Input Files Numeric require(id) left, one file at a time, then together Imports across files, one file at a time, then together
Issue fixture, webpack 5.101.3 (MIT) 4 2, then 0 0, then 2
Nextcloud Calendar 5.5.24 (AGPL-3.0-or-later): pinia and Vue runtime 2 1, then 0 0, then 1
Calendar: lodash chunk, then v-tooltip chunk 2 29, then 0 0, then 27
Calendar: 17 chunks, 6.4 MB, one newline added to each 17 1,479, then 562 0, then 827

I count import lines. The analyzer counts 6 edges on the fixture, and the issue counted 4 on an older main.

The 562 left over are 32 ids. 15 are defined only in entry bundles I did not pass in. 17 are defined in two of the chunks I did pass in. In the cases I checked, Wakaru writes a second module-N_2.js and the call keeps its number.

The newline problem

Calendar chunks end with a //# sourceMappingURL= comment and no final newline. The PR joins files with nothing between them. So the next file's first line lands inside that comment.

The pinia chunk, then the subscription-picker chunk, gives 1 module. The picker alone gives 3. Those 3 vanish, and the status stays complete with no warning. All 17 chunks as shipped give 1,008 modules, not 1,585. One newline added to each copy fixes both.

Not run

  • Node 22 and 26 for the full unit suite and for the real Wakaru check script.
  • The PR merged onto main 693ed33. I only checked that the diff applies cleanly.
  • Electron apps with separate main, preload and renderer files.
  • Other Wakaru versions and other systems.

Thanks, JingHao-Leon, for the PR. Thanks, pionxzh, for the issue and the repro.

Smaller findings
  • Every module points at the right input file in every run (1,585 of 1,585 in the largest). The digest matches and the range sits inside that file.
  • With the local fix, one-file calls match main and e5bc4e8 byte for byte on 6 inputs (modules, maps and the input copy). Only per-run values differ: temp path, elapsed time, their hashes and the Evidence id.
  • A module cut across two files keeps the first file's name and digest. Its byte range, though, counts bytes in the joined text. I split the pinia chunk at 9,000 bytes. The digest was for those 9,000 bytes, but the range ended at 19,033. The PR text says such a module keeps the joined identity.
  • A missing, bad or non-UTF-8 file in additional_paths is reported under path, not additional_paths.
  • /dir/./pinia.js slips past the duplicate check. The file is joined twice and a module-51849_2.js appears.
  • 16 extra paths work (17 files). 17 extra paths fail in the MCP schema: additional_paths: Too big: expected array to have <=16 items.
  • A repeated path gives additional_paths must not repeat path or each other.
  • A relative path gives additional_paths entries must be absolute filesystem paths on this host: relative/chunk.js.
  • Two 42,000,000-byte files pass the per-file limit but not the joined one. The call fails late with unreadable_output and names a private temp file.
  • The manifest source shows the first file with the size and digest of the whole join. Other inputs show up only inside module provenance.
  • The CLI has no option for additional_paths. It is MCP only.
  • npm run test:local uses --changed. In my copy (no git) it ran zero tests and exited 0. I ran the same projects without that flag: 376 files, 4,225 passed, 3 skipped, Node 24.
My local fix (6 lines)
-    source: { ...source, published_copy: publishedCopy },
+    source: {
+      path: source.path,
+      snapshot_path: source.snapshot_path,
+      sha256: source.sha256,
+      bytes: source.bytes,
+      published_copy: publishedCopy,
+    },

This is in src/javascript/recovery/WakaruPublication.ts. With it, the real Wakaru check script and the 29 boundary tests pass on Node 24.

Test setup
calendar license AGPL-3.0-or-later (js/**.js in REUSE.toml, <licence>agpl in info.xml)
wakaru sha256 664fa06782a61eda7ed15885134b52525fd565dd77607e642062ceb6cd927c38
calendar sha256 9a4e1b869aa478317363cb0876a5d128aa584e427216d2cbfb808215f5c296a8
element web 1.12.30 license AGPL-3.0-or-later OR GPL-3.0-or-later (README at that tag; a paid license also exists)
element web sha256 41ecae1e7af5d09baf2c1a7646cebad51ced6a44257d2096b9618bff3fee625d

Element Web was used for one of the six one-file inputs (its init chunk, which uses string ids).

Commands
# build each tree (Node 24): npm ci && npm run build && npm run test:prepare
export REA_WAKARU_COMMAND=/tmp/pr1686/wakaru/wakaru
export REA_JAVASCRIPT_FIXTURE_TOOLS=/tmp/pr1686/fixture-tools
node node_modules/vitest/vitest.mjs run src/javascript/recovery/RecoveryFiles.test.ts \
  src/javascript/recovery/WakaruPublication.test.ts src/application/javascript/JavaScriptRecoveryService.test.ts
node node_modules/vitest/vitest.mjs run --project boundary --project process-boundary tests/boundary/javascript-recovery
npm run verify:javascript:recovery
# MCP call (stdio, node scripts/rea.mjs mcp), tool recover_javascript_sources:
# {"path": "<first>", "additional_paths": ["<second>", ...], "output_directory": "<absent dir>"}
node scripts/rea.mjs analyze-javascript-application <output>/modules --json

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto
morluto merged commit 12c4160 into morluto:main Oct 11, 2026
30 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
3 tasks done
@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Thanks for taking on recovery across multiple JavaScript inputs, @JingHao-Leon, and welcome to REA. Runtime, shared and lazy chunks can now be recovered together and fed straight into application analysis. It's good to have this workflow in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Recover related scripts together in recover_javascript_sources

3 participants