Repository navigation
fix(ssh): Windows hosts without Add-Type staging; runtime-store GC on Windows - #24149
Conversation
|
| 'try{process.kill(Number(rawPid),0)}catch(e){if(e.code!=="ESRCH")answer("UNVERIFIABLE");pidDead=true}', | ||
| 'if(!pidDead)answer("ALIVE")', |
There was a problem hiding this comment.
Reused PID retains exited relay
The .relay-pid file remains after a Windows relay exits. If Windows later assigns that PID to another process, this check reports the relay as live without checking its pipes. Version cleanup then retains the exited relay directory indefinitely. Check that the PID still belongs to this relay before treating it as live.
| let executable = node.executable | ||
| let upload: PinnedNodeVaultUpload | undefined | ||
| let runtimeRef: { path: string; sha256: string } | undefined | ||
| let identityNode = options.verifiedNodePath | ||
| if (node.status === 'unsupported') { |
There was a problem hiding this comment.
Obsolete runtime reference persists
If the host’s Node gains SQLite support while the same relay version remains installed, setup uses the host Node but leaves the earlier .runtime-ref-node-* file in place. Runtime-store cleanup still sees the pinned runtime as referenced, so it cannot collect that runtime until the relay version directory is removed. Clear the old reference when publishing a host-Node reference.
There was a problem hiding this comment.
Important
The new Windows file-identity reader can print a different string than the legacy Add-Type helper for the same file, so the mixed-version stage recovery this PR promises can fail for such a stage.
Reviewed changes
- Windows stage identity through the pinned
node.exe—reserve/promote/cleanup/recoverread file IDs by running the verified pinned node with a fixedfs.lstatSyncscript instead of compiling P/Invoke;WindowsUploadStageIdentityis threaded through the stage commands and both deploy call sites, andConvertTo-OrcaFileIdentitynormalizes the two hex spellings. The legacyAdd-Typebranch remains only for host-Node relays. - Runtime-store GC on Windows — the blanket Windows skip is removed; a new
remote-node-runtime-store-windows.tssupplies the inventory (oneGet-CimInstance Win32_Processquery filtered on image path underruntimes\, never on image name) and stage sweep as single PowerShell lines,HELD_PATHaccepts\and ignores case, and the store lock is taken on Windows too. - Windows vault runtime goes through the store —
preparePinnedNodeForVaultinstalls the official archive into the sharedruntimes/store on every host (the client-extractednode.exepath is deleted) andpublishOpenCodeRuntimeReferenceCommandwrites a.runtime-ref-node-<sha>before renaming the reference into place, so GC never collects a referenced runtime. - Relay liveness honors a recorded
.relay-pid— the Windows pipe probe is extracted toWINDOWS_RELAY_LIVENESS_JSand answersALIVEfor a live PID before touching any pipe, only falling through to the marker/pipe rule otherwise. - Probe adoption and test wiring — a hash-matching
node.exewith no.verifiedis run and adopted; both new Windows test files are added to the Windows CI lane and the code-change-scope list.
I read the full diff and ran the 11 affected test files (pnpm exec vitest run --config config/vitest.config.ts …) — all pass, including the real-pwsh Windows-command tests on this Linux runner.
ℹ️ Nitpicks
materializeCachedNodeRuntime(src/main/ssh/pinned-runtime-materializer.ts:182) has no production caller left after this PR removed the Windows vault upload path; its doc comment still describes "Windows SSH vault reads" as the reason it exists. Both the function and that paragraph look like they should go with the path they served.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| */ | ||
| export const WINDOWS_UPLOAD_STAGE_IDENTITY_JS = | ||
| "const s=require('fs').lstatSync(process.argv[1],{bigint:true});const m=0xffffffffn;" + | ||
| "process.stdout.write((s.dev&m).toString(16)+':'+(s.ino>>32n).toString(16)+':'+(s.ino&m).toString(16))" |
There was a problem hiding this comment.
(s.ino >> 32n) is an arithmetic shift on a signed BigInt. Node fills bigint stats through AliasedBigInt64Array/int64_t (see src/node_file-inl.h), so on Windows stats.ino is negative whenever bit 63 of the file index is set, and this prints -80000000 where the legacy helper's uint IndexH.ToString("x") prints 80000000. ConvertTo-OrcaFileIdentity does not strip a leading -, so on such a volume the two readers disagree and a stage one client reserved cannot be promoted or cleaned by the other — the cross-version recovery the comment at lines 53-56 claims. Mask the high half.
Technical details
# Unsigned high 32 bits of the Windows file index
## Affected sites
- `src/main/ssh/ssh-relay-upload-stage-windows-commands.ts:60` — `(s.ino>>32n).toString(16)` sign-extends; the middle `vol:high:low` component can be `-80000000`.
- `src/main/ssh/ssh-relay-upload-stage-windows-commands.ts:65` (`ConvertTo-OrcaFileIdentity`) — normalizes case and leading zeros but not a leading minus, so the two spellings stay unequal.
- `src/main/ssh/ssh-relay-upload-stage-windows-commands.ts:135,137,165` — ownership compares normalized `$expectedIdentity` (file) against `$actualIdentity` (`& $getFileIdentity`), which is where the mismatch surfaces.
## Required outcome
- The emitted middle component must be the unsigned 32-bit half of the file index, matching `IndexH`, for every file index including those with bit 63 set. A single reader must still round-trip its own writes, and old/new readers must agree after normalization.
## Suggested approach
- Mask the shifted value: `((s.ino>>32n)&m).toString(16)`. `& m` on the two's-complement BigInt yields the correct unsigned low 32 bits of the shifted value; equivalently `BigInt.asUintN(64, s.ino) >> 32n`. `(s.dev&m)` and `(s.ino&m)` are already safe for negative inputs.
## Open questions for the human
- Is bit 63 of the file index reachable on the Windows hosts Orca targets (Heavily churned NTFS directories once the MFT sequence number reaches `0x8000`, and ReFS truncated IDs more readily)? If it is unreachable in practice this is latent, but the cost of the mask is zero.| "process.stdout.write((s.dev&m).toString(16)+':'+(s.ino>>32n).toString(16)+':'+(s.ino&m).toString(16))" | |
| "process.stdout.write((s.dev&m).toString(16)+':'+((s.ino>>32n)&m).toString(16)+':'+(s.ino&m).toString(16))" |
Windows SSH hosts now run runtime-store GC instead of skipping it: one PowerShell inventory reads .runtime-ref-node-<sha> and .runtime-node refs from every version dir, and one Get-CimInstance Win32_Process query filtered on an image path under runtimes\ adds process holds (never by image name; a failed query keeps everything). Stale upload stages are swept with the same rule as POSIX. Promotion and the post-upload hold check now take the store lock on Windows too, and the lock's own commands run unwrapped there. Windows relay version-dir liveness now honours .relay-pid (design D5): a live PID answers ALIVE before any pipe is touched, a dead one (ESRCH) plus refusing pipes is exited, anything else is unverifiable. The runtime probe adopts a pinned node.exe an earlier vault reader left without a .verified marker after running it.
…fied node.exe
Upload-stage file identity on Windows no longer compiles an Add-Type P/Invoke
helper when the relay runs on Orca's verified pinned node.exe: the stage
commands run a fixed fs.lstatSync(..., {bigint:true}) script through it. It
prints the legacy helper's vol:high:low lowercase hex, and identity files are
compared after normalising hex spelling, so old and new clients recover each
other's stages. Host-Node relays keep the legacy helper; the choice is
documented in windows-edr-posture.md.
The Windows OpenCode vault reader now installs the pinned runtime through
ensureRemoteOrcadNodeRuntime (official zip, host-side extraction, .verified,
store lock) instead of uploading a client-extracted node.exe, and the relay dir
gains a .runtime-ref-node-<sha> so store GC keeps the runtime the vault uses.
…indows lane The legacy/node.exe identity compatibility test and the Win32_Process hold path were gated to win32 but no CI lane ran them. Add both files to the Windows package lane and a real running-node.exe hold test.
… test The Windows promote now runs under runtimes/.store-lock, so the mocked host must answer the lock's CreateNew step.
92e345a to
2acf5e5
Compare
| signal?: AbortSignal | ||
| ): Promise<boolean> { | ||
| try { | ||
| await exec(conn, removeRemoteTreeCommand(host, path), signal) | ||
| await exec(conn, host, removeRemoteTreeCommand(host, path), signal) | ||
| return true |
There was a problem hiding this comment.
Failed deletion appears successful
On Windows, a locked file or an on-access scan can prevent a runtime tombstone from being deleted. The removal command suppresses that error, so this call reports the runtime as removed even though the tombstone remains on disk. Check that the tree is gone, or surface the deletion failure, before recording a removal.

ELI5
Windows SSH hosts no longer compile C# with
Add-Typewhen Orca's pinnednode.exeis present. It's a pattern endpoint-security software flags. Shared runtimes on Windows hosts are now cleaned up too.What Changed
node.exe(fs.lstatSyncwith bigint).vol:high:lowformat the old helper wrote, so old and new clients can recover each other's stages.Add-Typehelper, since Orca hasn't verified that binary. This choice is documented inwindows-edr-posture.md..runtime-ref-node-<sha>and.runtime-node.Win32_Processquery, never matching by image name..relay-pidliveness and the store lock on Windows..verifiedinstead of anode.exeextracted on the client.Win32_Processhold.Why
Design D5 and
docs/reference/windows-edr-posture.md.Linked Issue
Part of the Node runtime plan (Phase 2). Stacked on
OrcaWin/node-rt-p2-integration.Visual Proof
N/A. This changes remote host setup.
Testing
path.win32tests and command snapshots pass. The Windows-lane tests run in CI.Not yet run on a real Windows host. The Windows SSH provider harness needs to confirm that libuv's
dev/inomatch the old helper's IDs.Cost: GC adds about 4
powershell.exeprocesses per pinned connect.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.