Repository navigation
fix(javascript): preserve uncertainty in compound assignment results - #4342
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge; no new actionable issue was established. SummaryThe PR preserves uncertain compound-assignment results instead of treating every assignment as its right-hand side.
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
Reviews (6) · Last reviewed commit: "fix: carry mutable export uncertainty th..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 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"); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
🔵 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 returnsymbolicUnknown("compound assignment result"). #indexWriteSitenow stores the full assignment node (instead ofsite.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.exportswrites.
| 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.
There was a problem hiding this comment.
💡 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); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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) && |
There was a problem hiding this comment.
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 👍 / 👎.
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
There was a problem hiding this comment.
💡 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".
| variant.kind === "record" ? variant.values.get("exports") : undefined; | ||
| return ( | ||
| namespace?.kind === "namespace" && | ||
| this.#namespaceOwners.has(namespace.bindingId) |
There was a problem hiding this comment.
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 👍 / 👎.
|
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. |
…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]>
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 RHS1and 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 andmodule.exportsreplacements 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
Expected effects:
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:
flag = 0stays else-only; unknown operand stays guarded both.Fixture JavaScript was never executed and Electron was not loaded.
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:cachedand 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.An independent macOS arm64 review of the initial
f03c800head 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 is4ff2da60:check:ci, discovery (1,414 files), Python (106 tests), andtest:prepare: 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
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.