Repository navigation
Description
Problem
A held lease's liveness is its daemon connection. When the daemon restarts,
every held-lease connection is gone by definition — but StartupConverger
restores the persisted TTL timers anyway:
// src/core/startup-converger.ts:47
await this.options.timers.restoreExpiryTimers();So after any daemon restart (crash, pitlane daemon stop, machine sleep,
config change) a held lease survives with no holder at all, keeping its
device out of circulation for up to a full heldTtlBackstopMs.
The client side is equally stuck, but that half now lives in #35: the MCP
session caches a DaemonConnection that is dead after the restart and never
reconnects. This issue owns the daemon side only — see Notes.
This gets worse, not better, once #12 lands: a heartbeat-backed lease that
loses its daemon has no way to be re-established.
Proposed change
- On startup, classify persisted leases. A
heldlease cannot have a live
connection across a restart, so release it (reasonkilled) instead of
re-arming its timer.detachedleases keep today's timer restoration —
their liveness is the TTL, not a connection. - Ordering matters: this must run before running-capacity convergence so the
freed devices are visible to it.
Notes
- Split with MCP server never recovers from a daemon restart #35 by module. Everything inside
McpSession— the distinct
error code for a dead connection, clearing the stale owned lease, and the
reconnect itself — moved to MCP server never recovers from a daemon restart #35, so the two issues never edit
src/mcp/session.tsconcurrently. This issue stays daemon-side. - This issue makes the decision MCP server never recovers from a daemon restart #35 depends on. Releasing held leases at
startup means a reconnecting session's old lease is definitively gone, so
MCP server never recovers from a daemon restart #35 only has to clear its cached lease and notify — no mechanism for
re-attaching an existing lease to a new connection is needed. Settle it here
before MCP server never recovers from a daemon restart #35 is built. - Registry-only destruction still applies: released devices go through the
normal reclaim path, nothing outside the registry is touched. - Emit the existing
lease.releasedfact for each lease dropped this way so
the event stream shows why devices freed up at startup.
Depends on #12 for the "connection liveness is the lease's liveness" model to
be fully coherent, but the startup half can land independently.
Acceptance criteria
- Held leases persisted in
state.jsonare released at daemon startup;
detached leases still have their timers restored. - Devices freed this way are reclaimed and available to the next requester.
-
lease.releasedis emitted for each, with a reason distinguishing
startup orphan cleanup. -
docs/ARCHITECTURE.mdstartup-convergence description updated. -
pnpm checkgreen.
Activity
V3RON commentedon Aug 20, 2026
Overlaps #35 (MCP server never recovers from a daemon restart), which I filed before spotting that this issue's problem statement already names
McpSession.#connectionForUse().Worth settling here first, because the daemon-side decision determines the client-side one. The two disconnect paths are not symmetrical:
DaemonServerreleases that connection'sheldLeaseIds(src/daemon/server.ts). The lease is gone.StartupConverger.converge()callsrestoreExpiryTimers()(src/core/startup-converger.ts), so the held lease returns with no holder, as described above. The lease still exists.So a reconnecting MCP session on the restart path may find its old lease alive and orphaned. Either this issue expires orphaned held leases at startup — and then #35 simply clears
#ownedLeaseand firesonLeaseLost— or the session re-adopts the lease, which needs a daemon-side way to re-attach a lease to a new connection that does not exist today.Suggest deciding that here and treating #35 as the client half, so the two aren't built against contradictory assumptions.
fix(lease): release held leases orphaned by a daemon restart
fix(lease): release held leases orphaned by a daemon restart (#38)
V3RON commentedon Aug 20, 2026
Correcting one thing in the problem statement above, now that this has
been tested end to end against a real daemon.
The issue lists the triggering scenarios as "crash,
pitlane daemon stop,machine sleep, config change".
pitlane daemon stopdoes not belong onthat list.
DaemonServer.#stop()calls#releaseHeld(connection)acrossevery connection before the process exits, releasing each held lease with
reason
closed, so a graceful stop already frees the device and leavesnothing orphaned in
state.json.This surfaced as a failed test rather than a code review. The first run
followed the issue's own framing — take a held lease,
daemon stop,restart, assert the orphan release — and found
state.jsonhad an emptyleasesarray before the restart even happened. There was nothing torelease because the graceful shutdown had already released it.
Re-running with
kill -9against the daemon reproduced it immediately:lease.releasedwithreason: "orphaned", the device back toready,and the same simulator re-leased afterwards.
So the merged behaviour is correct, but its real scope is narrower than
this issue describes: it covers daemon death that skips the shutdown path
— a crash, an OOM kill,
kill -9, power loss — and not any orderly stop.Worth knowing for anyone reading this issue as background later, and worth
keeping in mind for #35, whose reconnect story only has to account for the
ungraceful case.