Skip to content

fix(Scripts): harden simulator ownership - #288

Open
kyleve wants to merge 6 commits into
codex/extract-xcode-script-pythonfrom
codex/harden-simulator-ownership
Open

fix(Scripts): harden simulator ownership#288
kyleve wants to merge 6 commits into
codex/extract-xcode-script-pythonfrom
codex/harden-simulator-ownership

Conversation

@kyleve

@kyleve kyleve commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Posted by an AI agent on kve's behalf.

Summary

  • make the per-checkout simulator registry the explicit ownership authority while keeping simctl authoritative for live state
  • validate checkout, UDID, device name, and exact runtime before deletion or prune
  • atomically persist private registry claims and refuse to transfer a stale claim to a same-named replacement
  • serialize resolve-or-create with macOS's kernel-backed lockf
  • add process-level concurrency and failure tests without touching CoreSimulator

Why

Name-derived devices are useful for discovery but are insufficient proof of ownership. A duplicate name on another runtime, stale claim, or concurrent first resolution must never authorize deletion or create twin devices.

Design decisions

  • shell retains xcrun simctl orchestration and live boot output
  • require-safe Ruby owns structured inventory/registry policy and atomic persistence
  • name-only matching may recover one unambiguous unclaimed device for use, but never authorizes deletion
  • /usr/bin/lockf owns concurrency; kernel release after process death eliminates stale owner files, PID reuse, and directory-takeover races
  • the persistent lock file carries no ownership state and is safe after interruption

Compatibility

Public flags, defaults, stdout/stderr conventions, and exit codes remain stable. Existing plain-text registry entries are validated and rewritten atomically.

Adversarial coverage

  • same names across runtimes, duplicates within one runtime, near-substring names, and stale/moved claims
  • malformed inventory/registry state and uninstalled runtimes
  • create/register/delete/registry-removal failures with visible child statuses
  • interrupted creation, abandoned lock files, and four concurrent first-time resolvers producing exactly one device
  • exact --delete/--recreate; mutation-free --prune --dry-run
  • mutations for substring matching, flattened runtimes, destructive dry-run, silent registry removal, and bypassed kernel locking are all killed

Testing

  • 35 retained Ruby tests / 323 assertions at this layer
  • 62 Python tests
  • ./simulator --no-boot and ./simulator --list against real CoreSimulator
  • ./test StuffCoreTests
  • full ShellCheck, formatting, attribution, and shard-plan gates

Stack

Third PR; based on #284.

Resolution.new(action: "create", udid: nil)
end

def deletion_target(name:, checkout:, device:, os:, runtime_key:, all:)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by an AI agent on kve's behalf.

Review focus: this is the destructive-operation boundary. A derived name is deliberately insufficient; deletion requires the registry entry plus exact checkout, device, OS, runtime, and UDID identity. A stale claim beside a same-named replacement is a refusal, not an ownership transfer.

@kyleve
kyleve force-pushed the codex/harden-simulator-ownership branch 2 times, most recently from 2e86799 to 55eab38 Compare August 19, 2026 02:58
@kyleve
kyleve force-pushed the codex/harden-simulator-ownership branch from 5c14c7b to db023c8 Compare August 19, 2026 03:22
@kyleve
kyleve force-pushed the codex/harden-simulator-ownership branch from db023c8 to 48de4de Compare August 19, 2026 03:49
@kyleve
kyleve force-pushed the codex/harden-simulator-ownership branch from 2c7657c to 0a3d86a Compare August 19, 2026 04:07
@kyleve
kyleve force-pushed the codex/harden-simulator-ownership branch 2 times, most recently from ab66b06 to c885558 Compare August 19, 2026 04:14
@kyleve
kyleve force-pushed the codex/harden-simulator-ownership branch from c885558 to 176709f Compare August 19, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant