[Bug]: Windows wait-for-setup startup policy never starts the agent — doubled quotes in the generated cmd wrapper leave ORCA_SETUP_MARKER unset
Operating system
Windows
Orca version
1.4.141
Details
Enabling the "wait for setup to finish before starting the agent" startup policy (the feature from #5183) breaks worktree creation on Windows. The agent never starts. Instead the pane emits a Test-Path error roughly once per second until the wrapper's 2-hour deadline expires and it exits 124.
Short version: the generated cmd.exe wrapper sets its env vars with doubled quotes, which cmd.exe does not unescape under /s. ORCA_SETUP_MARKER therefore never exists, so the PowerShell polling loop calls Test-Path -LiteralPath $null on every iteration, its exit condition is unreachable, and it spins for the full 7200 s.
A setup script is not required to trigger this — the wrapper is generated regardless of whether the repo has one.
What I see
D:\Task\.orca-workspaces\myeonglang\myeonglang\featherstar>cmd.exe /d /s /v:on /c "set ""ORCA_SETUP_MARKER=D:/Task/services/myeonglang/.git/worktrees/featherstar/orca/setup-runner.cmd.55e19708-eab0-4bf5-9a14-925d1205519c.done"" & set ""ORCA_SETUP_NONCE=55e19708-eab0-4bf5-9a14-925d1205519c"" & echo Waiting for setup to finish before starting agent... 1>&2 & powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ""$marker = $env:ORCA_SETUP_MARKER; $tmp = $marker + """".tmp""""; $nonce = $env:ORCA_SETUP_NONCE; $deadline = (Get-Date).AddSeconds(7200); while ($true) {; if (Test-Path -LiteralPath $marker) {; ... }"" & set ""ORCA_SETUP_STATUS=!ERRORLEVEL!"" & exit /b !ORCA_SETUP_STATUS!"
Waiting for setup to finish before starting agent...
Test-Path : Cannot bind argument to parameter 'LiteralPath' because it is null.
At line:1 char:177
+ ... ds(7200); while ($true) {; if (Test-Path -LiteralPath $marker) {; $co ...
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand
…and that Test-Path block repeats about once per second.
Root cause
set ""VAR=value"" does not create VAR. With /s, cmd.exe strips only the outermost pair of quotes from the /c string and passes everything else through verbatim, so set receives ""VAR=value"" and creates a variable literally named "VAR holding value".
Minimal repro — the first form is what Orca generates, the second is the standard cmd idiom:
C:\> cmd.exe /d /s /v:on /c "set ""FOO=hello"" & set FOO"
Environment variable FOO not defined
C:\> cmd.exe /d /s /v:on /c "set "FOO=hello" & set FOO"
FOO=hello
Dumping the whole environment shows the mangled name:
C:\> cmd.exe /d /s /v:on /c "set ""FOO=hello"" & set"
"FOO=hello
And the null propagates into the PowerShell child exactly as reported above:
C:\> cmd.exe /d /s /v:on /c "set ""ORCA_SETUP_MARKER=D:/tmp/marker.done"" & powershell.exe -NoProfile -Command "if ($null -eq $env:ORCA_SETUP_MARKER) { 'MARKER is NULL' } else { 'MARKER=' + $env:ORCA_SETUP_MARKER }; Test-Path -LiteralPath $env:ORCA_SETUP_MARKER"
MARKER is NULL
Test-Path : Cannot bind argument to parameter 'LiteralPath' because it is null.
Note that ORCA_SETUP_STATUS at the tail of the wrapper is built with the same set ""…"" construct, so the wrapper's exit-status propagation (exit /b !ORCA_SETUP_STATUS!) is broken by this too — it just isn't visible while the loop never reaches it.
Steps to reproduce
- On Windows, set a repo's agent startup policy to wait for setup before starting the agent.
- Create a worktree.
- The pane prints
Waiting for setup to finish before starting agent..., then emits theTest-Patherror once per second. The agent never starts; after 2 hours the wrapper exits 124.
Suggested fixes
- The bug itself — emit
set "VAR=value"(single quotes) instead ofset ""VAR=value"". Better still, passORCA_SETUP_MARKER/ORCA_SETUP_NONCEthrough the child process environment rather than asetchain inside/c, which sidesteps cmd quoting entirely. - Defense in depth — the polling loop should fail fast on a missing marker rather than spin.
Test-Path's failure here is non-terminating, sowhile ($true)cheerfully loops for the full 7200 s while printing an error every second. Aif ([string]::IsNullOrWhiteSpace($marker)) { exit 1 }guard ahead of the loop would have surfaced this on the first iteration instead of after two hours. /v:onenables delayed expansion, so a marker path containing!would be silently corrupted as well. The wrapper does need it for!ERRORLEVEL!, but the marker/nonce values would be safer resolved before delayed expansion is in play.
Related
- #5183 — the feature this implements. It was reported and presumably validated on macOS; the Windows path looks untested.
- #6896 — same area, still open: setup scripts are force-converted to a cmd batch on Windows. A separate bug, but it's the reason my setup script has to be a single PowerShell line in the first place.
- #7236 — earlier PowerShell wrapper breakage, fixed in 1.4.81. This install is 1.4.141, so that fix is present and is not what's happening here.
Environment
- Orca 1.4.141
- Windows 11 Pro 10.0.26200
powershell.exeresolves to Windows PowerShell 5.1.26100.8737
Workaround for now: leave the startup policy off.
Made with Orca 🐋
I can reproduce this on Windows against current main. I'm working on a focused fix for the cmd.exe /s /c quoting, with a real Windows child-process regression test for the setup-to-agent sequence and a fail-fast guard for a missing marker. I'll keep the PR scoped to this issue.
Agent reproduction package (Windows orchestration 2026-07-16)
Host context: Windows 11 / Orca 1.4.143.0 / repo path used: docs/bug-reproductions/
Labels applied: see issue labels (has_repro or cannot_repro).
Security: Do not run user-uploaded binaries from issue attachments. Recreate fixtures from the steps/scripts below.
Issue 8787 — wait-for-setup doubled quotes leave ORCA_SETUP_MARKER unset
Status: repro_confirmed
Host: Windows 11 10.0.26200, Orca 1.4.143, repo main
Label: has_repro
Summary
createSequencedSetupAgentCommands builds a Windows wait-for-setup startup command via wrapCmd + quoteWindowsArg, which doubles every " inside a cmd.exe /d /s /c "..." string. Nested set "VAR=value" becomes set ""VAR=value"". Under the full pattern (set + nested powershell.exe -Command with further quote doubling), ORCA_SETUP_MARKER and ORCA_SETUP_NONCE are empty in the child PowerShell process, so Test-Path -LiteralPath $marker fails forever (user sees null LiteralPath errors ~1/s until 7200s timeout).
Source: src/shared/setup-agent-sequencing.ts (wrapCmd, quoteWindowsArg, buildWindowsStartupCommand).
Repro (another agent)
cd <repo>
powershell -NoProfile -ExecutionPolicy Bypass -File docs/bug-reproductions/scripts/repro-8787-setup-marker-quoting.ps1
# Expect exit 0 and evidence JSON with bugReproduced=true
Evidence
docs/bug-reproductions/evidence/8787-20260716-021135.json- Probe stdout:
MARKER=/NONCE=empty, exit code 7 - Generated command pattern matches issue body
Expected vs actual
| Expected | ORCA_SETUP_MARKER set; wait loop sees marker file when setup finishes |
| Actual | Env vars empty; wait loop cannot succeed |
Notes
- Minimal
set ""FOO=bar""alone may still set FOO on Win11 26200; the full wrapCmd + nested PowerShell pattern is the decisive failure mode. - Maintainer comment on issue: already working on fix.
- Unit tests currently assert string shape only — they do not spawn cmd.exe, so they miss this.
Fix hint
Avoid double-encoding quotes for set under /s, or set env vars outside the /c string (e.g. spawn with env map), or use a .cmd file on disk instead of nested quoting.
Repro script: repro-8787-setup-marker-quoting.ps1
# Repro for https://github.com/stablyai/orca/issues/8787
# Windows wait-for-setup: doubled quotes in cmd /s /c leave ORCA_SETUP_MARKER unset.
#
# Usage (from anywhere):
# powershell -NoProfile -ExecutionPolicy Bypass -File docs/bug-reproductions/scripts/repro-8787-setup-marker-quoting.ps1
#
# Exit 0 = bug reproduced (marker unset / Test-Path null).
# Exit 2 = unexpected success (bug appears fixed).
# Exit 1 = script failure.
$ErrorActionPreference = 'Stop'
$root = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
if (-not (Test-Path (Join-Path $root 'src\shared\setup-agent-sequencing.ts'))) {
# script is under docs/bug-reproductions/scripts → repo root is 3 levels up
$root = Split-Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) -Parent
}
$evidenceDir = Join-Path (Split-Path $PSScriptRoot -Parent) 'evidence'
New-Item -ItemType Directory -Force -Path $evidenceDir | Out-Null
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$log = Join-Path $evidenceDir "8787-$stamp.log"
function Log([string]$msg) {
$line = "[$(Get-Date -Format o)] $msg"
Add-Content -Path $log -Value $line
Write-Host $line
}
Log "=== Issue 8787 repro: ORCA_SETUP_MARKER doubled-quote under cmd /s /c ==="
Log "Host: $([Environment]::OSVersion.VersionString)"
Log "PS: $($PSVersionTable.PSVersion)"
# Minimal mirror of src/shared/setup-agent-sequencing.ts wrapCmd + quoteWindowsArg + set lines.
# This is the exact quoting pattern the issue reports and the source still emits.
function Quote-WindowsArg([string]$value) {
return '"' + ($value -replace '"', '""') + '"'
}
$markerPath = Join-Path $env:TEMP "orca-8787-marker-$stamp.done"
$nonce = [guid]::NewGuid().ToString()
$inner = @(
"set `"ORCA_SETUP_MARKER=$markerPath`"",
"set `"ORCA_SETUP_NONCE=$nonce`"",
'echo Waiting for setup to finish before starting agent... 1>&2',
# Probe env vars immediately (no 2-hour wait)
'powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Write-Output (''MARKER='' + [string]$env:ORCA_SETUP_MARKER); Write-Output (''NONCE='' + [string]$env:ORCA_SETUP_NONCE); if ([string]::IsNullOrEmpty($env:ORCA_SETUP_MARKER)) { exit 7 } else { exit 0 }"'
) -join ' & '
$full = "cmd.exe /d /s /v:on /c $(Quote-WindowsArg $inner)"
Log "Generated command:"
Log $full
# Also show the minimal pure-cmd form from the issue body
$minimalBroken = 'cmd.exe /d /s /c "set ""FOO=bar"" & set FOO"'
$minimalGood = 'cmd.exe /d /s /c "set "FOO=bar" & set FOO"'
Log "--- Minimal broken form (issue body) ---"
$brokenOut = cmd.exe /d /s /c "set ""FOO=bar"" & set FOO" 2>&1 | Out-String
Log "stdout/stderr:`n$brokenOut"
$brokenHasFoo = $brokenOut -match '(?m)^FOO=bar'
Log "FOO=bar present? $brokenHasFoo (expect False for bug)"
Log "--- Minimal correct form ---"
$goodOut = cmd.exe /d /s /c "set `"FOO=bar`" & set FOO" 2>&1 | Out-String
Log "stdout/stderr:`n$goodOut"
Log "--- Full wait-wrapper probe ---"
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = 'cmd.exe'
$psi.Arguments = "/d /s /v:on /c $(Quote-WindowsArg $inner)"
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.UseShellExecute = $false
$psi.CreateNoWindow = $true
$p = [System.Diagnostics.Process]::Start($psi)
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
$p.WaitForExit(15000) | Out-Null
Log "exit=$($p.ExitCode)"
Log "stdout:`n$stdout"
Log "stderr:`n$stderr"
# Why: exit 7 is our deliberate probe code when $env:ORCA_SETUP_MARKER is empty.
# On Win11 10.0.26200 the *minimal* `set ""FOO=bar""` form can still set FOO, but
# the full wrapCmd pattern (set + nested powershell -Command with quote doubling)
# still leaves ORCA_SETUP_MARKER/NONCE empty — matching the user-facing bug.
$markerEmpty = ($p.ExitCode -eq 7) -or ($stdout -match '(?m)^MARKER=\s*$')
$markerSet = $stdout -match [regex]::Escape("MARKER=$markerPath")
$nonceEmpty = $stdout -match '(?m)^NONCE=\s*$'
$result = [ordered]@{
issue = 8787
stamp = $stamp
minimalBrokenFooSet = $brokenHasFoo
noteMinimal = 'On some Windows builds set ""FOO=bar"" still works; full wrapCmd is the decisive probe.'
fullProbeExit = $p.ExitCode
markerEnvEmpty = $markerEmpty
nonceEnvEmpty = $nonceEmpty
markerEnvCorrect = $markerSet
bugReproduced = $markerEmpty -and -not $markerSet
log = $log
command = $full
}
$jsonPath = Join-Path $evidenceDir "8787-$stamp.json"
$result | ConvertTo-Json -Depth 5 | Set-Content -Path $jsonPath -Encoding utf8
Log "Wrote $jsonPath"
Log "bugReproduced=$($result.bugReproduced) markerEmpty=$markerEmpty markerSet=$markerSet"
if ($result.bugReproduced) {
Log "PASS (bug confirmed): ORCA_SETUP_MARKER unset under doubled-quote wrapCmd pattern"
exit 0
}
Log "FAIL (bug NOT observed): quoting may be fixed or environment differs"
exit 2
How another agent should use this
- Read this comment fully (status, expected vs actual, blockers).
- If a script is included above, copy it to a temp file and run it on a Windows 11 host with Orca installed (prefer production install under
%LOCALAPPDATA%\Programs\orca). - Capture evidence (CLI
--json, screenshots, logs) under a local folder; optionally comment results back here. - If status is
cannot_repro/ needs_setup, satisfy the listed prerequisites first, then re-attempt and flip labels: removecannot_repro, addhas_reprowhen conclusive.