You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A fresh Android lease fails PROVISION_FAILED on Windows: the seed's second boot cannot replace emulator.log #1662
On Windows every lease that has to make an Android seed fails after about 4 minutes:
{"error":{"code":"PROVISION_FAILED","message":"EPERM: operation not permitted, rename 'D:\\sv\\home\\devices\\android\\sources\\seed_9ca84827-…\\simlock.avd\\.emulator.log.11600.16903aae-….tmp' -> 'D:\\sv\\home\\devices\\android\\sources\\seed_9ca84827-…\\simlock.avd\\emulator.log'"}}
Seen on Windows 11 23H2, Node 22.23.5, emulator 37.2.13, main at c9d82e3, with simlock lease --platform android --device "Pixel 9" --detach on a fresh SIMLOCK_HOME.
Why
A seed boots twice (#bootSeedTwice, src/drivers/android/seeds.ts:591). After the first boot's reboot -p, emulator.exe exits, but the emulator leaves a watchdog behind, emulator -kill <qemu pid> -sleep 20. It inherits the emulator's stdout, which is emulator.log, and keeps it open for about 20 s. The second boot calls EmulatorProcess.start, which empties the log with writeFileAtomic(logPath, "") (src/drivers/android/emulator.ts:251): a temp file renamed over emulator.log. Windows refuses a rename over a file another process has open, so the rename fails with EPERM.
Measured by hand with the same flags (-crash-report-mode never included): after emulator.exe exits, the rename fails for 20 s and then succeeds. Any open handle on the target is enough; a Node child holding the file as stdout reproduces it.
It came with the two-boot seed (#1222, 2026-11-04), after #1053 was checked on Windows (2026-10-30). The same start runs for every copy's boot, so a copy booted within 20 s of an emulator's exit on the same folder would hit it too.
Expected
Making a seed and booting a copy work on Windows. With the log emptied in place instead (fs.writeFile(logPath, ""), as a local test patch), a cold lease took 230 s and a warm one 4 s, and nuke and daemon stop left nothing running.
Confirmed: on Windows a rename over a file another process holds open fails EPERM, and emptying it in place works. EmulatorProcess.start replaces the log instead of emptying it.
Branch bug/1662-repro extends the existing test in src/drivers/android/index-boot.test.ts, now "sends the emulator's output to /emulator.log, mode 0600, emptied in place at each start". It said "truncated" but checked only contents and mode. It now also checks the file is the same one (stat().identity).
pnpm exec vitest run --project unit src/drivers/android/index-boot.test.ts -t "emulator.log"
AssertionError: emulator.log was replaced by another file, not emptied: expected '36' to be '35'
❯ src/drivers/android/index-boot.test.ts:564:7
Windows 11 host, Node v22.23.5, a child holding emulator.log as stdout (opened "a", as NodeProcessRunner does):
atomic replace: EPERM EPERM: operation not permitted, rename '...\.emulator.log.8540.<uuid>.tmp' -> '...\emulator.log'
in place: ok size=0 sameFile=true contents="" # writeFile(log, "", {mode}) + chmod(log, 0o600)
Root cause
Defect. src/drivers/android/emulator.ts:251 empties the log with writeFileAtomic, which renames a temp file over it (src/ports/filesystem.ts:262). The emulator's leftover -kill … -sleep 20 watchdog still holds the old log, so Windows refuses the rename. It shows in the seed's second boot (#bootSeedTwice) as PROVISION_FAILED, and every copy's boot runs the same start. The port has no in-place write.
Simplest fix
Add writeFileInPlace(path, contents, { mode }) to the Filesystem port. Node: writeFile, then chmod, so an existing 0644 log ends at 0600. Memory: keep the entry and its identity. Call it at emulator.ts:251. Tried: the reproduction, src/drivers/android/ and src/ports/filesystem.test.ts pass (777 tests). The two Filesystem literals in src/auth/admin-secret.test.ts need the new key.
Alternatives rejected
Open stdio with "w" in NodeProcessRunner: keeps an old mode, and no unit test sees it.
Retry the rename past 20 s: slower boots, timing-dependent.
rm first: Windows leaves a delete-pending name.
Risk
src/drivers/android/adb-server.ts:288 empties its log the same way. Nothing I found holds it open, so it is left out.
The ports manual's Windows section could say why the in-place write exists.
Activity
V3RON commentedon Nov 17, 2026
Reproduction
Confirmed: on Windows a rename over a file another process holds open fails
EPERM, and emptying it in place works.EmulatorProcess.startreplaces the log instead of emptying it.Branch
bug/1662-reproextends the existing test insrc/drivers/android/index-boot.test.ts, now "sends the emulator's output to /emulator.log, mode 0600, emptied in place at each start". It said "truncated" but checked only contents and mode. It now also checks the file is the same one (stat().identity).Windows 11 host, Node v22.23.5, a child holding
emulator.logas stdout (opened"a", asNodeProcessRunnerdoes):Root cause
Defect.
src/drivers/android/emulator.ts:251empties the log withwriteFileAtomic, which renames a temp file over it (src/ports/filesystem.ts:262). The emulator's leftover-kill … -sleep 20watchdog still holds the old log, so Windows refuses the rename. It shows in the seed's second boot (#bootSeedTwice) asPROVISION_FAILED, and every copy's boot runs the samestart. The port has no in-place write.Simplest fix
Add
writeFileInPlace(path, contents, { mode })to theFilesystemport. Node:writeFile, thenchmod, so an existing 0644 log ends at 0600. Memory: keep the entry and its identity. Call it atemulator.ts:251. Tried: the reproduction,src/drivers/android/andsrc/ports/filesystem.test.tspass (777 tests). The twoFilesystemliterals insrc/auth/admin-secret.test.tsneed the new key.Alternatives rejected
"w"inNodeProcessRunner: keeps an old mode, and no unit test sees it.rmfirst: Windows leaves a delete-pending name.Risk
src/drivers/android/adb-server.ts:288empties its log the same way. Nothing I found holds it open, so it is left out.Fast track
Written by an agent.
docs(ports): drop the manual line that took the manuals over their si…
V3RON commentedon Nov 17, 2026
Delivery run
Merged: #1669 (#1662)
Parked: none
Waiting: none
Decided: none
Written by an agent.
fix(android): empty the emulator log in place (callstackincubator#1662)…