Skip to content

test(javascript): preserve member-alias fanout and loop regressions - #1414

Closed
akushonkamen wants to merge 4 commits into
morluto:mainfrom
akushonkamen:fix-1401
Closed

akushonkamen wants to merge 4 commits into
morluto:mainfrom
akushonkamen:fix-1401

Conversation

@akushonkamen

@akushonkamen akushonkamen commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Retain useful member-mutation regression coverage after the fixed-point propagation fix merged in #1390. Preserve the contributor's twelve-member reassignment-loop test and add compiled public CLI coverage for writes and escapes across eight, nine, and twelve conditional alias branches. Both the first and last affected children must remain unknown, while an unrelated sibling remains literal with complete projected return-shape coverage.

Review reproduced an accuracy defect in this PR's former eight-arrival cap: a 1,218-byte, source-owned JavaScript target with nine alias branches reported an affected child's return value as literal 1, with complete coverage. The same public CLI input on main 4d95f2b2 correctly reports unknown. Eight branches pass; nine and twelve fail on the capped implementation. Simply integrating main still retained the cap, so the follow-up removes that superseded runtime change and uses main's existing fixed-point owner unchanged. Overlapping module regressions already covered by main and the stronger CLI workflow are removed.

The final diff adds tests only. It does not reintroduce a propagation cap, change default Evidence, or claim a new runtime performance improvement. Contributor commits are preserved through a normal merge and follow-up.

Validation:

  • Independently compiled the original PR and latest frozen main, then ran the same inert directory targets through the public CLI. No target application code was executed. Compared exact projected export return shapes, including value status and coverage, rather than just successful exit codes.
  • New public CLI regression: eight branches passed and nine/twelve failed with the retained cap before the follow-up. All three now pass for write/escape effects, affected first/last children, and unaffected siblings. All 377 tests in eight semantic/CLI suites pass, including the contributor's retained twelve-member loop.
  • Full runtime compilation, full typechecking, lint/module boundaries, changed-file formatting and whitespace checks pass. Used the pinned compiler's documented --singleThreaded and the exact focused Vitest files serially under the local two-CPU and 2 GiB process-family budget; the focused lane peaked at 1.10 GiB, typechecking at 1.36 GiB. Test-discovery verification confirms all 704 test files are discovered exactly once, including the new boundary file.
  • No native-provider or private application verification is claimed. Final published-head CI must pass before merge.

Refs #1401 and #1065. Prepared with AI assistance.

…ignment loops

A loop that reassigns one reference through k members reached every
injective member ordering because the cycle guard in markValue kept a
per-path lifetime set. Expanding each (binding, effect, mutation,
origin) state once bounds the traversal while every arrival still
records its own effect, so no fact is added or widened.

Fixes morluto#1401
Related morluto#1387
@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.

@N0zoM1z0

Copy link
Copy Markdown
Collaborator

I reproduced a missing effect on head 8a95fecce1b2dab5204fee02203ee60a0fbb45a2. Skipping initializer expansion by binding/site without including the reached path can leave a genuinely affected child literal:

export function result() {
  const left = { value: 1 };
  const right = { value: 2 };
  const source = { left, right };
  const alias = flag ? source.left : source.right;
  alias.value = 2;
  return left.value;
}

analyzeJavaScriptSemantics reports unknown on 7aa4d768, but literal 1 with this PR's collector. Replacing the write with mutate(alias) has the same regression. right.value remains unknown because that path is expanded first; reversing the branches changes which child is missed. These are static analyses, without executing the target.

The two arrivals reach the same binding/capture state with different paths. Recording both paths on source does not propagate the skipped path into the separately bound left object. Thus removing traversal can introduce false certainty even though no key is widened. Please preserve both affected children in addition to the unaffected sibling cases before merging.

I am maintaining the #1390 follow-up for #1401 and have retained its author's second commit and new write-depth regressions. The current follow-up passes these cases and the existing semantic suite; full CLI/MCP verification is being refreshed against current main. #1387 still has no confirmed common cause.

…budget

Collapsing every arrival of an alias state into its first expansion dropped
genuinely affected child literals: two arrivals that differ only in path can
select different children out of the same initializer (a conditional alias
walking source.left versus source.right), so the skipped path never reached
its child. Each distinct arrival path now expands, and only an alias state
whose expansion budget is saturated skips further replay, which keeps
reassignment loops polynomial.
@akushonkamen

Copy link
Copy Markdown
Contributor Author

Fixed in af1c093 — thank you for the precise reproducer.

Root cause of the regression: the expansion dedupe keyed an alias state by (binding, effect, mutation, origin) alone. The two arrivals behind flag ? source.left : source.right reach source with the same state key but different paths (["right", "value"] vs ["left", "value"]), and the path is what selects the child out of source's object initializer. The first arrival expanded and marked right; the second recorded its own effect on source but skipped the initializer walk, so left was never reached and left.value kept its literal. Replacing the write with mutate(alias) fails the same way.

Fix: the collector now expands every distinct arrival path — arrivals are already deduplicated by their recorded identity, which includes the path, so a novel arrival is a novel walk — and only bounds the replayed expansions per alias state (MAX_EXPANSIONS_PER_ALIAS_STATE = 8, expansionBudgets map). A k-member reassignment loop saturates each state after a constant number of expansions, so the polynomial loop bound holds.

Evidence on af1c093:

  • Your three cases — member write, mutate(alias), and reversed branches — now report unknown for the previously missed child. Added as three tests in javascriptSemanticAnalysis.member_mutations.test.ts; all three fail on 8a95fec and pass here. The three unrelated-member cases still pin literal 3.
  • Loop benchmark unchanged: 8 members 26 ms, 9 members 8 ms, 10 members 7 ms, 12 members 8 ms, 16 members 10 ms, status unknown at every size (Node 24.14.0, macOS arm64).
  • Subset src/domain/javascript src/application/javascript tests/composition/javascript-applications: 61 files, 1,020 tests passed. npm run check:fast, npm run verify:test-discovery (701 files), and oxfmt --check on the changed files pass.

One adjacent observation I left alone because it is pre-existing: with

const inner = { q: 1, r: 2 };
const box = { p: inner };
const alias = box;
mutate(alias.p.q, alias.p.r);
return inner.r;

the result is literal 2 on the base 499e2f5 as well — the walk already reaches inner with both tails there, but the escape does not invalidate the slot. It looked close to your write-depth work, so I am flagging it here rather than pinning it in this PR.

(This fix was prepared with AI assistance.)

@N0zoM1z0 N0zoM1z0 changed the title fix(javascript): dedupe member-mutation alias expansion through reassignment loops test(javascript): preserve member-alias fanout and loop regressions Oct 10, 2026
@N0zoM1z0

Copy link
Copy Markdown
Collaborator

The original two-path reproducer is fixed in af1c093, but the new eight-expansion cap still drops observed effects when a conditional alias has nine distinct paths. This does not require a loop:

export function result() {
  const c0 = { value: 0 }, c1 = { value: 1 }, c2 = { value: 2 };
  const c3 = { value: 3 }, c4 = { value: 4 }, c5 = { value: 5 };
  const c6 = { value: 6 }, c7 = { value: 7 }, c8 = { value: 8 };
  const source = { m0:c0, m1:c1, m2:c2, m3:c3, m4:c4, m5:c5, m6:c6, m7:c7, m8:c8 };
  const alias = flag===0 ? source.m0 : flag===1 ? source.m1 :
    flag===2 ? source.m2 : flag===3 ? source.m3 : flag===4 ? source.m4 :
    flag===5 ? source.m5 : flag===6 ? source.m6 : flag===7 ? source.m7 : source.m8;
  alias.value = 99;
  return c0.value;
}

This reports literal 0 on af1c093; the eight-path control reports unknown. mutate(alias) instead of the write also misses c0. A fixed replay ceiling silently loses facts, so it cannot establish sound bounded analysis without explicit incomplete coverage and uncertainty for the omitted paths.

#1390 has now merged as 28595276 after all 20 final-head checks passed, with exact-path propagation, write-depth regressions and real CLI/MCP Notion verification. #1401 is resolved by that change. Please do not merge this alternative ceiling over the completed fix.

The adjacent mutate(alias.p.q, alias.p.r) example passes primitive numbers, so preserving inner.r is expected in the reference model: the called function receives neither inner nor a property reference. mutate(alias.p) is the container-escape control.

@akushonkamen

Copy link
Copy Markdown
Contributor Author

Withdrawing in favor of #1390, which merged as 28595276 and resolves #1401 — thanks for landing the completed fix.

Agreed on the nine-path reproducer: a fixed replay ceiling silently drops observed effects for any arrival beyond the cap, so it cannot establish sound bounding without explicitly marking omitted paths as uncertain. Exact-path propagation is the right shape, and it keeps the reassignment-loop bound polynomial at the same time. Also fair on mutate(alias.p.q, alias.p.r): the call receives primitives, so inner.r keeping its literal is correct in the reference model (mutate(alias.p) being the container-escape control).

Thanks for the precise reproducers throughout — the two-path conditional case and the nine-way fanout cleanly isolated the semantics. Keeping the branch on the fork for reference.

(Prepared with AI assistance, consistent with the earlier comments on this PR.)

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: af1c093 fixes 14 of the 17 wrong values I found on the first commit. That includes the two-argument call and the maintainer's case. Two kinds still go wrong: a short write loop and a nested loop. The merged #1390 gets all of these right. This PR closed, so this is for the record.

Still wrong on af1c093

const i0 = { v: 1 }; const i1 = { v: 1 }; const i2 = { v: 1 };
const seed = { m0: i0, m1: i1, m2: i2 };
let node = seed;
let k = 0;
while (k++ < 1) {
  if (flag === 0) node = node.m0;
  else if (flag === 1) node = node.m1;
  else if (flag === 2) node = node.m2;
  node.v = 2;
}
return i0.v;

Real JS gives 2 when flag is 0. af1c093 says literal 1. Main says unknown. Two members are fine. From three members on, most children go wrong. That is far below the cap of 8. The nested form of the #1401 loop is also still literal "initial".

The nine-way case from the maintainer reproduces here too. Nine call arguments do the same thing.

Results

check Node 22 Node 24 Node 26
changed tests 240 of 240 240 of 240 240 of 240
new tests on main not run 158 of 158 not run
wrong of my first 55 not run 4 (main: 1) not run
wrong of 48 new cases not run 35 (main: 0) not run
#1401 loop, k = 12 40 ms 29 ms 29 ms

The one wrong case on main is the for...of one. It is #1428 now, and #1437 fixes it.

Not run

Thanks, akushonkamen, for the quick fix and the clear write-up. The cause you named matched what I saw.

All cases

Real JS ran each body many times, with flag set to each test value. mutate and use overwrite each plain field they get. "03a960eb" is the last #1390 head.

case main af1c093 03a960e real JS
loopN_iX, N = 2 unknown unknown unknown 1, 2
loopN_iX, N = 3 unknown 2 of 3 wrong unknown 1, 2
loopN_iX, N = 4 to 7 unknown all wrong unknown 1, 2
loop8_i0, loop9_i0 timeout literal 1 unknown 1, 2
wide_loop, 10 members timeout 3 of 3 wrong unknown 1, 2
args8_last unknown unknown unknown "M"
args9_last unknown literal 8 unknown "M"
wide_args, 10 args unknown last 2 wrong unknown "M"
tern8_first unknown unknown unknown 0, 99
tern9_first unknown literal 0 unknown 0, 99
wide_ternary, 10 ways unknown first wrong unknown value, 99
gen-nested-3, 6 unknown literal "initial" unknown "initial", "M"
gen-nested-8 out of memory literal "initial" unknown "initial", "M"
forof_two literal 1 literal 1 literal 1 2
other 51 of the first 55 no wrong value no wrong value no wrong value

The 14 cases fixed since the first commit:

  • two_args_right
  • n0z_left_write, n0z_left_mutate, n0z_right_write_swapped
  • short_first, deep_short_first, deep_same_len
  • logical_short_first, forof_short, loop_write
  • loop_distinct_inner0, loop_distinct_inner1
  • loop_order_m1m0, loop_order_leaf10

The six facts the first commit kept are still kept. 03a960e keeps them too.

Timings

This is the #1401 loop with k members. Times are the analysis alone, median of 3. Load was about 9 to 10 from other jobs, so these are rough.

k Node 22 Node 24 Node 26
6 33 ms 23 ms 23 ms
9 37 ms 26 ms 26 ms
12 40 ms 29 ms 29 ms

Every run said unknown. af1c093 and 03a960e took turns, 3 runs each, on Node 24:

input af1c0939 03a960eb
write loop, k = 9 29 ms 23 ms
write loop, k = 12 32 ms 25 ms
Hermes Desktop (MIT) React chunk 2.9 s, 458 MiB 1.5 s, 393 MiB

Both give the same output on the chunk. Both say literal "initial" on the write loop.

Next to #1390

#1390 merged first and closed #1401. Its last head was 03a960e. On every case here, 03a960e gives no wrong value but the old for...of one. I did not test the merge commit itself.

Commands
# each case: analyzeJavaScriptSemantics from the built dist/
node --max-old-space-size=3000 run.mjs <tree> file <case>.js

# loop timing, k = 6 to 12
node --max-old-space-size=3000 run.mjs <tree> loop <k>

# chunk, the two heads taking turns
node --max-old-space-size=5000 run.mjs <tree> module vendor-react-C4pS_tun.js

# changed tests
node node_modules/vitest/vitest.mjs run \
  src/domain/javascript/javascriptSemanticAnalysis.member_mutations.test.ts \
  src/domain/javascript/javascriptSemanticAnalysis.reference_lifetimes.test.ts

Every run used nice -n 10 and a 120 s cap.

Test setup

🤖 Generated with Claude Code (Opus 5.5) 🦊

@morluto morluto added the area: tests Test suite and verification label Oct 14, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks, @akushonkamen, for the concrete alias-fanout reproducers that exposed how deduplication could hide real writes. Main now preserves those path-sensitive effects while bounding reassignment-loop expansion (main).

@akushonkamen
akushonkamen deleted the fix-1401 branch October 25, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tests Test suite and verification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants