Skip to content

simlock component remove removes a component Simlock installed #221

Closed

Description

@V3RON

Part of #213.

Scope

After this PR an operator removes a component Simlock installed: simlock component remove ios 26.4 or simlock component remove android 35, with --dry-run to see what would go. Simlock removes only what it has a record of installing and what no device uses. The same operation is on the admin client and over HTTP.

On iOS the runtime is unregistered with simctl runtime delete. If its download stays behind in the macOS asset store (#79), the result says so.

Technical spec

File and line references are to main at 88c4eeb.

Modules touched

  • src/core/driver.ts: Driver.removeComponent(receipt, { signal }) returns { sizeBytes?, residue? }. The driver:
    1. finds the installed component whose receipt equals the one given, and throws ComponentNotOwnedError when there is none;
    2. throws ComponentInUseError when foreignDevices for it is above zero;
    3. removes it, bounded by a five-minute timeout;
    4. reads the installed components again and fails when it is still there.
      residue is a sentence for the operator when something stays on disk.
  • src/drivers/ios/index.ts: simctl runtime delete <image>, without --keep-asset. Afterwards look for the build in the asset store (#downloadedRuntimeAssets, :1318); when it is still there, residue says the download remains and names Xcode's Settings, Platforms as the way to reclaim it. simlock simctl runtime delete stays refused (:1439); its message points at simlock component remove.
  • src/drivers/android/index.ts: sdkmanager --uninstall <package>.
  • src/core/component-installer.ts: remove({ platform, version, dryRun, requesterId }).
    1. Find the registry's component record for the platform and version. None: ComponentNotOwnedError.
    2. Find it in list(). Not marked as Simlock's: ComponentNotOwnedError.
    3. devices or foreignDevices above zero: ComponentInUseError with both counts.
    4. An install running or waiting on that platform: ComponentBusyError.
    5. dryRun: answer { outcome: "would-remove", sizeBytes? } and stop. Every check a removal makes has run by now.
    6. Take the platform's turn, so an install that arrives waits behind the removal.
    7. Inside the serialized decision gate (decisions.run): count the devices again and mark the platform and version as being removed. From then until the removal settles, no device record is created for that platform and version, on any path: lease, warm pool, or startup convergence. A request that resolved to it is rejected with RUNTIME_MISSING.
    8. Call removeComponent. On success delete the record, clear the mark, emit component.removed, answer { outcome: "removed", sizeBytes?, residue? }. On failure clear the mark, keep the record, and rethrow.
  • src/core/registry.ts: deleteComponent(platform, version).
  • src/contract/operations.ts: component.remove, role: "admin". Input { platform, version, dryRun? }. Output { platform, version, outcome: "removed" | "would-remove", sizeBytes?, residue? }.
  • src/contract/errors.ts, src/daemon/error-code.ts: COMPONENT_NOT_OWNED (CLI exit 12, HTTP 409), COMPONENT_IN_USE with details { devices, foreignDevices } (exit 12, HTTP 409), COMPONENT_BUSY (exit 11, HTTP 409).
  • src/bus/index.ts: component.removed.
  • src/daemon/dispatcher.ts: the handler, with requesterId: session.principal. src/gateway/dispatcher.ts: UNSUPPORTED_IN_GATEWAY_MODE.
  • src/simlock-client/client.ts, types.ts: SimlockAdminClient.removeComponent(input).
  • src/cli/index.ts: component remove <platform> <version> [--dry-run] [--yes]. Without --dry-run it confirms or requires --yes, exactly as release --all does (:1220). One JSON line on stdout.
  • src/http/app.ts: DELETE /v1/components/{platform}/{version}, ?dryRun=true for the dry run. A JSON answer, no stream.
  • src/core/fake-driver.ts, e2e/fake-driver/fake-driver.ts: removeComponent, scriptable to fail and to leave residue.
  • docs/internal/agent-rules/safety.md rule 1: a component is removed only through its record, and never while any device uses it, Simlock's or not; a driver may read, never write, the platform's default device locations to count them.
  • Docs: docs/CLI.md (the command, the three codes, the runtime delete bullet), docs/HTTP-API.md, docs/CLIENT.md, docs/EVENTS.md and docs/internal/EVENTS.md, docs/internal/KNOWN-PITFALLS.md (iOS on-demand runtime downloads never actually free disk space (mobileassetd cache outlives simctl runtime delete) #79: what component remove reports; new entry: a second Simlock instance on the same machine is not counted as a user of a component, and a foreign device created after the driver's last count is not seen), docs/internal/ARCHITECTURE.md.

Contract and event changes

  • New operation component.remove. Three new error codes. No protocol change.
  • New event component.removed: platform, componentId, version, sizeBytes when known, residue when there is one, requesterId. Emitted by the installer after the record is deleted. Both EVENTS.md files gain the row.

Rules in play

  • ADR 0010 §5 and §8.
  • safety.md rule 1 (rewritten here), rule 2 (a leased device counts as a user, so its component is never removed), rule 5 (confirm or --yes; the dry run), rule 6 (the event names who asked), rule 8 (the record and the receipt, never a name).
  • architecture.md rule 5 (the removal is a direct call chain), rule 7 (the destructive step is a driver verb the core invokes), rule 10 (the "in use" answer comes from list(), the same place the listing gets it), rule 12 (the removing mark is cleared on every exit, including a throw).
  • events.md rules 1, 3, 6 and 8.
  • testing.md rules 1 to 4.

Tests

  • A component with a record and no users is removed, its record is deleted, and component.list no longer shows it.
  • A component with no record fails with COMPONENT_NOT_OWNED and removeComponent is never called.
  • A record whose receipt no longer matches what is installed fails with COMPONENT_NOT_OWNED and removeComponent is never called.
  • A component a registry device uses fails with COMPONENT_IN_USE naming the count, whatever the device's state, leased included.
  • A component a foreign device uses fails with COMPONENT_IN_USE naming the count.
  • A dry run answers would-remove with the size, calls no driver verb that changes anything, and leaves the record.
  • A dry run while an install is running on that platform fails with COMPONENT_BUSY, as the removal would.
  • A removal while an install is running on that platform fails with COMPONENT_BUSY.
  • An install that arrives during a removal starts only after the removal has ended.
  • A lease request that resolves to the version being removed is rejected with RUNTIME_MISSING, and no device record is created.
  • Warm-pool provisioning creates no device for a version being removed.
  • A removal the driver fails keeps the record, clears the mark, and emits no component.removed.
  • component.removed carries the admin principal as requesterId.
  • The iOS driver runs simctl runtime delete with the image identifier from the receipt and no --keep-asset.
  • The iOS driver reports residue when the build is still in the asset store afterwards, and none when it is gone.
  • The iOS driver refuses when a device in the default device set uses the runtime, and deletes nothing.
  • The Android driver runs sdkmanager --uninstall with the package from the receipt.
  • The Android driver refuses when an AVD in the user's AVD home names the image.
  • An agent session gets FORBIDDEN.
  • The CLI refuses without --yes when it cannot confirm, and does not ask under --dry-run.
  • On a gateway the operation answers UNSUPPORTED_IN_GATEWAY_MODE.

Done when

  • On real hardware: an Android image installed with simlock component install is removed, and its directory is gone. Ask the maintainer before running this.
  • On real hardware: an iOS runtime installed with simlock component install is removed and no longer in simlock catalog. Record in the PR whether its download left the asset store and whether the result carried residue. Ask the maintainer before running this.
  • e2e with the fake driver covers remove, dry run, not owned, in use, and the agent refusal.
  • pnpm check is green.

Out of scope

  • Removing on its own: no cleanup rule, idle tier or disk-pressure reaction removes a component.
  • Deleting a file in the macOS asset store. Simlock asks simctl to delete the runtime and reports what simctl left behind.
  • Removing through a gateway.
  • A force flag.

Depends on

Approval

  • Approved for delivery

Written by an agent.

Activity

  1. added
    task:draft
    on Oct 2, 2026
  2. V3RON commented on Oct 2, 2026

    @V3RON
    ContributorAuthor

    Spec updated: Technical spec makes the dry run do every check, and records two accepted gaps in KNOWN-PITFALLS.

    Written by an agent.

  3. added
    task:ready
    and removed
    task:draft
    on Oct 2, 2026
  4. github-actions commented on Oct 2, 2026

    @github-actions
    Contributor

    Now task:ready: approved, technical spec present, #220, #216 closed.

  5. self-assigned this
    on Oct 2, 2026
  6. added 2 commits that reference this issue on Oct 2, 2026
    a56ff51
    b3e59a9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

task:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions