Skip to content

Commit 9688b96

Browse files
ouyyyyangclaude
andcommitted
fix: don't write launcher PID into agent.pid on Windows
start-local-agent.ps1 was writing the wrapper PowerShell's PID into agent.pid before node even started. The agent's ensureSingleInstance() in server.ts then read that PID, saw the wrapper was still alive (naturally — it's node's parent), and aborted with "Another Screen Pilot agent is already running". server.ts writes its own real PID after binding the port, so the ps1 has no business pre-writing it. Also fix log encoding: replace '*>> \$LogFile' with '2>&1 | Out-File -Encoding utf8 -Append' so agent.log is clean UTF-8 instead of UTF-16 LE. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent de4e93b commit 9688b96

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

scripts/dev/start-local-agent.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ $serverCommand = @(
201201
"`$env:SCREEN_PILOT_PID_FILE='$PidFile'"
202202
"`$env:SCREEN_PILOT_PORT_FILE='$PortFile'"
203203
"Set-Location '$RootDir'"
204-
"& '$nodeAbsolute' build/node/core/agent/src/server.js *>> '$LogFile'"
204+
"& '$nodeAbsolute' build/node/core/agent/src/server.js 2>&1 | Out-File -FilePath '$LogFile' -Append -Encoding utf8"
205205
) -join "; "
206206

207207
$process = Start-Process `
@@ -211,7 +211,10 @@ $process = Start-Process `
211211
-WindowStyle Hidden `
212212
-PassThru
213213

214-
Set-Content -Path $PidFile -Value $process.Id
214+
# Do NOT write $process.Id to $PidFile here — $process is the launcher
215+
# PowerShell wrapper, not the node agent. server.ts writes its own real
216+
# PID once it binds the port. Writing the wrapper PID makes the agent's
217+
# ensureSingleInstance() see a "live" PID and exit immediately.
215218

216219
Write-Host "Starting agent..."
217220
for ($attempt = 0; $attempt -lt 30; $attempt += 1) {

0 commit comments

Comments
 (0)