Skip to content

iOS lease fails when a file its baseline recorded is missing from the copy #1790

Closed

Description

@V3RON

What happened

Follow-up to #1714 (fixed by #1786), raised by @maxlapides on #1714 and in #1785.

An iOS source (seed or baseline) records, in ios_source_files, the files and links that name its lineage. If a recorded entry is missing from a later copy, swapCopyFiles (src/drivers/ios/lineage-files.ts:24) throws ENOENT from stat/openFile/readlink, the copy is deleted, and the provision fails. Because the row stays, every lease of that source fails the same way until it is saved again.

A recorded path can go stale when a file the save walk found is renamed away afterwards, as CoreSimulator does with its atomic *.sb-* writes after simctl clone (#1714). A file that vanishes between the walk's lstat and its read is also recorded unreadable with a warning (classify, same file).

What you expected

A recorded file or link missing from a copy has nothing left to swap: the swap skips it and the lease goes on. A file that vanished before it was read is not recorded. Other errors still fail the copy (ADR 0076 §3).

How to reproduce

Unit level: seed ios_source_files with a file row whose path is absent in the copy, then provision — it fails with ENOENT and deletes the copy (today pinned by the "a recorded file gone" case in src/drivers/ios/index-seed-swap.test.ts).

Environment

main at 825608e. Measured on Xcode 27.2 / iOS 27.2: the real device.plist.sb-* holds only the clone's own UDID, so this path is not known to fire in practice today; the blast radius (every lease of a baseline) is the reason to fix it.

Logs and evidence

See #1714's comments and #1785's description.

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 20, 2026
  2. self-assigned this
    on Nov 20, 2026
  3. added a commit that references this issue on Nov 20, 2026
  4. V3RON commented on Nov 20, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Confirmed at 5b688e1ce: a recorded entry missing from a copy fails the provision and deletes the copy, and a file that vanishes after lstat is recorded unreadable with a warning. Branch bug/1790-repro has two tests. It also drops the "a recorded file gone" case, which pinned the old behaviour, and adds "a recorded link that cannot be read" (EACCES still fails, passes today).

    pnpm exec vitest run --project unit src/drivers/ios/index-seed-swap.test.ts src/drivers/ios/index-seed-record.test.ts
    
    × a copy whose source recorded a file and a link the copy does not have is kept, the provision succeeds and the entries still there are swapped
      index-seed-swap.test.ts:160  expect(outcome).toMatchObject({ lineage: [...] })
      + Error { "message": "ENOENT: no such file or directory, open '/Devices/CCCC…/data/GoneLogs'", "code": "ENOENT" }
    
    × a baseline is saved when a file in its clone is renamed away after the walk reaches it and before it is read, and that file is neither recorded nor warned about
      index-seed-record.test.ts:376  expect(recorded(saved.database)).toEqual([{ kind: "file", relative_path: "device.plist" }])
      + { "kind": "unreadable", "relative_path": "device.plist.sb-55c05b11-ISuHtw" }
    

    Root cause

    This is a defect. swapCopyFiles (src/drivers/ios/lineage-files.ts:31-52) calls readlink (:37) and eachWindow → stat (:176) / openFile (:190) on every recorded path and catches nothing. The ENOENT then reaches the catch in Seeds (src/drivers/ios/seeds.ts:246-250), which deletes the copy and fails the provision. The row stays, so every later copy of that source fails the same way. Separately, classify (:162-167) turns every read error into unreadable, ENOENT included, so a file renamed away after the walk's lstat leaves a stale row and a warning. The code already skips missing entries in two places: seeds.ts:520 for the dropped LaunchServices database, and visitFolder (:98-102, #1786) for a file gone before lstat.

    Simplest fix

    In swapCopyFiles, wrap each file or link swap in a try that skips isMissingPathError (ENOENT only) and counts it as missing. Add , N missing to the debug line at seeds.ts:525 and update the first test's expected log line. In classify, return undefined on ENOENT. Update the seeds line in src/drivers/ios/AGENTS.md.

    pnpm exec vitest run --project unit src/drivers/ios   → 34 files, 765 passed | 1 skipped
    pnpm typecheck                                        → clean
    

    Alternatives rejected

    • Skip without a counter: the debug log would no longer show that the record is stale.
    • Delete stale rows from ios_source_files on a miss: writes to the source from the copy path while other copies run at the same time.

    Risk

    • A copy that is really broken (its clone is incomplete) is now handed out, and only the debug count shows it.
    • Only ENOENT is skipped. ENOTDIR, EACCES and length changes still delete the copy.

    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 20, 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 20, 2026
  7. self-assigned this
    on Nov 20, 2026
  8. V3RON commented on Nov 20, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1793 (#1790), #1791 (revert of d7bd191, the #1790 reproduction pushed to main by mistake)
    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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions