Skip to content

fix(javascript): preserve uncertainty in compound assignment results - #4342

Merged
morluto merged 7 commits into
morluto:mainfrom
maxazure:fix/compound-assignment-paths-4206
Oct 16, 2026
Merged

morluto merged 7 commits into
morluto:mainfrom
maxazure:fix/compound-assignment-paths-4206

Conversation

@maxazure

@maxazure maxazure commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #4206. Preserve guarded IPC path alternatives when a compound assignment's result is not modeled, instead of pruning a branch using its right-hand side.

Problem and expected behavior

With let flag = 1; if (flag -= 1), the symbolic evaluator used the literal RHS 1 and kept only the unguarded then-channel. The subtraction actually produces zero. A conservative static analysis must preserve the alternatives when it cannot evaluate the operation.

Change and scope

Plain = still evaluates its RHS. Arithmetic and bitwise compound assignment results become unknown. Logical assignments (&&=, ||=, ??=) use the existing logical-selection semantics and preserve selected or guarded callable alternatives. Stored namespace writes retain the full assignment node, so export-property writes and module.exports replacements use the same operator-aware evaluator. This removes the second place that stripped the operator.

No arithmetic interpreter or target execution is added. This does not change the separate native-addon binding classifier addressed by #4338.

Contract and boundary impact

  • Semantic owner and earliest changed stage: JavaScriptSymbolicBindings, before contextual path selection.
  • Contribution scope fit and linked maintainer decision: ordinary static-analysis correctness fix; no new authority, decision not applicable.
  • CLI and MCP/tool-catalog contract: unchanged shape; unknown results retain guarded static candidates.
  • Provider, bridge, target-format, or platform compatibility: no provider changes.
  • Evidence, artifact, provenance, or reconstruction contract: preserve raw IPC observations and predicates; do not imply runtime invocation.
  • Target selection, authority, upstream behavior, and cleanup details: unchanged.
  • Generated metadata, 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

12 added static-analysis boundary cases cover inline arithmetic, bitwise and logical assignments, unknown operands, plain-assignment controls, and stored namespace property/replacement writes.

On base 42fc6c5, the new cases produce 8 failures with 57 passing existing/control cases. With the fix, all 65 pass.

The exact three-case public CLI reproduction from #4206 was run before and after against inert extracted applications:

  • Before: compound keeps only unguarded then.
  • After: compound retains both then/else with their predicates.
  • Plain flag = 0 stays else-only; unknown operand stays guarded both.
  • Both raw IPC calls survive in every case.

Fixture JavaScript was never executed and Electron was not loaded.

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

Initial revision validation (f03c800)

Pinned Node 24.18.0 / npm 11.16.0, Linux:

  • npm run test:focused -- src/domain/javascript/electronWrappedCallPaths.test.ts src/domain/javascript/javascriptSymbolicBindings.test.ts src/domain/javascript/electronModuleInterop.test.ts src/domain/javascript/electronBundledRequireIdentity.test.ts — 332 passed.
  • npm run build:cached and exact issue CLI reproduction — passed before/after with results above.
  • npm run check:fast — passed.
  • npm run check — passed.
  • npm run verify:test-discovery — 1,400 files discovered exactly once.
  • Normal commit hooks and diff whitespace checks — passed.

An independent macOS arm64 review of the initial f03c800 head repeated the four focused suites (332 passed), check:fast, check, discovery (1,400 files), and the exact CLI before/after reproduction with the pinned toolchain. Baseline production plus the regression tests produced the expected 8 failures / 57 passes; the PR head passed all 65. Additional inert static probes for nested assignments, later plain writes, and returned-function branches passed. No code changes were needed.

Review follow-up and CI preflight

The logical-assignment callable regression was reproduced with 11 failing cases before the follow-up. Fourteen added cases now cover RHS functions, resolvable LHS callables, skipped RHS and cyclic namespace reads. The focused suites passed 346 tests before syncing main.

After integrating main 2c75835 (including guarded factory completion), the tested tree is 4ff2da60:

  • Related regressions and upstream factory completion: 359 passed.
  • Cold check:ci, discovery (1,414 files), Python (106 tests), and test:prepare: passed.
  • Full source group: 8,574 passed, 12 failed, 8 skipped. All 12 failures reproduce on exact main in this environment.
  • Rechecked the 35 previously failing files: 153 failures across 29 files, all matching exact main by file and test name. Six formerly failing files passed.
  • Original issue CLI and logical-callable CLI reproductions passed.

Before syncing main, a clean-install CI-faithful source plus five built-shard run accounted for all 1,400 files: 16,032 passed, 159 failed, 141 skipped. All failures reproduced on the old base. Cold static/build, docs, real JavaScript recovery (12 observations), and Inspector (8 variants) passed. That complete shard run applies to the pre-sync tree, not the current tree. The full five built shards were not repeated after syncing.

Local host/provider restrictions prevent claiming a fully green local suite. Windows cross-build and the complete installed-package gate were not run because the cross-compiler/artifacts were unavailable. GitHub CI on the new head is pending.

Known pre-existing limitation: prior mutable namespace LHS callables can be lost through last-write lookup; this follow-up restores guarded RHS candidates without adding flow-sensitive write tracking.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Linux and macOS arm64 static CLI; no external provider.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new target execution or authority.
  • Proof gaps: the current merged tree has not had all five built shards repeated locally; no complete installed-package or Windows cross-build validation. No performance claim; stored plain assignments add a bounded evaluation layer.

Author readiness

Human owner: @maxazure. Initial readiness was confirmed by the owner on 2026-10-16 for f03c800; subsequent review fixes and their verification are recorded above.

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

@maxazure
maxazure marked this pull request as ready for review October 16, 2026 04:10
Copilot AI balanced review requested due to automatic review settings October 16, 2026 04:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 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-16T08:53:23.622381Z 221ed54 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.

@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issue was established.

Summary

The PR preserves uncertain compound-assignment results instead of treating every assignment as its right-hand side.

  • Assignment results keep guarded IPC paths when the operator is unknown.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Assignment expression] --> B{Operator}
  B -->|Plain assignment| C[Evaluate right side]
  B -->|Arithmetic or bitwise| D[Unknown result]
  B -->|Logical assignment| E[Evaluate left side]
  E --> F[Replace flagged namespace roots with unknown]
  F --> G[Keep selected or guarded alternatives]
  H[Stored namespace write] --> A
Loading

Reviews (6) · Last reviewed commit: "fix: carry mutable export uncertainty th..." · Reviewed by Greptile

@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: f03c800bcf

ℹ️ 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".

if (t.isAssignmentExpression(node))
return node.operator === "="
? this.evaluate(node.right, env)
: symbolicUnknown("compound assignment result");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve logical-assignment RHS candidates

For &&=, ||=, and ??=, this drops a reachable RHS value instead of merely making the result uncertain. For example, in an exposed wrapper containing (cb ||= () => ipcRenderer.send("x"))(), the assignment expression can evaluate to the RHS function; collectElectronWrappedCallPaths's call() only descends into function variants, so replacing the whole value with unknown prevents it from entering that closure and silently omits the reachable IPC call path, even when cb starts as null. Preserve the RHS (and, when resolvable, the LHS) as guarded variants for logical assignments; arithmetic and bitwise compounds can remain unknown.

AGENTS.md reference: AGENTS.md:L31-L31

Useful? React with 👍 / 👎.

Copilot AI 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.

🔵 Needs a closer look

Although no defects were found, the change alters core symbolic-evaluation semantics for all compound assignments across the JavaScript analyzer and the full test suite was not completed, so downstream effects warrant final human review.

0 open findings

What changed in this PR

This PR fixes a static-analysis correctness defect (#4206) in the JavaScript/Electron symbolic evaluator. Previously, a compound assignment used in a conditional test (e.g. if (flag -= 1)) was evaluated as its right-hand side literal, causing the analyzer to prune a valid guarded IPC branch and drop a predicate. The fix makes compound-assignment results conservatively unknown so alternative contextual IPC call paths are preserved, aligning with REA's requirement to preserve uncertainty across Evidence boundaries.

Changes:

  • In #evaluate, only plain = assignments evaluate their RHS; all compound/logical assignments (-=, +=, &=, &&=, ||=, ??=, etc.) now return symbolicUnknown("compound assignment result").
  • #indexWriteSite now stores the full assignment node (instead of site.right) so stored namespace/module-export writes reuse the same operator-aware evaluation, removing the second place that stripped the operator.
  • 12 new regression cases covering inline arithmetic/bitwise/logical assignments, unknown operands, plain-assignment controls, and stored exports/module.exports writes.
File Description
src/​domain/​javascript/​javascriptSymbolicBindings.ts Makes compound-assignment evaluation conservative and routes stored writes through the operator-aware evaluator by retaining the full assignment node.
src/​domain/​javascript/​electronWrappedCallPaths.test.ts Adds parametrized regression coverage for inline conditional assignments and stored module-export assignment semantics.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@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: 26b6e7f7bb

ℹ️ 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".

);
// Retain the operator so stored writes use the same result semantics as
// inline assignments, rather than treating every write as its RHS.
this.#indexWrite(direct, site, site);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Resolve prior module.exports writes before short-circuiting

When a bundled factory does module.exports = null; module.exports ||= { action() { ... } } (likewise with ??=), retaining site here causes the latest root write to be replayed as the assignment, but node.left then resolves through the synthetic module record whose exports entry still points at the initial truthy/non-nullish namespace rather than the preceding replacement in #writes. #logicalValue consequently skips the reachable RHS, so a later helper.action exposure loses its contextual IPC path; resolve the target's pre-write root value before applying logical short-circuit semantics.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@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: 56753ed27e

ℹ️ 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".

const writes = this.#namespaceWrites(namespace, { node, environment: env });
if (writes === undefined)
return symbolicUnknown("module export read boundary is unavailable");
const replacement = writes.findLast((write) => write.path.length === 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Ignore detached exports assignments when resolving module.exports

When a bundled factory's resulting export is exposed after module.exports = null; exports = {}; module.exports ||= { action: () => ipcRenderer.send("rhs") }, assigning the local exports parameter does not change module.exports, so the final logical assignment definitely installs the RHS. Because both parameter bindings are stored under the same namespace ID, this unrestricted path-empty findLast selects exports = {} as the prior module root, considers it truthy, and omits the reachable rhs call path; retain the receiver identity on writes (or otherwise exclude detached exports replacements) before resolving this history.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

const replacement = writes.findLast((write) => write.path.length === 0);
return replacement === undefined
? namespace
: this.evaluate(replacement.value, namespace.environment);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Resolve prior replacement reads before testing logical assignment

The new helper fixes the immediate sequence from the earlier thread, but a preceding self-assignment still reproduces the omission: with module.exports = null; module.exports = module.exports; module.exports ||= { action: () => ipcRenderer.send("rhs") }, the middle write must remain null and the last write must select the RHS. Evaluating that replacement here sends its RHS through the synthetic module record, whose exports slot is the original truthy namespace, so the RHS call path is skipped; make all factory-owned module.exports reads point-sensitive at their producing boundary rather than correcting only the final logical-assignment LHS.

AGENTS.md reference: AGENTS.md:L25-L25

Useful? React with 👍 / 👎.

@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: 95bed8f196

ℹ️ 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".


#assignmentLeft(node: t.Node, env: SymbolicEnvironment): SymbolicValue {
if (
t.isMemberExpression(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 wrapped targets before classifying module exports

When a recognized bundled factory wraps the whole target in TypeScript/Flow syntax—for example, module.exports = null; (module.exports as any) ||= { action: () => ipcRenderer.send("rhs") }—node is a TSAsExpression, so this check is bypassed. The fallback evaluate(node) unwraps to the stale synthetic namespace retained in the module record, treats it as truthy, and skips the reachable RHS, so exposing the loaded module loses the rhs call path. The fresh evidence is the whole-target wrapper; the added wrapped cases only wrap module before .exports. Normalize node with unwrapJavaScriptExpression before this member test.

AGENTS.md reference: AGENTS.md:L25-L25

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@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: ac4a1df044

ℹ️ 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 +648 to +651
variant.kind === "record" ? variant.values.get("exports") : undefined;
return (
namespace?.kind === "namespace" &&
this.#namespaceOwners.has(namespace.bindingId)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve exports uncertainty through object snapshots

When a recognized factory first writes module.exports = null and then snapshots it through an ordinary literal, for example const selected = (({exports: module.exports}).exports ||= {action: () => electron.ipcRenderer.send("rhs")}), the outer receiver is an object, so this record-only check is bypassed. The inner module.exports read still yields the synthetic record's original namespace; symbolicLogicalRight treats that namespace as truthy and skips the RHS, so exposing selected silently loses the reachable rhs call path even though runtime installs it. The fresh failing shape is this snapshot wrapper, which is not covered by the direct or conditional receiver cases; resolve mutable exports reads at the synthetic-record property boundary, or retain their uncertainty through snapshots, rather than only repairing direct assignment targets.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@morluto
morluto merged commit 17488bd into morluto:main Oct 16, 2026
33 checks passed
@morluto

morluto commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Thanks @maxazure for preserving guarded IPC alternatives when an arithmetic or bitwise compound assignment cannot be evaluated. Keeping the result unknown avoids pruning a path based only on the assignment’s right-hand side.

gensokyo-dev added a commit that referenced this pull request Oct 24, 2026
…6206)

* feat(javascript): link assignment right-hand sides to their writes

A declaration carries its value forward, but a later assignment to a
variable, a property or through a compound operator stopped the forward
trace at the right-hand-side read. The semantic IR now records one
syntactic assignment flow per simple assignment target (ranges, operator,
owning callable), and the graph projection connects each retained read
of the right-hand side to the write occurrence through a defines
relation. Compound assignments also consume the previous value of the
target; the written value itself stays unknown, keeping the boundary of
#4342 intact.

Fixes #6193

* fix(javascript): preserve computed key assignment ownership

* test(javascript): retain nested callback assignment ownership

* docs(javascript): record assignment influence verification

* test(mcp): isolate mocks and acknowledge cancellation boundaries

* test(javascript): retain CLI diagnostics and current-main verification

---------

Co-authored-by: gensokyo-dev <[email protected]>
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Nov 23, 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.

[Bug] Subtraction assignment prunes the wrong contextual IPC branch

3 participants