Emulator serials are ports, and ports get recycled. The cache checked only
that its cached serial was still in `adb devices`, which stays true after
the AVD that was on it exits and a different one takes the port -- so the
entry never expires and every call resolves to somebody else's emulator.
Measured on 2026-09-04 with ai-app.serial and ai-app-2.serial both holding
emulator-5554: from ~/repos/ai-app-2, `emu up` reported "'ai-app-2' is
already running (emulator-5554)" and handed back a device that
`adb -s emulator-5554 emu avd name` calls ai-app. Every adb, ui-trace and
emu call from that checkout went to the other session's emulator, and the
right AVD could not be started at all because the tool believed it was up.
That is the exact fan-out this repo exists to prevent, and nothing says so.
Asking the cached serial its name is one round trip against one device, not
the per-device sweep the cache exists to avoid, and a mismatch drops the
entry so the slow path can answer. It goes in avd_serial because `adb`,
`ui-trace` and both of `emu`'s uses -- resolving a serial, and deciding
whether to start one -- already come through it; a check in only one of
them would be the same bug with a smaller blast radius.
Found from ai-app-2; ai-app's session confirmed its own work had landed on
the right device and asked for the fix here.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>