Skip to content

feat(electron): report V8 cachedData compilation boundaries - #9501

Merged
morluto merged 8 commits into
morluto:mainfrom
2SinceJuly:fix/9482-v8-cached-bytes
Nov 9, 2026
Merged

morluto merged 8 commits into
morluto:mainfrom
2SinceJuly:fix/9482-v8-cached-bytes

Conversation

@2SinceJuly

@2SinceJuly 2SinceJuly commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

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

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

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T12:25:13.621990Z 57917a2 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.

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

@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5 Tier: plus

[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

  1. P1 Optional calls hide caches ▶
  2. P1 Destructuring names the wrong file ▶
  3. P2 Undefined options get cache warnings ▶
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.

Summary

Adds source-only node:vm cached-data compilation facts, worker serialization, graph boundaries and summary counts.

  • VM compilation sites now show whether cached data may be supplied.
  • Possible cached-data handoffs appear as unknown graph boundaries.
  • Electron summaries count declared V8 cached-data compilations.

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]
Loading

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

Copy link
Copy Markdown
Contributor Author

Rebased onto 4a1c4a59b locally (one conflict in ElectronBoundaryAnalysis.ts, resolved by keeping main's provenElectronFinding filters and appending dynamic_code, which carries no loader_authority). Reverted before pushing — the merged tree fails its own test and I have not finished the fix.

What breaks. electronStaticAnalysisDynamicCode.test.ts goes 4/4 → 3 failed after the merge. Traced it with an instrumented probe:

  • deferElectronDynamicCode still runs and finishElectronDynamicCodeSteps still sees the queued node (1 pending).
  • vmMemberAt then rejects it: provenVmModule requires provenance.status === "module", but fix(javascript): preserve loader authority for exact suffixes #9477 now returns {status: "ambiguous", reason: "CommonJS loader authority is unknown.", origins: [{specifier: "node:vm", loaderAuthority: "candidate"}]} for a plain const vm = require("node:vm"), because readSemanticRequireOriginCandidate marks every CommonJS require's loader authority as candidate.
  • So every vm.Script / compileFunction finding disappears, and electron.dynamic_code is undefined.

Why I did not just relax the check. Making provenVmModule accept candidate would restore the old behaviour but contradicts #9477's stated intent (candidate loaders are not proven identity). The right answer is presumably to keep the finding and mark it with the same candidate authority the other Electron fact families now carry, which means widening ElectronDynamicCodeFinding and its projection. That is a design decision on main's new contract, not a mechanical merge fix, so I would rather raise it than pick one unilaterally.

Leaving the branch at a018301dd unchanged. If you want a specific shape — candidate-tagged dynamic_code, or proven-only with the tests updated to drop the ambiguous cases — say which and I will implement it.

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

Copy link
Copy Markdown
Contributor Author

Merged origin/main (b46f4fceb, #9477) into the branch in 53e16134c to clear the conflict.

The only textual conflict was electronBoundaryFactCount: main added provenElectronFinding filtering to the seven existing fact families while this branch added the dynamic_code family, so the merge keeps both. The dynamic_code findings carry no loader_authority, so they are not filtered — they are recorded compilations, not candidate Electron identities.

One test-level follow-up: electronStaticAnalysisDynamicCode.test.ts parsed its fixture with analyzeJavaScriptStaticSource, which treats a .js fixture as ESM. After #9477 every require from an ESM-parsed file keeps only candidate loader authority, so the fs.readFileSync(path.join(...)) argument no longer resolved to a path and the cache artifact case failed. The production path was never wrong — the real .cjs boundary test (electronVmCachedData.test.ts) passed before and after the merge. The fixture now uses the shared CommonJS helper.

Verified locally: tsc --noEmit clean, electronStaticAnalysisDynamicCode.test.ts 4/4, electronVmCachedData.test.ts 3/3, javascriptStaticPathResolution.test.ts 114/114, electronBundledRequireIdentity.test.ts + electronModuleInterop.test.ts 301/301, oxfmt --check clean.

Not yet addressed: the review threads from chatgpt-codex-connector and greptile-apps on the pre-merge commit — I am working through them next.

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

@morluto morluto changed the title feat(electron): report V8 cachedData execution boundaries feat(electron): report V8 cachedData compilation boundaries Nov 9, 2026

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

@morluto

morluto commented Nov 9, 2026

Copy link
Copy Markdown
Owner

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.

@morluto
morluto merged commit 2c27c2a into morluto:main Nov 9, 2026
4 of 6 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: 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".

Comment on lines +155 to +157
: lookup.status === "missing"
? "absent"
: "unknown",

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 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 👍 / 👎.

Comment on lines +111 to +114
: options === undefined
? ({ status: "missing" } as const)
: (() => {
const resolved = resolveElectronOptionObject(

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 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 👍 / 👎.

Comment on lines +52 to +53
(t.isCallExpression(node) &&
syntacticMember(node.callee) === "compileFunction");

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 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 👍 / 👎.

@morluto morluto mentioned this pull request Nov 11, 2026
3 tasks done
Comment on lines +52 to +53
(t.isCallExpression(node) &&
syntacticMember(node.callee) === "compileFunction");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

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.

Comment on lines +235 to +238
const initializer = semanticStableInitializer(binding, index.bindings);
return initializer === undefined
? undefined
: unwrapJavaScriptExpression(initializer.node).node;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment on lines +109 to +113
const lookup = spreadBeforeOptions
? ({ status: "dynamic" } as const)
: options === undefined
? ({ status: "missing" } as const)
: (() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@morluto morluto added enhancement New feature or request provider: electron Analysis provider / engine: electron labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request provider: electron Analysis provider / engine: electron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants