[PR #4716] fix(javascript): bound alias-cycle call-target and returned-reference expansion #6368

Open
opened 2026-10-31 01:13:55 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/4716
Author: @ericbyz
Created: 10/17/2026
Status: 🔄 Open

Base: main ← Head: fix/javascript-alias-cycle-expansion


📝 Commits (2)

  • 418bf0b fix(javascript): bound alias-cycle call-target and returned-reference expansion
  • 2139d9b fix(javascript): keep degraded expansions conservative and settle scans bounded

📊 Changes

4 files changed (+348 additions, -163 deletions)

View changed files

📝 src/domain/javascript/javascriptSemanticCallResolution.test.ts (+130 -2)
📝 src/domain/javascript/javascriptSemanticCallResolution.ts (+154 -32)
📝 src/domain/javascript/javascriptSemanticCalls.ts (+5 -1)
📝 src/domain/javascript/javascriptSemanticReturnedReferences.ts (+59 -128)

📄 Description

Summary

Fixes #4348. analyze-javascript-application exhausted the owned JavaScript worker heap on React bundles (playwright-core@1.58.2 recorder/trace-viewer assets) since #4243; the same files analyzed in about 1.5 s before it. Both explosion sites named in the issue are bounded now: alias-cycle call-target resolution and the returned-reference expansion.

Problem and expected behavior

  • Call-target resolution: #4243 moved cycle cuts to initializer identity and correctly stopped memoizing cycleDependent results. Every read of a binding inside an alias cluster therefore re-enumerated initializer orders — an exponential simple-path search, repeated per call site.
  • Returned references: the same clusters were re-walked with path-scoped blocker contexts; the number of minimal blocker contexts per (expression, projection) multiplies combinatorially. Instrumented run: one callee in index-BhTWtUlo.js reached 3.7M task pops before the 4 GiB worker heap died.

Expected: bundle analysis completes with results equal on all acyclic and pinned cyclic shapes.

Change and scope

  • javascriptSemanticCallResolution.ts: resolution now runs a per-binding fixpoint. Expansion still cuts at re-entry (unchanged first-cut behavior), but cut results become provisional per binding and recompute monotonically until a pass changes nothing, then settle. The settled per-binding candidate set is canonical, so warm and cold resolutions agree (the "does not memoize alias cycle cuts across entry paths" semantics are preserved and its union reachability — e.g. fallback reachable through b → a → conditional — still resolves), and per-read results are deterministic, so they cache again.
  • javascriptSemanticReturnedReferences.ts: the blocker-context/frame machinery is replaced by a single expansion that visits each (expression, projection) pair once, and past a per-callee expansion budget (20k expansions) — or a 128-entry projection cap — degrades to unknown-projection navigation instead of dropping the branch (over-approximation). Degradation is an over-approximation: every function reachable at the empty projection is still reported, which stays on the conservative side for the only consumer (markEscaped in the member-mutation pass). Acyclic and small-cluster results are unchanged.
  • javascriptSemanticCalls.ts: one resolution memory per collection pass (replaces the per-call-site seenInitializers); settlement tracks provisional bindings in a dedicated set, so cycle-free files pay O(1) per call site.

Not included: precision recovery for wildcard-degraded clusters (only reachable on inputs that already exhausted the old expansion), and any change to reference/callable shapes.

Follow the contribution scope: not applicable — static-analysis-only fix, no provider/capability change.

Contract and boundary impact

  • Semantic owner and earliest changed stage: JavaScript semantic derived analysis; first affected stage is call-site/member-mutation collection over an indexed source.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: none; analyze-javascript-application inputs/outputs unchanged.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata/package impact: none.

Expected effects:

  • Read existing files or captured data.

Evidence and regression coverage

  • Tests added or updated (the scaling assertions fail on unchanged main; the semantic assertions pass on it):
    • "bounds alias-cycle initializer chains to the settled fixpoint" — pins warm≡cold and cycleDependent union results on the issue's alternating-write chain, and bounds scope lookups at depth 12 under 3× depth 8 (old code: exponential, 5.1 s at depth 12).
    • "bounds projecting alias-cycle expansion in returned references" — pins non-empty references through a projecting alias cycle and the same 3× lookup bound.
    • "degrades over-deep projections to unknown selection instead of dropping them" — 130-deep destructuring projection keeps its reference (review finding 1).
    • "keeps class members reachable when expansion degrades to unknown projections" — 20,001-alias chain past the expansion budget keeps C.make() reachable (review finding 2).
  • Base reproduction (executed, Windows 11, Node 22.23.3):
    • Synthetic chain, semantic phase in-process: depth 8/10/12 = 11 ms / 100 ms / 5,146 ms before; 1.4 / 0.3 / 0.2 ms after.
    • analyze-javascript-application on index-BhTWtUlo.js (363,108 B, SHA-256 c909272a…, matches the issue) and defaultSettingsView-CJSZINFr.js (640,870 B, SHA-256 212b6c02…): both exhaust the heap on unchanged main ("Owned JavaScript worker exhausted its heap"); both complete with sealed graphs and terminal: true on this branch (~19–46 s wall incl. worker startup).
    • Instrumented expansion of the exploding callee: 3.7M+ pops before OOM on unchanged main; bounded budget after.
  • Remaining proof gaps: results equality is proven by the existing 2,114 domain tests plus the two new scaling tests, not by an independent oracle; wildcard degradation precision is only exercised by inputs that previously exploded, so no user-visible before/after output exists for that mode.

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

  • npx vitest run src/domain/javascript — 80 files / 2,117 tests pass (includes the review-follow-up commit 2139d9b2a).
  • npx vitest run tests/acceptance/applications — 265 passed / 4 failed; the same 4 tests fail identically on unchanged main (verified by stashing this diff and rerunning the three files: 4 failed / 1 passed both ways).
  • npm run lint — 0 errors (3,902 pre-existing warnings).
  • npx tsc --noEmit -p tsconfig.json — clean.
  • npm run check:fast (pre-push) — passed.
  • Full npx vitest run (1,465 files) — 15,324 passed / 631 failed; failures concentrate in unrelated subsystems (adb, ghidra, hopper, gdb, cutter, wasm, install script — this Windows box lacks the toolchains; e.g. installScript 35/35, sourceToBundlePaths 52/58 fail on their own). Cross-checked the impact zone against unchanged main as above; unrelated subsystems were not re-baselined on clean main.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable to this change; Windows-only run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: not applicable.

Author readiness

Human owner: @ericbyz

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

(Left unchecked for the human owner per CONTRIBUTING — this PR was prepared with AI assistance.)

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/4716 **Author:** [@ericbyz](https://github.com/ericbyz) **Created:** 10/17/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/javascript-alias-cycle-expansion` --- ### 📝 Commits (2) - [`418bf0b`](https://github.com/morluto/rea/commit/418bf0b6371273e41175c04b3c3b849c7b12f40d) fix(javascript): bound alias-cycle call-target and returned-reference expansion - [`2139d9b`](https://github.com/morluto/rea/commit/2139d9b2a59a3f0eaa20181ce0898e971fb182e1) fix(javascript): keep degraded expansions conservative and settle scans bounded ### 📊 Changes **4 files changed** (+348 additions, -163 deletions) <details> <summary>View changed files</summary> 📝 `src/domain/javascript/javascriptSemanticCallResolution.test.ts` (+130 -2) 📝 `src/domain/javascript/javascriptSemanticCallResolution.ts` (+154 -32) 📝 `src/domain/javascript/javascriptSemanticCalls.ts` (+5 -1) 📝 `src/domain/javascript/javascriptSemanticReturnedReferences.ts` (+59 -128) </details> ### 📄 Description ## Summary Fixes #4348. `analyze-javascript-application` exhausted the owned JavaScript worker heap on React bundles (playwright-core@1.58.2 recorder/trace-viewer assets) since #4243; the same files analyzed in about 1.5 s before it. Both explosion sites named in the issue are bounded now: alias-cycle call-target resolution and the returned-reference expansion. ## Problem and expected behavior - Call-target resolution: #4243 moved cycle cuts to initializer identity and correctly stopped memoizing `cycleDependent` results. Every read of a binding inside an alias cluster therefore re-enumerated initializer orders — an exponential simple-path search, repeated per call site. - Returned references: the same clusters were re-walked with path-scoped blocker contexts; the number of minimal blocker contexts per (expression, projection) multiplies combinatorially. Instrumented run: one callee in `index-BhTWtUlo.js` reached 3.7M task pops before the 4 GiB worker heap died. Expected: bundle analysis completes with results equal on all acyclic and pinned cyclic shapes. ## Change and scope - `javascriptSemanticCallResolution.ts`: resolution now runs a per-binding fixpoint. Expansion still cuts at re-entry (unchanged first-cut behavior), but cut results become provisional per binding and recompute monotonically until a pass changes nothing, then settle. The settled per-binding candidate set is canonical, so warm and cold resolutions agree (the "does not memoize alias cycle cuts across entry paths" semantics are preserved and its union reachability — e.g. `fallback` reachable through `b → a → conditional` — still resolves), and per-read results are deterministic, so they cache again. - `javascriptSemanticReturnedReferences.ts`: the blocker-context/frame machinery is replaced by a single expansion that visits each (expression, projection) pair once, and past a per-callee expansion budget (20k expansions) — or a 128-entry projection cap — degrades to unknown-projection navigation instead of dropping the branch (over-approximation). Degradation is an over-approximation: every function reachable at the empty projection is still reported, which stays on the conservative side for the only consumer (`markEscaped` in the member-mutation pass). Acyclic and small-cluster results are unchanged. - `javascriptSemanticCalls.ts`: one resolution memory per collection pass (replaces the per-call-site `seenInitializers`); settlement tracks provisional bindings in a dedicated set, so cycle-free files pay O(1) per call site. Not included: precision recovery for wildcard-degraded clusters (only reachable on inputs that already exhausted the old expansion), and any change to reference/callable shapes. Follow the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope): not applicable — static-analysis-only fix, no provider/capability change. ## Contract and boundary impact - Semantic owner and earliest changed stage: JavaScript semantic derived analysis; first affected stage is call-site/member-mutation collection over an indexed source. - Contribution scope fit and linked maintainer decision: not applicable. - CLI and MCP/tool-catalog contract: none; `analyze-javascript-application` inputs/outputs unchanged. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: none. - Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable. - Generated metadata/package impact: none. Expected effects: - [x] Read existing files or captured data. ## Evidence and regression coverage - Tests added or updated (the scaling assertions fail on unchanged main; the semantic assertions pass on it): - "bounds alias-cycle initializer chains to the settled fixpoint" — pins warm≡cold and `cycleDependent` union results on the issue's alternating-write chain, and bounds scope lookups at depth 12 under 3× depth 8 (old code: exponential, 5.1 s at depth 12). - "bounds projecting alias-cycle expansion in returned references" — pins non-empty references through a projecting alias cycle and the same 3× lookup bound. - "degrades over-deep projections to unknown selection instead of dropping them" — 130-deep destructuring projection keeps its reference (review finding 1). - "keeps class members reachable when expansion degrades to unknown projections" — 20,001-alias chain past the expansion budget keeps `C.make()` reachable (review finding 2). - Base reproduction (executed, Windows 11, Node 22.23.3): - Synthetic chain, semantic phase in-process: depth 8/10/12 = 11 ms / 100 ms / **5,146 ms** before; 1.4 / 0.3 / **0.2 ms** after. - `analyze-javascript-application` on `index-BhTWtUlo.js` (363,108 B, SHA-256 `c909272a…`, matches the issue) and `defaultSettingsView-CJSZINFr.js` (640,870 B, SHA-256 `212b6c02…`): both exhaust the heap on unchanged main ("Owned JavaScript worker exhausted its heap"); both complete with sealed graphs and `terminal: true` on this branch (~19–46 s wall incl. worker startup). - Instrumented expansion of the exploding callee: 3.7M+ pops before OOM on unchanged main; bounded budget after. - Remaining proof gaps: results equality is proven by the existing 2,114 domain tests plus the two new scaling tests, not by an independent oracle; wildcard degradation precision is only exercised by inputs that previously exploded, so no user-visible before/after output exists for that mode. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npx vitest run src/domain/javascript` — 80 files / 2,117 tests pass (includes the review-follow-up commit 2139d9b2a). - `npx vitest run tests/acceptance/applications` — 265 passed / 4 failed; the same 4 tests fail identically on unchanged main (verified by stashing this diff and rerunning the three files: 4 failed / 1 passed both ways). - `npm run lint` — 0 errors (3,902 pre-existing warnings). - `npx tsc --noEmit -p tsconfig.json` — clean. - `npm run check:fast` (pre-push) — passed. - Full `npx vitest run` (1,465 files) — 15,324 passed / 631 failed; failures concentrate in unrelated subsystems (adb, ghidra, hopper, gdb, cutter, wasm, install script — this Windows box lacks the toolchains; e.g. `installScript` 35/35, `sourceToBundlePaths` 52/58 fail on their own). Cross-checked the impact zone against unchanged main as above; unrelated subsystems were not re-baselined on clean main. ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: not applicable to this change; Windows-only run. - Package or release metadata impact: none. - Security, privacy, process, or containment review: not applicable. ## Author readiness Human owner: @ericbyz - [ ] 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. (Left unchecked for the human owner per CONTRIBUTING — this PR was prepared with AI assistance.) ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6368
No description provided.