Skip to content

fix(ssh): Windows hosts without Add-Type staging; runtime-store GC on Windows - #24149

Merged
OrcaWin merged 5 commits into
mainfrom
OrcaWin/node-rt-p2-winhard
Oct 1, 2026
Merged

OrcaWin merged 5 commits into
mainfrom
OrcaWin/node-rt-p2-winhard

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​754 $\color{#cf222e}{\Huge{\mathbf{−}}}$​213 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​541
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​435 $\color{#cf222e}{\Huge{\mathbf{−}}}$​299 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​136

ELI5

Windows SSH hosts no longer compile C# with Add-Type when Orca's pinned node.exe is present. It's a pattern endpoint-security software flags. Shared runtimes on Windows hosts are now cleaned up too.

What Changed

  • Upload-stage file identity: now read through the verified pinned node.exe (fs.lstatSync with bigint).
    • The output uses the same vol:high:low format the old helper wrote, so old and new clients can recover each other's stages.
    • Relays on the host's own Node keep the Add-Type helper, since Orca hasn't verified that binary. This choice is documented in windows-edr-posture.md.
  • Runtime-store GC on Windows:
    • Honors the references in .runtime-ref-node-<sha> and .runtime-node.
    • Keeps a runtime while any process runs from it, using one path-scoped Win32_Process query, never matching by image name.
    • Adds .relay-pid liveness and the store lock on Windows.
  • Vault on Windows: now uses the store installer and .verified instead of a node.exe extracted on the client.
  • Fixed in review: the new Windows-only tests are now listed so the Windows CI lanes actually run them, and a real-process test covers the Win32_Process hold.

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.win32 tests 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/ino match the old helper's IDs.

  • Cost: GC adds about 4 powershell.exe processes per pinned connect.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Infrastructure and deployment workflows, plus build and runtime configuration.

The PR appears safe to merge, with a non-blocking Windows GC reporting issue and two previously reported cleanup issues still outstanding.

Findings

  1. P2 Failed deletion appears successful ▶
  2. P2 Reused PID retains exited relay ▶
  3. P2 Obsolete runtime reference persists ▶

Summary

The PR replaces Add-Type-based upload-stage identity reads with the verified pinned Node on Windows SSH hosts and enables Windows runtime-store collection.

  • It adds Windows inventory, process-hold and stale-stage handling, plus a store lock around runtime promotion.
  • It moves Windows OpenCode vault setup into the shared runtime store and adds Windows-lane coverage.

Reviews (4) · Last reviewed commit: "test(ssh): grant the store lock to the W..."

Comment on lines +225 to +226
'try{process.kill(Number(rawPid),0)}catch(e){if(e.code!=="ESRCH")answer("UNVERIFIABLE");pidDead=true}',
'if(!pidDead)answer("ALIVE")',

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

Comment on lines 154 to 157
let executable = node.executable
let upload: PinnedNodeVaultUpload | undefined
let runtimeRef: { path: string; sha256: string } | undefined
let identityNode = options.verifiedNodePath
if (node.status === 'unsupported') {

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

@pullfrog pullfrog Bot 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.

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/recover read file IDs by running the verified pinned node with a fixed fs.lstatSync script instead of compiling P/Invoke; WindowsUploadStageIdentity is threaded through the stage commands and both deploy call sites, and ConvertTo-OrcaFileIdentity normalizes the two hex spellings. The legacy Add-Type branch remains only for host-Node relays.
  • Runtime-store GC on Windows — the blanket Windows skip is removed; a new remote-node-runtime-store-windows.ts supplies the inventory (one Get-CimInstance Win32_Process query filtered on image path under runtimes\, never on image name) and stage sweep as single PowerShell lines, HELD_PATH accepts \ and ignores case, and the store lock is taken on Windows too.
  • Windows vault runtime goes through the store — preparePinnedNodeForVault installs the official archive into the shared runtimes/ store on every host (the client-extracted node.exe path is deleted) and publishOpenCodeRuntimeReferenceCommand writes 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 to WINDOWS_RELAY_LIVENESS_JS and answers ALIVE for 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.exe with no .verified is 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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))"

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.

(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.
Suggested change
"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))"

m4air and others added 5 commits October 1, 2026 02:56
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.
@OrcaWin
OrcaWin force-pushed the OrcaWin/node-rt-p2-winhard branch from 92e345a to 2acf5e5 Compare October 1, 2026 09:57
@OrcaWin
OrcaWin changed the base branch from OrcaWin/node-rt-p2-integration to main October 1, 2026 09:58
@OrcaWin OrcaWin closed this Oct 1, 2026
@OrcaWin OrcaWin reopened this Oct 1, 2026
Comment on lines 327 to 331
signal?: AbortSignal
): Promise<boolean> {
try {
await exec(conn, removeRemoteTreeCommand(host, path), signal)
await exec(conn, host, removeRemoteTreeCommand(host, path), signal)
return true

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

@OrcaWin
OrcaWin merged commit 14d4bb2 into main Oct 1, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant