← Back to Pull requests

fix(javascript): recover webpack chunks with array module tables #13829

Closed
unknown closed this pull request without merging on Nov 30, 2026 14:52 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 01:21 UTC
Author

Summary

analyze-javascript-application recovered no modules from webpack chunks whose module table is a sparse array, and from webpack 4 chunks registered on webpackJsonp. The files' candidate_enumeration still read complete. Webpack writes a sparse array whenever numeric module ids are dense. That is the normal output of webpack 4 production builds, and of webpack 5 with optimization.moduleIds: "natural" or "size". The docs say chunk registrations "represented as AST literals" are recovered.

Chunk registration now reads object, sparse-array and Array(n).concat([...]) tables, and treats webpackJsonp as a chunk runtime.

No linked issue. This came out of an audit and is a small fix within the existing recovery boundary, so the write-up is here rather than in a separate issue.

Problem and expected behavior

  • Trigger: the same three-module source built with webpack 5.101.3 in production mode with concatenateModules: false, once with moduleIds: "deterministic" and once with "natural". The natural build's chunk is (self.webpackChunk=self.webpackChunk||[]).push([[1],[,,(e,n,r)=>{…},(e,n,r)=>{…}]]). A webpack 4 chunk is (window.webpackJsonp=window.webpackJsonp||[]).push([[0],[function(e,t,n){…},…]]).

  • Before: inspectBundlerRegistration returned early unless the table was an ObjectExpression. findChunkRuntime matched only /(?:webpack|rspack)Chunk/. The chunk gave no registration and no unknown finding.

  • After: an array element's index, plus any Array(n).concat offset, is its module id. Holes are absent ids. Elements that aren't function literals are skipped, as non-factory object properties already are. Arrays containing spreads stay unrecognised, because their indexes aren't literal.
  • Change and scope

  • javascriptStaticAnalysisHelpers.ts: a moduleTableEntries helper yields { key, factory } slots for an object table (via the existing modulePropertyName / moduleFactory) or an array table. CHUNK_RUNTIME_NAME adds webpackJsonp, and the webpack vendor markers add webpackJsonp too. Without that, a minified webpack 4 chunk returned bundler: "webpack" registrations while vendors (and the artifact graph's vendor_markers) stayed empty.

  • javascriptStaticAnalysisBundler.ts: recoverBundlerModules takes those slots. Object tables produce the same keys and factories in the same order as before, so the bootstrap and esbuild paths are unchanged.

  • Docs: the reconstruction guide now names the recovered shapes.

  • Not included: standalone bootstrap tables in array form (e.g. var r=[,e=>{…}] in a natural-id entry bundle). That table also feeds javascriptBootstrapIntegrity, javascriptBundledRequireOrigin and javascriptSymbolicBindings, which read .properties. Widening it touches those proofs and is left for a follow-up. The guide line says bootstrap tables are recovered only in object form.

  • Array(n).concat is recovered only when the existing semantic model proves the native binding, unchanged concat behavior and valid array lengths. Shadowing, reassignment and visible inherited-slot mutations remain unresolved.

  • Contribution scope: not applicable (ordinary fix within an existing boundary).
  • Contract and boundary impact

  • Semantic owner and earliest changed stage: static analysis, chunk registration (inspectBundlerRegistration). Downstream consumers see more bundler_registrations[].modules and module ranges.

  • Contribution scope fit and linked maintainer decision: not applicable.

  • CLI and MCP/tool-catalog contract: no schema change. Existing fields are populated for more inputs.

  • Provider, bridge, target-format, or platform compatibility: none.

  • Evidence, artifact, provenance, or reconstruction contract: registrations for array-table chunks now appear. Object-table output is unchanged (see validation).

  • Target selection, authority, upstream behavior, and cleanup details: not applicable.

  • Generated metadata, package, or installation impact: none.
  • Read existing files or captured data.

  • Launch or attach to a process.

  • Inject instrumentation or run scripts/code.

  • Change process memory, registers, files, or configuration.

  • Contact network services.

  • Recover protected code or work around protections.

  • Documentation or usability only; no target interaction.

  • Not sure yet; investigation or maintainer guidance needed.
  • Evidence and regression coverage

  • Tests added: src/domain/javascript/javascriptStaticAnalysisArrayModuleTables.test.ts covers:

  • - a natural-id chunk;
    - webpack 4 webpackJsonp chunks with array and object tables, and their webpack vendor marker;
    - an Array(7).concat([…,,…]) offset table;
    - an array of non-functions, which registers the chunk keys with no modules.

    All 4 fail on the base revision d979c1849 (expected [] to deeply equal [ [ '2', '3' ] ], …) and pass with the change.

  • Base reproduction: CLI on real webpack 5.101.3 output.

  • - Before = built CLI at 9560457.
    - After = this branch on d979c1849.
    - Node 24.22.1, macOS arm64.
    - Command: rea analyze-javascript-application <dir> --json | jq -c '.normalized_result.statistics|{modules,findings}'

    | Input | Before | After |
    |---|---|---|
    | moduleIds: "deterministic" (object tables) | {"modules":3,"findings":6} | {"modules":3,"findings":6} |
    | moduleIds: "natural" (array chunk + array bootstrap) | {"modules":0,"findings":3} | {"modules":2,"findings":5}. The bootstrap's own module is the follow-up above. |
    | webpack 4 webpackJsonp array + object chunks, webpack 5 array + object chunks | {"modules":2,"findings":1} | {"modules":8,"findings":6} |

  • Remaining proof gaps:

  • - Standalone bootstrap tables in array form are not covered.
    - Not run against a large real-world webpack 4 application.

    Validation performed

    All on Node 24.22.1, macOS arm64.

  • npx vitest run src/domain/javascript

  • - Base: 200 files / 6180 tests passed.
    - With the change: 6183 passed and 1 failed, a 30 s timeout under machine load (load average about 7).
    - A second run timed out in electronWrappedCallPaths.test.ts and javascriptSemanticAnalysis.builtin_defaults.test.ts.
    - Both files pass when run alone with the change: 382/382, the slow test in 1.8 s. Neither is touched by this change.
  • npx vitest run tests/boundary/filesystem/javascript-applications/javascriptBundlerAdapters.test.ts tests/boundary/filesystem/javascript-applications/javascriptRuntimeReconciliation.test.ts — 22 passed.

  • npm run build:cached, then npx vitest run tests/boundary/cli/javascriptBundlerRuntimeScopes.test.ts tests/boundary/cli/javascriptBundlerSelfReferences.test.ts tests/acceptance/applications/webpackLoaderReturnsCli.test.ts tests/acceptance/applications/webpackRenamedExportsCli.test.ts — 21 passed.

  • npm run check:fast — passed (typecheck, lint, architecture guards).

  • After the vendor-marker follow-up (d7b303d): the new vendors assertion failed on 0633dfa (expected [] to deeply equal [ 'webpack' ]) and passes now. npx vitest run src/domain/javascript passed (201 files / 6184 tests), and check:fast, format:check, metadata:check, knip:production and docs:check all passed. lint:typed (3 errors) and knip fail only in files this PR doesn't touch.

  • npm run format:check, npm run metadata:check, npm run knip:production, npm run docs:check — passed.

  • npm run knip — fails on UefiLzmaStreamRequest (src/uefi/UefiLzmaProtocol.ts:21). It reports the same on an unmodified d979c1849 checkout, so this change didn't cause it.

  • npm run lint:typed — 1 error, in src/domain/webModuleImports.ts (switch-exhaustiveness-check). That file is untouched here. No new diagnostics in the changed files.
  • Compatibility, safety, and release

  • Breaking changes or migration steps: none. Object-table results are unchanged, and array-table inputs gain registrations.

  • Real Hopper/Ghidra, browser, or OS coverage: not applicable (static analysis). Run on macOS only.

  • Package or release metadata impact: none.

  • Security, privacy, process, or containment review: parsing only; nothing is executed.
  • Maintainer validation

    Array offsets now require the native Array binding, unchanged concat semantics and valid uint32 array lengths. Visible inherited-index mutations use the existing array-iteration uncertainty owner. Holes remain absent and no leading-hole array is allocated.

  • Canonical P2 review identified the inherited-slot gap; the scoped correction and controls are included.

  • All 20 static cases and both public CLI/stdio-MCP cases pass. The public cases verify exact module IDs 7/9, exports, source location and their dependency edge. Existing callback/export regressions also pass.

  • Six intrinsic/length regressions fail on the original reader; three inherited-index regressions fail before the final correction.

  • Typecheck, lint, module boundaries, docs checks and test discovery passed using the branch's locked dependencies, Node 24.22.1 and npm 11.21.3.
  • Author readiness

    Human owner: @thejesh23

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.

  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.

  • I declare this PR ready for initial maintainer review.
  • Before merge

  • This PR addresses a concrete problem or an agreed enhancement.

  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.

  • The PR has one focused outcome and the title follows type(scope): outcome.

  • Related issue is linked, or the reason for not linking one is stated above.

  • Tests cover changed observable behavior and meaningful failure paths.

  • Owning docs, contracts, and generated metadata are updated where needed.

  • User-visible CLI/MCP changes include representative output.

  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: thejesh23 Review duration: 10891m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #13829"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%
    Repository