Skip to content

A fresh Android lease fails PROVISION_FAILED on Windows: the seed's second boot cannot replace emulator.log #1662

Closed

Description

@V3RON

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.

Part of #1068.

Written by an agent.

Activity

  1. added this to the Windows support milestone on Nov 17, 2026
  2. added
    bug:newReported. An agent may triage it (rule 8); the fast track may set it ready (rule 17).
    on Nov 17, 2026
  3. assigned and unassigned on Nov 17, 2026
  4. V3RON commented on Nov 17, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    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.

    Fast track

    • Defect: yes
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: yes

    Written by an agent.

  5. removed their assignment
    on Nov 17, 2026
  6. added
    bug:readyAn agent may fix it.
    fast-trackBug set ready by the fast-track check, not the maintainer (rule 17).
    and removed
    bug:newReported. An agent may triage it (rule 8); the fast track may set it ready (rule 17).
    on Nov 17, 2026
  7. self-assigned this
    on Nov 17, 2026
  8. V3RON commented on Nov 17, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1669 (#1662)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:readyAn agent may fix it.fast-trackBug set ready by the fast-track check, not the maintainer (rule 17).

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions