Skip to content

refactor(windows): vendor the registry addon as @orca/windows-registry - #20438

Merged
nwparker merged 6 commits into
mainfrom
nwparker/vendor-windows-registry
Sep 13, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/vendor-windows-registry

Conversation

@nwparker

@nwparker nwparker commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​90 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​70
Prod 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​257 $\color{#cf222e}{\Huge{\mathbf{−}}}$​56 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​201

[email protected] was last published in 2023 by a single maintainer. Orca called exactly two of its exports, both read-only, so the whole dependency is replaced by a local N-API addon under native/windows-registry/.

What changed

  • Read-only by construction. setValue, createKey and deleteKey are gone, so RegDeleteTreeW no longer ships inside the app. Only getKey remains.
  • Two upstream defects fixed rather than carried over. The name/data scratch buffers were file-scope statics that two concurrent reads would scribble over; they are per-call locals now. createKey/deleteKey called .c_str() on a temporary Utf16Value() — that use-after-free left with the write surface.
  • Build wiring keeps its existing shape: still an optionalDependency gated to win32, still excluded from pnpm's allowBuilds so only Orca's own Windows rebuild runs node-gyp, still copied into packaged resources.
  • CI native caches now key on the vendored sources, so an addon.cc edit cannot restore a stale .node.

Verification on real Windows (awin)

  • The addon compiles on Windows via @electron/rebuild + node-gyp against the file:-linked package (orca_windows_registry.node produced), and again standalone for the Node ABI (gyp info ok). This was the main risk — no existing native/ module is a node-gyp addon, so this is a new build pattern for the repo.
  • New src/main/windows-registry-addon.test.ts checks the addon against reg.exe as an independent oracle — the real user PATH value and its REG_SZ/REG_EXPAND_SZ type must match. 4/4 pass on Windows, skipped elsewhere.

Note for reviewers

The awin worktree I used has a pre-existing broken node-pty build (its DLL was locked by the running Orca app), which fails 5-6 node-pty tests on both this branch and main. Those failures are environmental and unrelated; this PR's CI package (windows) job is the clean check.

[email protected] was last published in 2023 by a single
maintainer. Orca called two of its exports, both read-only, so the whole
dependency is replaced by a local N-API addon under native/.

The vendored addon is read-only by construction: setValue, createKey and
deleteKey are gone, so RegDeleteTreeW no longer ships in the app. Two
upstream defects are also fixed rather than carried over — the name/data
scratch buffers were file-scope statics that concurrent reads would
scribble over, and createKey/deleteKey called .c_str() on a temporary.

Build wiring keeps the existing shape: still an optionalDependency gated
to win32, still excluded from pnpm's allowBuilds so only Orca's own
Windows rebuild runs node-gyp for it, still copied into the packaged
resources. The CI native caches now key on the vendored sources so an
addon.cc edit cannot restore a stale .node.
The addon is vendored source, so no upstream release proves it still
decodes values the way Orca's PATH readers expect. reg.exe is the only
independent oracle on the box.
@coderabbitai

coderabbitai Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 4fb24bb3-1504-4846-8d4d-7248521ccc5c

📥 Commits

Reviewing files that changed from the base of the PR and between 2aeb55b and a556e72.

📒 Files selected for processing (1)
  • .gitignore
🚧 Files skipped from review as they are similar to previous changes (1)
  • .gitignore

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds a private @orca/windows-registry workspace package with a Windows N-API addon and TypeScript API. It replaces the previous registry dependency across runtime loading, native rebuilds, packaging, caches, documentation, and fixtures. It adds cache invalidation inputs and Windows-only integration tests for registry value decoding and error handling.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to a556e

The addon can omit an unusually named registry value, while Windows CI may rebuild unnecessarily and can fail for a valid casing of PATH. These are bounded issues and do not block merge, but should be addressed soon.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the implementation, rationale, scope, and Windows verification, but it omits most required template sections, including Linked Issue, Visual Proof or N/A, Testing checkboxes, … Complete the required template sections. Add a linked issue after “Fixes #”, provide Visual Proof or state N/A with a reason, record testing and platform coverage, complete the applicable checkboxes, and address AI Disclosure, Review, Agent…
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 14 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: vendoring the Windows registry addon as @orca/windows-registry.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the implementation, rationale, scope, and Windows verification, but it omits most required template sections, including Linked Issue, Visual Proof or N/A, Testing checkboxes, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist.

Resolution

Complete the required template sections. Add a linked issue after “Fixes #”, provide Visual Proof or state N/A with a reason, record testing and platform coverage, complete the applicable checkboxes, and address AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist.

Full details: Docstring Coverage

Explanation

Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 14 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

A Windows-gated file self-skips on ubuntu, so without both registrations
it reports success while running on no machine at all.

@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

src/main/windows-registry-addon.test.ts is Windows-gated but registered in neither Windows CI lane, so it runs on no machine and config/scripts/win32-test-lane-registration.test.mjs fails — the vendored addon's only coverage is doing nothing.

Reviewed changes

  • Vendored read-only addon: replaced [email protected] with native/windows-registry/ (addon.cc N-API source, binding.gyp, lazy index.js, index.d.ts, package.json) exposed as @orca/windows-registry; the setValue/createKey/deleteKey write surface (and RegDeleteTreeW) is gone, and the two upstream buffer/use-after-free defects are fixed with per-call locals.
  • Wiring rewired: root optionalDependencies (file:./native/windows-registry), pnpm-workspace.yaml allowBuilds, lockfile, ensure-native-runtime.mjs + rebuild-native-deps.mjs module lists and loader branches, packaged-runtime roots, CI native-cache paths/keys, and the docs reference; the config-script contract tests were updated and pass.
  • Loader swap: src/main/windows-native-registry.ts requires @orca/windows-registry; both PATH consumers keep their raw-value/expandable contract.
  • New Windows-only test: windows-registry-addon.test.ts pins the addon against reg.exe as an independent oracle.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/main/windows-registry-addon.test.ts Resolved

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

✅ No new issues found.

Reviewed changes

  • Registered the new Windows-only addon test: 4d6534256f adds src/main/windows-registry-addon.test.ts to both Windows lanes — WINDOWS_PACKAGE_TESTS in config/scripts/pr-code-change-scope.mjs and the Test Windows-specific boundaries vitest argv in .github/workflows/pr.yml — resolving the prior finding that it ran on no machine and left win32-test-lane-registration.test.mjs red. Verified locally: win32-test-lane-registration, pr-code-change-scope, and pr-workflow-parallelism all pass (80 tests).

Everything from the prior review still holds; no other changes since 2df51f4.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

As a `file:` dependency pnpm re-resolved and re-linked the package on
every install, including `--frozen-lockfile` (measured: "added 1" on a
repeat no-op install). That virtual-store churn ran concurrently with
node-gyp reading the same tree and cost @vscode/windows-process-tree its
binding.gyp mid-rebuild, failing package (windows) whenever the native
cache hit and only that module needed building. The linux packaging job
hit the same race from the other side, as a pnpm staging move failure.

A workspace link resolves once and leaves the store alone; repeat
installs are now 55ms no-ops. native/windows-registry is listed
explicitly so `packages:` still does not auto-discover mobile/.

@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 workspace:* switch in 7ba6826 moved the addon's build output out of pnpm's virtual store, but the Windows native cache still points at the old .pnpm location, so the compiled addon is never cached or restored. The same commit also committed the generated node-gyp build tree, which is machine-specific macOS/arm64 output.

Reviewed changes

Reviewed the delta since the prior pullfrog review at 4d65342.

  • Switched the addon to a pnpm workspace package: package.json now declares @orca/windows-registry: workspace:* instead of file:./native/windows-registry, pnpm-workspace.yaml lists native/windows-registry, the lockfile replaces the file:native/windows-registry entry with a link: importer, and [email protected] is no longer marked optional.
  • Updated the packaging contract test: package-electron-runtime-contract.test.mjs now expects workspace:*.
  • Committed the generated native/windows-registry/build/ tree: Makefile, binding.Makefile, config.gypi, gyp-mac-tool, and orca_windows_registry.target.mk produced by node-gyp on macOS/arm64.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

path: |
node_modules/.pnpm/node-pty@*/node_modules/node-pty/build
node_modules/.pnpm/windows-native-registry@*/node_modules/windows-native-registry/build
node_modules/.pnpm/@orca+windows-registry@*/node_modules/@orca/windows-registry/build

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.

With @orca/windows-registry now a workspace:* dependency, pnpm symlinks node_modules/@orca/windows-registry to native/windows-registry, so @electron/rebuild writes orca_windows_registry.node under native/windows-registry/build/Release — there is no longer any .pnpm/@orca+windows-registry@* entry. This cache path (and the identical one on the restore-only step at line 164) therefore matches nothing on Windows, so the compiled addon is rebuilt on every run and the cache-key hardening added earlier in this PR is inert for the registry addon.

Technical details
# Point the native cache at the workspace build output

## Affected sites
- `.github/actions/install-node-dependencies/action.yml:153` and `:164` — `node_modules/.pnpm/@orca+windows-registry@*/node_modules/@orca/windows-registry/build` no longer exists; `pnpm-lock.yaml` now records `native/windows-registry` as an importer with `version: link:native/windows-registry` and drops the `@orca/windows-registry` entries under `packages:`/`snapshots:`.
- `config/scripts/pr-workflow-parallelism.test.mjs:392` — asserts `cacheStep.with.path` contains `@orca+windows-registry@`, pinning the stale path.

## Required outcome
- The cached path resolves to where the Windows build actually writes the addon (the workspace package directory, `native/windows-registry/build`) on both the save and restore-only steps.
- The parallelism test asserts the new path rather than the removed virtual-store one.

Comment thread native/windows-registry/build/Makefile Resolved

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

Actionable comments posted: 5


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: b206ec4b-72cb-47b5-838f-5451aae346bc

📥 Commits

Reviewing files that changed from the base of the PR and between fbab61e and 7ba6826.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (26)
  • .github/actions/install-node-dependencies/action.yml
  • .github/workflows/pr.yml
  • config/packaged-runtime-node-modules.cjs
  • config/scripts/ensure-native-runtime.mjs
  • config/scripts/ensure-native-runtime.test.mjs
  • config/scripts/package-electron-runtime-contract.test.mjs
  • config/scripts/pr-code-change-scope.mjs
  • config/scripts/pr-workflow-parallelism.test.mjs
  • config/scripts/rebuild-native-deps-node-pty.test.mjs
  • config/scripts/rebuild-native-deps-test-fixtures.mjs
  • config/scripts/rebuild-native-deps.mjs
  • docs/reference/windows-process-enumeration.md
  • native/windows-registry/binding.gyp
  • native/windows-registry/build/Makefile
  • native/windows-registry/build/binding.Makefile
  • native/windows-registry/build/config.gypi
  • native/windows-registry/build/gyp-mac-tool
  • native/windows-registry/build/orca_windows_registry.target.mk
  • native/windows-registry/index.d.ts
  • native/windows-registry/index.js
  • native/windows-registry/package.json
  • native/windows-registry/src/addon.cc
  • package.json
  • pnpm-workspace.yaml
  • src/main/windows-native-registry.ts
  • src/main/windows-registry-addon.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

path: |
node_modules/.pnpm/node-pty@*/node_modules/node-pty/build
node_modules/.pnpm/windows-native-registry@*/node_modules/windows-native-registry/build
node_modules/.pnpm/@orca+windows-registry@*/node_modules/@orca/windows-registry/build

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.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

Cache the workspace addon's actual build directory in every native cache.

@orca/windows-registry is rooted at native/windows-registry, and node-gyp writes its output to native/windows-registry/build. The cache blocks at action.yml:153,164 and pr.yml:832,901 are separate configurations. Changing action.yml does not change the workflow paths.

Replace the stale path in all four blocks:

Proposed fix
-          node_modules/.pnpm/@orca+windows-registry@*/node_modules/@orca/windows-registry/build
+          native/windows-registry/build
📝 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.

Suggested change
node_modules/.pnpm/@orca+windows-registry@*/node_modules/@orca/windows-registry/build
native/windows-registry/build

Comment thread native/windows-registry/build/Makefile Resolved
if (!values) {
return null
}
const byName = {}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use a safe map for registry value names.

A registry value named __proto__ changes the prototype of this object at Line 30. It does not create an enumerable value entry. getRegistryKey then fails its keyed-value contract.

Proposed fix
-  const byName = {}
+  const byName = Object.create(null)
📝 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.

Suggested change
const byName = {}
const byName = Object.create(null)

Comment on lines +71 to +73
data[dataLength] = 0;
data[dataLength + 1] = 0;
entry.Set("value", Napi::String::New(env, reinterpret_cast<char16_t*>(data.get())));

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Validate UTF-16 data length before conversion.

RegEnumValueW reports dataLength in bytes. A registry value can have a string type with malformed data, including an odd byte count.

The bound Napi::String::New(env, const char16_t*) overload expects a null-terminated UTF-16 string. If dataLength is odd, the two appended zero bytes do not form a terminator at a UTF-16 boundary. The direct conversion and the REG_MULTI_SZ loop can then read beyond the initialized value data.

Reject odd-length UTF-16 data before both conversion branches.

Proposed fix
+    const bool isUtf16 =
+        valueType == REG_SZ || valueType == REG_EXPAND_SZ || valueType == REG_MULTI_SZ;
+    if (isUtf16 && dataLength % sizeof(WCHAR) != 0) {
+      RegCloseKey(key);
+      return env.Null();
+    }
+
     if (valueType == REG_SZ || valueType == REG_EXPAND_SZ) {

} catch {
return null
}
const line = stdout.split(/\r?\n/).find((candidate) => candidate.trim().startsWith(name))

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Match the reg.exe value name case-insensitively.

reg.exe matches registry value names without case sensitivity but prints the stored spelling. If the stored name is PATH, candidate.trim().startsWith(name) does not match Path. regQuery returns null, and the no-oracle branch then fails because the addon correctly returns PATH.

Parse the printed value name and compare it to name with toLowerCase() before parsing the type and data.

🧰 Tools
🪛 ast-grep (0.45.3)

[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFileSync } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(detect-child-process-typescript)

The build/ tree is generated per host and ABI; the committed copy was
macOS-specific gyp scaffolding from a local build and would have shipped
stale Makefiles to every checkout.

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

✅ No new issues found.

Reviewed changes

Reviewed the delta since the prior pullfrog review at 7ba6826.

  • Removed the committed node-gyp output: native/windows-registry/build/{Makefile,binding.Makefile,config.gypi,gyp-mac-tool,orca_windows_registry.target.mk} are no longer tracked.
  • Ignored the generated tree: .gitignore now excludes native/windows-registry/build/, so a local @electron/rebuild/node-gyp run no longer dirties the worktree.

Net: 2 insertions, 1804 deletions across 6 files; no source or runtime behavior changed.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

node-gyp also emits bin/<platform>-<abi>/ beside build/; both are per-host
generated output that must never be committed.
@nwparker
nwparker merged commit 5127d1e into main Sep 13, 2026
53 of 55 checks passed
nwparker added a commit that referenced this pull request Sep 13, 2026
main vendored windows-native-registry as the workspace package
@orca/windows-registry (#20438). A workspace link resolves on every
host, so including it in the installed-Windows-addons checks proved
nothing. @vscode/windows-process-tree is the only os: win32 npm addon
left, so it alone decides whether the win32 resource plan resolves.
nwparker added a commit that referenced this pull request Sep 13, 2026
* Reduce native dependency installs to the host platform

* Remove install policy documentation

* Guard cross-arch packaging and scope release installs to the runner

electron-builder only logs a warning for a missing extraResources source,
so a host-only install silently shipped a foreign-arch slice without its
natives — `pnpm build:mac` on Apple Silicon produced an x64 DMG with no
sherpa-onnx-darwin-x64 and no @parcel/watcher-darwin-x64. The previous
beforePack hook covered only win32.

- Add assertPackagedNativeVariantsInstalled, an arch-aware check over the
  target's sherpa-onnx, @parcel/watcher, and (on Windows) node-gyp addons.
  beforePack now runs it for every platform, with remedies split: another
  architecture comes from install:release, the os:win32 addons need a
  Windows host.
- Drop --os from the release installs. Every packaging job already runs on
  a runner whose OS matches its target, so only the macOS lanes need extra
  breadth, and only on CPU for their x64+arm64 config. Windows and Linux
  packaging return to a plain host-only install.
- Add --frozen-lockfile to install:release so a bare run cannot rewrite
  the lockfile.
- Restore the install policy reference doc and the CONTRIBUTING note, plus
  the rationale comments dropped from the runtime contract test.
- Gate the packaging-closure assertions on whether the Windows addons are
  installed rather than on the host OS, so a cross-arch install exercises
  them off Windows too.
- Make the workflow contract test read `run:` steps as well as retry-action
  commands, and enforce host-only scoping on the non-macOS packaging lanes.
- Remove the unreferenced install measurement script; its numbers live in
  the policy doc.

* Track the install policy doc and index it from AGENTS.md

docs/** is ignored behind a per-file allow-list, so the new reference doc
was only committed via git add -f and future edits would be skipped. Add
it to the allow-list and give it an AGENTS.md entry like every other
tracked reference doc, so the host-only install rule is discoverable
before someone packages a second architecture.

* Route Windows-lane removals through the retrying helper

Adding these four specs to the PR Windows lane pulled them into the
windows-lane-tree-removal-boundary ratchet, which failed on 20 raw
recursive removals. On Windows a bare rmSync races a handle the OS has
not released, throwing EPERM after the assertions already passed and
reporting a green test as a lane failure.

* Adapt the packaging guard to the vendored Windows registry addon

main vendored windows-native-registry as the workspace package
@orca/windows-registry (#20438). A workspace link resolves on every
host, so including it in the installed-Windows-addons checks proved
nothing. @vscode/windows-process-tree is the only os: win32 npm addon
left, so it alone decides whether the win32 resource plan resolves.
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