Skip to content

feat(wsl): fetch and cache a remote WSL hosts policy (kill switch, remote half 1/2) - #35528

Merged
nwparker merged 2 commits into
mainfrom
nwparker/wsl-hosts-remote-policy
Oct 29, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/wsl-hosts-remote-policy

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

WSL hosts will eventually be on by default. If something goes wrong after that, we need a way to turn them off for people without shipping a new release. This PR adds the part of Orca that downloads and remembers a small "WSL hosts: allow or block" file. Nothing acts on that file yet; the stacked PR that follows does.

What Changed

  • src/shared/wsl-hosts-policy.ts: the file format is { version: 1, revision, wslHosts: 'allow' | 'block' }, capped at 16 KB.
    • Fields added later are ignored rather than rejected, so older builds keep honoring the file after its format grows.
    • An unknown format or switch value is rejected.
  • src/main/wsl/wsl-hosts-policy-live-update.ts: downloads the file and keeps it current.
    • It comes from a fixed release-asset URL with one file per channel: wsl-hosts-policy-stable and wsl-hosts-policy-next. A stable build therefore never applies a prerelease-only switch, even when the two share a profile.
    • Checks every 4 hours, with a 30 s timeout and a bounded read.
    • The file is cached atomically in userData, and a sync reader serves the startup gate.
  • Every failure keeps the last good cache: offline, 404 (the normal state while nothing is published), server errors, or a malformed file.
  • A download whose revision is lower than or equal to the cached one never replaces it. A stale mirror or replayed file can't undo a newer switch, and lifting a block takes a higher-revision allow.
  • Unpackaged dev and test runs never download.

Before and after, as the user sees it: no change. Nothing calls this yet. The shared module also exposes the cached policy as allow, block or missing for the gate and telemetry in the stacked PR.

Why

This copies the existing agent-state-rules live updater: release-asset URL, channel split, unpackaged guard, atomic cache, bounded read. That mechanism is already proven, so this adds no new remote-config service. I used a revision number rather than a timestamp so client clock skew can't cause a downgrade.

Flag-off: with ORCA_INTERNAL_WSL_HOSTS unset nothing changes. This PR adds code that nothing calls; the stacked PR starts the download only with the internal gate open.

Status

Ready. Head 68d9910c71e. Checks run locally: pnpm tc, pnpm run typecheck:ci, wsl-hosts-policy-live-update.test.ts (18), check:code-quality:changed, anti-slop oxlint, ast-grep gates. Reviews requested from fix-reviewer and e9-reviewer.

Linked Issue

Internal: WSL-host kill switch (part 1 of the remote half; the serve-only gate is #34683).

Visual Proof

N/A: no UI and no behavior change, since nothing reads the policy yet.

Testing

  • Automated tests added: src/main/wsl/wsl-hosts-policy-live-update.test.ts (18 tests)
    • parse and forward compatibility
    • channel split
    • caching
    • monotonic revision
    • the last good cache kept on 404, 5xx, malformed and offline
    • no download when unpackaged
    • an unreadable cache read as no policy
  • Manual: not applicable until the next PR wires it in. No policy file is published by this PR.

Review

Agent skill upstream boundary

  • Not applicable.

Notes

  • Security: the input is bounded, schema-validated and never executed. The URL is fixed HTTPS on the main release repo.
  • Cross-platform: path handling uses path.join.
  • SSH and remote: unaffected. This only runs on the desktop, and nothing goes over the wire.
  • Performance: one small GET every 4 hours, only where the next PR enables it.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visuals, with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote impact considered
  • Targeted vitest, pnpm tc:node and check:code-quality:changed pass locally; CI covers the rest

Adds the client half of a remote switch that can turn WSL hosts off: a
small versioned policy file, downloaded from a fixed release-asset URL per
channel, validated, bounded, and cached in userData with a monotonic
revision. Nothing reads it yet; wiring into the gate follows.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a39e9983-c049-4421-8305-ae03e045d85e
Commits

Reviewing files that changed from the base of the PR and between 134226a and 68d9910.

Files selected for processing: 3
  • src/main/wsl/wsl-hosts-policy-live-update.test.ts
  • src/main/wsl/wsl-hosts-policy-live-update.ts
  • src/shared/wsl-hosts-policy.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Low impact] The PR adds a policy updater and cache but does not connect them to WSL behavior.

Update the caller in PR #35529 or retain wslHostsPolicyBlocks before merging the stack.

Findings

  1. P1 Stacked desktop build breaks ▶
  2. P2 Older policy can win ▶

Summary

Adds a remote WSL hosts policy format, bounded downloads, and separate stable and prerelease caches.

  • WSL policy files use a small, versioned format.
  • The desktop can cache newer WSL policies separately by release channel.

Reviews (2) · Last reviewed commit: "refactor(wsl): expose the cached WSL hos..." · Reviewed by Greptile

Comment on lines +134 to +140
const cached = readCachedWslHostsPolicy(this.deps.userDataPath, this.deps.appVersion)
// A stale mirror or replayed file must never undo a newer switch.
if (cached && parsed.policy.revision <= cached.revision) {
return
}
try {
await writePluginFileAtomically(

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 Older policy can win

Two overlapping refresh() calls can both read revision 4 and accept newer revisions before either write finishes. If revision 5 finishes after revision 6, it replaces the newer policy. writePluginFileAtomically prevents partial files, but does not order writes.

This is non-blocking while the updater remains unused. Before wiring it into startup, serialize the revision check and write, and add a test that overlaps two refreshes and checks that the highest revision survives.

Comment on lines +35 to +38
export type WslHostsPolicyState = 'allow' | 'block' | 'missing'

export function wslHostsPolicyState(policy: WslHostsPolicy | null): WslHostsPolicyState {
return policy?.wslHosts ?? 'missing'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Stacked desktop build breaks

Removing wslHostsPolicyBlocks breaks the startup caller in stacked PR #35529. At its supplied head, src/main/wsl/wsl-host-gate-startup.ts still imports and calls that export. Once #35529 includes this change, the import will fail type checking.

Keep the boolean helper alongside wslHostsPolicyState, or update #35529 to compare the new result with 'block'.

@nwparker
nwparker merged commit 5433c70 into main Oct 29, 2026
50 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