Skip to content

build(runtime): gate new Electron imports reachable from the Orca runtime - #15919

Merged
nwparker merged 5 commits into
mainfrom
nwparker/runtime-electron-ratchet
Aug 23, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/runtime-electron-ratchet

Conversation

@nwparker

@nwparker nwparker commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​215 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​214

Stacked on #15918 → #15916. Review those first.

ELI5

The two PRs below this one moved Electron-specific calls behind small interfaces, so the Orca runtime gets closer to running on plain Node.

The problem: nothing stops that from silently undoing itself. The import that breaks portability is almost never in the file being reviewed — it's three hops away. Someone adds import { app } from 'electron' to a module, that module is imported by another, which is imported by the runtime, and no reviewer ever sees the edge.

This PR adds a gate that does see it. It bundles the runtime, asks the bundler which modules ended up importing electron, and compares that list to a checked-in file. A new one fails CI. The list may only shrink.

Why a build gate and not a lint rule

A lint rule sees one file. The thing that matters here is reachability — the transitive edge. So this bundles orca-runtime.ts and runtime-rpc.ts with esbuild and reads the metafile, which is the only cheap way to get a true answer. It runs in pnpm lint alongside the existing ratchets.

Modelled directly on config/scripts/check-max-lines-ratchet.mjs, which exists for the same reason: freeze today's set, fail on growth, force the baseline to tighten when it shrinks.

The number

Baseline starts at 36. It was 50 before #15916 and #15918 landed their ports. That is the migration made measurable — and it's why the gate also fails when the count drops: a stale baseline that doesn't tighten is a gate quietly losing its floor.

Proof it works

Not just "the tests pass" — I proved the gate actually gates:

$ node config/scripts/check-runtime-electron-ratchet.mjs
[runtime-electron-ratchet] ok — 36 entries, unchanged.          exit 0

# add `import { app } from 'electron'` to src/main/runtime/runtime-relative-paths.ts
$ node config/scripts/check-runtime-electron-ratchet.mjs
[runtime-electron-ratchet] 1 new module(s) reachable from the Orca runtime
now import electron:
  + src/main/runtime/runtime-relative-paths.ts

The runtime must stay bootable on plain Node. Put the Electron facility behind
a port in src/main/host/ and depend on the port, or move the code out of the
runtime's import graph. See docs/design/node-only-runtime-backend.html.
                                                                exit 1
# revert
$ node config/scripts/check-runtime-electron-ratchet.mjs
[runtime-electron-ratchet] ok — 36 entries, unchanged.          exit 0
Check Result
Gate on clean tree passes, exit 0
Gate with an injected regression fails with an actionable message, exit 1
Gate after revert passes, exit 0
check-runtime-electron-ratchet.test.mjs 6 tests pass
oxlint clean

The test file covers the pure functions (baseline parsing, diffing in both directions) plus one real end-to-end assertion that the checked-in baseline still matches what the runtime actually reaches. That last one is deliberately not a fixture: the value of this gate is the transitive edges, and a fixture cannot model those.

User-facing trade-offs

None at runtime. One developer-facing cost: pnpm lint gets an esbuild bundle (a few seconds). If someone legitimately needs a new Electron import inside the runtime graph, the failure message tells them the two ways out (put it behind a port in src/main/host/, or move it out of the graph) rather than just refusing.

Review loops

Round Reviewer Outcome
1 Grok 4.6 (adversarial, design) Independently endorsed this mechanism — listed "plain-node-entry-guard" among the design's sound parts. This generalises that existing guard from fork-entry chunks to the runtime's whole reachable graph.
2 Self Fixed two prefer-template lint errors; verified the gate's three-state behaviour empirically rather than assuming it.

Verdict: ready to merge, after #15918. This is the piece that makes the other two durable — without it they decay.


Commits added after this PR was opened

Commit Why
fix(runtime-ratchet): resolve paths from the script, not the caller's cwd Run from anywhere but the repo root, the gate died with an unhandled ENOENT stack instead of a usable message. It failed closed, so it was never unsafe — just undebuggable. Now anchors to import.meta.dirname and passes absWorkingDir to esbuild so metafile keys stay repo-relative.
ci(runtime-ratchet): actually run the gate in CI The gate would never have fired. It was wired into the lint npm script, but CI's static-analysis job runs the individual checks rather than pnpm lint — so this would have looked enforced while enforcing nothing. Now a step next to the max-lines ratchet, on ubuntu-latest, so the checked-in baseline is only ever produced by one platform.

The second one is worth dwelling on: a ratchet that does not run is worse than no ratchet, because it manufactures false confidence. Caught by reading .github/workflows/pr.yml rather than assuming pnpm lint was the CI entrypoint.


Final regression evidence

Check Result
Full local suite, whole stack, run alone 6,070 files / 57,140 tests pass, 0 failures
Baseline: full local suite on main 57,173 tests pass, 0 failures — same shape
pnpm typecheck (node + web + cli projects) clean
oxlint (full repo) clean

Round-2 review findings applied

Two more landed after the last push, both against this file, both fail-open bugs — the class this PR exists to prevent:

Finding Fix
The gate silently did nothing on Windows. The entry guard compared import.meta.url against a `file://${process.argv[1]}` template. On Windows argv[1] is C:\repo\... while import.meta.url is file:///C:/repo/..., so main() never ran and pnpm lint exited 0 without bundling or reading the baseline. Use pathToFileURL — the idiom check-max-lines-ratchet.mjs:225 already uses and I should have copied. CI runs on ubuntu so enforcement was never actually lost; a Windows developer just got a green gate that checked nothing.
Temp-directory leak in the shared vitest setup (fixed in #15918). mkdtempSync at module scope runs once per test environment — one per file, not per worker — with nothing removing them. Proven: a three-file run under an isolated TMPDIR previously added directories, now leaves zero.

Reviewer verdict on the rest: P0 none. Security and backcompat sections came back clean — "desktop at-rest encryption and userData resolution are pass-throughs of the previous Electron calls; already-sealed credentials keep the same byte path." The ProcessMetric cast was checked and structurally satisfies every field the collector reads; the sole isPackaged() rewrite calls the method; missing-baseline and esbuild-failure both fail closed.

@nwparker
nwparker force-pushed the nwparker/runtime-electron-ratchet branch 4 times, most recently from 1ed1500 to a25d8f1 Compare August 22, 2026 10:05
@nwparker

Copy link
Copy Markdown
Contributor Author

Verified on a real Windows host

The Windows fail-open fix was previously argued from Node's documented path/URL forms. It is now proven on an actual Windows machine (Git Bash / MINGW64), running this branch at a25d8f1fdc.

1. The bug and the fix, measured:

ARGV1=C:\Users\neil\probe.mjs
TEMPLATE_MATCH=false        <- the guard I shipped: never matches, main() never runs
PATHTOFILEURL_MATCH=true    <- the fix

2. The gate now actually runs there, and agrees with macOS:

$ node config/scripts/check-runtime-electron-ratchet.mjs
[runtime-electron-ratchet] ok — 36 entries, unchanged.
WINDOWS_RATCHET_EXIT=0

36 entries on Windows, 36 on macOS — this also closes the open question about whether the checked-in baseline could diverge per platform. It does not: the repo-relative forward-slash normalisation holds.

3. It still fails when it should, with a usable message:

$ # inject: import { app } from 'electron' into src/main/runtime/runtime-relative-paths.ts
[runtime-electron-ratchet] 1 new module(s) reachable from the Orca runtime now import electron:
  + src/main/runtime/runtime-relative-paths.ts
...
WIN_REGRESSION_EXIT=1

Note the path renders forward-slash on Windows too, so the failure message and the baseline speak the same dialect.

Before this fix, all three of those runs would have printed nothing and exited 0.

@nwparker
nwparker force-pushed the nwparker/app-environment-port branch from b7e5155 to e74e60c Compare August 22, 2026 10:22
@nwparker
nwparker force-pushed the nwparker/runtime-electron-ratchet branch from a25d8f1 to 0c3b4c0 Compare August 22, 2026 10:22
@nwparker
nwparker force-pushed the nwparker/app-environment-port branch from e74e60c to a5c8f3d Compare August 22, 2026 22:33
@nwparker
nwparker force-pushed the nwparker/runtime-electron-ratchet branch from 0c3b4c0 to 3bf6460 Compare August 22, 2026 22:33
@nwparker
nwparker force-pushed the nwparker/app-environment-port branch from a5c8f3d to cd29acb Compare August 22, 2026 23:11
@nwparker
nwparker force-pushed the nwparker/runtime-electron-ratchet branch from 3bf6460 to 17ab89b Compare August 22, 2026 23:11
@nwparker
nwparker force-pushed the nwparker/app-environment-port branch from cd29acb to 66c5ccc Compare August 22, 2026 23:24
@nwparker
nwparker force-pushed the nwparker/runtime-electron-ratchet branch 2 times, most recently from 4c1133a to bd69e21 Compare August 23, 2026 01:15
@nwparker
nwparker requested a review from brennanb2025 as a code owner August 23, 2026 01:15
@greptile-apps

greptile-apps Bot commented Aug 23, 2026

Copy link
Copy Markdown

Too many files changed for review (177 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

@nwparker
nwparker changed the base branch from nwparker/app-environment-port to nwparker/app-environment-port-v2 August 23, 2026 01:30
@nwparker

Copy link
Copy Markdown
Contributor Author

The one red check is a pre-existing failure on main, not from this PR

e2e / changed e2e specs fails on tests/e2e/worktree-jump-palette-filter.spec.ts:184 › pressing Enter creates a worktree from a typed name. It failed on rerun too, so it is reproducible rather than a flake — which is why I checked it against main instead of re-running until green.

Reproduced on origin/main at 063b8042988 with none of this branch present:

1 failed
  [electron-headless] › tests/e2e/worktree-jump-palette-filter.spec.ts:184:7 ›
    Worktree jump-palette filters › pressing Enter creates a worktree from a typed name

Error: expect(locator).toBeHidden() failed
Locator:  getByRole('dialog', { name: /Create (Workspace|Worktree)/i })
Expected: hidden
Received: visible
Timeout:  10000ms

Escape does not close the Create Workspace dialog. The spec arrived with 9ea1d289707 Fix Cmd+J Enter for worktree creation (#15970).

Evidence it is not this PR:

  • This branch changes 0 renderer or dialog files (git diff --name-only origin/main...HEAD | grep -c 'renderer\|dialog' → 0). The diff is the gate script, its CI wiring, the baseline, and two path resolutions.
  • #15927 and #15968 sit on top of this branch and are fully green — they contain every line of it. The difference is only which specs the changed-spec lane selects per PR.
  • It reproduces on main alone, above.

Not fixing it here: it is someone else's regression and a renderer concern unrelated to this change. Flagging so it is not mistaken for stack fallout, and so whoever owns #15970 sees it.

Every other check on this PR is green (52 passing).

…time

The runtime is meant to become host-agnostic so it can also run on plain Node,
but nothing enforced that. `orca-runtime.ts` reaches dozens of modules that
import `electron`, and the count grows silently: the import that breaks
portability is usually several hops away, so no reviewer sees the edge.

Add a reachability ratchet, modelled on the existing max-lines one. It bundles
the runtime and its RPC server with esbuild, reads the metafile for every module
importing `electron`, and diffs that against a checked-in baseline. A new module
fails; a removed one forces the baseline to tighten. The list may only shrink.

A per-file lint rule cannot do this — the point is precisely the transitive
edges — so this runs as a build gate in `pnpm lint`.

Baseline starts at 36, down from 50 before the SecretStore and AppEnvironment
ports landed, which is the migration made measurable.

Verified: gate passes clean, fails with an actionable message when an `electron`
import is added to a runtime module, and passes again when reverted.
… cwd

Run from anywhere but the repo root, the gate died with an unhandled ENOENT stack
instead of a usable message. It failed closed, so it was never unsafe — just
undebuggable. Anchor ROOT to import.meta.dirname and pass absWorkingDir to esbuild
so metafile keys stay repo-relative.
The ratchet was wired into the `lint` npm script, but CI's static-analysis job
runs the individual checks rather than `pnpm lint`, so the gate would never have
fired on a PR — it would have looked enforced while enforcing nothing.

Runs on ubuntu-latest alongside the max-lines ratchet, so the checked-in baseline
is only ever produced by one platform.
ssh2's optional cpu-features dep points at a prebuilt .node that only exists
where a build toolchain has run. Loading it made the gate pass locally and
hard-fail on CI with 'Could not resolve ../build/Release/cpufeatures.node'.

The gate only reads the import graph, never the addon, so resolve every .node to
an external stub instead. Verified by hiding the local prebuild — which is CI's
state — and re-running: still 36 entries, exit 0.
The entry guard compared import.meta.url against a `file://${process.argv[1]}`
template. On Windows argv[1] is a native path (C:\repo\...) while import.meta.url
is file:///C:/repo/..., so they never match: main() never ran and `pnpm lint`
exited 0 on Windows without bundling, reading the baseline, or enforcing anything.

Use pathToFileURL, which is the idiom check-max-lines-ratchet.mjs:225 already uses.
CI runs this on ubuntu so enforcement was never actually lost, but a Windows
developer got a green gate that checked nothing.
@nwparker
nwparker changed the base branch from nwparker/app-environment-port-v2 to main August 23, 2026 04:13
@nwparker
nwparker force-pushed the nwparker/runtime-electron-ratchet branch from bd69e21 to fda832f Compare August 23, 2026 04:13
@coderabbitai

coderabbitai Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds an esbuild-based check for electron imports reachable from Orca runtime entry points. It compares detected importers with a checked-in baseline and supports baseline regeneration. Tests cover parsing, diffing, and current runtime agreement. Package scripts and the static-analysis workflow run the check.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The description references stacked pull requests but does not provide the required linked issue in the Fixes # section. Add the issue reference that this pull request addresses under the required Linked Issue section.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Title check ✅ Passed The title clearly and concisely describes the runtime Electron-import reachability gate added by this pull request.
Description check ✅ Passed The description clearly explains the change, rationale, implementation, scope, and validation results, but omits several template headings.
Out of Scope Changes check ✅ Passed The changes remain focused on adding, testing, and enforcing the runtime Electron-import ratchet and its checked-in baseline.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d48d25b8-25a8-4ae8-9b71-255eb337d5b3

📥 Commits

Reviewing files that changed from the base of the PR and between 0bbc6c8 and fda832f.

📒 Files selected for processing (5)
  • .github/workflows/pr.yml
  • config/runtime-electron-baseline.txt
  • config/scripts/check-runtime-electron-ratchet.mjs
  • config/scripts/check-runtime-electron-ratchet.test.mjs
  • package.json

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

Comment on lines +122 to +132
async function main() {
const write = process.argv.includes('--write')
const current = await collectElectronImporters()

if (write) {
writeFileSync(BASELINE_PATH, `${renderBaseline(current)}\n`)
console.log(`[runtime-electron-ratchet] wrote ${current.length} entries to ${BASELINE_PATH}`)
return
}

const baseline = readBaseline(readFileSync(BASELINE_PATH, 'utf8'))

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 | 🟠 Major | ⚡ Quick win

Prevent --write from expanding the baseline.

Line 126 writes the current set before the script reads the existing baseline. If a new reachable Electron importer exists, --write adds it to the baseline and makes later CI checks pass. This bypasses the stated shrink-only ratchet.

Read and diff the baseline before this branch. Reject --write when added.length > 0. Allow it only to remove entries.

Proposed fix
 async function main() {
   const write = process.argv.includes('--write')
   const current = await collectElectronImporters()
+  const baseline = readBaseline(readFileSync(BASELINE_PATH, 'utf8'))
+  const { added, removed } = diffAgainstBaseline(current, baseline)
 
   if (write) {
+    if (added.length > 0) {
+      console.error('[runtime-electron-ratchet] refusing to expand the baseline')
+      process.exitCode = 1
+      return
+    }
     writeFileSync(BASELINE_PATH, `${renderBaseline(current)}\n`)
     console.log(`[runtime-electron-ratchet] wrote ${current.length} entries to ${BASELINE_PATH}`)
     return
   }
-
-  const baseline = readBaseline(readFileSync(BASELINE_PATH, 'utf8'))
-  const { added, removed } = diffAgainstBaseline(current, baseline)
📝 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
async function main() {
const write = process.argv.includes('--write')
const current = await collectElectronImporters()
if (write) {
writeFileSync(BASELINE_PATH, `${renderBaseline(current)}\n`)
console.log(`[runtime-electron-ratchet] wrote ${current.length} entries to ${BASELINE_PATH}`)
return
}
const baseline = readBaseline(readFileSync(BASELINE_PATH, 'utf8'))
async function main() {
const write = process.argv.includes('--write')
const current = await collectElectronImporters()
const baseline = readBaseline(readFileSync(BASELINE_PATH, 'utf8'))
const { added, removed } = diffAgainstBaseline(current, baseline)
if (write) {
if (added.length > 0) {
console.error('[runtime-electron-ratchet] refusing to expand the baseline')
process.exitCode = 1
return
}
writeFileSync(BASELINE_PATH, `${renderBaseline(current)}\n`)
console.log(`[runtime-electron-ratchet] wrote ${current.length} entries to ${BASELINE_PATH}`)
return
}

@nwparker
nwparker merged commit cbea753 into main Aug 23, 2026
54 of 69 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 23, 2026
…time (stablyai#15919)

* build(runtime): gate new Electron imports reachable from the Orca runtime

The runtime is meant to become host-agnostic so it can also run on plain Node,
but nothing enforced that. `orca-runtime.ts` reaches dozens of modules that
import `electron`, and the count grows silently: the import that breaks
portability is usually several hops away, so no reviewer sees the edge.

Add a reachability ratchet, modelled on the existing max-lines one. It bundles
the runtime and its RPC server with esbuild, reads the metafile for every module
importing `electron`, and diffs that against a checked-in baseline. A new module
fails; a removed one forces the baseline to tighten. The list may only shrink.

A per-file lint rule cannot do this — the point is precisely the transitive
edges — so this runs as a build gate in `pnpm lint`.

Baseline starts at 36, down from 50 before the SecretStore and AppEnvironment
ports landed, which is the migration made measurable.

Verified: gate passes clean, fails with an actionable message when an `electron`
import is added to a runtime module, and passes again when reverted.

* fix(runtime-ratchet): resolve paths from the script, not the caller's cwd

Run from anywhere but the repo root, the gate died with an unhandled ENOENT stack
instead of a usable message. It failed closed, so it was never unsafe — just
undebuggable. Anchor ROOT to import.meta.dirname and pass absWorkingDir to esbuild
so metafile keys stay repo-relative.

* ci(runtime-ratchet): actually run the gate in CI

The ratchet was wired into the `lint` npm script, but CI's static-analysis job
runs the individual checks rather than `pnpm lint`, so the gate would never have
fired on a PR — it would have looked enforced while enforcing nothing.

Runs on ubuntu-latest alongside the max-lines ratchet, so the checked-in baseline
is only ever produced by one platform.

* fix(runtime-ratchet): mark native addons external so CI can run the gate

ssh2's optional cpu-features dep points at a prebuilt .node that only exists
where a build toolchain has run. Loading it made the gate pass locally and
hard-fail on CI with 'Could not resolve ../build/Release/cpufeatures.node'.

The gate only reads the import graph, never the addon, so resolve every .node to
an external stub instead. Verified by hiding the local prebuild — which is CI's
state — and re-running: still 36 entries, exit 0.

* fix(runtime-ratchet): stop the gate failing open on Windows

The entry guard compared import.meta.url against a `file://${process.argv[1]}`
template. On Windows argv[1] is a native path (C:\repo\...) while import.meta.url
is file:///C:/repo/..., so they never match: main() never ran and `pnpm lint`
exited 0 on Windows without bundling, reading the baseline, or enforcing anything.

Use pathToFileURL, which is the idiom check-max-lines-ratchet.mjs:225 already uses.
CI runs this on ubuntu so enforcement was never actually lost, but a Windows
developer got a green gate that checked nothing.

(cherry picked from commit cbea753)
CodeHourra pushed a commit to CodeHourra/orca that referenced this pull request Aug 23, 2026
…time (stablyai#15919)

* build(runtime): gate new Electron imports reachable from the Orca runtime

The runtime is meant to become host-agnostic so it can also run on plain Node,
but nothing enforced that. `orca-runtime.ts` reaches dozens of modules that
import `electron`, and the count grows silently: the import that breaks
portability is usually several hops away, so no reviewer sees the edge.

Add a reachability ratchet, modelled on the existing max-lines one. It bundles
the runtime and its RPC server with esbuild, reads the metafile for every module
importing `electron`, and diffs that against a checked-in baseline. A new module
fails; a removed one forces the baseline to tighten. The list may only shrink.

A per-file lint rule cannot do this — the point is precisely the transitive
edges — so this runs as a build gate in `pnpm lint`.

Baseline starts at 36, down from 50 before the SecretStore and AppEnvironment
ports landed, which is the migration made measurable.

Verified: gate passes clean, fails with an actionable message when an `electron`
import is added to a runtime module, and passes again when reverted.

* fix(runtime-ratchet): resolve paths from the script, not the caller's cwd

Run from anywhere but the repo root, the gate died with an unhandled ENOENT stack
instead of a usable message. It failed closed, so it was never unsafe — just
undebuggable. Anchor ROOT to import.meta.dirname and pass absWorkingDir to esbuild
so metafile keys stay repo-relative.

* ci(runtime-ratchet): actually run the gate in CI

The ratchet was wired into the `lint` npm script, but CI's static-analysis job
runs the individual checks rather than `pnpm lint`, so the gate would never have
fired on a PR — it would have looked enforced while enforcing nothing.

Runs on ubuntu-latest alongside the max-lines ratchet, so the checked-in baseline
is only ever produced by one platform.

* fix(runtime-ratchet): mark native addons external so CI can run the gate

ssh2's optional cpu-features dep points at a prebuilt .node that only exists
where a build toolchain has run. Loading it made the gate pass locally and
hard-fail on CI with 'Could not resolve ../build/Release/cpufeatures.node'.

The gate only reads the import graph, never the addon, so resolve every .node to
an external stub instead. Verified by hiding the local prebuild — which is CI's
state — and re-running: still 36 entries, exit 0.

* fix(runtime-ratchet): stop the gate failing open on Windows

The entry guard compared import.meta.url against a `file://${process.argv[1]}`
template. On Windows argv[1] is a native path (C:\repo\...) while import.meta.url
is file:///C:/repo/..., so they never match: main() never ran and `pnpm lint`
exited 0 on Windows without bundling, reading the baseline, or enforcing anything.

Use pathToFileURL, which is the idiom check-max-lines-ratchet.mjs:225 already uses.
CI runs this on ubuntu so enforcement was never actually lost, but a Windows
developer got a green gate that checked nothing.
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…time (stablyai#15919)

* build(runtime): gate new Electron imports reachable from the Orca runtime

The runtime is meant to become host-agnostic so it can also run on plain Node,
but nothing enforced that. `orca-runtime.ts` reaches dozens of modules that
import `electron`, and the count grows silently: the import that breaks
portability is usually several hops away, so no reviewer sees the edge.

Add a reachability ratchet, modelled on the existing max-lines one. It bundles
the runtime and its RPC server with esbuild, reads the metafile for every module
importing `electron`, and diffs that against a checked-in baseline. A new module
fails; a removed one forces the baseline to tighten. The list may only shrink.

A per-file lint rule cannot do this — the point is precisely the transitive
edges — so this runs as a build gate in `pnpm lint`.

Baseline starts at 36, down from 50 before the SecretStore and AppEnvironment
ports landed, which is the migration made measurable.

Verified: gate passes clean, fails with an actionable message when an `electron`
import is added to a runtime module, and passes again when reverted.

* fix(runtime-ratchet): resolve paths from the script, not the caller's cwd

Run from anywhere but the repo root, the gate died with an unhandled ENOENT stack
instead of a usable message. It failed closed, so it was never unsafe — just
undebuggable. Anchor ROOT to import.meta.dirname and pass absWorkingDir to esbuild
so metafile keys stay repo-relative.

* ci(runtime-ratchet): actually run the gate in CI

The ratchet was wired into the `lint` npm script, but CI's static-analysis job
runs the individual checks rather than `pnpm lint`, so the gate would never have
fired on a PR — it would have looked enforced while enforcing nothing.

Runs on ubuntu-latest alongside the max-lines ratchet, so the checked-in baseline
is only ever produced by one platform.

* fix(runtime-ratchet): mark native addons external so CI can run the gate

ssh2's optional cpu-features dep points at a prebuilt .node that only exists
where a build toolchain has run. Loading it made the gate pass locally and
hard-fail on CI with 'Could not resolve ../build/Release/cpufeatures.node'.

The gate only reads the import graph, never the addon, so resolve every .node to
an external stub instead. Verified by hiding the local prebuild — which is CI's
state — and re-running: still 36 entries, exit 0.

* fix(runtime-ratchet): stop the gate failing open on Windows

The entry guard compared import.meta.url against a `file://${process.argv[1]}`
template. On Windows argv[1] is a native path (C:\repo\...) while import.meta.url
is file:///C:/repo/..., so they never match: main() never ran and `pnpm lint`
exited 0 on Windows without bundling, reading the baseline, or enforcing anything.

Use pathToFileURL, which is the idiom check-max-lines-ratchet.mjs:225 already uses.
CI runs this on ubuntu so enforcement was never actually lost, but a Windows
developer got a green gate that checked nothing.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…time (stablyai#15919)

* build(runtime): gate new Electron imports reachable from the Orca runtime

The runtime is meant to become host-agnostic so it can also run on plain Node,
but nothing enforced that. `orca-runtime.ts` reaches dozens of modules that
import `electron`, and the count grows silently: the import that breaks
portability is usually several hops away, so no reviewer sees the edge.

Add a reachability ratchet, modelled on the existing max-lines one. It bundles
the runtime and its RPC server with esbuild, reads the metafile for every module
importing `electron`, and diffs that against a checked-in baseline. A new module
fails; a removed one forces the baseline to tighten. The list may only shrink.

A per-file lint rule cannot do this — the point is precisely the transitive
edges — so this runs as a build gate in `pnpm lint`.

Baseline starts at 36, down from 50 before the SecretStore and AppEnvironment
ports landed, which is the migration made measurable.

Verified: gate passes clean, fails with an actionable message when an `electron`
import is added to a runtime module, and passes again when reverted.

* fix(runtime-ratchet): resolve paths from the script, not the caller's cwd

Run from anywhere but the repo root, the gate died with an unhandled ENOENT stack
instead of a usable message. It failed closed, so it was never unsafe — just
undebuggable. Anchor ROOT to import.meta.dirname and pass absWorkingDir to esbuild
so metafile keys stay repo-relative.

* ci(runtime-ratchet): actually run the gate in CI

The ratchet was wired into the `lint` npm script, but CI's static-analysis job
runs the individual checks rather than `pnpm lint`, so the gate would never have
fired on a PR — it would have looked enforced while enforcing nothing.

Runs on ubuntu-latest alongside the max-lines ratchet, so the checked-in baseline
is only ever produced by one platform.

* fix(runtime-ratchet): mark native addons external so CI can run the gate

ssh2's optional cpu-features dep points at a prebuilt .node that only exists
where a build toolchain has run. Loading it made the gate pass locally and
hard-fail on CI with 'Could not resolve ../build/Release/cpufeatures.node'.

The gate only reads the import graph, never the addon, so resolve every .node to
an external stub instead. Verified by hiding the local prebuild — which is CI's
state — and re-running: still 36 entries, exit 0.

* fix(runtime-ratchet): stop the gate failing open on Windows

The entry guard compared import.meta.url against a `file://${process.argv[1]}`
template. On Windows argv[1] is a native path (C:\repo\...) while import.meta.url
is file:///C:/repo/..., so they never match: main() never ran and `pnpm lint`
exited 0 on Windows without bundling, reading the baseline, or enforcing anything.

Use pathToFileURL, which is the idiom check-max-lines-ratchet.mjs:225 already uses.
CI runs this on ubuntu so enforcement was never actually lost, but a Windows
developer got a green gate that checked nothing.
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