Repository navigation
fix(javascript): trace wrapped Electron IPC paths in large bundles - #1874
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1017d61dbe
ℹ️ 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 fn = symbolicVariants( | ||
| args[1] ?? symbolicUnknown("missing handler"), | ||
| ).find((v): v is SymbolicFunction => v.kind === "function"); |
There was a problem hiding this comment.
Reject ambiguous IPC handler variants
When a wrapped registration receives a conditional or otherwise union-valued handler (for example, register("copy", flag ? copy : cut)), .find(...) silently chooses the first function variant. The analyzer then emits one literal handler finding and can classify the channel as uniquely paired, producing a caller-to-handler edge for only one of the possible callbacks instead of leaving the handler ambiguous. Require exactly one function variant (and no unresolved variants), or retain all variants as ambiguity.
AGENTS.md reference: AGENTS.md:L17-L17
Useful? React with 👍 / 👎.
| if ( | ||
| (node.operator === "&&" && truth === false) || | ||
| (node.operator === "||" && truth === true) | ||
| ) |
There was a problem hiding this comment.
Respect nullish coalescing before walking the right operand
When a handler contains a statically non-nullish left operand such as "ready" ?? event.sender.copy(), this short-circuit check handles only && and ||, so it walks the right side and emits an impossible terminal path. Unknown ?? operands are also annotated using truthiness rather than nullishness. Handle ?? using whether the symbolic literal is null/undefined, and leave genuinely unknown nullish state unresolved.
Useful? React with 👍 / 👎.
| const branch = | ||
| truth === false ? statement.alternate : statement.consequent; |
There was a problem hiding this comment.
Evaluate both returns when a condition is unknown
When a wrapper uses if (flag) return first; else return second; and flag is symbolic/unknown, this expression always selects the consequent because truth !== false; the alternate is never evaluated. As a result, only first can be connected to an exposed bridge member and the valid second call path disappears without being represented as unknown. Union the return values from both branches when the condition cannot be resolved.
AGENTS.md reference: AGENTS.md:L17-L17
Useful? React with 👍 / 👎.
|
This is great work, thank you! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cfc32c4421
ℹ️ 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".
| location, | ||
| }; | ||
| if (existing) | ||
| existing.value.members.length === 0 && |
There was a problem hiding this comment.
Preserve direct empty bridge observations
For a direct exposeInMainWorld("desktop", {}) call, the syntax pass has already recorded an exact object-literal observation with zero members, but this length check treats it as unresolved and replaces it with the symbolic finding (api_status: "dynamic", resolution_basis: "wrapper-substitution"). The graph consequently downgrades observed source syntax to inferred evidence even though no wrapper was involved; only replace an existing finding when its status/unknown count actually indicates unresolved input.
AGENTS.md reference: AGENTS.md:L5-L5
Useful? React with 👍 / 👎.
| const initializer = | ||
| binding.initializers.length === 1 ? binding.initializers[0] : undefined; | ||
| if (!initializer) | ||
| return symbolicUnknown("missing or ambiguous initializer"); |
There was a problem hiding this comment.
Reject initializers that have not executed
When an exposed member reads a variable before its declaration, such as exposeInMainWorld("desktop", {copy}); const copy = () => e.ipcRenderer.send("copy"), this resolves the later initializer without considering the read/call position and emits a desktop.copy path. At runtime the const form throws in the TDZ (and var supplies undefined), so this is an impossible path rather than an execution-unverified candidate; require proof that non-hoisted initializers are available at the relevant invocation point, otherwise retain the member as unresolved.
AGENTS.md reference: AGENTS.md:L23-L23
Useful? React with 👍 / 👎.
| const modules = new Map<string, SymbolicValue>(); | ||
| for (const property of bootstrap.table.properties) { | ||
| const factory = moduleFactory(property); | ||
| if (!factory) continue; |
There was a problem hiding this comment.
Invalidate mutated bootstrap module tables
In a recognized bootstrap where modules[id] is overwritten before load(entry) runs, this snapshots every original literal factory into an independent modules map and never associates that map with writes to the actual table binding. For example, replacing the factory that exports Electron with a fake factory still lets consumer modules resolve the original require("electron"), producing bridge/IPC paths that cannot execute; reject or invalidate a bootstrap when its table or indexed slots are mutated.
AGENTS.md reference: AGENTS.md:L23-L23
Useful? React with 👍 / 👎.
| export const symbolicTruth = (value: SymbolicValue): boolean | undefined => | ||
| value.kind === "literal" | ||
| ? Boolean(value.value) | ||
| : ["function", "object", "namespace", "array"].includes(value.kind) | ||
| ? true |
There was a problem hiding this comment.
Treat symbolic records and loaders as truthy
Inside a recovered module factory, record represents the concrete module object and loader represents its loader function, so both are always truthy. Omitting them here makes expressions such as module || event.sender.copy() unresolved; the call-path walker then follows the right operand with a !(module) guard and emits an impossible terminal path. Include these known object/function kinds in the truthy set, as the nullish helper already does.
Useful? React with 👍 / 👎.
| return truth === undefined | ||
| ? symbolicUnion([ | ||
| this.evaluate(node.consequent, env), | ||
| this.evaluate(node.alternate, env), | ||
| ]) |
There was a problem hiding this comment.
Retain predicates on symbolic branch unions
For an exposed member such as {action: flag ? copy : cut}, the new union now retains both callbacks, but it strips the selecting predicate from each variant. The bridge walker therefore emits both IPC paths with conditions: [], losing the guard that distinguishes flag from !flag; carry branch provenance into the variants (or leave the member unresolved) so feature traces preserve the condition attached to each candidate.
AGENTS.md reference: AGENTS.md:L17-L17
Useful? React with 👍 / 👎.
| Math.min( | ||
| MAX_TRANSFER_BYTES, | ||
| Math.max(TRANSFER_BYTES, Math.floor(resultBudgetBytes / 8)), | ||
| ); |
There was a problem hiding this comment.
Apply scaled transfer budget during module preflight
When parent admission permits a transfer above 512 MiB and the semantic module rows themselves exceed 512 MiB, this larger budget is only used by the final writer. measureJavaScriptModuleTransfer runs first and calls encodeTransferRecord with its unchanged 512 MiB default, so analysis fails before the advertised scaled (up to 2 GiB) transfer can be used; thread the same computed byte budget through module measurement.
AGENTS.md reference: AGENTS.md:L44-L44
Useful? React with 👍 / 👎.
Summary
Recover candidate feature paths through Electron wrapper functions and literal CommonJS module tables, and allow large bundles to retain their semantic graph within explicit caller-selected budgets.
An exposed member such as
desktop.copy: sender("example:copy")currently loses its connection toipcRenderer.sendand the wrapped main-process callback. This change letstrace-application-featurefollow that member through a unique literal IPC pairing toevent.sender.copy(), preserving source locations, guards, and inferred authority.Problem and expected behavior
The following pattern should produce a candidate cross-file path:
Large bundles hit the fixed 20,000-node per-file semantic projection limit even when more heap is available. This PR adds explicit node budgets and bounded adaptive result transfer. A class/getter alias regression also incorrectly retains a literal after its shared object escapes through a loop.
These were found while testing publicly distributed Notion desktop JavaScript. This PR includes the reproduction directly; no separate issue was opened. Upstream integration: merged
mainat6611bcf6e86630c775c24e6afa00d7239c64e70e, preserving #1857 and #1912 (the fix for #1909). The upstream intrinsic-invocation and module-interop owners and their regression tests are unchanged. Upstream source selection and cancellation behavior are retained.Change and scope
Review fixes
false,0, and"") exclude the fallback; nullish values select it; unknown values retain a nullish guard.undefined, and excludes statements after all branches definitely exit.Contract and boundary impact
max_semantic_nodesandmax_semantic_nodes_per_file(CLI:--max-semantic-nodes,--max-semantic-nodes-per-file), integers from 1 through 1,000,000. Explicit choices are retained in Evidence parameters; omitted choices remain absent.electron.call_paths,resolution_basis: "wrapper-substitution", and contextualjavascript-expressiongraph nodes. New paths and IPC joins are inferred candidates; runtime execution and guard acceptance remain unverified. Resource exhaustion is reported in coverage.Evidence and regression coverage
On base
d3e9ee5505251f760666bb8e1e6c295b6d6aedb2, the wrapper and reference-lifetime regression files produced 5 failures / 115 passes: four missing wrapper-path behaviors and the getter escape case. The corresponding tests pass with this patch.A compiled public CLI test runs analysis and then
trace-application-featureusing the complete returned Evidence and only thedesktop.copyseed. It asserts the path, guards, inferred authority, and separation fromdesktop.cut; a competing untraced handler prevents pairing.Additional coverage exercises bootstrap syntax, shadowing/overwrites, helper-name spoofing, definite throws/returns, explicit node limits across files, transfer admission, IPC provenance, cancellation, and MCP resource recovery.
Notion 7.37.1 macOS arm64: the two unchanged distributed bundles (
.webpack/main/index.jsand.webpack/renderer/tab_browser_view/preload.js) were analyzed with the public CLI, using a 6,144 MiB worker heap, 24,576 MiB parent old-space budget, 750,000 total nodes, and 700,000 nodes per file. No Notion binaries or source files are included in this PR.Verified analysis result: 651,734 semantic nodes / 635,848 relations, both files parsed, zero parse failures,
truncated: false, zero omitted nodes/relations, and no resource limits. Analysis exited successfully in 105.4 s. The 220,735 dynamic/ambiguous facts remain unknown; overall semantic coverage is stillunknown.Passing the complete returned Evidence to
trace-application-featurewith only the API seed__electronApi.copyandmatch: "contains"recovered all three candidate paths below (63.292 s, exit 0). The source hashes, every directed edge, guard evidence, and unique literalnotion:copyjoin were independently checked against the saved CLI output.__electronApi.copyipc-event.sender.copy__electronApi.copyTextnavigator.clipboard.writeText__electronApi.copyImagenavigator.clipboard.writeInput SHA-256 digests (for reproducibility):
Remaining proof gaps: static candidates do not establish actual Notion UI/clipboard execution, accepted senders, OS implementation, or client reimplementation. Dynamic JavaScript unknowns remain explicitly reported.
Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Validation performed
npm run test:focused -- …across 91 JavaScript/Electron source, filesystem, CLI, worker, MCP, and acceptance test files: 1,548 tests passed on macOS arm64, Node 24.18.0 / npm 11.16.0.npm run check: passed, including typecheck, lint, formatting, knip, metadata, module boundaries, and architecture guards.npm run docs:check: passed.npm run verify:test-discovery: all 892 test files discovered exactly once.git diff origin/main --check: passed. The committed tree exactly matches the tested tree; working tree is clean.Compatibility, safety, and release
Review checklist
type(scope): outcome.