Skip to content

fix(snapshot): survive cold PowerShell starts in Windows staging gates - #123633

Merged
steipete merged 5 commits into
mainfrom
steipete/windows-powershell-cold-spawn
Aug 14, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/windows-powershell-cold-spawn

Conversation

@steipete

@steipete steipete commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

src/snapshot/local-repository.windows.test.ts > "verifies and cleans staging when the SQLite path exceeds MAX_PATH" failed flakily on PR #123509 (run 31775262530, checks-windows-node-test-1, attempt 1, ~11.1s) with an unrelated diff, then passed on rerun. The failure was Unable to verify private Windows ACL for SQLite staging: ... from assertTrustedWindowsStagingPath — and the job log contains a PowerShell CLIXML progress record Preparing modules for first use.

Root cause: the fail-closed Windows ACL probe (runEncodedWindowsPowerShell) bounded its powershell.exe -EncodedCommand spawn at 10 s. Cold first-use PowerShell module analysis / NGEN compilation on a loaded runner exceeds 10 s, execa kills the child, and the bare catch {} discarded the timeout error — so the failure surfaced with no cause at all. This is a production bug, not just a CI flake: a slow user machine hits the same fail-closed error during snapshot create/verify. The identical 10 s bound (and duplicated encoded-spawn plumbing) existed in two sibling fail-closed owners: createPrivateSqliteDirectory (which compiles C# via Add-Type — the slowest cold path) and createPrivateWindowsPlanFile.

Why This Change Was Made

  • New src/infra/windows-powershell-spawn.ts owns the shared invariant: WINDOWS_POWERSHELL_COLD_SPAWN_TIMEOUT_MS = 60_000 (the bound exists only to stop true hangs; fail-closed gates must out-wait cold starts) and buildEncodedPowerShellArgs() (canonical -NoLogo -NoProfile -NonInteractive -EncodedCommand argv + utf16le/base64 encoding, previously copy-pasted in three files).
  • src/snapshot/local-repository.ts, src/infra/sqlite-private-directory.ts, and src/secrets/private-plan-file.ts now share both; ACL/creation logic is byte-identical otherwise.
  • assertTrustedWindowsStagingPath now preserves the underlying spawn error as cause — the same diagnostics-loss class already fixed in the sibling by fix(sqlite): preserve Windows private-directory diagnostics #123023; without it this flake was undiagnosable from CI output.
  • Deliberately untouched: src/daemon/schtasks-runtime.ts (5 s fail-open best-effort probe → "unknown", a different contract) and src/cli/completion-cli.test-support.ts (interactive test host).
  • Related but distinct: fix(snapshot): Windows backup fails when PowerShell 7 is installed #121618 fixes a different root cause behind the same error string (PowerShell 7 module shadowing in this probe); no overlap in the fix.

User Impact

Windows snapshot create/verify/restore, private SQLite staging directory creation, and private plan file creation no longer fail closed when PowerShell needs a cold start on a slow or loaded machine; when the probe does fail, the error now carries the underlying cause.

Evidence

  • Failing CI: run 31775262530 (checks-windows-node-test-1, attempt 1) on refactor(computer-use): one canonical wire contract + node-host provider seam #123509 — 11103 ms ≈ setup + the 10 s timeout, with the Preparing modules for first use. CLIXML record; attempt 2 passed unchanged.

  • Regression test src/snapshot/local-repository.windows-acl-probe.test.ts (mock pattern from fix(sqlite): preserve Windows private-directory diagnostics #123023) fails pre-fix on both counts — pre-fix output: expected undefined to be Error: Command timed out after 60000 milliseconds (cause discarded) and timeoutMs: 10_000 — and passes post-fix.

  • Focused local proof (trusted worktree): node scripts/run-vitest.mjs on local-repository.windows-acl-probe.test.ts (1 passed), local-repository.test.ts (65 passed, 1 skipped), sqlite-private-directory.test.ts (3 passed), private-plan-file.test.ts (1 passed); pnpm format + git diff --check clean.

  • Remote check backends (Blacksmith/Crabbox) were unreachable at proof time; per repo fallback policy, pnpm tsgo and scripts/run-oxlint.mjs on the changed files ran locally: both clean.

  • Real-Windows validation rides this PR's checks-windows-node-test lanes, which execute local-repository.windows.test.ts on windows-latest.

  • Production LOC +55/−50 (net +5, the new shared module's comment lines); test +44/−0.

  • Exact-flake reproduction on demand is infeasible (depends on the runner image's PowerShell module-analysis cache state and load); the captured failing run is the reproduction evidence.

  • Unrelated red main: build-artifacts fails on latest main (run 31797901898, a 5-byte Control UI startup-JS budget overrun from fix(ui): autosave acks wipe open add-entry drafts and in-progress JSON text #123502) and therefore on every PR merge-ref build including this one. Dedicated fix: fix(ci): record startup JS growth in the Control UI budget baseline #123639. All other lanes on this PR are unaffected.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 14, 2026 11:56
@steipete
steipete requested a review from a team as a code owner August 14, 2026 11:56
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 14, 2026
@steipete
steipete force-pushed the steipete/windows-powershell-cold-spawn branch from 6eea4ee to 9e13580 Compare August 14, 2026 12:18
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 9:41 AM ET / 13:41 UTC.

ClawSweeper review

What this changes

The PR centralizes encoded Windows PowerShell launches for snapshot, private SQLite-directory, and private plan-file security gates, extends their cold-start timeout to 60 seconds, and preserves sanitized failure causes.

Regression provenance

Possible regression — probable (failure trace; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this protected maintainer PR open for the explicit timeout tradeoff and exact-head Windows validation. Current main still has the three 10-second fail-closed launches; no discrete patch defect was found in the shared, sanitized replacement.

Priority: P1
Reviewed head: fb3143e384d6a870f41eac68a2166d5ad542fa17
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a coherent owner-boundary repair with focused regression evidence; the remaining concern is the maintainer-selected timeout and pending Windows confirmation.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its body nevertheless includes a captured Windows CI failure and focused after-fix regression evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its body nevertheless includes a captured Windows CI failure and focused after-fix regression evidence.
Evidence reviewed 6 items Current-main failure boundary: Current main still launches the private SQLite-directory PowerShell command with a 10-second timeout, so the central behavior is not already implemented on main.
Three fail-closed owners share the invariant: The PR head routes snapshot ACL inspection, private SQLite creation, and private plan creation through one 60-second encoded-launch helper while retaining each owner's ACL logic.
Sanitized error boundary: The shared failure receipt builds a new error from bounded, filtered stderr/stdout rather than retaining the raw child-process error and its encoded command argv.
Findings None None.
Security None None.

How this fits together

Windows snapshot and secret-plan operations use PowerShell to establish or verify private ACLs before handling local data. A successful gate permits the operation; a failed gate stops it with a diagnostic.

flowchart LR
  A[Snapshot or plan request] --> B[Private ACL security gate]
  B --> C[Encoded PowerShell launch]
  C --> D{Gate succeeds?}
  D -->|Yes| E[Secure file operation]
  D -->|No| F[Sanitized failure diagnostic]
Loading

Decision needed

Question Recommendation
Should fail-closed Windows ACL and private-file operations wait up to 60 seconds for a cold PowerShell start rather than fail after 10 seconds? Accept the cold-start budget: Keep the shared 60-second bound after exact-head Windows validation confirms cold starts recover and invalid ACLs still fail closed.

Why: This is an intentional security-gate availability tradeoff; source review can confirm the preserved fail-closed behavior but cannot choose the acceptable operator wait budget.

Before merge

  • Resolve merge risk (P1) - A genuinely hung PowerShell security gate can now delay snapshot, private-directory, or plan-file failure for up to 60 seconds rather than 10; the supplied exact-head Windows checks were still running.
Agent review details

Security

None.

PR surface

Source +35, Tests +73. Total +108 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 111 76 +35
Tests 3 77 4 +73
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 188 80 +108

Review metrics

Metric Value Why it matters
Production versus test LOC production +55/-50 (net +5 after moved-code consolidation); tests/support +77/-4 The remaining production growth is the shared timeout/sanitization invariant; the change replaces duplicated launch plumbing across three owners.

Merge-risk options

Maintainer options:

  1. Confirm the security-gate tradeoff (recommended)
    Wait for the current head's Windows lanes and accept the 60-second bound only if invalid ACL paths remain fail-closed.
  2. Accept the longer failure window
    Maintainers may merge with the known possibility that a truly hung PowerShell process delays these operations by up to one minute.

Technical review

Best possible solution:

Retain one shared sanitized launcher and the 60-second fail-closed bound once a maintainer accepts that availability tradeoff and current-head Windows lanes confirm both successful cold starts and continued ACL rejection.

Do we have a high-confidence way to reproduce the issue?

No high-confidence on-demand reproduction is available because the cold-start condition depends on runner cache and load. Current main's three 10-second launch sites plus the supplied timeout trace make the owner path source-reproducible.

Is this the best way to solve the issue?

Yes, subject to the timeout decision: the three owners duplicated the same encoded-launch, timeout, and sanitization policy, while the fail-open LAN route probe remains deliberately separate.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5523f8a334c9.

Labels

Label justifications:

  • P1: Cold PowerShell starts can interrupt Windows snapshot, private-directory, and secret-plan workflows used by real operators.
  • merge-risk: 🚨 security-boundary: The new common helper governs fail-closed PowerShell ACL verification and private-file creation paths.
  • merge-risk: 🚨 availability: Increasing the launch bound changes the maximum time affected operations can wait before reporting a failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its body nevertheless includes a captured Windows CI failure and focused after-fix regression evidence.

Evidence

What I checked:

Likely related people:

  • vincentkoc: Introduced the current sanitized private-directory diagnostic owner and has substantial verified-snapshot history. (role: recent area contributor; confidence: high; commits: 732b3da091c5, 2f25e9cba384; files: src/infra/sqlite-private-directory.ts, src/snapshot/local-repository.ts)
  • steipete: Introduced the git-backed snapshot path and authored the current shared Windows cold-start repair series. (role: feature owner and recent area contributor; confidence: high; commits: 37b4fc8621d9, fb3143e384d6; files: src/snapshot/local-repository.ts, src/infra/windows-powershell-spawn.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm the exact current head's Windows lanes before merge.
  • Record the maintainer decision on the one-minute fail-closed wait budget.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-14T12:23:15.805Z sha 9e13580 :: needs changes before merge. :: [P1] Sanitize the PowerShell failure before attaching it
  • reviewed 2026-08-14T12:46:54.613Z sha 883ea61 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T12:59:50.672Z sha cdad781 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T13:27:51.600Z sha 9a2a22d79caff8fe4b1a3f1a72c20986f67dc0f9 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
CI run 31775262530, checks-windows-node-test-1 attempt 1, showed the fail-closed ACL probe timing out during PowerShell first-use module preparation. Centralize encoded one-shot spawning, budget 60 seconds for cold starts, and preserve the underlying probe failure as the error cause.
check-lint-core-2 flagged preserve-caught-error at the private plan file
catch; retaining the raw error would re-leak the -EncodedCommand argv the
sanitization contract strips, so the suppression is intentional (same
idiom as setup-inference-activate.ts).
checks-windows-node-test-2 (run 31804325922) hit the same cold-start flake
class this PR fixes: the codepage-proof test spawns real powershell.exe
bounded at 3s, which a cold runner cannot meet. Production keeps its
fail-open 3s route-hint probe; only the test's real-spawn verification
uses the shared cold-spawn budget.
@steipete
steipete force-pushed the steipete/windows-powershell-cold-spawn branch from 5600df3 to fb3143e Compare August 14, 2026 13:35
@steipete

Copy link
Copy Markdown
Contributor Author

All actionable findings addressed at the current head; per-item disposition:

  • [P1] Sanitize the PowerShell failure before attaching it — fixed. runEncodedWindowsPowerShell no longer rethrows the raw process error. Failures convert to the bounded, encoded-command-free diagnostic contract from fix(sqlite): preserve Windows private-directory diagnostics #123023, now owned by the shared module (buildPowerShellFailureCause / sanitizePowerShellOutputText in src/infra/windows-powershell-spawn.ts): status/exit/killed/signal facts plus stderr/stdout with any EncodedCommand line stripped, UTF16-safe bounded to 1000 chars, original error object never retained. privateDirectoryError in sqlite-private-directory.ts now delegates to the same helper (its fix(sqlite): preserve Windows private-directory diagnostics #123023 tests pass unmodified, pinning the exact message shape), and createPrivateWindowsPlanFile — which attached a raw cause even before this PR — now uses it too, so the sanitization contract holds across all three fail-closed gates.
  • Security concern (raw encoded command via cause) — resolved by the same change.
  • Regression assertion — added. local-repository.windows-acl-probe.test.ts now injects an execa-shaped error carrying -EncodedCommand <base64> in message/command/escapedCommand/stderr, walks the full surfaced cause chain, and asserts: the timeout diagnostics survive (code=ETIMEDOUT, killed=true, sanitized stderr), the original error object is absent from the chain, and no chain element retains EncodedCommand (case-insensitive) or the injected base64 payload.
  • [P1] Availability (60 s on three fail-closed gates) — intended tradeoff, no code change. The prior 10 s bound was measurably failing real runs (run 31775262530: cold Preparing modules for first use. module analysis), producing spurious fail-closed errors on the default path — a worse outcome class than a slower bounded failure of an already-stalled process. Success latency is unchanged; the bound exists only to stop true hangs, and the constant's comment records this contract.
  • Windows lane confirmation — checks-windows-node-test-1/2/3 green on the repaired head (see checks).

@steipete
steipete merged commit b4f91fa into main Aug 14, 2026
168 checks passed
@steipete
steipete deleted the steipete/windows-powershell-cold-spawn branch August 14, 2026 13:49
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
openclaw#123633)

* fix(snapshot): survive cold PowerShell starts in Windows staging gates

CI run 31775262530, checks-windows-node-test-1 attempt 1, showed the fail-closed ACL probe timing out during PowerShell first-use module preparation. Centralize encoded one-shot spawning, budget 60 seconds for cold starts, and preserve the underlying probe failure as the error cause.

* fix(snapshot): sanitize PowerShell failure causes in Windows staging gates

* fix(secrets): explain the sanitized plan-file failure cause suppression

check-lint-core-2 flagged preserve-caught-error at the private plan file
catch; retaining the raw error would re-leak the -EncodedCommand argv the
sanitization contract strips, so the suppression is intentional (same
idiom as setup-inference-activate.ts).

* test(lint): register the private-plan-file suppression in the inventory

* test(infra): give the LAN-host real PowerShell spawn a cold-start budget

checks-windows-node-test-2 (run 31804325922) hit the same cold-start flake
class this PR fixes: the codepage-proof test spawns real powershell.exe
bounded at 3s, which a cold runner cannot meet. Production keeps its
fail-open 3s route-hint probe; only the test's real-spawn verification
uses the shared cold-spawn budget.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant