Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -1388,9 +1388,11 @@ Entries are ordered by platform, then version, then variant.
have not been deleted. Simlock does not track which variant a device uses,
so two variants of one version show the same count.
- `foreignDevices` counts the devices outside Simlock that use the
component: simulators in Xcode's default device set, or AVDs in your own
AVD home (`ANDROID_AVD_HOME`, or `~/.android/avd`). Simlock only reads
them.
component. On iOS that is the simulators in Xcode's default device set
that have been booted at least once; macOS creates a set of simulators for
every runtime it installs, and those do not count until someone uses one.
On Android it is every AVD in your own AVD home (`ANDROID_AVD_HOME`, or
`~/.android/avd`). Simlock only reads them.

A platform whose tools cannot answer is left out, and the other platform is
still listed. A gateway answers `UNSUPPORTED_IN_GATEWAY_MODE`; run the
Expand Down Expand Up @@ -1434,26 +1436,33 @@ every one of them and removes nothing.
way, is never removed, and there is no flag to force it.
- **No device uses it.** None of Simlock's own devices of that platform and
version, in any state, leased ones included, and none of yours: a
simulator in Xcode's default device set or an AVD in your own AVD home,
booted or not. Otherwise it fails with `COMPONENT_IN_USE` (exit 12), and
the error says how many of each use it. Delete those devices first.
simulator in Xcode's default device set that has been booted at least
once, running now or not, or any AVD in your own AVD home. Otherwise it
fails with `COMPONENT_IN_USE` (exit 12), and the error says how many of
each use it. Delete those devices first. Simulators in the default device
set that were never booted do not block a removal.
- **Nothing else is installing or removing on that platform.** Otherwise it
fails with `COMPONENT_BUSY` (exit 11). Run it again once that ends. A
`component install` or lease download that arrives while a removal runs
waits for it, and no new Simlock device is created on the component being
removed: a lease request for it fails with `RUNTIME_MISSING`.

An iOS runtime is removed with `simctl runtime delete`. macOS can keep the
runtime's download in its own asset store afterwards. When it does, the
result carries `residue`, a sentence that says so and how to get the space
back: remove the platform in Xcode's Settings, under Platforms. Simlock never
deletes files there itself. An Android image is removed with
`sdkmanager --uninstall`.
An iOS runtime is removed with `simctl runtime delete`. Two things can stay
behind, and the result's `residue` names each one that did:

- The never-booted simulators of that runtime in Xcode's default device set.
They become unavailable, and Simlock does not delete them. `residue` says
how many there are; `xcrun simctl delete unavailable` clears them.
- The runtime's download in macOS's own asset store. `residue` says so and
how to get the space back: remove the platform in Xcode's Settings, under
Platforms. Simlock never deletes files there itself.

```text
{"platform":"ios","version":"26.4","outcome":"removed","sizeBytes":9103456789,"residue":"The download of iOS 26.4 (23E244) ..."}
{"platform":"ios","version":"26.4","outcome":"removed","sizeBytes":9103456789,"residue":"11 never-used simulators in the default device set are now unavailable; ... The download of iOS 26.4 (23E244) ..."}
```

An Android image is removed with `sdkmanager --uninstall`.

Every removal emits `component.removed`, naming the component and who asked;
see [EVENTS.md](EVENTS.md#components). Nothing removes a component on its
own: no cleanup rule, idle timer or low-disk reaction does. Stopping the
Expand Down
18 changes: 12 additions & 6 deletions docs/CLIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ const { components } = await client.listComponents({ platform: "android" });
- `devices` counts Simlock's own devices of this platform and version that
have not been deleted; two variants of one version show the same count.
`foreignDevices` counts the devices outside Simlock that use the
component: simulators in Xcode's default device set, AVDs in the user's
own AVD home.
component: simulators in Xcode's default device set that have been booted
at least once, and every AVD in the user's own AVD home. The simulators
macOS creates by itself for each runtime it installs do not count until
someone boots one.
- A gateway rejects it with `UNSUPPORTED_IN_GATEWAY_MODE`.

## Removing a runtime: `removeComponent`
Expand All @@ -398,13 +400,17 @@ const result = await admin.removeComponent({ platform: "ios", version: "26.4" })
- `outcome` is `removed`, or `would-remove` for a dry run. `sizeBytes` is
absent when it could not be read. The catalog stops listing the component
at once.
- `residue`, when present, says what stayed on disk and how to reclaim it:
on iOS, macOS can keep the runtime's download in its asset store, which
Xcode's Settings, under Platforms, removes.
- `residue`, when present, says what stayed behind and how to reclaim it.
On iOS that can be the runtime's never-booted simulators in Xcode's
default device set, now unavailable, which `xcrun simctl delete
unavailable` clears, and the runtime's download in macOS's asset store,
which Xcode's Settings, under Platforms, removes. Simlock deletes
neither.
- It rejects, removing nothing, with `COMPONENT_NOT_OWNED` when Simlock did
not install the component or it changed on disk since,
`COMPONENT_IN_USE` when a device uses it, Simlock's or not (`details`
carries `devices` and `foreignDevices`), and `COMPONENT_BUSY` while an
carries `devices` and `foreignDevices`; a never-booted simulator in the
default device set does not count), and `COMPONENT_BUSY` while an
install or removal runs or waits on that platform. Other rejections:
`FORBIDDEN` for an agent session, `NO_DRIVER`, and
`UNSUPPORTED_IN_GATEWAY_MODE` from a gateway.
Expand Down
16 changes: 11 additions & 5 deletions docs/HTTP-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,9 @@ still the same one on disk, and `installedAt` is when it did. `devices`
counts Simlock's own devices of this platform and version that have not been
deleted; two variants of one version show the same count. `foreignDevices`
counts the devices outside Simlock that use the component: simulators in
Xcode's default device set, AVDs in the user's own AVD home.
Xcode's default device set that have been booted at least once, and every
AVD in the user's own AVD home. The simulators macOS creates by itself for
each runtime it installs do not count until someone boots one.

A platform whose tools cannot answer is left out. `400 BAD_REQUEST` for a
`platform` other than `ios` or `android`; `501 UNSUPPORTED_IN_GATEWAY_MODE`
Expand All @@ -855,9 +857,12 @@ The answer is one JSON body, not a stream:

`outcome` is `removed`, or `would-remove` for a dry run. `sizeBytes` is the
disk the component took, left out when it could not be read. `residue`
appears when something stayed on disk after the removal: on iOS, macOS can
keep the runtime's download in its own asset store, and `residue` says so and
how to reclaim it (remove the platform in Xcode's Settings, under Platforms).
appears when something stayed behind after the removal, and names each
thing. On iOS that is the runtime's never-booted simulators in Xcode's
default device set, which become unavailable (`residue` says how many, and
that `xcrun simctl delete unavailable` clears them), and the runtime's
download when macOS keeps it in its own asset store (remove the platform in
Xcode's Settings, under Platforms). Simlock deletes neither.
A removed component leaves `GET /v1/catalog` and `GET /v1/components` at once,
and the removal is reported as a `component.removed` event naming who asked.

Expand All @@ -869,7 +874,8 @@ platform. Each refusal removes nothing:
disk since. There is no way to force it.
- `409 COMPONENT_IN_USE` — a device uses it: one of Simlock's, in any state,
leased ones included, or one outside Simlock (a simulator in Xcode's
default device set, an AVD in the user's own AVD home). The body carries
default device set that has been booted at least once, an AVD in the
user's own AVD home). Never-booted simulators do not block it. The body carries
`devices` and `foreignDevices`, how many of each.
- `409 COMPONENT_BUSY` — an install or removal runs or waits on that
platform; try again once it ends.
Expand Down
11 changes: 9 additions & 2 deletions docs/internal/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,10 @@ read-only, never downloads, and every process it starts is bounded, like
`listCatalog`. iOS reads `simctl runtime list -j` (iOS images only) and
counts devices per runtime in the default device set with an unscoped
`simctl list -j devices`, the one unscoped call besides the pre-root path's.
One function, `devicesPerRuntime`, decides which of them count for the
listing and the removal alike: only a device whose entry carries
`lastUsedAt`, so the never-used simulators macOS creates for every installed
runtime do not block a removal (#241).
Android reads the installed images, sizes each directory with
`Filesystem.directorySize`, and counts AVDs in the user's own AVD home whose
`config.ini` names the image's directory. On both platforms a foreign-device
Expand Down Expand Up @@ -1573,8 +1577,11 @@ steps run through `runBoundedProcess` (`src/drivers/installer-process.ts`),
which ends the process `SIGTERM` then `SIGKILL` and answers only once it has
exited. iOS runs `simctl --set <root> runtime delete <image>` without
`--keep-asset` (the `--set` from `#scopedSimctlArgv`, like every scoped call),
then reads the asset store (#79) and reports `residue` when the build's
download is still there; `simlock simctl runtime delete` stays refused and
then reports `residue`: how many never-used default-set simulators of the
runtime, counted in the listing taken before the delete, are now unavailable
(Simlock deletes none of them; `xcrun simctl delete unavailable` does), and,
after reading the asset store (#79), that the build's download is still
there, each when it applies; `simlock simctl runtime delete` stays refused and
points at `simlock component remove`. Android runs
`sdkmanager --uninstall <package>`. A second
Simlock instance's devices and a foreign device created after the driver's
Expand Down
5 changes: 3 additions & 2 deletions docs/internal/EVENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ emits it after the driver's `removeComponent` returned and the component record
from the registry (events rule 3); a dry run, a refusal (`COMPONENT_NOT_OWNED`,
`COMPONENT_IN_USE`, `COMPONENT_BUSY`) and a driver failure emit nothing, and a failure keeps the
record. `requesterId` is the admin session's principal, never a caller-supplied id (safety rule
6). `residue` is the driver's sentence, carried unread: on iOS it names the asset-store download
`simctl runtime delete` left behind (#79).
6). `residue` is the driver's text, carried unread: on iOS it names the never-used default-set
simulators the removal left unavailable and the asset-store download `simctl runtime delete`
left behind (#79), each when there is one.

## System

Expand Down
32 changes: 25 additions & 7 deletions docs/internal/KNOWN-PITFALLS.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ build, its version) is still there, the result and `component.removed` carry
way to reclaim it. The removal itself succeeded either way, and Simlock still
never deletes a file in the store (ADR 0010 §8).

**Measured:** on Xcode 26.4.1 (macOS 26.6.1), on 2026-10-02, `simctl runtime
delete` of the iOS 18.6 runtime, without `--keep-asset`, unregistered it — it
left `simctl runtime list` — and left its download in the store: the 8.9 GB
asset was still there two minutes after the delete. So `residue` is the
expected result of an iOS removal on that Xcode, not an edge case.

**The knob:** `downloads.policy` decides whether the host downloads runtimes
at all; short of that, the reclaim is manual and periodic, driven by what
`doctor` and `component remove` report.
Expand All @@ -373,10 +379,18 @@ at all; short of that, the reclaim is manual and periodic, driven by what
`simlock component remove` refuses while a device uses the component: every
device in this instance's registry, in any state but `deleted` (and every
device being provisioned that has no record yet), plus the devices the driver
counts outside Simlock — simulators in the machine's default device set,
AVDs in the user's own AVD home.
counts outside Simlock — simulators in the machine's default device set
that have been used at least once, AVDs in the user's own AVD home.

**The pitfall:** three kinds of device are not counted.

**The pitfall:** two kinds of device are not counted.
- A **never-used simulator in the default device set** — one with no
`lastUsedAt` in `simctl list -j devices`. macOS creates about eleven of
them for every runtime it installs, so counting them would make every
runtime unremovable (#241). A simulator the user created by hand and has
not booted yet looks the same and is not counted either. The removal makes
it unavailable; Simlock does not delete it, and `residue` says how many
there are and that `xcrun simctl delete unavailable` clears them.

- A **second Simlock instance** on the same machine keeps its devices in its
own root, which this instance cannot see and must not read. Removing a
Expand All @@ -386,13 +400,17 @@ AVDs in the user's own AVD home.
once in the removal's checks and once more in the driver, just before the
platform's own removal. A simulator or AVD the user creates between that
count and the end of `simctl runtime delete` / `sdkmanager --uninstall` is
not seen. A new *Simlock* device cannot slip in the same way: the removal
not seen, and neither is a never-used simulator the user boots for the
first time in that window. A new *Simlock* device cannot slip in the same way: the removal
marks the component inside the decision gate, and `DeviceProvisioner`
refuses every device on a marked component until the removal settles.

**Why it is accepted:** both need knowledge Simlock does not have without
reaching outside what it owns. The ADR accepts them (Consequences, and §8's
"a foreign device created after the driver's last count is not seen"), and
**Why it is accepted:** the second and third need knowledge Simlock does not
have without reaching outside what it owns, and the first is the only rule
under which a runtime Simlock installed can be removed at all; a never-used
simulator holds no user data, and becoming unavailable loses nothing. The ADR
accepts them (Consequences, and §8's rule on unused simulators and "a
foreign device created after the driver's last count is not seen"), and
removal is never automatic: an operator runs it, after reading
`simlock component list`.

Expand Down
21 changes: 18 additions & 3 deletions docs/internal/adr/0010-components-have-one-owner-in-the-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
`--allow-download` does nothing through a gateway "until the downloads
feature is specified" becomes permanent (§7). Changes safety rules 1 and
4; each changes in the task that makes its new text true (§4, §8).
- **Amended:** §8 by
[#241](https://github.com/callstackincubator/simlock/issues/241), before
it was implemented, on the maintainer's decision: a foreign device counts
as a user when the driver says it is one, and never-used iOS simulators do
not.
- **Depends on:** ADR 0003 (the contract), ADR 0005 (the gateway), ADR 0008
(the catalog).

Expand Down Expand Up @@ -212,12 +217,22 @@ Counting foreign devices is the only place a driver looks at devices that
are not Simlock's: the platform's default device set on iOS, the user's own
AVD home on Android. It reads them and never writes there.

A foreign device counts as a user when the driver says it is one. On Android
that is every AVD in the user's AVD home. On iOS it is a simulator in the
default set that has been used at least once: when a runtime install ends,
macOS creates a batch of unused simulators for it by itself, and counting
them would make every runtime Simlock installs unremovable ([#241](https://github.com/callstackincubator/simlock/issues/241)).
One driver function decides this for the listing and the removal alike.
The unused simulators are left in place: removing the runtime makes them
unavailable, and the result reports how many there are and how to clear
them. Simlock deletes none of them.

`component.remove` is an admin operation. It removes a component only when
all of these hold:

- it is Simlock's (§5);
- no device Simlock can see uses it: none of its own in any state but
`deleted`, and no foreign one, booted or not;
`deleted`, and no foreign one the driver counts as a user, running or not;
- no install is running or waiting on that platform.

The check and the removal cannot be split by a new Simlock device. The installer
Expand All @@ -228,8 +243,8 @@ device created after the driver's last count is not seen.

The driver gains `removeComponent(receipt)`. It proves the receipt again,
counts foreign devices again, removes, and verifies. When something stays on
disk it says so: an iOS runtime's download can outlive `simctl runtime
delete` (#79). Simlock asks `simctl` to delete the runtime and reports what
disk it says so: an iOS runtime's unused simulators, now unavailable, and its
download, which can outlive `simctl runtime delete` (#79). Simlock asks `simctl` to delete the runtime and reports what
`simctl` left; it never deletes a file in the macOS asset store itself.

A dry run does every check a removal does and removes nothing. The CLI confirms or requires
Expand Down
16 changes: 10 additions & 6 deletions docs/internal/agent-rules/safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ never enforce them only inside an individual rule or driver.
admin's explicit `component.remove`, and only when a component record's
receipt equals the receipt of what is installed now
([ADR 0010](../adr/0010-components-have-one-owner-in-the-core.md) §5, §8).
It is never removed while any device uses it, Simlock's own in any state
but `deleted` or a foreign one, booted or not; and nothing removes one on
its own — no cleanup rule, idle tier or disk-pressure reaction. To count
foreign devices a driver may read the platform's default device locations
(the machine's default simulator set, the user's own AVD home), and never
writes there. Simlock never deletes a file in the macOS asset store: it
It is never removed while any device uses it: Simlock's own in any state
but `deleted`, or a foreign one the driver counts as a user, running or
not. On iOS a foreign user is a simulator that has been used at least
once, because macOS creates unused ones by itself for every installed
runtime; on Android every AVD in the user's AVD home is one. Unused
simulators are left in place, and the removal reports them. Nothing
removes a component on its own — no cleanup rule, idle tier or
disk-pressure reaction. To count foreign devices a driver may read the
platform's default device locations (the machine's default simulator set,
the user's own AVD home), and never writes there. Simlock never deletes a file in the macOS asset store: it
asks `simctl` to delete the runtime and reports what `simctl` left.

There is exactly one exception, and it is opt-in: `doctor --purge-orphans`
Expand Down
8 changes: 5 additions & 3 deletions src/core/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ export interface InstalledComponent {
* `findComponent` and `installComponent` use, so a listed component and the record of its install
* compare equal with `sameReceipt`. `variant` is the driver's own words for what tells two
* components of one version apart, carried unread. `sizeBytes` is absent when the driver could
* not read it. `foreignDevices` counts the devices outside Simlock's root that use it.
* not read it. `foreignDevices` is the number of devices outside Simlock's root that count as
* users of it; the driver decides what counts as a user, and a removal is refused while it is
* above zero.
*/
export interface DriverComponent extends InstalledComponent {
readonly variant?: string;
Expand All @@ -543,8 +545,8 @@ export interface ComponentInstallResult extends InstalledComponent {

/**
* What one `removeComponent` freed and left. `sizeBytes` is the component's size as listed just
* before it was removed, absent when the driver could not read it. `residue` is a sentence for
* the operator when something stays on disk after the removal, and how to reclaim it.
* before it was removed, absent when the driver could not read it. `residue` is one sentence or
* more for the operator when something stays on disk after the removal, and how to reclaim it.
*/
export interface ComponentRemoval {
readonly sizeBytes?: number;
Expand Down
Loading
Loading