Skip to content

The agent that grows with you

fix(desktop): pipe Windows spawn lock to stdin

Brooklyn Nicholson0466a04bc874
diff --git a/apps/desktop/electron/windows-remote-lifecycle.test.ts b/apps/desktop/electron/windows-remote-lifecycle.test.ts
index b5695c1bc09..9c2ea723330 100644
--- a/apps/desktop/electron/windows-remote-lifecycle.test.ts
+++ b/apps/desktop/electron/windows-remote-lifecycle.test.ts
@@ -57,6 +57,8 @@ test('Windows spawn publishes the initial ownership record before releasing the
assert.match(script, /read-lock/)
assert.match(script, /write-lock/)
+ assert.match(script, /\$lock\s*\|\s*&.*write-lock/)
+ assert.doesNotMatch(script, /write-lock[^;]*\$lock\|Out-Null/)
assert.ok(script.indexOf('write-lock') < script.indexOf('Unlock'))
})
diff --git a/apps/desktop/electron/windows-remote-lifecycle.ts b/apps/desktop/electron/windows-remote-lifecycle.ts
index becfd7fba2d..ea387d514bc 100644
--- a/apps/desktop/electron/windows-remote-lifecycle.ts
+++ b/apps/desktop/electron/windows-remote-lifecycle.ts
@@ -279,7 +279,7 @@ function atomicWindowsSpawnCommand(runtime, reservation: any = {}) {
: ' if($LASTEXITCODE -ne 0){exit $LASTEXITCODE}',
reservation.ownershipId
? ` $spawned=$spawnLines[-1]|ConvertFrom-Json; $lock=[ordered]@{schemaVersion=2;protocolVersion=1;ownershipId=${psLiteral(reservation.ownershipId)};spawnNonce=${psLiteral(reservation.spawnNonce)};pid=[int]$spawned.pid;creationTimeNs=[string]$spawned.creationTimeNs;port=0;profile=${psLiteral(reservation.profile)};hermesPath=${psLiteral(reservation.hermesPath)};hermesHome=${psLiteral(reservation.hermesHome)};tokenFingerprint=${psLiteral(reservation.tokenFingerprint)};startedAt=${psLiteral(reservation.startedAt)}}|ConvertTo-Json -Compress; ` +
- ` & ${helper('write-lock').map(psLiteral).join(' ')} ${psLiteral(reservation.ownershipId)} $lock|Out-Null; if($LASTEXITCODE -ne 0){exit $LASTEXITCODE}; $spawnLines|Write-Output`
+ ` $lock | & ${helper('write-lock').map(psLiteral).join(' ')} ${psLiteral(reservation.ownershipId)} | Out-Null; if($LASTEXITCODE -ne 0){exit $LASTEXITCODE}; $spawnLines|Write-Output`
: '',
' if([IO.File]::Exists($marker)){throw "remote update marker claimed during backend spawn"}',
'}finally{try{$mutex.Unlock(0,1)}catch{};$mutex.Dispose()}'