Skip to content

fix(javascript): preserve uncertainty after references escape to calls - #1292

Merged
morluto merged 10 commits into
morluto:mainfrom
Y0UW1SH:fix/javascript-comparison-accuracy
Oct 9, 2026
Merged

morluto merged 10 commits into
morluto:mainfrom
Y0UW1SH:fix/javascript-comparison-accuracy

Conversation

@Y0UW1SH

@Y0UW1SH Y0UW1SH commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Object and array return shapes could remain literal after a helper, method, constructor, or tagged template could mutate a shared reference. Export comparisons could then report definite changes from incomplete evidence.

Preserve call-site uncertainty across aliases, awaited arguments, logical assignments, destructuring defaults, and genuinely shared children. Rest copies exclude consumed keys and known array prefixes. Spread copies respect later explicit overwrites and known array offsets. Accessors and uncertain or custom iteration remain conservative, including observed shared array-prototype changes.

Keep copied primitive slots and unrelated source values known. Deduplicate reference traversal, preserve current-main alias assignment ordering, and record a session unknown when partial comparisons produce no differing projections.

Tested:

  • npm run test:changed -- --base origin/main: 1,074 tests passed across 66 files; 1 skipped.
  • npm run test:focused -- tests/acceptance/applications/applicationWorkflowCli.test.ts tests/boundary/filesystem/javascriptExportShapeComparison.test.ts tests/boundary/mcp/applicationExportShapeMcp.test.ts: 69 tests passed across 3 files.
  • npm run check:ci and npm run docs:check.
  • Authored runtime controls for the four copy-boundary regressions.
  • Regressions for custom iteration, shared prototype changes, getters and setters, nested spread termination, and unaffected source values.
  • GitHub Actions on fe9c7c75: all 22 CI jobs and Real JavaScript recovery passed. Full suite: 6,144 tests passed; 89 skipped. Includes coverage/timing, build, documentation, static checks, Windows/Linux/macOS package checks, and real Apple artifact CLI/MCP E2E.

Not tested: real Hopper, Ghidra, or IDA provider execution.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T23:00:50.230920Z c3701e0 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Y0UW1SH
Y0UW1SH marked this pull request as draft October 9, 2026 14:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 71cbf17e40

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Keep rest exclusions, object overwrite ordering, and array spread offsets when tracking escaped references. Preserve conservative origins for accessors and uncertain iteration, and deduplicate deferred reference paths.

Integrate current main while preserving alias assignment ordering.
Use the canonical Unicode ordering implementation after upstream export cleanup. Reuse source-analysis fixture setup for the public CLI regressions.

Integrate the latest main branch.
Include the upstream translated README correction so documentation facts remain consistent.
@Y0UW1SH
Y0UW1SH marked this pull request as ready for review October 9, 2026 16:20
@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.

…rsal

Resolve aliases at their use or capture point, discard replaced rest/default origins, and preserve primitive snapshots before later calls. Retain saved and restored references while deduplicating conditional copied-slot selections to avoid exponential traversal.

Integrate upstream main and add source regressions plus a public CLI/stdio MCP comparison verified against executed fixtures.

Validation: 1,164 affected tests passed (1 skipped), 70 CLI/MCP and boundary tests passed, and npm run check:ci passed. Independent review found no remaining blockers.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d400632da9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@CassieFox23

CassieFox23 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: I checked this on Linux, and it fixes the case it targets. On 6.2.0 and on current main, a helper that adds a field still shows up as a definite "added" change. On this branch the same comparison comes back partial, with no definite changes.

The five changed test files pass: 237 tests.

For a before and after, I used two v1/v2 fixture pairs. Each build made its own Evidence. Then compare-javascript-export-shapes compared the default export of parser.mjs.

  • A is the awaited-helper case from this PR's CLI test.
  • B isn't in the PR's tests. In v1, make() builds { kind: "record" } and hands it to tag(). That helper lives in a second module and sets extra. In v2, make() returns { kind: "record", extra: 1 }.
Build A B
Published 6.2.0 /extra added, complete-within-inputs the same
main at 7738c1f /extra added, complete-within-inputs the same
This branch 0 changes, 2 unknown, partial the same

One small note. On the branch, both return variants come back as unpaired unknowns at path "". So the v2 side's plain literal also reads as unknown. The result's own limitations say variants pair only by a literal key, so that fits. I'm only flagging it in case one unknown at /extra was the goal.

Not run: the full suite, and my fixtures over MCP. GitHub says the branch merges cleanly, though it's 40 commits behind main.

Test setup
  • Box: Linux x86-64
  • Node: 22.23.1
  • Head: d400632da, built from a fresh clone

🤖 Generated with Claude Code (Opus 5.5) 🦊

@CassieFox23

CassieFox23 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: Follow-up to my last comment. The full suite is clean, apart from one failure the base already has. But over MCP I hit a regression. After one partial comparison, the next comparison in the same session fails with revision_conflict. That doesn't happen on this branch's base, on main, or on 6.2.0.

Full suite. npx vitest run covered 699 files and 6,416 tests, and five files failed. Four just needed build files that npm run test:prepare makes. With those, they pass. The fifth is a real failure: cliJsonInput.test.ts, "reports a valid file beyond the runtime string limit as too large". It fails the same way at the base, 750fb6565. It passes on main at 7738c1f. So it comes from the older base, not from this change.

My fixtures over MCP. Over stdio, I analyzed each v1/v2 pair, then ran compare_javascript_export_shapes. I tried inline Evidence and retained IDs. For the first pair in a session, the results match the CLI. 6.2.0 and main report /extra as added. This branch gives 2 unknowns and partial coverage.

The regression. It shows up with two different pairs in one session:

Second comparison in the same session Result
Published 6.2.0 ok
main at 7738c1f ok
This branch's base, 750fb6565 ok
This branch revision_conflict

The error says "Evidence state changed before the update completed. Refresh the current state and try again."

It needs the first comparison to be partial. My third pair has an unresolved package import, so it comes back partial, with 2 unknowns, on every build. I compared it first, then pair A. That works on 6.2.0, main and the base, and fails on this branch. Comparing the same pair twice works. Analyzing all four folders up front doesn't help. Inline and retained inputs both fail.

I didn't trace the cause. This PR adds a docs line about partial comparisons recording an unknown in the MCP session. That may be related.

Test setup
  • Box: Linux x86-64
  • Node: 22.23.1
  • Head: same head d400632da

🤖 Generated with Claude Code (Opus 5.5) 🦊

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

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

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

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

@CassieFox23

CassieFox23 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: A correction to my last comment, sorry. The revision_conflict isn't a regression from this branch. 6.2.0 and main do it too, when two partial comparisons run back to back in one session. This branch makes more results partial, as it should. So it just hits the older bug more often.

This ran over stdio MCP. In one session I analyzed two different v1/v2 pairs. Each imports a package that isn't there. So each comparison comes back partial, with 2 unknowns. Then I ran compare_javascript_export_shapes on the first pair, then on the second.

Build First Second
Published 6.2.0 partial, 2 unknowns revision_conflict
main at 7738c1f partial, 2 unknowns revision_conflict

In my last comment, the second pair was A. On main and the base, A comes back complete, so that second call worked. That's what made it look new.

So the bug predates this PR, and it likely needs its own issue.

Test setup
  • Box: the same Linux box
  • Node: 22.23.1

🤖 Generated with Claude Code (Opus 5.5) 🦊

@morluto

morluto commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Reviewed d400632. No blocking issue found in the reviewed escape/capture logic. The change keeps explicit writes and possible call escapes separate, invalidates referenced children rather than replacing the containing slot, preserves shallow-copy exclusions/rest selections, and bounds repeated reference traversal. The point-local capture exception is constrained to a demonstrable same-body ordering, while outer/persistent origins still receive their own effects; that distinction is essential to avoid publishing a pre-mutation primitive from a later activation.

The CLI/filesystem/MCP regressions and the incomplete-comparison coverage handling are appropriate, and CI is green at this head. Recommended merge sequencing: land #1351 first, then rerun both its exported-binding cases and this PRs reference-lifetime/escape cases against the combined tree. The two PRs touch the same semantic collection/state mechanisms, so individual green CI is not evidence for every combined interaction.

Review scope: static review of the changed semantic owners and supplied regression evidence. I did not independently rerun the complete matrix or real binary/browser providers, and I am not making a performance claim.

Preserve iterative escape/reference propagation and extended initializer types alongside lexical module-link bindings, conditional initializer tracking, and function-body entry origins. Validation: 337 focused tests including CLI/MCP capture-lifetime and exported-binding regressions, typecheck/lint, architecture guards, and formatting.
@morluto
morluto merged commit 355a292 into morluto:main Oct 9, 2026
19 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c3701e03f9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +447 to +451
slot?.presence === "present" &&
(slot.value.status === "literal" ||
slot.value.status === "union" ||
slot.value.status === "object" ||
slot.value.status === "array")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Evaluate fallback guards at destructuring time

When a definitely present object-valued source is escaped through the selected binding, that escape changes the slot's value to unknown before referenceSourcesInactive runs, so this status whitelist incorrectly treats the fallback as reachable. For const fallback={value:"TOKEN"}; const source={child:{}}; const {child: copy=fallback}=source; mutate(copy); return fallback.value, the fallback is never selected at runtime, but the analysis escapes it and reports its value as unknown; preserve the guard value from the destructuring point instead of consulting the mutation-completed state.

AGENTS.md reference: AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

Comment on lines +73 to +75
const statement = parents.get(node);
return t.isExpressionStatement(statement) && statement.expression === node
? statementPosition(statement, parents)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Track calls nested in later statements

When an escape call is wrapped in a variable initializer, await, or another expression, its immediate parent is not an expression statement and directMutationPosition loses its ordering entirely. Thus const source={value:1}; const snapshot=source.value; const ignored=mutate(source); return snapshot reports snapshot as unknown even though the primitive was copied before the call; locate the containing unconditional statement so later nested calls can be excluded from earlier captures.

AGENTS.md reference: AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

Comment on lines +213 to +217
!t.isObjectExpression(initializer.node) &&
!t.isArrayExpression(initializer.node) &&
!t.isIdentifier(initializer.node) &&
!t.isMemberExpression(initializer.node) &&
!t.isOptionalMemberExpression(initializer.node)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Unwrap transparent syntax before classifying capture origins

This classification examines the raw initializer node, so transparent TypeScript/Flow wrappers prevent an otherwise supported object or alias origin from preserving an earlier primitive. For const source=({value:1} as {value:number}); const snapshot=source.value; mutate(source); return snapshot, the TSAsExpression fails these checks and the analysis reports the snapshot as unknown; classify unwrapJavaScriptExpression(initializer.node).node instead.

AGENTS.md reference: AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

Comment on lines +189 to +192
sourcePosition !== null &&
capturePosition !== null &&
sourcePosition.body === capturePosition.body &&
sourcePosition.index < capturePosition.index

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve declarator ordering when capturing primitives

Using only the enclosing statement index makes sequential declarators appear simultaneous. In const source={value:1}, snapshot=source.value; mutate(source); return snapshot, JavaScript initializes source before evaluating snapshot, but both positions have the same index, so semanticBindingPrecedesCapture rejects the capture and the later escape turns the copied primitive unknown; retain declarator or source-offset ordering within a declaration.

AGENTS.md reference: AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

@CassieFox23

CassieFox23 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: Thanks for merging both, morluto. I ran the combined check you asked for on main, and it's clean. Both PRs' cases still come out right together. And the session bug from my earlier comments is fixed now. Commit e2f3b1a4 did it.

This is main at 73a664bc. It has #1351 as a9f5dad5 and this PR as 355a2921.

Full suite. After npm run test:prepare: 698 files, 6,341 tests. 6,252 passed, 89 skipped, 0 failed.

Both PRs' cases, through the CLI:

Case On main
#1351's P1 and P3 1 unknown, partial
#1351's P2, a reassigned alias 1 unknown, partial
#1351's S1, the control /count changed
This PR's A and B 2 unknowns, partial

Each matches what its own branch gave.

Over stdio MCP, two different partial pairs now work back to back in one session. Replaying the first pair works too. Published 6.2.0 still fails the second call with revision_conflict, on the same pairs.

Test setup
  • Box: Linux x86-64
  • Node: 22.23.1

🤖 Generated with Claude Code (Opus 5.5) 🦊

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
morluto#1292)

* fix(javascript): preserve uncertainty after references escape to calls

* fix(javascript): track iterator root escapes and preserve static captures

* fix(javascript): scope comparison unknowns to their evidence

* fix(javascript): track parameter origins at function body entry

---------

Co-authored-by: morluto <[email protected]>
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants