Skip to content

fix(windows): stop blocking OpenCode with PowerShell permission checks - #175

Merged
Phototonic merged 5 commits into
devfrom
fix/windows-no-acl-queries
Nov 18, 2026
Merged

Phototonic merged 5 commits into
devfrom
fix/windows-no-acl-queries

Conversation

@Phototonic

@Phototonic Phototonic commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Fixes #172

Summary

On native Windows the companion blocked OpenCode's event loop for 28 to 43 seconds while loading, because every ownership/ACL check started Windows PowerShell synchronously (1 to 2.4 s each): about 10 to 20 times in initialize(), once per tool hook and twice per status inspection. The models.dev request then timed out and /api/provider answered 503 for the life of the process.

Decision (by maintainer): the Windows ACL checks are removed everywhere, and Windows relies on the user profile's default per-user permissions, like other per-user applications. No process is started for any permission check, on any platform.

  • No windowsSecurityQuery, PowerShell spawn, ACL cache, private-ACL creation or verification, "permissive/foreign ACL" or "unsafe ancestor" refusal, spawn ceiling, cold-start budget or PowerShell mutex barrier remain, in the companion, the service, setup or shared code.
  • Windows keeps the checks that need only plain Node filesystem calls: drive-qualified path syntax, canonical path (realpath), refusal of symbolic links and junctions (lstat), refusal of hard-linked owned state files, markers, hashes and schema validation. Directories are created with default inheritance. Nothing applies or repairs an ACL.
  • Existing installs whose roots carry private ACLs keep working unchanged; a native test proves their ACLs are left byte-for-byte as found.
  • Linux and macOS uid/mode checks are unchanged.
  • The companion hot path (load, guard(), tool hooks, status inspect) only re-reads the binding with plain filesystem calls.
  • Kept: the 17 s work / 18 s response deadlines, the writer slots, requirePlatformStoreFence, fresh validation of every mutation, and the step names/journal formats. accounting.securitySpawns stays on the wire as a constant 0 (the UI validates that exact shape), and the fixed diagnostic codes windows-security-unavailable, private-permissions and unsafe-parent stay accepted but are no longer produced, so earlier journals and clients keep working.

OpenSpec change windows-default-permissions (not archived; the release PR does that) modifies managed-companion-delivery and windows-setup-responsiveness. Guides updated: docs/setup.md, docs/backend.md, docs/contracts.md, docs/compatibility.md, setup/managed-steps.md, CONTRIBUTING.md, README.md.

Removed or changed checks, by file

  • shared/platform.ts: removed windowsSecurityQuery, windowsSecurity, the PowerShell scripts and bootstrap, DACL policy script, platformSecurityScope/beginPlatformSecurityScope and both caches, the spawn counter/launch()/ceiling, windowsDocumentPath. windowsPath(s) now does syntax + lstat + realpath only; isOwned is POSIX-only (true on Windows); privatePaths on Windows checks "not a link, hard-link count 1"; privateDirectory creates ordinary directories on Windows.
  • shared/binding.ts, managed-binding.ts, store.ts, cleanup.ts, plugin/document.ts, service/setup-controller.ts, service/suggestions.ts, setup/*: removed the scope wrappers and the dead security-error paths; call sites otherwise unchanged.
  • service/request-worker.ts: removed the shared attempt counter and the loopback nonce handshake that only the PowerShell child used; the writer slots themselves are unchanged.
  • shared/managed-steps.ts: removed securitySpawns limit and the spawn allocation table.

Tests removed or rewritten, and why

Deleted:

  • tests/backend/windows-security-query.test.ts: covered windowsSecurityQuery itself (environment hygiene, first-query retry, budget charging, shared counter, writer-fence mutex handshake, timeout/exit mapping). The function is gone.
  • tests/backend/windows-spawn-budget.test.ts: counted fake PowerShell launches per managed operation. Replaced by the no-process assertions below.
  • tests/backend/managed-step-prepare-budget.test.ts: a six-launch feasibility measurement and slow-helper deadline cases. The deadline-before-creation behaviour is covered by a new case in managed-fresh-store.test.ts and managed-migration-steps.test.ts.

Rewritten (ACL or launch-count assertions removed, the rest kept):

  • windows-platform.test.ts (native Windows only): removed private-ACL creation/refusal, ACL cache invalidation, callback/object/audit ACE, PowerShell module bootstrap, ancestor-owner and ancestor-replacement-rights, foreign-owner, public-ACL store and side-file, and unsafe-historical-ancestor cases. Added: default-permission creation with no process, existing owner-only ACL roots keep working and are not modified, an ordinary or widely readable folder is accepted. Hard-link, junction, canonical-path, lifecycle, capture, cleanup and legacy-plugin cases are kept.
  • windows-service.test.ts (native Windows only): removed the empty-delayed journey, the 2.5 s helper mode of the 1.1.1 migration, injected timeout/private/overrun helper faults and the held-spawn concurrent-health check; every request now asserts zero launches.
  • windows-service-observer.test.ts and the observer/driver/probe fixtures: the observer now counts every child-process launch (not only powershell.exe) and no longer injects latency or faults.
  • managed-inspection, managed-migration-steps, managed-step-engine, managed-step-removal, managed-step-upgrade: "at most six launches" tests now assert zero launches on the projected Windows path; "enclosing security scope" assertions and spawn/time exhaustion variants were reduced to the deadline case.
  • managed-step-contract: removed the spawn allocation arithmetic; the deadline ordering assertion stays.
  • managed-step-http, managed-http-worker, managed-request-worker, managed-migration, managed-health: removed cold-query latency, helper timeout, counter and windows-security-unavailable fault cases.

Regression tests (fail first)

tests/backend/windows-no-process.test.ts (commit 1 of this PR, before the fix). On the unmodified code it failed with the number of child-process calls per phase on the simulated Windows path: setup and service 34, companion load 27, one guarded report 12, tool hooks 6, status inspect 6; plus a static check that nothing under plugin/, service/, setup/ or shared/ imports node:child_process. After the fix every phase is 0.

Judgement calls and risks

  • Spawn-count reservations are gone; a time-only headroom stays. Steps used to reserve time for their planned PowerShell launches (for example 13.5 s for a prepare). They now reserve a fixed 2.5 s (STEP_HEADROOM_MS) before the engine publishes an intent and right before an exclusive folder or database creation, so the 17 s deadline cannot land between a creation and its checkpoint. This applies on every platform. The response deadline, the writer slots and uncertain-effect handling are unchanged.
  • The PowerShell mutex and nonce barrier is removed. It fenced a Windows security child that outlived its service; with no such child there is nothing to fence. The loopback writer slots and requirePlatformStoreFence are unchanged.
  • The "mutation inside a read scope" refusal is gone on every platform, because the scope and its cache no longer exist.
  • Retired codes stay. windows-security-unavailable, private-permissions and unsafe-parent stay in the fixed vocabulary and in the Setup UI copy (one string still mentions PowerShell), so old journals and clients render; nothing produces them any more.
  • Custom store folders can be anywhere; one outside the profile simply has whatever permissions it already carries (stated in docs/setup.md).
  • Wire compatibility. accounting.securitySpawns is kept as a constant 0 rather than removed, because the UI validates that exact shape.

Verification

  • bun run typecheck, bun run tsc --noEmit -p ui/tsconfig.json, bun run build:all (no generated output tracked): pass.
  • bun run test:all on the pushed head: all portable groups pass.
  • bun run package and bun run verify:package: pass (the packaged service reports 0 launches).
  • openspec validate windows-default-permissions --strict and openspec validate --all --strict: pass.
  • Native Windows CI (the only place the native path runs): the pull request run 44363489894 passes (fast Windows set, Linux jobs). A manual dispatch of the workflow on this branch, which runs the full Windows set including the released 1.1.1 migration, passes: run 44363501921 (13 platform tests and 6 service journeys, none skipped). Every request in those journeys asserts zero child-process launches through an independent observer; the platform suite asserts that roots with an existing owner-only ACL keep working and keep that ACL unchanged.
  • Not tested: a real Windows host with OpenCode loading the companion (the reporter's 28 to 43 s stall itself); the portable and native tests prove no process is started, not wall-clock latency inside OpenCode.

Checklist

  • Scope and target branch follow CONTRIBUTING.md.
  • Relevant tests and documentation/contracts are updated.
  • Source PRs contain no generated runtime outputs.
  • Diff, examples, and attachments contain no credentials, raw logs, private paths/content, or internal tracker data.
  • Third-party license notices are preserved, if applicable (not affected).

@Phototonic Phototonic added bug Something isn't working documentation Improvements or additions to documentation platform:windows Only happens on Windows area:setup Setup, capture, and migrating from the old install area:service The extension's background service and its API area:companion The OpenCode companion: reporting, hints, sub-agents labels Nov 18, 2026
Comment thread shared/platform.ts Resolved
@kilo-code-bot

kilo-code-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

The new deadline headroom is checked before exclusive creation without reintroducing PowerShell. No new critical findings in this increment. The Windows permissions issue remains open: the documentation now describes the behavior, but the access boundary has not changed.

Overview

Severity Count
CRITICAL 1
WARNING 0
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
shared/platform.ts 156 Windows privatePaths checks links but not access. When a custom Store folder grants inheritable read access to other accounts, those accounts can read captured documents, plan history, and cleanup backups directly from disk. In the standalone legacy flow, executable plugin files in shared writable folders also lack protection from cross-account modification. Refuse paths that cannot provide the required isolation without restoring synchronous PowerShell to the companion hot path.
Files Reviewed (12 files)
  • docs/backend.md - 0 issues
  • docs/compatibility.md - 0 issues
  • docs/setup.md - 0 issues
  • openspec/changes/windows-default-permissions/specs/windows-setup-responsiveness/spec.md - 0 issues
  • setup/managed-step-engine.ts - 0 issues
  • shared/platform.ts - 1 issue
  • shared/store.ts - 0 issues
  • tests/backend/managed-fresh-store.test.ts - 0 issues
  • tests/backend/managed-step-engine.test.ts - 0 issues
  • tests/backend/platform-budget.test.ts - 0 issues
  • tests/browser/model.test.ts - 0 issues
  • ui/shared/setup.ts - 0 issues

Static incremental review at bb41fca6d36bc7de95bfde5392f8e422f617200c; no project code or tests were run.

Previous Review Summary (commit 0acdc0a)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 0acdc0a)

Status: 1 Issue Found | Recommendation: Address before merge

Removing synchronous PowerShell from the companion hot path addresses the startup bottleneck without changing the Setup wire format. The remaining blocker is that Windows Setup still accepts paths where the profile's default permissions do not apply.

Overview

Severity Count
CRITICAL 1
WARNING 0
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
shared/platform.ts 151 Windows checks links but not access. Custom Store folders can inherit permissions that expose captured documents, plan history, and cleanup backups to other accounts. The same check also admits executable legacy plugin files without verifying that other accounts cannot modify them. Refuse paths that cannot provide the required isolation without bringing PowerShell back to the hot path.
Files Reviewed (54 files)
  • .github/workflows/ci.yml - 0 issues
  • CONTRIBUTING.md - 0 issues
  • README.md - 0 issues
  • docs/backend.md - 0 issues
  • docs/compatibility.md - 0 issues
  • docs/contracts.md - 0 issues
  • docs/setup.md - 0 issues
  • openspec/changes/windows-default-permissions/proposal.md - 0 issues
  • openspec/changes/windows-default-permissions/specs/managed-companion-delivery/spec.md - 0 issues
  • openspec/changes/windows-default-permissions/specs/windows-setup-responsiveness/spec.md - 0 issues
  • openspec/changes/windows-default-permissions/tasks.md - 0 issues
  • plugin/document.ts - 0 issues
  • scripts/verify-package.ts - 0 issues
  • service/request-worker.ts - 0 issues
  • service/setup-controller.ts - 0 issues
  • service/suggestions.ts - 0 issues
  • setup/lifecycle.ts - 0 issues
  • setup/managed-inspection.ts - 0 issues
  • setup/managed-migration.ts - 0 issues
  • setup/managed-observation.ts - 0 issues
  • setup/managed-step-effects.ts - 0 issues
  • setup/managed-step-engine.ts - 0 issues
  • setup/managed-step-journal.ts - 0 issues
  • setup/managed-steps.md - 0 issues
  • shared/binding.ts - 0 issues
  • shared/cleanup.ts - 0 issues
  • shared/managed-binding.ts - 0 issues
  • shared/managed-steps.ts - 0 issues
  • shared/platform.ts - 1 issue
  • shared/store.ts - 0 issues
  • tests/backend/managed-fresh-store.test.ts - 0 issues
  • tests/backend/managed-health.test.ts - 0 issues
  • tests/backend/managed-http-worker.ts - 0 issues
  • tests/backend/managed-inspection.test.ts - 0 issues
  • tests/backend/managed-migration-steps.test.ts - 0 issues
  • tests/backend/managed-migration.test.ts - 0 issues
  • tests/backend/managed-request-worker.test.ts - 0 issues
  • tests/backend/managed-step-contract.test.ts - 0 issues
  • tests/backend/managed-step-engine.test.ts - 0 issues
  • tests/backend/managed-step-http.test.ts - 0 issues
  • tests/backend/managed-step-journal.test.ts - 0 issues
  • tests/backend/managed-step-prepare-budget.test.ts - 0 issues
  • tests/backend/managed-step-removal.test.ts - 0 issues
  • tests/backend/managed-step-upgrade.test.ts - 0 issues
  • tests/backend/windows-no-process.test.ts - 0 issues
  • tests/backend/windows-platform.test.ts - 0 issues
  • tests/backend/windows-security-query.test.ts - 0 issues
  • tests/backend/windows-service-observer.test.ts - 0 issues
  • tests/backend/windows-service.test.ts - 0 issues
  • tests/backend/windows-spawn-budget.test.ts - 0 issues
  • tests/fixtures/windows-acl.ts - 0 issues
  • tests/fixtures/windows-observer-probe.mjs - 0 issues
  • tests/fixtures/windows-service-driver.ts - 0 issues
  • tests/fixtures/windows-service-observer.mjs - 0 issues

Static review only; no project code or tests were run.


Reviewed by gpt-6.2-sol · Input: 36 · Output: 5.1K · Cached: 601K

@Phototonic
Phototonic merged commit 78ac143 into dev Nov 18, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:companion The OpenCode companion: reporting, hints, sub-agents area:service The extension's background service and its API area:setup Setup, capture, and migrating from the old install bug Something isn't working documentation Improvements or additions to documentation platform:windows Only happens on Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant