Skip to content

fix(javascript): preserve graphs with async chunk self-references - #1152

Merged
N0zoM1z0 merged 1 commit into
mainfrom
fix/javascript-bundler-self-reference
Oct 9, 2026
Merged

N0zoM1z0 merged 1 commit into
mainfrom
fix/javascript-bundler-self-reference

Conversation

@N0zoM1z0

@N0zoM1z0 N0zoM1z0 commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

A Webpack or Rspack registration that requests one of its own chunk IDs produced a self-referential chunk edge, causing schema validation to discard the entire application analysis. Omit those unrepresentable edges and disclose their count in graph/result limitations. Preserve the original AST observations, source locations, module relationships, resolved sibling edges and unresolved references.

Fixes #1146

Validation:

  • Both new CLI regressions failed on the base; single-ID Webpack and merged-ID Rspack cases now pass.
  • npm run test:focused -- tests/boundary/cli/javascriptBundlerSelfReferences.test.ts tests/boundary/cli/javascriptSelfImportRelationships.test.ts tests/composition/javascript-applications/javascriptBundlerAdapters.test.ts tests/boundary/cli/javascriptApplicationJsonOutput.test.ts tests/boundary/cli/javascriptApplicationProgress.test.ts tests/boundary/filesystem/javascriptApplicationWorkflows.test.ts — 33 passed.
  • Built stdio MCP on the exact public one-file reproduction: valid graph, disclosed omission, all 138 tools discoverable, subsequent ping succeeds, no server stderr.
  • npm run build:cached, npm run check:fast, git diff --check — passed.

No tool-schema or inventory changes. No Hopper/Ghidra runtime changes or real-provider claims for this fix.

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

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Adjacent case this PR doesn't cover yet: a bundled module that requires its own module key fails the same invariant through the static-reference composer (addReference in JavaScriptArtifactGraphFindings.ts), not the bundler runtime edges.

Repro on this branch (built at fix/javascript-bundler-self-reference), one file 5.js:

"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[5],{50(e,t,r){r(50)}}]);

analyze-javascript-application <dir> --json → unreadable_output, Result schema rejected 1 issue at /edges/1 (custom). resolveReference returns module 50 as the target of module 50's own reference.

I'd opened #1153 for #1146 a few minutes after this one. It covers the async-chunk case and this one, skipping resolved?.node.node_id === source.node_id in addReference and disclosing "N static reference(s) resolved back to the referencing module itself…". I'm closing #1153 as a duplicate so this PR stays the fix for #1146. If you'd rather not fold the static-reference case in here, I'll send it as a small follow-up after this merges. I also checked self-spawning workers, self dynamic imports, HTML <script src> to its own document, self sourceMappingURL and CommonJS self-require: none of those produce self-edges.

@N0zoM1z0 N0zoM1z0 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer self-review: only chunk-to-itself composition is omitted; raw AST keys/source ranges, module relationships, sibling edges and unresolved references remain available, with counted limitations propagated to the result. Both base regressions failed; 33 focused tests and the exact public reproduction through built stdio MCP passed. Build/static checks and all 22 exact-head CI checks passed. No blocking findings.

@N0zoM1z0
N0zoM1z0 merged commit 7220166 into main Oct 9, 2026
22 checks passed
@N0zoM1z0
N0zoM1z0 deleted the fix/javascript-bundler-self-reference branch October 9, 2026 01:37
kaoru0822-kitauji added a commit that referenced this pull request Oct 9, 2026
The self-import (#1130), async-chunk (#1152) and static-reference
disclosures repeated one sentence template in three composers, and the
new test repeated the analyze-and-check sequence of its neighbour. That
put jscpd at its 2.5% threshold. Share the template through
selfReferenceOmissions with identical wording, and share one test helper
for the graph-wide self-reference invariants.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
N0zoM1z0 pushed a commit that referenced this pull request Oct 9, 2026
…ure (#1157)

* fix(javascript): omit self-referential static references with disclosure

A bundled module that requires its own key (`r(50)` inside webpack
module 50) resolved, through the static-reference composer, to its own
module node. The resulting self-referential imports edge failed result
validation and lost the entire analysis ("Result schema rejected 1
issue ... (custom)"). This is the same invariant as #1146; #1152 fixed
the bundler async-chunk composer, and this is the remaining adjacent
composer.

Skip a reference whose resolved target is its own source, count it, and
disclose the omission the way #1152 discloses async-chunk references.
Sibling requires are kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(javascript): share the self-reference omission disclosure

The self-import (#1130), async-chunk (#1152) and static-reference
disclosures repeated one sentence template in three composers, and the
new test repeated the analyze-and-check sequence of its neighbour. That
put jscpd at its 2.5% threshold. Share the template through
selfReferenceOmissions with identical wording, and share one test helper
for the graph-wide self-reference invariants.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…ure (morluto#1157)

* fix(javascript): omit self-referential static references with disclosure

A bundled module that requires its own key (`r(50)` inside webpack
module 50) resolved, through the static-reference composer, to its own
module node. The resulting self-referential imports edge failed result
validation and lost the entire analysis ("Result schema rejected 1
issue ... (custom)"). This is the same invariant as morluto#1146; morluto#1152 fixed
the bundler async-chunk composer, and this is the remaining adjacent
composer.

Skip a reference whose resolved target is its own source, count it, and
disclose the omission the way morluto#1152 discloses async-chunk references.
Sibling requires are kept.


* refactor(javascript): share the self-reference omission disclosure

The self-import (morluto#1130), async-chunk (morluto#1152) and static-reference
disclosures repeated one sentence template in three composers, and the
new test repeated the analyze-and-check sequence of its neighbour. That
put jscpd at its 2.5% threshold. Share the template through
selfReferenceOmissions with identical wording, and share one test helper
for the graph-wide self-reference invariants.


---------
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] analyze_javascript_application fails result validation when a webpack chunk lazily requests its own chunk id

3 participants