Skip to content

iOS clone can skip its lineage swap when its seed is deleted between clone and swap #1731

Closed

Description

@V3RON

What happened

Found by reading the code, not seen on a device yet.

provision (src/drivers/ios/seeds.ts:214) clones the seed inside the seed's turn (:227-232), then leaves the turn. Only afterwards does it swap the clone's lineage files, reading the seed's file list from ios_source_files (#swapLineage, :508-516, filesOf(seed.sourceId)).

A seed can be deleted in between. Its deletion waits only for clones that are still inside the turn (takeToDelete, :320-321). Then deleteRow drops the seed's ios_source_files rows (src/drivers/ios/source-data.ts:170-175). The clone that already left the turn then reads an empty list, swaps no files, and is handed out still naming the seed's throwaway UDID in its files and links: the state ADR 0076 exists to prevent.

Paths that delete a ready seed while a clone may be between the two steps:

  • a stale seed remade by another provision of the same kind (#findOrMakeSeed → #destroySeed, :324-329, :458-461), for example after a runtime build change;
  • destroySource (:197-212);
  • destroySeedsOf on runtime removal (:559-573).

What you expected

A clone's lineage swap uses the file list of the seed it was cloned from, whatever happens to that seed afterwards.

How to reproduce

  1. Provision a kind so its seed exists.
  2. Start a provision of that kind and hold it after the clone returns, before #swapLineage.
  3. Destroy the seed (stale remake or destroySource) and let it finish.
  4. Let the provision go on: the swap reads no files, and the device is returned with its lineage files unswapped.

A unit test with a fake simctl and a gate after createSimulator should show it.

Environment

main at 6729e67, iOS driver, both device sets.

Logs and evidence

The swap's debug line would read swapped 0 files and 0 links for a seed that recorded files. Surfaced while designing background seed settling (#1540), which would replace seeds routinely and widen the window.

Written by an agent.

Activity

  1. added
    bug:new
    on Nov 18, 2026
  2. self-assigned this
    on Nov 19, 2026
  3. V3RON commented on Nov 19, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Confirmed as reported. src/drivers/ios/index-seed-swap.test.ts, "a copy swaps every file and link its seed recorded even when the seed is destroyed between the clone and the swap", on bug/1731-repro. The test holds the provision after the clone returns, at the LaunchServices folder check, then runs destroySource on the seed to the end and lets the provision go on. The seed recorded two files and one link, and the test asserts all three.

    pnpm exec vitest run --project unit src/drivers/ios/index-seed-swap.test.ts
    
    AssertionError: first: expected '/Devices/AAAAAAAA-1111-2222-3333-BBBB…' to be '/Devices/CCCCCCCC-4444-5555-6666-DDDD…'
     ❯ src/drivers/ios/index-seed-swap.test.ts:259:38
    

    Root cause

    Defect. The bug is in src/drivers/ios/seeds.ts:514-515 (#swapLineage, reached from :242). It reads this.#sources.filesOf(sourceId) after the clone's turn (:227-232) has ended. A seed's deletion waits only for turns that are still open (#deleteSeedInTurn, :320-321, then deleteRow at :211, :460 or :565). So the file rows can be gone by the time the swap reads them. The swap then gets an empty list and returns a device whose files still name the seed's lineage. Nothing fails until that device boots.

    Simplest fix

    Read the file list inside the clone's turn and pass it to #swapLineage:

    const { files, result } = await this.#seedTurns.take(seed.udid, async () => ({
      files: this.#sources.filesOf(seed.sourceId),
      result: await this.#simctl.createSimulator([...], {...}),
    }));
    ...
    if (seed.lineage !== undefined) await this.#swapLineage(files, seed.lineage, udid);

    #swapLineage(files: readonly SourceFile[], ...) then filters files instead of calling filesOf. I tried it (21 lines in seeds.ts):

    pnpm exec vitest run --project unit src/drivers/ios/index-seed-{swap,sources,provision,record,throwaway}.test.ts src/drivers/ios/index-save-source-lifecycle.test.ts
     Test Files  6 passed (6)
          Tests  73 passed (73)
    pnpm typecheck   # clean
    

    Alternatives rejected

    • Keep the turn open through the swap: clones of one seed would then swap one at a time, which slows parallel provisions.
    • Read the files together with the seed row (ReadySeed.files): this works too, but it changes findReadySeed, #namedSource and #makeSeed for the same result.
    • Delete a seed's file rows only after the last clone is done: this needs per-clone counting for a list that is never used after the clone.

    Risk

    Fast track

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

    Side findings

    Written by an agent.

  4. removed their assignment
    on Nov 19, 2026
  5. added
    bug:ready
    fast-track
    and removed
    bug:new
    on Nov 19, 2026
  6. self-assigned this
    on Nov 19, 2026
  7. added a commit that references this issue on Nov 19, 2026
    66d8e73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:readyfast-track

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions