Repository navigation
fix(windows): stop main-thread PowerShell ACL storm on env-store reads - #5011
Merged
nwparker merged 3 commits intoJun 9, 2026
Merged
Conversation
Two changes fix the v1.4.52+ Windows performance regression (stablyai#4901 regression against stablyai#4840) where 49 powershell.exe processes were spawned in 27 seconds during load, saturating the Electron main thread and causing black terminals and runtimeEnvironments:call timeouts. Root cause: `readEnvironmentStore` calls `hardenExistingSecureFile` on every read. The env-store parent directory's mtime churns constantly (every secure write updates it), so the mtime-keyed idempotency cache never matched → `bestEffortRestrictWindowsPath` (powershell, ~1-1.5s synchronous) fired on every call. After stablyai#4901, the remote-runtime tab-sync loop reads the store ~2×/s, turning sporadic mtime misses into a continuous main-thread storm. Fix 1 – path-cached directory hardening: add `hardenedDirectoryPathsThisProcess (Set<string>)` that caches directory hardening by PATH for the process lifetime. A directory's required ACL does not change when its mtime changes; only file hardening retains the metadata-keyed cache so post-rename inode changes are detected correctly. Fix 2 – async ACL application: replace `execFileSync(powershell.exe, ...)` with `execFile` (fire-and-forget). PowerShell cold-start is ~1-1.5s; the function is already named `bestEffortRestrictWindowsPath` so async/optimistic caching is correct. `applySecurePathRestriction` returns `true` optimistically on win32 so the cache entry is written before the background process completes. Tests: new regression tests verify the directory is hardened exactly once even when its mtime changes between calls, that unchanged files are not re-hardened, and that ACL application goes through async execFile (not execFileSync).
Follow-up rigor on the env-store PowerShell ACL storm fix (stablyai#5006). The read-path storm fix (path-cached async directory hardening + async file re-harden) is retained, but switching ALL ACL application to async opened a narrow Windows-only security window: because writeFileSync({mode}) is a no-op on Windows, writeSecureFile returned with the credential file still carrying the parent directory's inherited (broader) ACL for the ~1-1.5s PowerShell cold-start, affecting the e2ee keypair, device registry, and runtime env auth store. Fix: apply the credential FILE's ACL synchronously (execFileSync) on the infrequent write path, before the atomic rename publishes it, and cache the path as hardened only on confirmed success so a failed apply retries. Keep the DIRECTORY hardening async + path-cached for the process lifetime (that is what killed the stablyai#4901/stablyai#5006 main-thread storm). The read path's existing-file re-harden stays async + metadata-cached (fires at most once per file, no storm). Also: - Document the dir-path cache process-lifetime known limitation (deleted+ recreated dir not re-hardened until restart). - Remove the redundant double dir-cache write in writeSecureFile. - Add docs/windows-secure-file-acl-hardening.md describing the sync-file/ async-dir model and a manual Windows e2e test plan (the cross-platform Playwright harness runs on Linux and cannot reach the PowerShell path). Tests (src/shared/secure-file.test.ts, 13 passing): credential file hardened synchronously while dir stays async (no async file-ACL window); failed sync file-ACL apply is not cached and retries; dir hardened exactly once across many writes despite mtime churn; no PowerShell spawned on non-win32. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
nwparker
force-pushed
the
fix/windows-env-store-acl-harden-storm
branch
from
June 9, 2026 08:47
36e3894 to
f2ca3b3
Compare
This was referenced Jun 25, 2026
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
stablyai#5011) * fix(windows): stop main-thread PowerShell storm on env-store reads Two changes fix the v1.4.52+ Windows performance regression (stablyai#4901 regression against stablyai#4840) where 49 powershell.exe processes were spawned in 27 seconds during load, saturating the Electron main thread and causing black terminals and runtimeEnvironments:call timeouts. Root cause: `readEnvironmentStore` calls `hardenExistingSecureFile` on every read. The env-store parent directory's mtime churns constantly (every secure write updates it), so the mtime-keyed idempotency cache never matched → `bestEffortRestrictWindowsPath` (powershell, ~1-1.5s synchronous) fired on every call. After stablyai#4901, the remote-runtime tab-sync loop reads the store ~2×/s, turning sporadic mtime misses into a continuous main-thread storm. Fix 1 – path-cached directory hardening: add `hardenedDirectoryPathsThisProcess (Set<string>)` that caches directory hardening by PATH for the process lifetime. A directory's required ACL does not change when its mtime changes; only file hardening retains the metadata-keyed cache so post-rename inode changes are detected correctly. Fix 2 – async ACL application: replace `execFileSync(powershell.exe, ...)` with `execFile` (fire-and-forget). PowerShell cold-start is ~1-1.5s; the function is already named `bestEffortRestrictWindowsPath` so async/optimistic caching is correct. `applySecurePathRestriction` returns `true` optimistically on win32 so the cache entry is written before the background process completes. Tests: new regression tests verify the directory is hardened exactly once even when its mtime changes between calls, that unchanged files are not re-hardened, and that ACL application goes through async execFile (not execFileSync). * fix(windows): apply credential-file ACL synchronously on write path Follow-up rigor on the env-store PowerShell ACL storm fix (stablyai#5006). The read-path storm fix (path-cached async directory hardening + async file re-harden) is retained, but switching ALL ACL application to async opened a narrow Windows-only security window: because writeFileSync({mode}) is a no-op on Windows, writeSecureFile returned with the credential file still carrying the parent directory's inherited (broader) ACL for the ~1-1.5s PowerShell cold-start, affecting the e2ee keypair, device registry, and runtime env auth store. Fix: apply the credential FILE's ACL synchronously (execFileSync) on the infrequent write path, before the atomic rename publishes it, and cache the path as hardened only on confirmed success so a failed apply retries. Keep the DIRECTORY hardening async + path-cached for the process lifetime (that is what killed the stablyai#4901/stablyai#5006 main-thread storm). The read path's existing-file re-harden stays async + metadata-cached (fires at most once per file, no storm). Also: - Document the dir-path cache process-lifetime known limitation (deleted+ recreated dir not re-hardened until restart). - Remove the redundant double dir-cache write in writeSecureFile. - Add docs/windows-secure-file-acl-hardening.md describing the sync-file/ async-dir model and a manual Windows e2e test plan (the cross-platform Playwright harness runs on Linux and cannot reach the PowerShell path). Tests (src/shared/secure-file.test.ts, 13 passing): credential file hardened synchronously while dir stays async (no async file-ACL window); failed sync file-ACL apply is not cached and retries; dir hardened exactly once across many writes despite mtime churn; no PowerShell spawned on non-win32. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix: keep POSIX secure directory hardening metadata-aware --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Neil <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows (v1.4.52+), connecting to a remote/paired runtime made the app extremely
slow during load and timed out session-tabs loading
(
[web-session-tabs-sync] … RemoteRuntimeClientError: Timed out waiting for the remote Orca runtime to respond). The env-store read path was re-hardening the parentdirectory's NTFS ACL on every read by spawning
powershell.exesynchronously on theElectron main thread — ~1.8 spawns/sec, continuous through the whole load window — which
saturated the main thread so it could not service
runtimeEnvironments:call.This PR makes env-store reads stop storming the main thread while keeping credential
files locked down. No visual change.
Fixes #5006.
Root cause
readEnvironmentStorecallshardenExistingSecureFileon every read. Hardening waskeyed on directory mtime/ctime, but the env-store parent directory's mtime churns
constantly (every secure write updates it), so the idempotency cache never matched and
bestEffortRestrictWindowsPath(PowerShellGet-Acl/Set-Acl, ~1–1.5 s cold-start) ranon every call. The remote-runtime tab-sync loop reads the store ~2×/s, turning sporadic
mtime misses into a continuous synchronous-PowerShell storm on the main thread. Regressed
in v1.4.52 (worked in v1.4.51). Instrumented Windows process creation showed 49
powershell.exespawns in 27 s on a cold launch.The fix
Two coordinated changes in
src/shared/secure-file.ts, applying the rightcaching + execution strategy per path type:
Path-cached directory hardening (kills the storm). Directories are now cached as
hardened by path for the process lifetime (
hardenedDirectoryPathsThisProcess),not by mtime. A directory's required ACL does not change because a child write bumped
its mtime, so once hardened in this process it is trusted. Directory hardening is
async (
execFile, fire-and-forget) so it never blocks the main thread.re-hardened until the next process restart (the
.orcasecure dirs are not deletedat runtime).
Synchronous credential-file ACL on the write path (closes a security window).
Switching the file ACL to async would have left a regression:
writeFileSync({ mode })is a no-op on Windows, so a freshly written credential file carries the parent
directory's inherited (broader) ACL until PowerShell finishes ~1–1.5 s later. To avoid
writeSecureFilereturning with the credential briefly readable under inherited ACLs,the file ACL (temp file + renamed target) is applied synchronously
(
execFileSync) on the write path, and cached as hardened only on confirmedsuccess so a failed apply retries. The write path is infrequent; it was the read
path that stormed, and that stays async + cached.
The read path's existing-file hardening stays async + metadata-cached (fires at most once
per file per process, so it does not storm; it only re-asserts an ACL on a file that
already exists).
Test plan
Unit tests —
src/shared/secure-file.test.ts(vitest run, 13 passing)New / updated coverage:
across many writes (the Fix remote runtime terminal sharing with mobile #4901/App extremely slow + session-tabs timeout on Windows (v1.4.52+): main thread saturated re-hardening env-store ACLs via synchronous powershell on every read #5006 storm condition), exercised on both the read and
write paths.
changes.
execFileSync) on the write path while thedirectory stays async (
execFile) — asserts there is no async file-ACL window.win32-only guard: no PowerShell (sync or async) is ever spawned on non-win32; POSIXuses
chmodSynconly.Run:
vitest run --config config/vitest.config.ts src/shared/secure-file.test.tsCI gates (run locally on the changed files)
oxlint(lint) — cleanoxlintswitch-exhaustiveness onsrc/shared— cleanoxfmt --check— cleantsgotypecheck (node / web / cli configs) — all cleanEnd-to-end — manual on Windows (no automated coverage possible here)
The Playwright e2e harness runs on
ubuntu-latest, whereapplySecurePathRestrictionshort-circuits tochmodSyncand never reaches thePowerShell path, so the Windows ACL storm cannot be reproduced in the cross-platform
harness. Manual Windows plan documented in
docs/windows-secure-file-acl-hardening.md:powershell.exeprocesses during load.0; app loads without the timeout.icaclson the credential file immediately after a write shows only current user /SYSTEM / Administrators (no inherited entries) — confirms the synchronous file-ACL apply
closed the async window.
AI Review Report
Adversarial review covered: cross-platform — all PowerShell paths are guarded by
platform === 'win32'; POSIX behavior (chmodSync) unchanged; a test asserts noPowerShell on non-win32. SSH/remote/local — change is in the shared secure-file
writer used by local and remote runtimes alike; behavior is identical, only the Windows
ACL execution model changed. Performance — this PR removes a hot-path main-thread
stall (the whole point); the only added synchronous work is on the infrequent write path.
Security — the review flagged that a naive async switch would publish credential files
under inherited ACLs for ~1–1.5 s; addressed by applying the file ACL synchronously on the
write path and caching only on confirmed success. No UI change.
Security Audit
-NoProfile -NonInteractive -ExecutionPolicy Bypass,windowsHide, a 5 s timeout, and a fixed embedded script;arguments (path, SID, isDirectory flag) are passed as
execFile/execFileSyncargv (noshell interpolation). No change to the argument-passing model.
pathutilities and the existinggetWindowsSystemToolPathhelper (resolves
powershell.exe/whoami.exeunder%SystemRoot%\System32); nouser-controlled tool paths.
have their restrictive ACL applied synchronously before
writeSecureFilereturns,removing the async window where they would carry inherited (broader) ACLs.
PowerShell ACL APIs are locked down); a failed file-ACL apply is left uncached so it
retries rather than being silently trusted.
Notes
(
chmodSync) are untouched and covered by the non-win32 guard test.src/shared/secure-file.tsand its test.Rollback = revert the commit; restores prior behavior (the storm). The directory cache
is process-lifetime only (no persisted state), so there is no migration concern.