Repository navigation
feat(electron): report V8 cachedData compilation boundaries - #9501
Conversation
analyze-javascript-application treated new vm.Script(source, {cachedData}) and vm.compileFunction(..., {cachedData}) as ordinary source. V8 deserializes previously compiled bytecode for those calls, so an Electron preload wrapper that delegates its whole contextBridge and IPC surface to a .cache/.jsc snapshot appeared to have been fully analyzed with zero exposed APIs.
Record each vm compilation with its inert cache path when the cachedData value traces to a readFileSync/readFile of path syntax, and project a cached-data execution unknown plus a loads edge from the owning source. Compilations without a cache stay recorded as no-cached-data so absence remains distinguishable from an unparsed snapshot. Count cachedData executions in the Electron summary and state the coverage limit in the graph limitations.
Codex Review Summary: ✅ CompletedThis 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: 043abdaf0f
ℹ️ 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".
[Medium impact] The PR changes Electron JavaScript artifact analysis and its reported graph and summary. Fix the missing optional-call boundaries and incorrect cache-source attribution before merging. Findings
Fix with agent prompt### Issue 1
src/domain/javascript/electronStaticAnalysisDynamicCode.ts:52-53
`vm.compileFunction?.(source, [], { cachedData })` produces an `OptionalCallExpression`, which this filter skips. Even with a proven `vm` import, the call produces no `dynamic_code` record, graph boundary or summary count. Admit optional calls through the same settled callable check.
### Issue 2
src/domain/javascript/electronStaticAnalysisDynamicCode.ts:235-238
`stableExpression` returns the whole initializer while dropping its selected property and possible default. For `const { cachedData = otherBytes } = fs.readFileSync(path.join(__dirname, "a.cache"))`, the normal Buffer result has no `cachedData` property, so the supplied value is `otherBytes`. This code instead reports `a.cache` as its source.
Reject projected or fallback bindings unless their selected value is proved. This violates the `AGENTS.md` requirement to preserve identity and uncertainty across boundaries.
### Issue 3
src/domain/javascript/electronStaticAnalysisDynamicCode.ts:109-113
Both `new vm.Script(source, void 0)` and `vm.compileFunction(source, [], void 0)` omit cache options. Their argument nodes still reach `resolveElectronOptionObject`, fail object lookup and become `unknown` rather than `absent`. That adds an opaque-cache node and warning to source-only compilation. Treat proven undefined options as missing before object lookup.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds source-only
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Source AST] --> B[Deferred VM candidates]
B --> C[Settled callable identity]
C --> D[Options and cache-source facts]
D --> E[Worker contract]
E --> F[Compilation summary]
E --> G[Graph cache boundary]
G --> H[Inventory lookup for proven source-directory paths]
Reviews (4) · Last reviewed commit: "fix(electron): exclude disabled caches f..." · Reviewed by Greptile |
The `inspect-native-data-type` argument description line is 82 columns, over the repository's 80-column `.oxfmtrc.json` limit, so `npm run format:check` fails on main and on every branch merged from it. It came in with morluto#9465 and the following commits to this file did not touch it. Reformat the one call the formatter objects to; no behaviour change.
`npm run format:check` fails on this branch, which is what `Static checks` reports: oxfmt wants the `pendingDynamicCode` union on one line. Applying it is the whole change; no behaviour is touched.
|
Rebased onto What breaks.
Why I did not just relax the check. Making Leaving the branch at |
main renamed the Electron loader-authority handling in morluto#9477, so the merge only needed the summary count to keep both sides: main's proven-finding filters for the seven existing fact families plus this branch's dynamic_code family. The domain fixture now parses as CommonJS because a .js fixture resolves as ESM and every require keeps only candidate loader authority, which hid the cache path from the unit test while the real .cjs boundary test already passed.
|
Merged The only textual conflict was One test-level follow-up: Verified locally: Not yet addressed: the review threads from |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 53e16134c4
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 54812cec5d
ℹ️ 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".
|
The reviewed boundary and sibling fixes are published: shared complete-callable authority after mutation indexing handles ESM and replaced VM methods; intact options use the existing owner, while argument spreads stay unknown. Synchronous and awaited promise reads retain parsed path bases through the worker contract. Relative literal paths remain unresolved instead of becoming source siblings. Proven undefined cache values preserve their expression but do not create cache boundaries. One shared possible-cache classifier now owns graph projection, global warnings and Electron recovery counts. Cache declaration/acceptance/execution remain separate, and the feature spec/plan/tasks are present. Validation: 25 final domain/public workflow tests passed; new callable/spread/read and absence/recovery controls failed on earlier implementations; check:fast and docs:check passed. No real cache acceptance or target execution was qualified. These changes address the outstanding option, identity, path, summary, specification and uncertainty findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57917a2063
ℹ️ 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".
| : lookup.status === "missing" | ||
| ? "absent" | ||
| : "unknown", |
There was a problem hiding this comment.
Propagate unresolved cache options into semantic coverage
For an otherwise fully examined source containing new vm.Script("0", getOptions()), this records cached_data_status: "unknown" without incrementing accumulator.unknownFindings. Consequently, finalizeStaticAnalysis can report zero unknown findings and parse_status: "complete", which javascriptAnalysisCoverage and graphCoverage propagate as complete coverage despite the unresolved cache applicability. Account for dynamic cache-option lookups in the owning uncertainty counter, as the browser-window and IPC producers already do.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| : options === undefined | ||
| ? ({ status: "missing" } as const) | ||
| : (() => { | ||
| const resolved = resolveElectronOptionObject( |
There was a problem hiding this comment.
Normalize source-only VM options before property lookup
For cache-free calls such as new vm.Script(code, undefined), vm.compileFunction(code, [], void 0), or new vm.Script(code, "file.js"), Node applies default options or the filename overload without supplying cachedData. Here, only a missing AST argument is recognized as omission; these valid non-object forms fail object resolution and become unknown. This creates spurious opaque-cache nodes and limitations, and can incorrectly change otherwise empty Electron semantics to recovered. Normalize each API's proven default and filename-only forms before resolving an option object.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| (t.isCallExpression(node) && | ||
| syntacticMember(node.callee) === "compileFunction"); |
There was a problem hiding this comment.
Admit optional VM compilation calls to the deferred analysis
With a proven ESM VM import, both vm?.compileFunction(code, [], { cachedData }) and vm.compileFunction?.(code, [], { cachedData }) perform valid compilations, but Babel represents them as OptionalCallExpression. This predicate rejects them before the shared callable owner can establish their identity, so the declaration disappears from dynamic_code, the compilation count, and the cache-boundary graph. Include optional-call nodes throughout the deferred pipeline, as the sibling Electron producers do.
Useful? React with 👍 / 👎.
| (t.isCallExpression(node) && | ||
| syntacticMember(node.callee) === "compileFunction"); |
There was a problem hiding this comment.
vm.compileFunction?.(source, [], { cachedData }) produces an OptionalCallExpression, which this filter skips. Even with a proven vm import, the call produces no dynamic_code record, graph boundary or summary count. Admit optional calls through the same settled callable check.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/electronStaticAnalysisDynamicCode.ts
Line: 52-53
Comment:
**Optional calls hide caches**
`vm.compileFunction?.(source, [], { cachedData })` produces an `OptionalCallExpression`, which this filter skips. Even with a proven `vm` import, the call produces no `dynamic_code` record, graph boundary or summary count. Admit optional calls through the same settled callable check.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| const initializer = semanticStableInitializer(binding, index.bindings); | ||
| return initializer === undefined | ||
| ? undefined | ||
| : unwrapJavaScriptExpression(initializer.node).node; |
There was a problem hiding this comment.
Destructuring names the wrong file
stableExpression returns the whole initializer while dropping its selected property and possible default. For const { cachedData = otherBytes } = fs.readFileSync(path.join(__dirname, "a.cache")), the normal Buffer result has no cachedData property, so the supplied value is otherBytes. This code instead reports a.cache as its source.
Reject projected or fallback bindings unless their selected value is proved. This violates the AGENTS.md requirement to preserve identity and uncertainty across boundaries.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/electronStaticAnalysisDynamicCode.ts
Line: 235-238
Comment:
**Destructuring names the wrong file**
`stableExpression` returns the whole initializer while dropping its selected property and possible default. For `const { cachedData = otherBytes } = fs.readFileSync(path.join(__dirname, "a.cache"))`, the normal Buffer result has no `cachedData` property, so the supplied value is `otherBytes`. This code instead reports `a.cache` as its source.
Reject projected or fallback bindings unless their selected value is proved. This violates the `AGENTS.md` requirement to preserve identity and uncertainty across boundaries.
**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| const lookup = spreadBeforeOptions | ||
| ? ({ status: "dynamic" } as const) | ||
| : options === undefined | ||
| ? ({ status: "missing" } as const) | ||
| : (() => { |
There was a problem hiding this comment.
Undefined options get cache warnings
Both new vm.Script(source, void 0) and vm.compileFunction(source, [], void 0) omit cache options. Their argument nodes still reach resolveElectronOptionObject, fail object lookup and become unknown rather than absent. That adds an opaque-cache node and warning to source-only compilation. Treat proven undefined options as missing before object lookup.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/electronStaticAnalysisDynamicCode.ts
Line: 109-113
Comment:
**Undefined options get cache warnings**
Both `new vm.Script(source, void 0)` and `vm.compileFunction(source, [], void 0)` omit cache options. Their argument nodes still reach `resolveElectronOptionObject`, fail object lookup and become `unknown` rather than `absent`. That adds an opaque-cache node and warning to source-only compilation. Treat proven undefined options as missing before object lookup.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Refs #9482. Report source-visible node:vm cached-data compilation boundaries without claiming cache acceptance or execution.
The producer settles mutation facts and uses the shared complete-callable owner for CommonJS and ESM VM APIs. Replaced methods are excluded. Intact options resolve through the existing owner; argument spreads remain unknown. Proven undefined cache values remain absent while their source expression is retained. A shared classifier keeps absent caches out of graph uncertainty and recovered Electron boundary counts.
Proven synchronous filesystem reads and awaited fs/promises reads retain cache source paths and their parsed bases through worker serialization. Only a proven source-directory base resolves against application inventory; relative literal paths retain their spelling without inventing a working directory. Graph paths, lookup results, source expressions and inference limits remain separate. The owning feature specification, plan and tasks are under docs/specs/javascript/v8-cached-data/.
Validation: 25 final domain/public filesystem tests passed, covering worker serialization, ESM and replaced callables, spread arguments, awaited reads, path bases, disabled caches, graph projection and source-only Electron summary state. The new spread/callable/read and absence/recovery controls failed against earlier implementations. check:fast, docs:check (9 README checks), formatting and diff checks passed. Node's VM implementation and contract informed the callable/compilation distinction. No target JavaScript, real V8 cache acceptance or full repository gate was executed.
Author readiness
Human owner: @2SinceJuly