Skip to content

fix(process): handle launcher exit races and retain CommonJS regressions - #1357

Closed
Y0UW1SH wants to merge 12 commits into
morluto:mainfrom
Y0UW1SH:fix/commonjs-exports-reassignment
Closed

Y0UW1SH wants to merge 12 commits into
morluto:mainfrom
Y0UW1SH:fix/commonjs-exports-reassignment

Conversation

@Y0UW1SH

@Y0UW1SH Y0UW1SH commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

When a process-table snapshot races launcher exit, its stale command can make otherwise owned cleanup fail. This PR refreshes that snapshot only after a fresh table proves that the launcher PID has exited. Surviving or reused PIDs, unavailable inspection, foreign group members, and detached continuations retain cleanup uncertainty and the existing ownership checks.

The binary-layout verifier keeps its configured launcher alive while its resource-limited Python child runs, preserving process-group identity through timeout cleanup. Its memory fixture forces an allocation failure rather than racing section processing against a deadline.

The CommonJS correction is now present in upstream main, including assignment-chain and captured-receiver handling. This branch retains that implementation unchanged and adds CLI/MCP regressions using Node's real CommonJS loader as the oracle. Expectations now recognize discarded named exports as missing and resolve nested local assignment chains. A CLI regression also checks decoded error-message paths, including literal-backslash POSIX filenames.

The branch includes upstream main at f88c99021b88ce67e513025901f57478d8107d0c through merge commit 8d1dfc986a52e09b78443b025ce812c3d75f3dc1. Both histories are retained; no force push was used. GitHub reports the branch mergeable.

Validation with Node 24.18.0 and npm 11.16.0:

  • Runtime compilation and packaged skill generation pass.
  • npm run check:ci passes all eight tasks and architecture guards, including typechecking, lint, formatting, unused-code checks, metadata, duplication and debt-marker checks.
  • npm run docs:check passes.
  • 239 JavaScript domain regressions and 71 process-ownership tests pass.
  • One native host-identity test and the compiled CLI/MCP checks cannot be verified in this container: its PID namespace makes process inspection fail with fatal library error, lookup self. Those checks require GitHub's native runner; no production fallback or test assertion was weakened to bypass the restriction.

The PR remains draft while CI for the updated commit runs.

@Y0UW1SH
Y0UW1SH marked this pull request as ready for review October 9, 2026 19: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.

@Y0UW1SH
Y0UW1SH marked this pull request as draft October 9, 2026 19:56
@Y0UW1SH
Y0UW1SH marked this pull request as ready for review October 9, 2026 20:15
@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.

@Y0UW1SH
Y0UW1SH marked this pull request as draft October 9, 2026 20:17
@Y0UW1SH
Y0UW1SH marked this pull request as ready for review October 9, 2026 21:38
@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.

@CassieFox23

CassieFox23 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: I tested this on Linux, and it fixes both cases. On 6.2.0 and on main, both get a fake definite change. On this branch, both match what Node really exports. A real export still shows its change. MCP agrees with the CLI.

This is head efb9054e8, which moved at 6:16 PM my time. The three changed test files pass: 54 tests.

The full suite ran with --maxWorkers=4: 703 files and 6,361 tests, with one failure. That was a 30 s timeout in analysisSelectorCli.test.ts, while the box was under heavy load. Run alone, it passed twice, in 27 s and 30 s. This PR doesn't touch that file.

For each case, I wrote a v1/v2 pair of parser.cjs files that differ only in a count value. Then I ran analyze-javascript-application on each, and compare-javascript-export-shapes on the default export. I checked each file with Node's require first.

Case Node exports 6.2.0 and main This branch
1. A bare exports = function {} /count changed missing, partial
2. A shadowed alias chain inner parse, count: 7 /count changed no changes
3. Control: module.exports = function 1 vs 2 /count changed /count changed

Case 2 is the PR's own: an outer parse, shadowed inside configure(), then module.exports = exports = parse. Main here is 7738c1f.

Over stdio MCP, one session compared two different pairs back to back. I tried case 1 then 3, and case 2 then 1. On all three builds, the results match the CLI, and the second call works.

Not run: Windows or macOS, a real app, and the process cleanup change beyond its tests.

Edit: This line said JADX by mistake. The cleanup change is the process one, in ProcessOwnership.ts. The newer head f28febacb is tested in this comment.

Test setup
  • Box: Linux x86-64
  • Node: 22.23.1

🤖 Generated with Claude Code (Opus 5.5) 🦊

@morluto

morluto commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Reviewed 665749c. No blocking issue found in the changed logic. Skipping a bare exports rebinding as a default export is correct; compound/logical writes no longer establish a callable from the RHS alone, and the recognized module.exports = exports = fn chain is deliberately narrow.

I also reviewed the separate ProcessOwnership change in this PR: the exit refresh only settles a launcher mismatch when a fresh table no longer contains that PID, keeps surviving detached-descendant uncertainty, and leaves token/identity validation in place before signaling. That is materially more appropriate than relaxing ownership based on the command name alone.

The supplied tests exercise real CommonJS loading with public CLI/MCP comparison and the ownership failure paths. CI is green at this head. Looks ready subject to final checks; I did not independently rerun its full process/native suite. After merging #1351 or #1292, rerun these CommonJS cases because those PRs modify the same semantic collection/binding area. For future changes, splitting the semantic and process-supervision fixes would make independent review easier.

Combine assignment-aware CommonJS exports with the lexical module-link binding owner, retaining parameter-copy and process ownership fixes. Validation: 118 focused tests including public CLI/MCP exported-binding regressions, typecheck/lint, architecture guards, and formatting.
@CassieFox23

CassieFox23 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: Thanks for the review, morluto. I reran the CommonJS cases on this branch merged with current main, which now has #1351 and #1292. It's clean. The bare exports = … fix still holds, and main alone still gets that one wrong. Main now handles the shadowed alias case too, through #1351, and the two agree.

I merged main at 39dabd06 into this head, 12e45d6f, in a scratch clone. Git merged it with no conflicts.

Full suite. After npm run test:prepare: 700 files, 6,389 tests. 6,300 passed, 89 skipped, 0 failed.

My three parser.cjs pairs, through compare-javascript-export-shapes:

Case main at 73a664bc This branch plus main
1. A bare exports = function /count changed missing, partial
2. A shadowed alias chain no changes no changes
3. Control: module.exports = function /count changed /count changed

Case 2 was wrong on main at 7738c1f. #1351's head alone fixes it. So this branch and #1351 overlap there, and they agree.

Over stdio MCP, I compared two different pairs back to back in one session: case 1 then 3, and case 2 then 1. Both builds match their CLI results, and the second call works.

Test setup
  • Box: Linux x86-64
  • Node: 22.23.1

🤖 Generated with Claude Code (Opus 5.5) 🦊

Merge current main and follow refreshed descendants of the original process lineage before accepting a stale-launcher exit. A newly detached descendant now retains cleanup uncertainty during both planning and pre-signal validation instead of being left alive behind a successful cleanup result.

Validated with Node 24.18.0 and npm 11.16.0: build:cached, all eight check:ci tasks, and 574 focused tests. The real Linux process-identity case is unavailable on this host and remains enabled in CI.
@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The CommonJS fix still holds on the new head f28febacb. Its code and tests are the same as on the last head, apart from line numbers. The merge commit also adds new process-cleanup code, and its tests pass.

This head merges main at 0d8997833 into 12e45d6fc. I got the same results on Node 22.23.1, 24.18.0 and 26.11.1.

What the merge changed. I compared each head's diff against its own main. The CommonJS change in javascriptSemanticProjection.ts and both CommonJS test files match, except for line numbers. Git merged that file and verify-binary-layout.mjs with no conflict. Three other files hold new lines that are in neither parent: ProcessOwnership.ts, ProcessOwnership.validation.test.ts and ProcessOwnershipProcessTree.ts. The new tests in that test file expect cleaned: false and no signal when a child detaches as the launcher exits. The commit subject describes that change, and no commit on any branch I fetched has that subject.

Tests. The three changed test files pass: 63 tests, on all three Nodes. That was 54 at efb9054e8, my first run, and 61 at 12e45d6fc. The commit 889c17ba9 and the first main merge came between those two. This merge adds 2 process tests. npm run check:fast passes on Node 24.18.0, in a fresh clone.

Cases. I used the same parser.cjs v1/v2 pairs as in my last comment, through compare-javascript-export-shapes.

Case main 0d8997833 Head f28febacb
1. A bare exports = function /count changed missing, 0 changed
2. A shadowed alias chain no changes no changes
3. Control: module.exports = function /count changed /count changed
4. Real package: ms 2.0.0 vs 2.1.3 (MIT) 0 changed, 4 unknown 0 changed, 4 unknown, same as main

Main is one commit ahead of this merge's parent 0d8997833: c1217e711 (#1577). It touches none of this PR's files. I did not test a merge with it.

Still not run

  • Windows or macOS.
  • A real app. Row 4 is one small package.
  • verify:binary:layout. It needs pwntools, which is not installed here. I only compiled its new C fixture with gcc -Wall -Wextra -Werror, and that passed.
  • The full test suite on this head.
  • My two-pair stdio MCP session from the earlier comments. The PR's own MCP test file passed instead: 38 tests.
  • The process cleanup change beyond its tests. My first comment called it a JADX change by mistake; it is in ProcessOwnership.ts.
  • A merge with main at c1217e711 (fix(javascript): retain runtime scope in bundled module relationships #1577).

Edit: The newest head cf4fc9c has the same CommonJS and process code as f28feba, and the same tests. Only line numbers moved, and one 6-line test file, referenceSourceImportStatus.test.ts, is new in the PR's diff. My four cases give the same results, and the PR's four test files pass: 75 passed, 2 skipped.

Commands
  • Diff check: git diff <main parent> <head> for 12e45d6fc (parent a9f5dad5a) and for f28febacb (parent 0d8997833), compared with diff.
  • New lines in neither parent: git diff-tree --cc -p f28febacb.
  • Build: git archive, then npm ci and npm run build, once per commit.
  • Tests: vitest run tests/boundary/cli/commonJsExportsReassignment.test.ts tests/boundary/mcp/commonJsExportsReassignmentMcp.test.ts src/process/ProcessOwnership.validation.test.ts --maxWorkers=4, once per Node.
  • Cases: analyze-javascript-application <dir> --json on each v1 and v2 folder. Then compare-javascript-export-shapes on the default export. For row 4 the request went in a .json file, since the two analyses were too big for one command line.
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • 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: f28febacb / 0d8997833

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

Merge upstream main at 926c2d6, preserving the CommonJS exports reassignment fix and launcher-exit ownership safeguards.

Incorporate upstream browser cancellation cleanup, the EVM cleanup diagnostic fix, and firmware/Qwen regression expectations matching intended cleanup behavior.

Verification: check:ci (8 tasks and architecture guards), docs:check, strict C fixture compilation, and JavaScript syntax check passed. Focused tests: 539 passed, 2 skipped; 42 native-process cases failed at the container's procps/process-identity boundary (fatal library error, lookup self). CommonJS CLI/MCP, browser cancellation, Qwen uninstall, and session snapshot regressions passed. Native lanes require GitHub CI verification.
Check CLI failure message fields directly instead of comparing a raw path with re-serialized JSON, which escapes Windows backslashes. Keep the category, error, full-output wrapper, exit status, logging and recovery assertions intact.

Exercise JSON escaping on POSIX with a literal backslash in the root filename so the regression reproduces without a Windows host. Apply the decoded-message assertions to the permission case as well.

Verification with pinned Node 24.18.0 and npm 11.16.0: the four preflight cases fail with the old assertion and pass with this change; three existing platform/permission cases are skipped on this host. check:ci passes all eight tasks and architecture guards. GitHub CI on parent a1537d3 has confirmed the original failing shard and real binary-layout/EVM lanes pass.
Merge upstream main at 54e2890, including its equivalent decoded-path assertions and browser formatting repair. Resolve the overlapping CLI assertions with the upstream checks while preserving the literal-backslash fixture regression on POSIX.

Preserve the CommonJS feature, conservative launcher-exit cleanup, all existing branch commits, and the new upstream browser, JavaScript package-path, and client-environment fixes.

Verification with Node 24.18.0/npm 11.16.0: check:ci passes all eight tasks and architecture guards; docs:check passes. Focused integration suites: 345 passed, 4 existing availability/platform cases skipped. Two Electron tests failed before launch at the local procps/process-identity boundary (fatal library error, lookup self), so their native verification remains with GitHub CI. CommonJS CLI/MCP, process-ownership validation, session snapshot, setup, package-path, browser cancellation, and decoded-path regressions pass.
@Y0UW1SH
Y0UW1SH marked this pull request as draft October 11, 2026 02:10
Retain upstream CommonJS assignment-chain and captured-receiver semantics.
Align existing MCP regressions with missing detached exports and resolved
local assignment chains, while preserving launcher-exit cleanup hardening.

Validation: pinned Node 24.18.0/npm 11.16.0; check:ci and docs:check pass;
310 domain/process-ownership tests pass. Local compiled CLI/MCP and one
host-identity test remain blocked by the container process namespace.
@Y0UW1SH Y0UW1SH changed the title fix(javascript): correct CommonJS exports reassignment fix(process): handle launcher exit races and retain CommonJS regressions Oct 11, 2026
morluto added a commit that referenced this pull request Oct 11, 2026
Refresh a mismatched launcher snapshot only when a new live process table proves its PID absent. Preserve uncertainty for detached descendants and continue checking ownership of surviving group members before signaling. Index retained lineage membership instead of rescanning it for each refreshed process.

Adapted from #1357. Validation: 71 source tests passed, one Linux-only identity case skipped; 32 real process-boundary tests passed on macOS.

Co-authored-by: You Wish <[email protected]>
morluto added a commit that referenced this pull request Oct 11, 2026
Keep the configured launcher alive while its limited Python child runs so ownership checks retain the admitted executable identity. Trigger memory exhaustion with one oversized ELF zero-fill tail rather than racing section traversal against a timeout.

Adapted from #1357. JavaScript syntax, strict C syntax compilation, formatting, and static checks passed. The Linux pwntools verification lane was not run on this macOS host.

Co-authored-by: You Wish <[email protected]>
@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Thanks for the launcher-exit diagnosis and regression cases. The changes are integrated on main as 80896a1 (launcher exit and retained descendant lineage), e385504 (resource-limited verifier controls), and a99b2fd (focused CommonJS and escaped-path regressions).

The integration preserves conservative cleanup when the process table is unavailable or a launcher identity remains present. It uses the existing CLI/MCP acceptance suite rather than adding a second broad regression matrix. Source/composition checks, focused compiled boundaries, and the distinct regression cases passed; 32 real macOS process-boundary tests also passed. The Linux resource-limited binary-layout verifier was not run on this macOS host.

Closing as superseded by the main commits, with contributor credit retained.

@morluto morluto closed this Oct 11, 2026
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: I ran the Linux binary-layout verifier that was not run on macOS. It passed 3 times out of 3 on main, ea06264 (#1688). The CommonJS cases and the process tests also pass on Node 22, 24 and 26.

Linux binary-layout verifier

I ran main's scripts/verify-binary-layout.mjs on Linux, 3 times. Nothing changed its files after e385504. All 3 runs exited 0 and printed "status": "passed", with 149 public cases and 4 bootstrap boundary cases. Each run took 215, 302 and 199 seconds.

The resource limits come from prlimit on the Python child, set by the C fixture that e385504 adds. They were address space 2 GiB, address space 96 MiB, 1 second of CPU, and file size 1,024 bytes and 1 byte. The fixture also turns core dumps off.

CommonJS and process results

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
Tests from a99b2fd, 2 files 67 passed, 2 skipped 67 passed, 2 skipped 67 passed, 2 skipped
Process test file from 80896a1 30 passed 30 passed 30 passed

The 2 skipped tests only run on Windows.

I also reran my earlier cases on main. The "earlier run" column is my result on the PR head f28feba and cf4fc9c, from my earlier comments.

Case Main ea06264 (#1688) Earlier run, PR head
1. bare exports = function missing, 0 changed, 1 unknown missing, 0 changed, 1 unknown
2. shadowed alias chain no changes no changes
3. control module.exports = function /count changed /count changed
4. ms 2.0.0 vs 2.1.3 (MIT) 0 changed, 4 unknown 0 changed, 4 unknown

All four rows matched on all three Nodes. Main also changed the CommonJS code in 8b2f851 and 1e51c73. The commit a99b2fd adds tests only.

Not run

  • The large 65,281-section MCP variant of the verifier (REA_VERIFY_LARGE_ELF_MCP=1).
  • The full test suite and npm run check:fast.
  • Windows and macOS, including the 32 macOS process tests.
  • A real app. Row 4 is one small package.
  • The verifier the CI way. That means npm run verify:binary:layout, the CI memory setting, the CI Python and Node 22 or 26. I ran Node 24 only.

Thanks, morluto, for folding the work into main.

Thanks, Y0UW1SH, for the diagnosis and the test cases.

Commands
  • Build: npm ci, npm run build, npm run test:prepare, on Node 24.18.0.
  • Verifier: node scripts/verify-binary-layout.mjs, with REA_PWNTOOLS_PYTHON and REA_VERIFY_STRACE_COMMAND=/usr/bin/strace set. I ran it directly after the build. npm run verify:binary:layout adds a cached build first. I did not set NODE_OPTIONS=--max-old-space-size=768, which the CI workflow sets.
  • Tests: npm run test:focused -- tests/acceptance/applications/exportedFunctionBindingsCli.test.ts tests/boundary/cli/referenceSourceImportStatus.test.ts and npm run test:local -- src/process/ProcessOwnership.validation.test.ts, once per Node.
  • Cases: analyze-javascript-application on each v1 and v2 folder, then compare-javascript-export-shapes on the default export.
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Compiler: gcc 16.2.1 (Red Hat 16.2.1-2)
  • Python for the verifier: 3.14.7 in a throwaway venv with pwntools 4.15.0, pyelftools 0.33 and Unicorn 2.1.2. Unicorn built from source here, since pip found no wheel for Python 3.14. The CI workflow uses ubuntu-24.04.
  • strace 7.2, prlimit from util-linux 2.41.5
  • Main: ea06264 (docs(website): list the setup guide first on the Guides page #1688)

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

@morluto morluto added bug Something isn't working area: runtime Process capture and runtime observation labels Oct 14, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants