Skip to content

Android: on ext4 and NTFS every lease copies the whole seed, 3 to 5 GB #1750

Closed

Description

@V3RON

What happened

Every Android lease gets its own copy of its kind's seed AVD folder (ADR 0061), made by Filesystem.copyTree (src/ports/filesystem.ts:224-235):

Worker Copy Disk per lease
macOS, APFS cp -c -p -R (clone) only what the emulator writes
Linux, btrfs / XFS cp -a --reflink=auto (clone) only what the emulator writes
Linux, ext4 cp -a --reflink=auto falls back to a full copy without a word (ext4 has no reflink) the whole seed
Windows, NTFS Node fs.cp, always a full copy the whole seed

A seed is 2.7 GB (one kind on a macOS worker, du of sources/seed_*/simlock.avd) to ~4.8 GB (ADR 0061's measurement), most of it the boot snapshot's ram.bin (2.0 GB) and userdata-qemu.img.qcow2. So on ext4 and NTFS, the most common filesystems of Linux and Windows workers, each Android lease writes 3 to 5 GB before its emulator boots, and ten leases at once hold 30 to 50 GB. ADR 0061 names the cost ("elsewhere each Android copy is a full copy") but nothing bounds it.

What you expected

An Android lease on any supported worker costs about what its emulator writes, not a whole seed, or at least the worker knows the cost before it takes it: a lease is refused or waits when the copy would not fit, instead of filling the disk.

How to reproduce

  1. On a Linux worker with an ext4 root (or a Windows worker on NTFS), lease one Android emulator: simlock lease --platform android.
  2. Before and after the lease, read the free space of the volume holding drivers.android.deviceRoot (df -k <root>, or Get-PSDrive on Windows).
  3. Free space drops by the seed's size (du -sh <root>/sources/seed_*/simlock.avd), plus what the emulator writes.

Not yet run on an ext4 or NTFS worker: the numbers above come from reading copyTree and from a seed and a copy on a macOS worker.

Environment

Any Linux worker without reflink (ext4) or any Windows worker. Simlock at main fb42676.

Logs and evidence

  • src/ports/filesystem.ts:224-235: the three copyTree paths.
  • src/drivers/android/seeds.ts:696-714: #copyAvd copies the whole simlock.avd folder for every device.
  • ADR 0061, Consequences: "Copies are copy-on-write on APFS and on Linux filesystems with reflink; elsewhere each Android copy is a full copy."
  • ADR 0061, Alternatives: a copy under another AVD name loses the snapshot (~16 s cold boot), and a shared -read-only AVD breaks the ownership gate, so neither is a drop-in fix.

Found while specifying #1745.

Written by an agent.

Activity

  1. added
    bug:newReported. An agent may triage it (rule 8); the fast track may set it ready (rule 17).
    on Nov 19, 2026
  2. self-assigned this
    on Nov 19, 2026
  3. V3RON commented on Nov 19, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Gap. ADR 0061 accepts a full copy on ext4 and NTFS; making it cheap there is a decision (a superseding ADR; its Alternatives rule out both drop-ins). What is missing is a free-space check before the copy. The expectation is a proposal: refuse with InsufficientDiskSpaceError.

    src/drivers/android/seeds-copies.test.ts, "refuses a copy of the seed that does not fit in the device root's free space before copying, and copies one that fits exactly", on bug/1750-repro:

    pnpm exec vitest run --project unit src/drivers/android/seeds-copies.test.ts -t 'does not fit'
    AssertionError: promise resolved "{ address: '', …(2) }" instead of rejecting
      ❯ seeds-copies.test.ts:321  await expect(short.provision).rejects.toMatchObject({ ... requiredBytes: seedBytes })
    

    A 4,112-byte seed is copied into a root with 4,111 bytes free; the exact-fit case passes.

    Root cause

    src/drivers/android/seeds.ts:696-714 (#copyAvd) calls filesystem.copyTree with no free-space check; DiskSpaceGuard (src/core/driver.ts:761) serves only component installs (component-installer.ts:607). Today a copy that does not fit runs until cp hits ENOSPC, filling the volume for every other emulator, and is then removed (existing test "removes the device's folder and throws when copying the seed fails").

    Simplest fix

    Reserve the seed's simlock.avd size against the device root through a DiskSpaceGuard that Seeds owns, released when the copy ends; an unreadable size reserves 0, as today.

    const release = await this.#copySpace.reserve(this.#filesystem, "android",
      await this.#filesystem.directorySize(join(fromHome, `${SEED_AVD_NAME}.avd`)).catch(() => 0),
      this.#deviceRoot);
    try { /* mkdirp + copyTree as today */ } finally { release(); }

    Tried: reproduction passes; src/drivers/android/, src/leasing/, component-installer.test.ts green (1404 passed).

    Alternatives rejected

    • Wait in the queue instead: a new waiting reason, which is public.
    • Check only where the copy does not clone (--reflink=always first): a port change and a probe per OS.
    • Share the installer's guard: it lives in core; drivers never see it.

    Risk

    • On APFS and reflink a clone is free, yet this refuses below the seed's size (3–5 GB).
    • Through a lease it retries once, then shows PROVISION_FAILED with "to install a android component": the message and errors.mdx need rewording.
    • Baseline copies (#provisionFromSource) are checked too.

    Fast track

    • Defect: no — a gap; ADR 0061 accepts full copies
    • Fix tried: yes
    • Nothing public added or broken: no — refuses leases that clone on APFS/reflink
    • No ADR or rule changed: yes
    • One fix: no — wait-vs-refuse and clone-aware check change what users see

    Written by an agent.

  4. removed their assignment
    on Nov 19, 2026
  5. V3RON commented on Nov 20, 2026

    @V3RON
    ContributorAuthor

    Maintainer decision on the triage report (2026-11-20):

    Approved as proposed: reserve the seed's full size against the device root before every copy (seed and baseline copies) and refuse with InsufficientDiskSpaceError when it does not fit, on every filesystem. Accepted: a clone on APFS or reflink can be refused when less than the seed's size is free.

    Also reword the refusal: the PROVISION_FAILED message must not say "to install a android component" for a seed copy, and errors.mdx follows.

    Written by an agent.

  6. removed
    bug:newReported. An agent may triage it (rule 8); the fast track may set it ready (rule 17).
    on Nov 20, 2026
  7. self-assigned this
    on Nov 20, 2026
  8. V3RON commented on Nov 20, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1794 (#1750)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

  9. added a commit that references this issue on Nov 22, 2026
    c654a40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions