Skip to content

fix(javascript): invalidate references stored through property targets - #1445

Merged
N0zoM1z0 merged 2 commits into
mainfrom
fix/javascript-stored-slot-aliases
Oct 10, 2026
Merged

N0zoM1z0 merged 2 commits into
mainfrom
fix/javascript-stored-slot-aliases

Conversation

@N0zoM1z0

@N0zoM1z0 N0zoM1z0 commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Later object/array-slot stores could leave shared.x reported as literal 1 after a write through the stored reference actually changed it to 2. Treat selected references stored through property targets as escapes using the existing semantic effect machinery. This covers ordinary/logical assignments, nested/destructured stores, and spread/rest copies without adding a slot execution model. Binding and store projections share the existing static object-pattern key rule; both regression journeys share a CLI/MCP fixture.

Copied primitive values, excluded object-rest keys/array-rest prefixes, and unrelated properties remain known. Reference stores are conservative: a read-only store may also become unknown; no stale literal is retained. CLI/MCP contracts and tool inventory are unchanged.

Validation:

  • Real compiled CLI and SDK stdio MCP acceptance: 33 slot-store variants, plus the existing 24 iteration-alias variants; text/structured Evidence parity and subsequent ping.
  • Source-owned runtime oracles and public MCP probes on Node 22.22.2 and 24.18.0.
  • Six adjacent semantic suites: 343 tests.
  • npm run check:ci (including duplication, unused-code and architecture guards), npm run check:fast, and npm run verify:test-discovery.

No native provider changes; real Hopper/Ghidra verification was not performed.

Closes #1442.

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

Reviewed final head 319c8a3. The existing escape machinery now covers later property stores, including logical/destructured assignments and rest-copy exclusions, without pretending to evaluate slot writes. Verified real CLI/stdio MCP (33 slot-store variants + 24 iteration variants), 343 adjacent semantic tests, Node 22/24 runtime/MCP probes, and typecheck/lint. Conservative unknowns for read-only stores are documented. Full CI is pending.

@N0zoM1z0 N0zoM1z0 added area: domain Domain logic, errors, and pure functions bug Something isn't working labels Oct 10, 2026

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

Reviewed final head c56a386. The escape fix covers later property stores while preserving scalar copies and excluded rest items; conservative read-only unknowns are documented. Shared rest-key selection and the CLI/MCP fixture remove duplicated rules/setup without weakening assertions. Real CLI/stdio MCP (33 store + 24 iteration variants), 343 adjacent tests, Node 22/24 probes, and the complete local check:ci pass. Final CI 38027911689 and Real JavaScript recovery 38027911705 both succeeded; all 20 check-runs are green, with no unresolved threads. Ready to merge.

@N0zoM1z0
N0zoM1z0 marked this pull request as ready for review October 10, 2026 05:47
@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
N0zoM1z0 merged commit e09cfe9 into main Oct 10, 2026
20 checks passed
@N0zoM1z0
N0zoM1z0 deleted the fix/javascript-stored-slot-aliases branch October 10, 2026 05:47
@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: This merged while I was testing, so this is a post-merge check. I tested head c56a3866, merged as e09cfe9b. Both have the same file tree. The fix works for my issue #1442. All 10 wrong forms now give an honest unknown. Three right answers also turn into unknown. I found one wrong form it doesn't catch. A function that returns shared still fools REA. That one breaks with no slot at all, so it's a separate bug.

The second commit only moves a helper. I built and tested c56a3866 from the start.

The 24 cases from #1442

Each case ran on Node 22, 24 and 26, through the CLI and MCP. Every cell matched across all six. Coverage says complete on every row.

Form Real JS base head
The 10 slot forms from the issue 2 1, wrong unknown
9 forms that were already honest 2 or 1 unknown unknown
o.a = { ...shared } and a fresh-only slot 1 1 1
o.a = shared; const y = o.a.x 1 1 unknown
o.a = shared; o.a = { x: 5 }; o.a.x = 2 1 1 unknown
o.a = shared; o.a = { x: 0 }; o.a.x = 2 1 1 unknown

So none of the 24 is wrong now. Three rows lose a right 1. The PR warns about the read-only one. The other two differ. There, shared goes in the slot, then a fresh object replaces it. The write only hits the fresh object. Still, unknown is safe, just careful.

New probes

I wrote 48 more probes and checked each in real JS. On base, 36 gave a wrong 1. On head, 30 of those turn unknown. The other 6 stay wrong, and all come from one source:

const shared = { x: 1 };
const get = () => shared;
get().x = 2;
return shared.x; // real 2, REA says literal 1

The same happens with const t = get(); t.x = 2. It happens with o.a = get(). A function declaration, an IIFE and an object method do it too. The first two have no slot. So this is not #1442. REA seems to lose track of a reference a call returns. I filed it as #1449.

The rest held up. ??=, ||= and a destructured store all go unknown, as the PR says. So do closures, a module-level holder and arr[arr.length]. Copying a number (o.a = shared.x) keeps 1. An unrelated object keeps its value. Storing shared and never touching it again gives unknown. That matches the read-only note.

Regression, tests and speed

Check Result
38 for...of cases 37 same IR, 1 fixed (arr[0] = shared loop)
59 #1390 cases 59 same IR
New wrong, lost fact, timeout none
New test, head passes on Node 22, 24, 26
New test, base fails, as it should
Loop alias test passes
src/domain/javascript tests 721 of 721 pass
Loop timings, k = 6, 9, 12 same as base
Hermes Desktop (MIT) chunk same speed and memory

On the chunk, one function's unknown reason changed. Nothing else did. The box was busy, so treat timings as rough. Numbers are in the fold.

Two loop forms are still wrong on base and head. One is a while loop that walks m0 twice. The other is a for...of over a generator. This PR didn't cause them.

Not run

  • check:fast and verify:test-discovery. My copy had no git history.
  • The full test suite.
  • Timings on an idle box.
  • macOS and Windows.

Thanks, N0zoM1z0, for such a fast fix.

Full 24-case matrix

Same on Node 22, 24 and 26, CLI and MCP. Each case starts with const shared = { x: 1 }.

Case Real JS base head Verdict
o.a = shared; o.a.x = 2 2 literal 1 unknown fixed
arr[0] = shared; arr[0].x = 2 2 literal 1 unknown fixed
o.a = shared; const t = o.a; t.x = 2 2 literal 1 unknown fixed
o.a.b = shared; o.a.b.x = 2 2 literal 1 unknown fixed
o.a = shared; o.a.inner.x = 2 2 literal 1 unknown fixed
o.a = p; p.b = shared; o.a.b.x = 2 2 literal 1 unknown fixed
o[k] = shared; o[k].x = 2 2 literal 1 unknown fixed
o.a = { x: 0 }; o.a = shared; o.a.x = 2 2 literal 1 unknown fixed
o.a = other; o.a = shared; o.a.x = 2 2 literal 1 unknown fixed
o.a = shared; o2 = { ...o }; o2.a.x = 2 2 literal 1 unknown fixed
const o = { a: shared }; o.a.x = 2 2 unknown unknown honest
const arr = [shared]; arr[0].x = 2 2 unknown unknown honest
m.set('k', shared); m.get('k').x = 2 2 unknown unknown honest
new Set([shared]) + for...of write 2 unknown unknown honest
s.add(shared) + for...of write 2 unknown unknown honest
Class method this.a = s; this.a.x = 2 2 unknown unknown honest
Static method C.a = s; C.a.x = 2 2 unknown unknown honest
shared.x = 2 (direct) 2 unknown unknown honest
o.a = shared; const y = o.a.x; return shared.x + 0 * y 1 unknown unknown honest
o.a = { x: 5 }; o.a.x = 2 1 literal 1 literal 1 correct
o.a = { ...shared }; o.a.x = 2 1 literal 1 literal 1 correct
o.a = shared; const y = o.a.x; return shared.x 1 literal 1 unknown lost
o.a = shared; o.a = { x: 5 }; o.a.x = 2 1 literal 1 unknown lost
o.a = shared; o.a = { x: 0 }; o.a.x = 2 1 literal 1 unknown lost
All 48 new probes

Same on Node 22, 24 and 26, CLI and MCP. Real JS gives 2 unless noted.

Still wrong on head (also wrong on base):

Probe head
const get = () => shared; o.a = get(); o.a.x = 2 literal 1
function get() { return shared; }; o.a = get() literal 1
o.a = (() => shared)(); o.a.x = 2 literal 1
o.a = box.get() (method returns shared) literal 1
const t = get(); t.x = 2 (no slot) literal 1
get().x = 2 (no slot) literal 1

Wrong 1 on base, unknown on head:

  • o?.a read, then a write
  • o?.a && (o.a.x = 2)
  • store inside a closure, then a write
  • write inside a closure after the store
  • arr[arr.length] = shared
  • let o; o = {}; o.a = shared
  • o.a ??= shared and o.a ||= shared
  • ({ a: o.a } = { a: shared })
  • o.a = o.b = shared
  • (o.a = shared, o.a.x = 2)
  • o.a = true ? shared : {...}
  • store inside if and inside a loop
  • module-level holder.a = shared
  • receiver alias made before the store
  • o.a.x++
  • o['a'] = shared, then o.a.x = 2
  • a setter that saves shared
  • Object.assign(o.a, { x: 2 })
  • o.a = [shared][0], (0, shared) and shared ?? null
  • const { a } = o and const [first] = [o.a] reads
  • const s = shared; o.a = s
  • return y.x where y = shared
  • arr[i] = shared with let i = 0
  • an arrow that returns (o.a = shared)
  • const t = o.a; delete o.a; t.x = 2

unknown on both:

  • Object.assign(o, { a: shared })
  • Reflect.set(o, 'a', shared)
  • Object.defineProperty(o, 'a', { value: shared })
  • a helper put(o, shared) that stores it
  • push, splice and unshift
  • a class that stores in one method and writes in another
  • o.a = Object(shared)

Controls:

Probe Real JS base head
o.a = shared.x; o.a = 5 1 literal 1 literal 1
o.a = shared; o.a.x = 2; return keep.y 3 literal 3 literal 3
o.a = shared; return shared.x 1 literal 1 unknown
Speed and loop cases

The 38 for...of cases and 59 #1390 cases ran on Node 24, base and head. All 194 runs exited clean.

Still wrong on both base and head:

  • while loop that walks m0 twice (in both sets)
  • for...of over a generator

Loop timings, median of 3, Node 24:

Loop k base head
#1401 loop 6 21.1 ms 21.7 ms
#1401 loop 9 23.0 ms 22.5 ms
#1401 loop 12 23.9 ms 23.6 ms
write loop 6 21.7 ms 21.7 ms
write loop 9 23.2 ms 23.5 ms
write loop 12 24.6 ms 24.5 ms

Results and IR match base for every k.

Hermes Desktop (MIT) vendor chunk, 258 KB, median of 3, Node 24, 5000 MB heap:

base head
Wall time 1.71 s 1.75 s
Analysis 1462 ms 1508 ms
Max RSS 394 MiB 395 MiB
Literal returns 211 211

Load sat between 6.7 and 7.1 from other jobs.

Commands
  • Real JS: import each app.js and call result(), on all three Nodes.
  • CLI: rea analyze-javascript-application <dir> --artifact-format directory --json.
  • MCP: one stdio server per tree and Node. It calls analyze_javascript_application with format: "directory".
  • All 432 CLI runs and 432 MCP calls exited clean. MCP matched the CLI on every call.
  • Regression: analyzeJavaScriptSemantics called directly, as in my fix(javascript): preserve effects through yielded array references #1437 and fix(javascript): bound member-mutation paths through reassignment loops #1390 runs.
  • Tests: vitest run --project acceptance for the two app tests. vitest run --project domain src/domain/javascript for the rest.
  • Base test: I copied the new test and its fixture into base.
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head / base: c56a3866 / 33b9b31a
  • Merge commit e09cfe9b: same tree as c56a3866, not built separately

🤖 Generated with Claude Code (Opus 5.5) 🦊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Assigning an object into a slot, then writing through it, reports a stale literal

2 participants