Skip to content

Creating a new Android emulator makes every existing one wipe on its next reclaim #1048

Closed

Description

@Nabil372

What happened

After Simlock created another emulator, the existing emulator's next reclaim took the wipe path instead of loading its clean baseline, and its next lease took 61-76 s instead of seconds (on our build with local patches, where that rebuild also re-runs a setup program of ours). avdmanager (create avd, and also list avd) adds a hw.device.hash2=... line to the config.ini of every AVD in the home that lacks one. Simlock's AVDs lack one: for a library profile (the default Pixel 9 is one), #applyLibraryProfile replaces the seed device's hw. lines with the profile's, which leave hw.device.hash2 out. Simlock's config hash reads every hw. line of config.ini (#avdConfig, src/drivers/android/index.ts line 1880 on main at 7ac7f18), so that new line changes the hash of each existing AVD, which then no longer matches the hash stored with its baseline, and the reclaim wipes and rebuilds it.

What you expected

Creating a device leaves the other devices' clean baselines valid: a key that avdmanager adds and that changes nothing about the emulator's hardware is not part of the hash.

How to reproduce

  1. simlock daemon start with lease.identity.android at reusable and room for two emulators
  2. simlock lease --platform android (device A), release it, wait for the reclaim
  3. Lease A again, then from a second shell with a different SIMLOCK_AGENT_ID (one lease per requester by default) run simlock lease --platform android, so Simlock creates device B
  4. Release A: simlock events shows its reclaim with strategy: wipe, and config.ini of A now has a hw.device.hash2 line it did not have before step 3.

Seen in one run of ours.

Environment

Simlock 0.3.0 at commit 6316e10 (the Android driver is unchanged on main at 7ac7f18), Android only. macOS 27.0.1 on an M5 Max (128 GB), Android emulator 37.2.12, platform-tools 37.0.1, cmdline-tools 22.0 (avdmanager), image system-images;android-37.0;google_apis;arm64-v8a, default Pixel 9 profile. Seen on a build with our local patches; the hash code and avdmanager behaviour involved are unchanged from 6316e10. simlock doctor output was not captured at the time.

Logs and evidence

device.reclaimed events with strategy: wipe for the older device right after the new one was created, and its next lease at 61-76 s on our patched build. The older AVD's config.ini had gained a hw.device.hash2 line, and Simlock's config hash includes every hw. line. We have a tested change that leaves hw.device.hash2 out of the hash (other hw.device.* keys still count), as src/drivers/android/profiles/library.test.ts:35 already leaves it out of the library profiles' hardware keys; happy to open it as a PR if you want it.

Activity

  1. added
    bug:new
    on Oct 29, 2026
  2. self-assigned this
    on Oct 31, 2026
  3. V3RON commented on Oct 31, 2026

    @V3RON
    Contributor

    Reproduction

    Defect, confirmed as reported. Test on bug/1048-repro (e57ebd1), src/drivers/android/index.test.ts: "restores the clean baseline on a standard reclaim after a hw.device.hash2 line is added to config.ini". It captures a baseline, appends the line avdmanager adds, and reclaims.

    pnpm exec vitest run --project unit src/drivers/android/index.test.ts -t "hw.device.hash2"
    
    AssertionError: promise rejected "Error: Unexpected process invocation: /an…" instead of resolving
     ❯ src/drivers/android/index.test.ts:845:71
    Caused by: Error: Unexpected process invocation: /android-sdk/platform-tools/adb -s emulator-5586 emu kill
     ❯ AndroidDriver.#shutdown src/drivers/android/index.ts:2272:33
     ❯ src/drivers/android/index.ts:1125:9
    

    The emu kill is the stale-hash branch of reclaim (index.ts:1124), which returns shutdown / wipe.

    Root cause

    src/drivers/android/index.ts:1899 (#avdConfig) hashes every hw. line of config.ini, hw.device.hash2 included. The emulator ignores that key: it is not in the emulator's list of hardware properties (checked on this host, emulator 36.5.11). So the hash changes even though the snapshot would still load. A library profile drops the seed's hw.device.hash2 (isSeedHardwareLine, index.ts:2685, used at index.ts:1506). The next avdmanager create avd or list avd writes the line back into each such AVD. After that, reclaim (:1124) and makeReady (#baselineVerdict) see a stale hash and wipe the device.

    Simplest fix

    In #avdConfig, leave out lines starting with hw.device.hash2=. Other hw.device.* keys still count. With this change the whole file passes (300 passed).

    Alternatives rejected

    • Keep the seed's hw.device.hash2 in #applyLibraryProfile: it would hash the seed device, not the profile. It also leaves the hash open to the next key avdmanager adds.
    • Hash only the emulator's known hardware properties: right in principle, but much larger and tied to one emulator version.

    Risk

    • Upgrade: for AVDs whose config.ini already has hw.device.hash2 (SDK and devices.xml profiles get it at create), the hash changes once, so each one wipes once after the upgrade. The pinned hash in "keeps a clean baseline captured before android.emulator existed" won't catch this, because its fixture has no hash2 line.
    • The emulator's hardware list was checked on 36.5.11, not on the reporter's 37.2.12.

    Written by an agent.

  4. removed their assignment
    on Oct 31, 2026
  5. added
    bug:ready
    and removed
    bug:new
    on Oct 31, 2026
  6. self-assigned this
    on Oct 31, 2026
  7. V3RON commented on Oct 31, 2026

    @V3RON
    Contributor

    Decision

    Upgrade behaviour: an AVD whose config.ini already holds hw.device.hash2 (SDK and devices.xml profiles) gets a new config hash once after the upgrade, so its next reclaim wipes and rebuilds its clean baseline once. Accepted: no hash-version migration. Pinned by the existing hash tests and "restores the clean baseline on a standard reclaim after a hw.device.hash2 line is added to config.ini". (decided in delivery, pending the maintainer)

    Written by an agent.

  8. V3RON commented on Oct 31, 2026

    @V3RON
    Contributor

    Maintainer confirmed the decision above: the one-time wipe after the upgrade is accepted, with no hash-version migration. The fix shipped in #1147.

    Written by an agent.

  9. added a commit that references this issue on Oct 31, 2026
    3cc39b4
  10. V3RON commented on Nov 2, 2026

    @V3RON
    Contributor

    Follow-up: #327 (Named baselines, ADR 0061) removes the shared clean-baseline snapshot and its config-hash wipe. Each emulator is a copy of a source in its own AVD folder (task #1205), so creating one emulator can no longer invalidate another.

    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:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions