Repository navigation
fix(javascript): stop widened alias joins from exhausting the worker heap - #8392
arjunprabhulal wants to merge 1 commit into
Conversation
…heap Static analysis of the public react-dom 18.3.1 production UMD build (132 KB) exhausts the JavaScript worker's 1024 MiB heap during the static stage, so the file is skipped. Its minified update-queue drain alone (1,367 bytes) reproduces the failure. collectSemanticMemberMutationsSteps widens markValue's alias traversal after SEMANTIC_ALIAS_SELECTION_LIMIT alternatives and records alias-selections, but the widened joins are keyed by path depth and capture vector. Reassigned linked-list cursors add a different segment on each alias lap, so the key set grows without bound and the worklist passes 500,000 entries. Widened joins now share the same budget. When it is exhausted, markValue stops the precise walk and escapes the receiver, which covers every omitted longer effect, as the getter-expansion fallback already does.
[Medium impact] The change affects JavaScript static-analysis results within a bounded analysis workflow. The PR appears safe to merge, with a non-blocking test gap around the escape fallback. Findings
Fix with agent prompt### Issue 1
src/domain/javascript/javascriptMemberMutationCoverage.test.ts:130-138
This test checks completion and `alias-selections`, but the existing widening branch already records that limit before `joinsExhausted` fires. Removing the new escape fallback could therefore leave this test green while dropping mutation effects. Add a focused assertion that exhausting widened joins records an empty-path escape on the original receiver.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryBounds widened joins in
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Walk exact alias selections] --> B{Selection budget exceeded?}
B -- No --> A
B -- Yes --> C[Disclose alias-selections]
C --> D[Walk widened joins]
D --> E{Join budget exceeded?}
E -- No --> D
E -- Yes --> F[Stop current walk]
F --> G{Already an empty-path escape?}
G -- No --> H[Retry receiver with empty-path escape]
G -- Yes --> I[Return partial facts]
H --> I
Reviews (1) · Last reviewed commit: "fix(javascript): stop widened alias join..." · Reviewed by Greptile |
| it("bounds widened alias joins on a growing linked-list cycle", () => { | ||
| const facts = analyzeJavaScriptStaticSource(growingAliasCycleSource); | ||
| expect(facts.parse_status).not.toBe("failed"); | ||
| expect( | ||
| facts.analysis_coverage?.examination.semantic_resource_limits, | ||
| ).toContain("alias-selections"); | ||
| expect(facts.limitations).toContain( | ||
| semanticResourceLimitReason("alias-selections"), | ||
| ); |
There was a problem hiding this comment.
Escape fallback goes unchecked
This test checks completion and alias-selections, but the existing widening branch already records that limit before joinsExhausted fires. Removing the new escape fallback could therefore leave this test green while dropping mutation effects. Add a focused assertion that exhausting widened joins records an empty-path escape on the original receiver.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptMemberMutationCoverage.test.ts
Line: 130-138
Comment:
**Escape fallback goes unchecked**
This test checks completion and `alias-selections`, but the existing widening branch already records that limit before `joinsExhausted` fires. Removing the new escape fallback could therefore leave this test green while dropping mutation effects. Add a focused assertion that exhausting widened joins records an empty-path escape on the original receiver.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
TL;DR: The PR's changed test file passed all 24 tests on three Node versions. With the source file put back to the merge base, 1 test failed on each version. In the red run, that test hit the 30-second timeout on all three versions.
Not run
Test setupCommandsnpm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/domain/javascript/javascriptMemberMutationCoverage.test.ts🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊 |
Summary
analyze_javascript_applicationexhausts the JavaScript worker's 1024 MiB heap on the public react-dom 18.3.1 production UMD build (131,835 bytes) and skips the file, so the application graph is empty. React's minified update-queue drain alone (1,367 bytes) reproduces the failure. With this change the heap stays bounded, the file is parsed and thealias-selectionslimitation is disclosed. The full react-dom file still reaches the 300 s default analysis timeout after the static stage, so this is a partial fix for the report.Refs #8294. Related: #6127, #6344.
Problem and expected behavior
collectSemanticMemberMutationsStepswidensmarkValue's alias traversal afterSEMANTIC_ALIAS_SELECTION_LIMIT(512) alternatives and recordsalias-selections, documented as "maximum 512 additional selector states". After widening, joins are keyed by[context, captures], where the context includes the path depth. Reassigned linked-list cursors such asitem = item.next,other = other.next = {…}andlane = item, item = lane.nextadd a different segment on each alias lap. The exact-prefix cycle check never repeats, so the set of join keys grows without bound. Instrumenting one top-level.next = …write in react-dom showed the widened worklist passing 518,000 pending entries and more than 10,000 joined states, still growing, until the heap was exhausted.Expected: once the documented budget is exhausted, the traversal stops and the result is disclosed as limited, without exhausting the worker heap.
Change and scope
Widened joins now count against the same
SEMANTIC_ALIAS_SELECTION_LIMIT. When it is exhausted,markValuestops the precise walk and escapes the original receiver with an empty path. An escaped prefix already covers every longer write in this collector (see the existing self-alias and setter handling), and this mirrors thegetter-expansionfallback, which retries finitely after its bound. Unwidened queries, and queries that widen without exhausting the budget, are unchanged.Not included: the remaining time that keeps the full react-dom file over the 300 s default. Measured in-process on the patched build:
collectSemanticMemberMutationsStepsis about 111 s. There are 9,758 top-levelmarkValuequeries; 301 of them take 0.1–1 s each and none exceeds 1 s. Each one is bounded, but many spend their full budget.indexSemanticMemberMutationFactsStepsrunning again on the fresh state thatanalyzeParsedJavaScriptSemanticsStepscreates.possiblePath, about 30 s) andhasCommonJsModuleSource(about 11 s), both already bounded per query.Reusing one member-mutation index across the static and semantic stages would remove about 110 s, but it changes state ownership between the stages, so I have left it for a maintainer decision. Deduplicating non-identifier worklist entries across alias histories did not reduce time (169.6 s) and doubled peak heap, so it is not included. Contribution scope: an ordinary fix within existing boundaries; maintainer scope decision not applicable.
Contract and boundary impact
collectSemanticMemberMutationsSteps/markValuein member-mutation indexing (static and semantic stages). No consumer changes.alias-selectionsinsemantic_resource_limitsand limitations instead of a skipped file.docs/public/product-catalog.json), package, or installation impact: none.Expected effects:
Evidence and regression coverage
bounds widened alias joins on a growing linked-list cycleinsrc/domain/javascript/javascriptMemberMutationCoverage.test.tsuses a fixture with the same shape as the update-queue drain, written with independent names. It asserts that static analysis completes and disclosesalias-selections. With the source change reverted, it fails (Test timed out in 30000ms, 73.6 s). With the change, it passes in about 1.8 s.rea analyze-javascript-application <dir> --detail summary --evidence_output <bundle>on[email protected]/umd/react-dom.production.min.js(sha25635f4f974f4b2bcd44da73963347f8952e341f83909e4498227d4e26b98f66f0d) took 33.2 s and returnedparsed_javascript_files: 0,skipped_javascript_files: 1, with "Owned JavaScript worker exhausted its 1024 MiB V8 old-space heap (max_heap_mb) while analyzing react-dom.production.min.js during static". In-process, the extracted 1,367-byte drain function exhausts a 1024 MiB heap after about 21 s.parsed_javascript_files: 1,skipped_javascript_files: 0,semantic_resource_limits: ["alias-selections"], static facts retained (parse_status: "partial"), thenprovider_timeoutat the 300,000 ms default. The in-process static stage completed in about 186 s with about 520 MB of heap.alias-selectionsdisclosed. Not checked: Linux, Windows, Bun, or other React 18 bundles.For evidence-bearing changes:
Validation performed
npm run test:local -- <all 204 test files under src/domain/javascript, src/application/javascript, src/javascript>: 204 files, 5256 tests passed.npm run test:local -- src/domain/javascript/javascriptMemberMutationCoverage.test.ts src/domain/javascript/javascriptStaticCoverage.test.ts: 30 passed after rebasing onmain.Test timed out in 30000ms.npm run check:fast: typecheck and lint passed.Compatibility, safety, and release
Author readiness
Human owner: @arjunprabhulal
Before merge
type(scope): outcome.