Repository navigation
fix(windows): prune the unpatched conpty prebuild by header, not host arch - #20048
Conversation
There was a problem hiding this comment.
Important
One residual hole: the verifier still keys its fallback off build/Release presence, not whether that addon targets the slice arch, so a wrong-arch-but-patched build/Release still masks an unpatched loadable prebuild. Detail inline; a one-line fix closes it.
Reviewed changes
conptyTargetsArchPE reader — new helper inconfig/scripts/node-pty-job-ownership.cjsreads the PEMachinefield to decide whetherbuild/Release/conpty.nodetargets the slice arch, mirroringreadElfMachine().- Prune arch proxy removed —
prunePackagedNodePtynow deletes the stale prebuild only when the header read confirms the addon targets the slice, replacing theelectronArch === process.archguess. - Verifier prebuild fallback —
verifyPackagedConptyBreakawayMarkerchecks the loader's prebuild fallback whenbuild/Releaseis absent, andelectron-builder.config.cjspasses the target arch through a newnodeArchByArchEnum. - Tests — prune and verifier suites extended for the cross-arch (
build/ReleaseIS the slice arch) and non-PE cases, plus the prebuild-fallback paths. - Docs — records the measured packaging-gate runs and the prebuild gap.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Reconciliation check: the three-writer hazard does not materializeFlagged concern was that up to three agents wrote to Exactly three versions exist, and they are strictly linear — no merge commit anywhere in the chain:
This branch's copy is byte-identical to the PE-machine original, so nothing was reconciled by hand. One implementation, one call site. The remaining host-arch gate is not a duplicate. No uncommitted third version. The shared main checkout's The last commit adds a 4-line comment (no logic) recording that the proxy is superseded, not complementary, so a later reader does not restore it as insurance and silently reopen the arm64 skip. Still outstanding: real packaging verificationEverything above is static and unit-level: 24 passed under That is not an electron-builder artifact. Routed to |
There was a problem hiding this comment.
ℹ️ No new issues in this delta — the residual hole is closed cleanly. The one remaining open item is the stale docs section, already tracked as a review thread and unchanged by these commits.
Reviewed changes
- Verifier fallback now keys off arch, not presence —
verifyPackagedConptyBreakawayMarkertreats a wrong-archbuild/Release(conptyTargetsArch === false) as absent, so a patched-but-wrong-arch addon no longer masks an unpatched loadable prebuild. Closes the residual hole from the prior review. - Strict tri-state arch check —
targetsArch === false(rather than!targetsArchor!== true) preserves the "wrong arch" vs "unreadable" distinction, keeping the unreadable case fail-closed throughassertCygwinBreakawayDenied. - Verifier tests — four new cases pin the wrong-arch fallthrough, the true-arch primary check, and the no-arch guard.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
f9850f9 to
dfc25f9
Compare
074f167 to
5821626
Compare
dfc25f9 to
c28a0a4
Compare
|
Important Review skippedWe couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe change validates node-pty ConPTY binaries for the MSYS breakaway-denial marker and target architecture. Runtime loading, Windows rebuilds, and packaged builds now pass addon paths to these checks. Packaging uses architecture headers when pruning prebuild fallbacks. Tests cover patched, stale, missing, unreadable, and cross-architecture binaries. New documentation records the Windows process behavior and maintainer guidance. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to Some Windows package layouts can either lose their usable ConPTY fallback or ship an unchecked stale Debug addon, so the packaging checks should be corrected before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 39.13% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 11 files. (3 skipped: 3 unsupported.) Full details: Description checkExplanation The description gives a detailed explanation of the problem, solution, scope, and verification. However, it omits several required template sections, including Linked Issue, Visual Proof, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. It also does not provide the required issue reference or Testing checklist. Resolution Add all required template sections. Include a linked issue after “Fixes #”, write ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: e7059839-e0b6-4898-97c8-d5832389d114
📒 Files selected for processing (14)
.gitignoreAGENTS.mdconfig/electron-builder.config.cjsconfig/packaged-runtime-node-modules.cjsconfig/scripts/ensure-native-runtime-job-ownership.test.mjsconfig/scripts/ensure-native-runtime.mjsconfig/scripts/node-pty-job-ownership.cjsconfig/scripts/packaged-node-pty-prebuild-prune.test.mjsconfig/scripts/rebuild-native-deps-node-pty.test.mjsconfig/scripts/rebuild-native-deps-test-fixtures.mjsconfig/scripts/rebuild-native-deps.mjsconfig/scripts/verify-packaged-node-pty-job-ownership.cjsconfig/scripts/verify-packaged-node-pty-job-ownership.test.mjsdocs/reference/windows-msys-job-breakaway.md
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| { dir: '../build/Release/' }, | ||
| 'conpty' | ||
| ) | ||
| ).toBe('/app/node_modules/node-pty/build/Release/conpty.node') |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use platform-native absolute paths in these assertions.
nodePtyAddonPath uses node:path.resolve. On Windows, it does not return /app/.... These assertions therefore fail on Windows.
Build the input and expected paths from fixtureDir with join.
Proposed fix
- '/app/node_modules/node-pty/lib/utils.js',
+ join(fixtureDir, 'app', 'node_modules', 'node-pty', 'lib', 'utils.js'),
{ dir: '../build/Release/' },
'conpty'
)
- ).toBe('/app/node_modules/node-pty/build/Release/conpty.node')
+ ).toBe(join(fixtureDir, 'app', 'node_modules', 'node-pty', 'build', 'Release', 'conpty.node'))
- '/app/resources/node-pty/lib/utils.js',
+ join(fixtureDir, 'app', 'resources', 'node-pty', 'lib', 'utils.js'),
{ dir: './build/Release/' },
'conpty'
)
- ).toBe('/app/resources/node-pty/lib/build/Release/conpty.node')
+ ).toBe(
+ join(fixtureDir, 'app', 'resources', 'node-pty', 'lib', 'build', 'Release', 'conpty.node')
+ )Also applies to: 135-135
| if (binary.length < 0x40) { | ||
| return null | ||
| } | ||
| const peHeaderOffset = binary.readUInt32LE(0x3c) | ||
| if (peHeaderOffset + 6 > binary.length) { | ||
| return null | ||
| } | ||
| return binary.readUInt16LE(peHeaderOffset + 4) === expected |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Validate the PE signatures before accepting Machine.
The current parser treats any sufficiently long file as a PE image. A malformed or non-PE file can set offset 0x3c and the target Machine value. prunePackagedNodePty will then delete the loadable prebuild and can produce a package without a usable ConPTY addon.
Check both the MZ signature and the PE\0\0 signature before returning true.
Proposed fix
- if (binary.length < 0x40) {
+ if (binary.length < 0x40 || binary.readUInt16LE(0) !== 0x5a4d) {
return null
}
const peHeaderOffset = binary.readUInt32LE(0x3c)
if (peHeaderOffset + 6 > binary.length) {
return null
}
+ if (binary.readUInt32LE(peHeaderOffset) !== 0x00004550) {
+ return null
+ }
return binary.readUInt16LE(peHeaderOffset + 4) === expected📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (binary.length < 0x40) { | |
| return null | |
| } | |
| const peHeaderOffset = binary.readUInt32LE(0x3c) | |
| if (peHeaderOffset + 6 > binary.length) { | |
| return null | |
| } | |
| return binary.readUInt16LE(peHeaderOffset + 4) === expected | |
| if (binary.length < 0x40 || binary.readUInt16LE(0) !== 0x5a4d) { | |
| return null | |
| } | |
| const peHeaderOffset = binary.readUInt32LE(0x3c) | |
| if (peHeaderOffset + 6 > binary.length) { | |
| return null | |
| } | |
| if (binary.readUInt32LE(peHeaderOffset) !== 0x00004550) { | |
| return null | |
| } | |
| return binary.readUInt16LE(peHeaderOffset + 4) === expected |
| const fallbackPath = (options.prebuiltConptyPath ?? prebuiltConptyPath)( | ||
| resourcesDir, | ||
| options.arch | ||
| ) | ||
| if (fallbackPath && exists(fallbackPath)) { | ||
| assertCygwinBreakawayDenied(fallbackPath, { dir: fallbackPath }) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Check build/Debug before the prebuild.
The documented loader order checks build/Debug before prebuilds. This branch skips that candidate.
If a target-loadable stale Debug addon exists, node-pty loads it instead of the checked prebuild. Packaging can then pass while the effective addon lacks the breakaway-denial marker.
Select and validate the first target-loadable candidate in the full loader order: Release, Debug, then prebuild.
| Measured on Windows 11 `10.0.26200.9168`, Git `2.55.0.windows.3`, | ||
| bash `5.3.15(1)-release`, node `v24.18.0`, `useConptyDll: true`, for | ||
| `node-pty.spawn('C:\Program Files\Git\bin\bash.exe', ['--noprofile','--norc','-i'])` |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Escape the Windows path in the JavaScript example.
node-pty.spawn(...) is JavaScript, so \b in C:\Program Files\Git\bin\bash.exe becomes a backspace escape when copied. Use C:\\Program Files\\Git\\bin\\bash.exe or String.raw so the example addresses the intended executable.
5821626 to
dd11411
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Rebased the PR onto
mainand cut it from three commits to one; the verifier fix and theelectron-builder.config.cjsarch wiring are now onmainthrough the #20047 squash, leaving only the prune change here. - Prune reads the PE header instead of guessing the host arch —
prunePackagedNodePtynow calls a localconptyTargetsArch, which comparesbuild/Release/conpty.node'sIMAGE_FILE_HEADER.Machine(viareadPeMachinefromwindows-pe-machine.cjs) against the slice'sPE_MACHINEentry, replacing theelectronArch === process.archproxy. The prebuild is deleted exactly when the source build targets the slice arch; absent, wrong-arch, or non-PE builds keep it. - Tests — the prune suite now seeds real minimal PE headers and adds cases for the cross-arch slice whose
build/ReleaseIS the target arch (now pruned), the cross-host wrong-arch build (kept), and a non-PEbuild/Release(kept). All three can fail against the old guard. - Docs — the loader-fallthrough table flips row three to "prebuild pruned" and the paragraph describes the PE-machine check and the residual fall-through it closes, retiring the last stale section.
Verified locally: packaged-node-pty-prebuild-prune + verify-packaged-node-pty-job-ownership + windows-pe-machine = 61 passed; check:code-quality:changed = 0 findings.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
… arch `prunePackagedNodePty` deleted the published `prebuilds/win32-<arch>/conpty.node` only when `electronArch === process.arch`. That proxy stood in for "build/Release holds an addon this slice can load", and it is false for the arm64 slice cross-built on an x64 Windows host — a rebuild that DOES emit a correct arm64 addon. That slice shipped the unpatched prebuild. Nothing loads it today: `verifyPackagedConptyBreakawayMarker` resolves the addon the way node-pty's loader does, so the patched `build/Release` wins and the release passes correctly. But the loader swallows every require failure and falls through, so an AV quarantine or a missing dependency on `build/Release` hands the pane to that unpatched prebuild — the silent downgrade the gate exists to close, with the binary still sitting in the package. Read the PE `Machine` field instead of guessing, reusing `readPeMachine` from the verifier's `windows-pe-machine.cjs` so prune and verifier ask one question. A missing, truncated or non-PE `build/Release` reads as unloadable and keeps the prebuild, which is what the true cross-host case needs: packaging Windows from macOS leaves no Windows binary in `build/Release`, and removing the prebuild there would leave the package with no ConPTY at all. Mutation-proven: restoring the `electronArch === process.arch` guard fails exactly the two new rows in packaged-node-pty-prebuild-prune.
3fd138a to
d509026
Compare

ELI5
On Windows, Orca ships a small native piece called
conptythat lets terminalpanes kill everything a command started. We patch it, because the stock build
lets background processes escape and keep running after you close the tab.
The installer we build contains that piece more than once — one copy per CPU
type, plus some spares node-pty keeps around as fallbacks. Only the patched copy
should survive packaging; the rest get pruned out.
The prune decides "is this copy for the machine we're building for?" by asking
which CPU this build machine is, not which CPU the installer is for. On a
normal build those are the same and nothing goes wrong. On a cross-build — an
arm64 installer made on an x64 machine — they differ, the check says no, and an
unpatched copy is left inside the shipped app.
Normally nothing loads it: the patched copy sits earlier in the search order and
wins. It only matters if the patched one fails to load at runtime — antivirus
quarantines it, or a system DLL it needs is missing. Then node-pty walks on to
the next candidate, finds the unpatched one we meant to delete, and loads it
silently. No error, no log line. The terminal works, and closing a tab quietly
stops killing background processes that detached from the console.
This PR makes the prune ask about the target CPU instead of the build
machine's, using the PE-header reader already on
main. One fewer wrong binaryin the package, and no fallback to an unpatched one.
Worth knowing before you approve:
electron-builder --winruns with no arch flag and packages x64 only; thev1.4.206 release carries a single
orca-windows-setup.exewhose NSIS payloadis
app-64.7zalone. So no shipped package has ever hit this defect. The fixis for the day a Windows arm64 slice is added, which the x64 runner would
cross-build (the relay addon already does exactly that).
mainalready refuses to ship a package whose loadable addon is unpatched; what is
left is the silent fall-through above, which needs a second failure first.
docs/reference/windows-msys-job-breakaway.mdlists this as a knownresidual — this PR closes that row and updates the table.
Closing this PR instead is a defensible call; nothing ships broken either
way.
Note
Rebased onto
main2026-09-18, and cut from three commits to one. Severitydropped with it — read this before reviewing the old body's claims.
This was stacked on #20047, which has since squash-merged. That squash landed
considerably more than the branch it was cut from, including a rewritten
verifyPackagedConptyBreakawayMarkerthat resolves the addon the way node-pty'sloader does. Two of this PR's three fixes are inside it:
mainpackagedConptyCandidatesconptyTargetsArchis not re-added tonode-pty-job-ownership.cjs:mainnow has
config/scripts/windows-pe-machine.cjswithreadPeMachine, so theprune reuses that and prune and verifier read the header through one function.
What is left, and how bad it is
prunePackagedNodePtydeletes the publishedprebuilds/win32-<arch>/conpty.node— which has never carried the MSYSbreakaway denial — only when
electronArch === process.arch.That proxy stands in for "build/Release holds an addon this slice can load", and
it is false for an arm64 slice cross-built on an x64 Windows host — a rebuild
that does emit a correct arm64 addon (measured:
node-gyp rebuild --arch=arm64on an x64 Windows 11 host with the VS 2022 ARM64 cross toolset emits a
conpty.nodewith PE machine0xaa64). That slice would ship the unpatchedprebuild.
Nothing loads it, and the release gate is right to pass it. The verifier walks
the loader's candidate order, the patched
build/Releasewins, and the prebuildis never reached. It is the residual: an unpatched binary left in the package,
sitting exactly where node-pty's loader falls through to when
build/Releasefails to load for an unrelated reason. The loader swallows every require failure
silently — measured on Windows: zero bytes written to stdout, stderr, or console
during a fall-through from a corrupted or wrong-arch
build/Releaseto theprebuild.
The fix
Read the PE
Machinefield instead of guessing.build/Releasethat is missing,truncated, or not a PE at all reads as unloadable and the prebuild stays — which
is what the true cross-host case needs: packaging Windows from macOS leaves no
Windows binary there, and removing the prebuild would leave the package with no
ConPTY at all, a crash in place of a silent degradation.
Rows two and four of the doc table are unchanged; row three flips to pruned, and
the table and its paragraph are updated to say why, including that no release
currently builds row three.
Verification
packaged-node-pty-prebuild-prune+verify-packaged-node-pty-job-ownership+windows-pe-machine— 61 passed locally; CI shard 8/8 ✓ on the prune file.pnpm tc,pnpm run check:code-quality:changed— pass.electronArch === process.archguard fails exactly the two new rows; ignoring the PE header fails the
wrong-arch and non-PE rows; dropping the
existsSyncguard fails theno-source-build row; comparing against a fixed arch fails the host-arch row.
Sibling-preservation and darwin/linux rows pass under every mutation
(bare-shape controls).
mainkeeps the target prebuild on the cross-arch/correct-build shape; this branch
removes it and keeps
pty.node,winpty.dll,winpty-agent.exe,conpty_console_list.node. Cross-host and wrong-arch shapes keep it on both.v1.4.206 installer both carry a
build/Release/conpty.nodewith machine0x8664and the MSYS marker, and noprebuilds/win32-x64/conpty.node— thenative prune works. With the unpatched prebuild forced as the loaded addon, a
pane child started via
Start-Process(new console, parent exited) survivesteardown; with the patched addon
terminateJobkills it.