Skip to content

fix(javascript): preserve runtime path bytes and Electron ownership - #4941

Merged
morluto merged 73 commits into
morluto:mainfrom
ShuaixinHuang:codex/fix-runtime-path-ownership-resubmit
Oct 20, 2026
Merged

morluto merged 73 commits into
morluto:mainfrom
ShuaixinHuang:codex/fix-runtime-path-ownership-resubmit

Conversation

@ShuaixinHuang

@ShuaixinHuang ShuaixinHuang commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem and outcome

Electron renderer/preload paths require the original filename bytes and a proven application owner. The shared JavaScript analysis now retains unsupported loads, competing owners and possible app-path mutations as explicit uncertainty instead of resolving them to a decoy. This replaces #4327.

The current fixes use the existing source and export owners:

  • Preserve possible app-path setters when a native Electron app object escapes through an export, while retaining definite local replacements.
  • Model Object.assign exports as the own enumerable fields actually copied, including later-source overwrites, and retain shared module provenance.
  • Share mutable path/URL default-import and native child-object identities across aliases.
  • Preserve opaque alternatives in conditional createRequire factories.
  • Normalize TypeScript-wrapped member-store targets at the shared iteration-source producer. A typed assignment now retains the same loader RHS and write-target identity as its untyped counterpart; local replacements remain inert. This follow-up adds two production lines.

Synced upstream main at 833136507dd79d959340b09862a53af344e4f1b3. Its process UID/exit-scope/lifecycle implementation and recorded-crash trace policy replace the superseded local observer. The upstream canonical base64 schema replaces the separate schema translator; MCP metadata/intersection controls remain. Process production and recorded-crash verification match that upstream base. Its readiness fork-association fix (#5316) also applies.

Executed validation

Current revision: 35e2cad5bdbbf90f15adb5c814297b25e36f4c79, Windows x64, Node 24.18.0/npm 11.16.0.

  • Final combined source and ownership regressions: 173 files, 4,153 passed and 8 existing platform skips. This includes the JavaScript/application/worker, native ownership, trace-policy, canonical-schema and four typed-store controls.
  • Final compiled CLI/MCP indirect-loader checks: 82/82 passed locally, including all 78 existing cases and four added typed-store CLI/MCP controls (252.85 s). The same 82 tests also pass on hosted Linux (178.329 s)..
  • The typed-store source controls reproduced 2 failures with 2 passing local controls on the previous revision. The compiled CLI/MCP controls independently reproduced 2 failures and 2 passes on 31d6970b, with 78 unrelated cases excluded by the name filter.
  • The Linux-only CI failure in the literal-punctuation fixture used an unbound path identifier. The fixture now supplies actual CommonJS native-path and Electron bindings and checks the same exact preload%20?#.cjs result through full static analysis. The filtered test failed before and passes after on Windows (1 executed, 26 excluded). The current hosted Linux run passes all 27 tests in this file; shard 1 passes 1,935 tests with zero failures.
  • Final npm run check: six tasks passed, 2,277 resolved module boundaries, 1,594 architecture guards, zero lint errors. Build, MCP catalog and diff checks passed. Test discovery registered all 1,766 files exactly once.
  • Representative completed-task cost evidence: the same 38 samples in two rounds produced 1 mismatch before and 0 after, comparing 31d6970b to this committed source (83 input hashes; artifact 48cf3aee8d13290c4bdb603071d894b6268aa8aefdef2fff056a414d9ed38baf; workload df41bf234b49076137628cd8f858807acc8fde439ca5996078cd669f9e7b5af9). Before/after wall times were 134.852/210.824 ms and 70.360/149.873 ms; CPU 187/265 ms and 140/94 ms; whole-child high-water RSS 84,532/85,048 KiB and 90,892/89,576 KiB. Mixed results under uncontrolled desktop load establish neither a speedup nor a definite regression. Imports/bundling and complete CLI/native process-family costs are excluded.

Current-head hosted Linux executes all 16 jadx controls successfully (12.453 s), including cancellation of an in-flight Java readiness probe and joining cancelled Java until its owned child exits. These are actual Linux passes, independent of the 16 POSIX-only local skips. Earlier validation on the immediately preceding 31d6970b revision also passed 148 compiled public/Node/schema controls across nine files; that historical count is not added to the current-head totals.

Current-head hosted status: SUCCESS on this exact revision: https://github.com/morluto/rea/actions/runs/39350036839. All five portable test shards and CI required passed: 10,251 tests passed, zero failed, 162 existing skips; 1,025 test files passed. Source tests, static checks, build, docs, real JavaScript recovery, Apple artifact E2E, Windows package/capability checks and all three native package baselines passed. Independently scheduled sigrok/tshark checks also passed. Scope-excluded lanes remain skipped and are not counted as passes. PR readiness is SUCCESS (https://github.com/morluto/rea/actions/runs/39350091288). GitHub reports mergeable=true and mergeable_state=clean against upstream 8331365..

The four reviewed inline threads were replied to with evidence and resolved at 31d6970b. The typed-store follow-up also addresses the older outside-diff finding in #4941 (comment).

No analyzed target or real Electron application is executed by the public analysis fixtures. Authored Node oracle fixtures establish only the native semantics they exercise. Real provider execution, complete CLI process-family costs and token usage remain unmeasured unless explicitly reported above. Prepared with AI assistance; the original human initial-readiness declaration is preserved.

Author readiness

Human owner: @ShuaixinHuang

The human owner explicitly confirmed review, evidence, responsibility and initial readiness for this PR on 2026-10-18.

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

…x-runtime-literal-percent

# Conflicts:
#	tests/boundary/filesystem/ghidraProfileArtifactOwnership.test.ts
@ShuaixinHuang
ShuaixinHuang marked this pull request as ready for review October 18, 2026 07:52
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Comment on lines +1453 to +1458
while (
remaining.length > 1 &&
(remaining[0] === "posix" || remaining[0] === "win32")
) {
selected = `path/${remaining[0]}`;
remaining = remaining.slice(1);

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 Changed helpers select decoys

The new path identities lose writes across names that share the same object. On POSIX, require("node:path") and require("node:path/posix") are identical. After changed.resolve = first => first through the first name, a read through the second checks a different write bucket. A preload such as p.resolve(runtimePath, __dirname, "decoy.cjs") is then reported as decoy.cjs, although the replacement returns runtimePath.

Parent-slot writes have the same gap: replacing changed.posix is stored under path, while a separate default import reading path.posix.resolve checks path/posix. Preserve shared-object writes and parent-slot writes before proving the selected helper native.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSemanticRequireOrigin.ts
Line: 1453-1458

Comment:
**Changed helpers select decoys**

The new path identities lose writes across names that share the same object. On POSIX, `require("node:path")` and `require("node:path/posix")` are identical. After `changed.resolve = first => first` through the first name, a read through the second checks a different write bucket. A preload such as `p.resolve(runtimePath, __dirname, "decoy.cjs")` is then reported as `decoy.cjs`, although the replacement returns `runtimePath`.

Parent-slot writes have the same gap: replacing `changed.posix` is stored under `path`, while a separate default import reading `path.posix.resolve` checks `path/posix`. Preserve shared-object writes and parent-slot writes before proving the selected helper native.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +299 to +305
for (const name of fields.definite)
if (!overwritten.has(name))
exported.push({
exportedName: name,
value,
projection: [name],
ownEnumerable: true,

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 Object.assign invents setters

Object.assign can invoke a target setter without storing the source value. For Object.defineProperty(exports, "change", {set(value){}, enumerable:true}); Object.assign(exports, {change:app.setAppPath});, the setter discards the function and exports.change remains undefined.

This loop still publishes app.setAppPath. The helper therefore adds app_path_changes, and an importing entrypoint loses its valid loadFile("index.html") link. Check the target's selected property and descriptor too, rather than treating every selected source field as the resulting export.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptCommonJsExportReceivers.ts
Line: 299-305

Comment:
**`Object.assign` invents setters**

`Object.assign` can invoke a target setter without storing the source value. For `Object.defineProperty(exports, "change", {set(value){}, enumerable:true}); Object.assign(exports, {change:app.setAppPath});`, the setter discards the function and `exports.change` remains `undefined`.

This loop still publishes `app.setAppPath`. The helper therefore adds `app_path_changes`, and an importing entrypoint loses its valid `loadFile("index.html")` link. Check the target's selected property and descriptor too, rather than treating every selected source field as the resulting export.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Copy link
Copy Markdown
Contributor Author

Follow-up for the older outside-diff “Typed writes lose module loads” finding in #4941 (comment): fixed in 35e2cad5bdbbf90f15adb5c814297b25e36f4c79. The shared iteration-source producer now unwraps TypeScript assignment targets using the same normalization as write-target discovery (two production lines); no consumer fallback was added.

Before: the typed/untyped native/local source controls were 2 failed / 2 passed, and the independent compiled CLI/MCP controls on 31d6970b were also 2 failed / 2 passed. After: all 82 compiled indirect-loader controls pass, including the four added typed-store cases; the combined source/ownership suite passes 4,153 tests with eight existing platform skips. Native Node oracle and local-replacement controls remain covered.

The previous hosted Linux run also passed all 16 jadx controls, including the original Java readiness cancellation test. Its one portable-test failure was an unbound path in the literal-punctuation fixture; that fixture now supplies the real native bindings and retains the exact filename assertion. New current-head CI is running: https://github.com/morluto/rea/actions/runs/39350036839. Readiness is successful and GitHub reports the PR mergeable. The PR body records the current evidence and remaining validation limits.

@morluto
morluto merged commit e9fc8fb into morluto:main Oct 20, 2026
44 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 20, 2026
3 tasks done

@CassieFox23 CassieFox23 left a comment

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.

TL;DR: At 35e2cad, my four earlier findings and the four bot findings I reproduced last time are all fixed. The six threads the author closed since then also hold. The two bot threads still open both reproduce, and one test still fails on Node 22 because of Node 22 itself.

This PR merged after my run, at the same head I tested. I'm posting this as a record. The two open threads below now apply to main.

I ran fixtures and named test files only. I did not run real apps. Thanks, ShuaixinHuang, for the quick fixes.

My earlier findings

"Old" is my result at the head named in the first column. "Now" is my result at 35e2cad. Node 22.23.1, 24.18.0 and 26.11.1 gave the same result on every probe below.

# Finding Old Now
5 Bound module.require (c4ec17d, my review) Reproduced Fixed. bind, .call, .apply, Reflect.apply and a captured-then-bound alias all give unavailable.
6 Windows-relative package main (c4ec17d) Reproduced Fixed. sub\main.cjs gives unavailable.
14 Module gaps across archive containers (c4ec17d) Reproduced Fixed. require(process.env.X) inside app.asar gives unavailable.
16 app.setAppPath (c4ec17d) Reproduced Fixed. A direct call and a returned alias both give unavailable.
- packageImportAliases.test.ts on Node 22 (c4ec17d) 1 failed Still fails on Node 22 only. The same test fails with ERR_INVALID_MODULE_SPECIFIER. A tiny package with only the imports key #/x fails the same way on plain Node 22.23.1 with no rea code. It passes on Node 24.18.0 and 26.11.1.
- Valid preload links disappear (my newer review, 01cd14e) Reproduced: no preload role Fixed. With var __dirname; the preload resolves to a/preload.cjs, the same as without the var.
- Prove dirname anchors (01cd14e) Reproduced: a/decoy.cjs Fixed. helper.dirname(__filename) and helper.dirname(import.meta.url) no longer give a/decoy.cjs. No preload link is drawn. A real path.dirname(__filename) still gives a/decoy.cjs.
- Retain require.main.require (01cd14e) Reproduced: b/index.html Fixed. The renderer is unavailable.
- Exported setAppPath delegate (01cd14e) Reproduced: a/index.html Fixed. change.call(app, lib) gives unavailable.

The four author replies on these last four threads say "Fixed in eb553d5". I tested the behaviour, not the replies.

Bot threads the author closed since my last review

All of these are resolved with an author reply ("Fixed in" 93969ba or 31d6970). I tested one fixture each, in the shape the thread describes.

Thread Result at 35e2cad
Retain process.mainModule require calls Holds. process.mainModule.require(...) gives unavailable.
Track setters exported with Object.assign Holds. change.call(app, lib) gives unavailable.
Exported app keeps stale paths Holds. A caller that sets the app path gives unavailable. One side effect, see below.
Changed helpers select decoys Holds for two default imports of node:path (no decoy). The newer open thread shows a gap that remains.
Overwritten setters hide valid pages Holds. With {change(){}} as the later source, the renderer resolves to a/index.html. With the setter as the later source, it is unavailable.
Typed writes lose module loads Holds. (box.make as any) = () => module in main.ts gives unavailable, the same as the untyped form. A typed local store gives b/index.html, as it should. I built the fixture from the new test in 35e2cad, because I did not fetch the original finding text.

One side effect shows on the "exported app" thread. Take a helper that exports the native app. An entrypoint imports it but never calls setAppPath. That now also gives unavailable. The correct page is a/index.html. This is cautious, not a wrong link. The same happens for a setter module imported without a call.

Open bot threads at 35e2cad

Both are from 12:40 AM UTC today. Both reproduce.

Thread Sev Result What I saw
Changed helpers select decoys P1 Reproduces const changed = require("node:path"); const p = require("node:path/posix"); changed.resolve = first => first;, then p.resolve(BASE, __dirname, "decoy.cjs"): the preload resolves to a/decoy.cjs. Plain Node returns BASE, because require("node:path") === require("node:path/posix") is true. The parent-slot half, changed.posix = {resolve: first => first} then path.posix.resolve(...), does the same. Both halves fail in CommonJS and in ESM. The control with no replacement correctly gives a/decoy.cjs.
Object.assign invents setters P1 Reproduces Object.defineProperty(exports, "change", {set(value){}, enumerable: true}); Object.assign(exports, {change: app.setAppPath});. Plain Node leaves exports.change as undefined. An entrypoint that only imports this module, then loads index.html, gets unavailable. The correct page is a/index.html. A setter module without the defineProperty gives unavailable too, so the descriptor is not what decides it. The case is still a missing valid link.

Tests

On Node 24.18.0 I ran 31 test files, 903 tests: all passed. They are the files the PR touched since my last review (19 of 22 still exist) plus the 12 from my last round. On Node 22.23.1 the same files give 902 of 903; the one failure is the Node 22 test above. I ran packageImportAliases.test.ts on Node 26.11.1 (13 passed), and no other test file there. The test count is not comparable with the 571 from last round, because the set of files is different. The tests pass while my two open-thread fixtures fail, so the tests do not cover those shapes.

Not run

  • Real apps, live Electron or browser captures. Every result comes from fixture folders I wrote and the graph builder.
  • The original text of the "Typed writes lose module loads" finding. I used the shape from the PR's own new test.
  • How the fixed threads behaved before their fix commits. That includes "Typed writes lose module loads". I did not build 31d6970 or 93969ba.
  • The factory choices thread.
  • The other resolved threads I did not name above.
  • N6 (alias stall) at depths other than 18 levels; 18 levels took about 1 second on all three Node versions.
  • Other shapes of the two open threads.
  • Windows hosts. The Windows path rows are path-syntax checks on Linux.
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.11
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head / base: 35e2cad / 8331365 (the PR base). main is now 3fca2e0.
  • Other: the box was shared with other test jobs, so timings are rough.
Commands
git archive 35e2cad5b into a fresh folder
npm ci --ignore-scripts; npm run build:cached; npm run test:prepare   (Node 24)
npm run test:focused -- <probe files>   (Node 22, 24 and 26)
npm run test:focused -- <31 test files>   (Node 24; Node 22 for the same files)
node -p 'require("node:path")===require("node:path/posix")'   (true on Node 22, 24, 26)
node -e 'const e={};Object.defineProperty(e,"change",{set(v){},enumerable:true});Object.assign(e,{change:1});console.log(e.change)'   (undefined on Node 22, 24, 26)

Fixture for the first open thread (CommonJS):

a/package.json  {"main":"main.cjs"}
a/main.cjs      const {BrowserWindow}=require("electron"); const changed=require("node:path"); const p=require("node:path/posix"); changed.resolve=first=>first; new BrowserWindow({webPreferences:{preload:p.resolve(process.env.BASE, __dirname, "decoy.cjs")}});
a/decoy.cjs     (empty)

Expected: no preload resolved to a/decoy.cjs. Seen: resolved, a/decoy.cjs.

Fixture for the second open thread:

a/package.json  {"main":"main.cjs"}
a/setter.cjs    const {app}=require("electron"); Object.defineProperty(exports,"change",{set(value){},enumerable:true}); Object.assign(exports,{change:app.setAppPath});
a/main.cjs      require("./setter.cjs"); require("./win.cjs");
a/win.cjs       const {BrowserWindow}=require("electron"); new BrowserWindow().loadFile("index.html");
a/index.html, a/lib/index.html, index.html

Expected: renderer resolved, a/index.html. Seen: unavailable.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

kaoru0822-kitauji added a commit to To3akaRin/rea that referenced this pull request Oct 21, 2026
main's morluto#5224 and morluto#4941 rewrote the snapshot, capture-progress, ZIP and runtime-observation tests that this branch's shared test-hardening commits patched. Take main's version of those files so the branch diff is only the HAR entry-scoping fix (12c6316).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kaoru0822-kitauji added a commit to To3akaRin/rea that referenced this pull request Oct 21, 2026
main's morluto#5224 and morluto#4941 rewrote the snapshot, capture-progress, ZIP and runtime-observation tests that this branch's shared test-hardening commits patched. Take main's version of those files so the branch diff is only the ARM32 Mach-O slice fix (1ccb40d).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kaoru0822-kitauji added a commit to To3akaRin/rea that referenced this pull request Oct 21, 2026
main's morluto#5224 and morluto#4941 rewrote the snapshot, capture-progress, ZIP and runtime-observation tests that this branch's shared test-hardening commits patched. Take main's version of those files so the branch diff is only the Webpack loader-alias changes (bdd57b4, 641f662, 3a0fd8a).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto morluto added area: runtime Process capture and runtime observation bug Something isn't working provider: electron Analysis provider / engine: electron labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working provider: electron Analysis provider / engine: electron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants