Skip to content
147 changes: 147 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,152 @@
# Changelog

## Unreleased

ADR 0004 (`docs/adr/0004-ttl-first-leases-on-every-transport.md`): there is
now one kind of lease, on every transport. A lease carries a TTL, and the
only thing that keeps it alive is a client-initiated `lease.renew` arriving
before the deadline — on the unix socket, over HTTP, over MCP, and through a
gateway alike. Held mode is gone as a daemon concept; staying alive to renew
and releasing on exit is now the CLI's and the MCP session's own policy over
an ordinary lease. This is a breaking release for the contract, three config
keys, and one user-visible behaviour; see below.

ADR 0004 is **Accepted — not yet implemented**: the entries in this section
describe the decided end state, and they land with the PRs that implement it
(the client's renew timers, and the daemon's heartbeat removal, config
rename, and protocol bump).

### ⚠ BREAKING CHANGES

- **Contract:** `lease.heartbeat` is removed as an operation, and `heartbeat`
is removed as a `hello` capability. The daemon never pushes to a client to
prove liveness any more; nothing replaces it, because `lease.renew` already
did the job on every transport that has one.
- **`mode` leaves the contract.** `lease.request` no longer accepts it, and the
lease record no longer carries it. `ttlMs` is now accepted on **every**
`lease.request` — supplying it used to be `BAD_REQUEST` for a held lease —
and is capped at `lease.maxTtlMs`, above which a request or a renew is
`BAD_REQUEST` rather than silently clamped. A caller reading `lease.mode` off
a grant now reads `undefined`, which is falsy, not an error; there is nothing
to branch on any more.
- **A body-less renew re-applies the lease's own TTL, not
`lease.defaultTtlMs`.** The lease record stores the `ttlMs` it was granted
with (or last renewed with, when a renew carried one), and `lease.renew`
without a `ttlMs` resets the deadline to now + that width.
`lease.defaultTtlMs` now applies in exactly one place: a `lease.request` that
names no `ttlMs`. A caller that relied on renew snapping every lease back to
the 15-minute default will find a four-hour lease staying four hours wide.
- **`lastRenewedAt` replaces `lastHeartbeatAt` — as a new stored field, not a
rename.** `lastHeartbeatAt` was never persisted: the dispatcher derived it as
`ttlDeadline - heldTtlBackstopMs`, which only worked because every held lease
shared one backstop width. With per-lease TTLs that arithmetic has no answer,
so the daemon now writes `lastRenewedAt` onto the lease record at grant and
on every renew, and `simlock status` renders it as "last renewed". A consumer
reading `lastHeartbeatAt` gets `undefined`.
- **Socket protocol:** moves to protocol 4 with no compatibility shim; the
range a daemon and client advertise is `{min: 4, max: 4}`. A
version-mismatched client fails `hello` with `PROTOCOL_VERSION_UNSUPPORTED`
and never restarts the daemon — run `simlock daemon stop` once it's idle.
`daemon.stop` remains a frozen exception, accepted at any protocol version
the daemon has ever spoken.
- **Config:** three `lease.*` keys are retired — `lease.detachedTtlMs`,
`lease.heldTtlBackstopMs`, and `lease.heartbeatIntervalMs`. All three are now
simply unrecognized: `simlock config` warns about each and ignores it,
exactly as it does for any other unknown key. **None of them is aliased onto
a new key**, so a config still setting `lease.detachedTtlMs` gets
`lease.defaultTtlMs`'s default rather than the value it wrote — copy the
value across. New: `lease.defaultTtlMs` (15 minutes, applied to a request
that names no `ttlMs`) and `lease.maxTtlMs` (4 hours). Both must be positive
numbers with `lease.defaultTtlMs <= lease.maxTtlMs`; a config that breaks
either rule is **rejected at load and the daemon does not start**, naming the
offending key, rather than being clamped. Note the two treatments are
different on purpose: a retired key is warned about and ignored, because it
is a leftover; a TTL pair that contradicts itself has no safe fallback to be
ignored in favour of. See `docs/CONFIGURATION.md#retired-lease-keys`.
- **Upgrading over a live held lease:** a lease a pre-ADR-0004 daemon
persisted in held mode survives the upgrade with its persisted deadline
intact — up to the old one-hour `lease.heldTtlBackstopMs`. Nothing can
renew it: its holder speaks protocol 3 and the new daemon speaks
`{min: 4, max: 4}`, so its `hello` fails. The lease simply expires on that
deadline and its device is reclaimed, or `simlock release <lease-id>` ends
it sooner. Stopping the old daemon while it is idle, as the protocol-
mismatch error already advises, avoids the situation entirely.
- **A holder killed with `SIGKILL` keeps its device until the TTL expires.**
The daemon keeps no per-connection lease state and releases nothing when a
connection closes, on any transport — so a holder that dies without running
its own release path (`SIGKILL`, a crash, a lost machine) holds its device
until `expiresAt`, at most the lease's own TTL after its last renew —
`lease.defaultTtlMs` unless the request asked for more, never more than
`lease.maxTtlMs` — against today's immediate release on socket close. A
holder that exits normally, is `SIGTERM`ed, or whose parent dies still
releases at once, because that is its own policy. This is the one behaviour
change a local user notices, and it is the accepted price of a single
mechanism; the reverse case improves, as a machine sleep or a socket hiccup
no longer costs a live holder its device. `lease.defaultTtlMs` and `--ttl`
bound it — see `docs/known-pitfalls.md`.
- **`simlock daemon stop` no longer releases leases**, and there is no
orphaned-lease sweep at daemon startup. Leases persist across a restart and
the next daemon restores each one's TTL timer from its deadline; one whose
deadline passed in between expires as soon as a daemon is there to expire it.
- **Events:** `lease.granted`'s payload drops `mode`. `lease.released` loses
the `closed` and `orphaned` reasons — a closing connection is not a release
and never was a fact worth emitting, and there is no startup sweep to produce
an orphan. `explicit`, `killed`, and `device-lost` remain.
- **`simlock/client`:** `onLeaseLost` no longer fires with reason
`daemon-connection-lost` when a connection dies. The lease is still granted
and still yours — reconnect and renew it, or let its TTL run out.
`onConnectionLost` is what reports the dead connection; `onLeaseLost` now
only ever reports a lease the daemon actually ended.
- **The MCP server's renew timer reconnects, but never launches a daemon.** ADR
0003 §10/§11 gave MCP one lazy reconnect trigger, the next tool call; ADR
0004 adds a second. When the renew timer fires against a dead client the
session reconnects and renews, so an idle session no longer loses its lease
waiting for a call that may not come. That trigger only ever connects to a
daemon that is already listening — auto-launch stays a tool-call concern, so
an operator's `simlock daemon stop` is not undone by an idle session, and a
lease held across a stopped daemon expires unless the daemon is back before
its deadline.
- **A running `simlock lease` exits `1` when its daemon connection dies**,
writing one `DAEMON_CONNECTION_LOST` line that names the lease id and its
`ttlDeadline`. The CLI still does not reconnect (ADR 0003 §10), so it can
neither renew nor release — but it no longer implies the lease went with it.
The lease stands until its deadline and any later invocation can
`simlock lease renew <lease-id>` it. Exit `14` keeps its narrower meaning:
the daemon ended the lease while the connection was alive.

### Features

These ship with the PRs that implement ADR 0004; this section describes what
those changes add, alongside the breaking changes above.

- **cli:** `simlock lease` (without `--detach`) renews its own lease at one
third of the lease's TTL for as long as it runs — sending no TTL of its
own, so the deadline keeps the width the lease was granted with — and
releases on exit, parent death, or `SIGINT`/`SIGTERM`. `--detach` prints
the grant and exits; the lease it leaves behind is the same kind of lease,
and renewing it is the caller's job.
- **cli:** `simlock lease --ttl <duration>` sets a lease's initial TTL in
place of `lease.defaultTtlMs`, capped by `lease.maxTtlMs`.
- **daemon:** one expiry path for every frontend — startup restores every
lease's TTL timer from its persisted deadline, and the held-lease
bookkeeping kept for release-on-close is deleted along with the
`StartupConverger` orphan sweep that existed to clean up after it.
- **config:** `lease.maxTtlMs` bounds what any caller may ask for, so one
client cannot pin a device for a day by naming a large `ttlMs`.

### Documentation

- record ADR 0004 as **Accepted — not yet implemented**
(`docs/adr/0004-ttl-first-leases-on-every-transport.md` and
`docs/adr/README.md`): the documentation describes the decided end state;
the code catches up in the changes that implement ADR 0004.
- rewrite the lease model across `docs/CLI.md`, `docs/CLIENT.md`,
`docs/HTTP-API.md`, `docs/CONFIGURATION.md`, `docs/ARCHITECTURE.md`
("Leases", the frontend topology, and startup convergence),
`docs/EVENTS.md`, `docs/ABOUT.md`, and `README.md`; record the SIGKILLed
holder and re-frame the reparented-holder fix around renew timers in
`docs/known-pitfalls.md`.

## [0.3.0](https://github.com/callstackincubator/simlock/compare/v0.2.0...v0.3.0) (2026-09-03)

ADR 0003 (`docs/adr/0003-one-typed-daemon-contract-behind-every-frontend.md`):
Expand Down
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ simlock lease --platform ios --device "iPhone 16" --detach
"deviceId": "dev_1a2b",
"requesterId": "agent-1",
"ownerId": "agent-1",
"mode": "detached",
"grantedAt": 1735689600000,
"ttlMs": 900000,
"lastRenewedAt": 1735689600000,
"ttlDeadline": 1735690500000
},
"timing": {
Expand All @@ -76,10 +77,12 @@ simlock lease --platform ios --device "iPhone 16" --detach
```

That's the whole interaction: ask for a platform and a device model, get
back an identified, ready-to-use device. Release it explicitly, or let its
TTL expire. This is the contract's own `LeaseGrant` shape, serialized
as-is — the CLI's `--json` output is a contract value, not a bespoke
rendering (see [docs/CLI.md](docs/CLI.md)).
back an identified, ready-to-use device. Release it explicitly, renew it
before `ttlDeadline` to keep it, or let its TTL expire. Drop `--detach` and
`simlock lease` stays running instead, doing the first two for you — renewing
on a timer and releasing when it exits. This is the contract's own
`LeaseGrant` shape, serialized as-is — the CLI's `--json` output is a
contract value, not a bespoke rendering (see [docs/CLI.md](docs/CLI.md)).

Now say a second agent asks for the same `iPhone 16` a moment later. It's
already leased to the first agent — no problem, Simlock just provisions
Expand All @@ -104,8 +107,9 @@ the lease result lands on stdout the moment the new device is ready:
"deviceId": "dev_3c4d",
"requesterId": "agent-2",
"ownerId": "agent-2",
"mode": "detached",
"grantedAt": 1735689630000,
"ttlMs": 900000,
"lastRenewedAt": 1735689630000,
"ttlDeadline": 1735690530000
},
"timing": {
Expand Down Expand Up @@ -155,27 +159,28 @@ The daemon starts on demand — there's no separate setup step. Use
Simlock-managed devices.

See [docs/CLI.md](docs/CLI.md) for the full command reference and
[docs/CLI.md#mcp-integration-optional](docs/CLI.md) or the [README section
[docs/CLI.md#simlock-mcp](docs/CLI.md#simlock-mcp) or the [README section
below](#mcp-integration-optional) for wiring up an MCP client.

## MCP integration (optional)

The CLI remains Simlock's primary, full operator interface. MCP is a
narrower, agent-focused integration: it intentionally exposes neither
status, configuration, events, lease renewal, nor destructive or other
operator commands. Start it with `simlock mcp` — it reserves stdout for MCP
JSON-RPC, so lease results never mix with protocol framing.
The CLI remains Simlock's primary, full operator interface. MCP is a narrower,
agent-focused integration: it intentionally exposes neither status,
configuration, events, manual lease renewal, nor destructive or other operator
commands — the server renews its own session's lease on a timer, so an agent
never has to ask it to. Start it with `simlock mcp` — it reserves stdout for
MCP JSON-RPC, so lease results never mix with protocol framing.

`SIMLOCK_AGENT_ID` sets the server's stable requester identity. Simlock
allows at most one active lease per identity, so give each agent session a
distinct, stable id — run one MCP server process per agent session, each
with its own id.

The server exposes exactly four tools: `list_devices` (read-only catalog of
what can be leased), `lease_simulator`, `release_simulator`, and
`lease_status` (cheap, safe to poll after a context compaction to check
whether a device is still held). Full tool contracts, progress reporting,
and lease-loss notifications are documented in
what can be leased), `lease_simulator`, `release_simulator`, and `lease_status`
(cheap, safe to poll after a context compaction to check whether a device is
still leased to this session). Full tool contracts, progress reporting, and
lease-loss notifications are documented in
[docs/CLI.md](docs/CLI.md#simlock-mcp).

## Documentation
Expand Down
13 changes: 9 additions & 4 deletions docs/ABOUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ programmatic client the CLI and MCP frontends are themselves built on (see
- **Advisory coordination.** Simlock does not sandbox anything. It works
because agents are instructed to never call `simctl` / `avdmanager` directly
and to only use devices handed to them by a lease.
- **Process-held leases.** The `lease` command stays running in the
background; the open connection to the daemon is the heartbeat. Killing the
process releases the lease. A daemon-side TTL is the backstop for zombies.
- **TTL leases, one kind everywhere.** Every lease carries a TTL and lives
until it expires, is renewed, or is released — on the socket, over HTTP,
and over MCP alike. `simlock lease` stays running in the background,
renewing on a timer and releasing when it exits, so killing it normally
frees the device at once; `--detach` skips the staying alive and leaves the
renewing to you. A holder that dies without releasing costs its device only
until the TTL runs out.
- **One lease per agent** (v1).
- **Managed-device registry.** Simlock only ever shuts down, erases, or
deletes devices it created itself. Everything else on the machine is
Expand All @@ -50,4 +54,5 @@ programmatic client the CLI and MCP frontends are themselves built on (see

See [ARCHITECTURE.md](ARCHITECTURE.md) for how it's built, [CLI.md](CLI.md)
for the command surface, [CLIENT.md](CLIENT.md) for the programmatic client,
and [known-pitfalls.md](known-pitfalls.md) for accepted gaps.
[HTTP-API.md](HTTP-API.md) for the network API, and
[known-pitfalls.md](known-pitfalls.md) for accepted gaps.
Loading