Skip to content

fix(javascript): stop widened alias joins from exhausting the worker heap - #8392

Closed
arjunprabhulal wants to merge 1 commit into
morluto:mainfrom
arjunprabhulal:fix/javascript-bound-widened-alias-joins
Closed

arjunprabhulal wants to merge 1 commit into
morluto:mainfrom
arjunprabhulal:fix/javascript-bound-widened-alias-joins

Conversation

@arjunprabhulal

@arjunprabhulal arjunprabhulal commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

analyze_javascript_application exhausts 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 the alias-selections limitation 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

collectSemanticMemberMutationsSteps widens markValue's alias traversal after SEMANTIC_ALIAS_SELECTION_LIMIT (512) alternatives and records alias-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 as item = item.next, other = other.next = {…} and lane = item, item = lane.next add 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, markValue stops 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 the getter-expansion fallback, 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:

  • Static stage: about 165 s, of which collectSemanticMemberMutationsSteps is about 111 s. There are 9,758 top-level markValue queries; 301 of them take 0.1–1 s each and none exceeds 1 s. Each one is bounded, but many spend their full budget.
  • Semantic stage: 123.7 s, of which 109.8 s (89%) is indexSemanticMemberMutationFactsSteps running again on the fresh state that analyzeParsedJavaScriptSemanticsSteps creates.
  • Smaller contributors: Electron app-path changes (possiblePath, about 30 s) and hasCommonJsModuleSource (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

  • Semantic owner and earliest changed stage: collectSemanticMemberMutationsSteps / markValue in member-mutation indexing (static and semantic stages). No consumer changes.
  • Contribution scope fit and linked maintainer decision: ordinary fix; not applicable.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: affected sources now report alias-selections in semantic_resource_limits and limitations instead of a skipped file.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects:

  • 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 or updated: bounds widened alias joins on a growing linked-list cycle in src/domain/javascript/javascriptMemberMutationCoverage.test.ts uses a fixture with the same shape as the update-queue drain, written with independent names. It asserts that static analysis completes and discloses alias-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.
  • Base reproduction (executed, macOS arm64, Node 24.22.1): rea analyze-javascript-application <dir> --detail summary --evidence_output <bundle> on [email protected]/umd/react-dom.production.min.js (sha256 35f4f974f4b2bcd44da73963347f8952e341f83909e4498227d4e26b98f66f0d) took 33.2 s and returned parsed_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.
  • After the change (executed, same command): parsed_javascript_files: 1, skipped_javascript_files: 0, semantic_resource_limits: ["alias-selections"], static facts retained (parse_status: "partial"), then provider_timeout at the 300,000 ms default. The in-process static stage completed in about 186 s with about 520 MB of heap.
  • Remaining proof gaps: the full react-dom file still times out (see scope). After widening, the fallback escape can itself exhaust the budget. I counted 98 such fallbacks on react-dom, and in that case the walk stops with alias-selections disclosed. Not checked: Linux, Windows, Bun, or other React 18 bundles.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

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 on main.
  • Same regression file with only the source change reverted: the new test fails with Test timed out in 30000ms.
  • npm run check:fast: typecheck and lint passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; macOS arm64 only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: reduces worker memory use on untrusted input; no new process or I/O.

Author readiness

Human owner: @arjunprabhulal

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

…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.
@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P2 Escape fallback goes unchecked ▶
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.

Summary

Bounds widened joins in markValue and retries the original receiver as an empty-path escape when the budget runs out.

  • JavaScript analysis caps widened alias walks and reports the limit.

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
Loading

Reviews (1) · Last reviewed commit: "fix(javascript): stop widened alias join..." · Reviewed by Greptile

Comment on lines +130 to +138
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"),
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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!

@CassieFox23

Copy link
Copy Markdown
Contributor

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.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Head 3c39578, javascriptMemberMutationCoverage.test.ts pass: 1 of 1 files, 24 of 24 tests pass: 1 of 1 files, 24 of 24 tests pass: 1 of 1 files, 24 of 24 tests
Red run: javascriptSemanticMemberMutations.ts at merge base 6e9ee97 fail: 1 of 1 files, 1 failed, 23 passed fail: 1 of 1 files, 1 failed, 23 passed fail: 1 of 1 files, 1 failed, 23 passed
  • On all three Node versions, the failing test in the red run is bounds widened alias joins on a growing linked-list cycle.
  • That red failure is a timeout. Each log says Test timed out in 30000ms. On Node 24.22.1, the test ran 100310ms.
  • In the passing run on Node 24.22.1, the test bounds widened alias joins on a growing linked-list cycle took 2247ms.
  • The PR changes 2 files: src/domain/javascript/javascriptMemberMutationCoverage.test.ts and src/domain/javascript/javascriptSemanticMemberMutations.ts.
  • On head 3c39578, the CI, PR readiness and PR title workflow runs are completed/success.
  • 23 check runs are success, including Source tests, Static checks, Portable tests and Test shard (1/8) to Test shard (8/8).
  • 22 check runs are skipped.
  • The commit status PR readiness is pending.
  • The PR is a draft, with mergeable true and state unstable.
  • The head is 422 commits behind main 90c95a6.

Not run

  • A probe that counts widenedJoins against additionalAlternatives in javascriptSemanticMemberMutations.ts for one query. It would show whether the count can exceed the documented 512 limit.
  • A probe that exhausts the recursive fallback in javascriptSemanticMemberMutations.ts (the 98 cases). It would check whether the remaining alias paths get an escape mark.
  • A merge with current main, 90c95a6.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 3c39578 / 6e9ee97 (merge base with main)
  • Red run: 3c39578 with the changed source file from 6e9ee97
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1
Commands
npm 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 🦊

@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you for your work on this! Closing this PR as the target issue (#8294) has been closed as fixed via #11144 (d07ab79f9b), #11181 (0f53849160), #11187 (49ec3f67fe), and #14153 (c4916a6ff7), which bound member-mutation alias-state work and fall back on dense React alias clusters.

@morluto morluto closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants