feat(cli): release the proxy lease after close

Merged
V3
1mo ago
+780-29

Summary

In proxy mode the daemon ends a session's lease on close, but no release goes over the wire, so a gateway in front of the daemon never learns the lease ended. The CLI also kept the old lease id, so the next open heartbeated it, got LEASE_NOT_FOUND, and allocated a new lease.

Now, after a successful proxy close, the CLI sends lease_release for its stored lease and removes the lease from its local connection state. A failed or "not found" release does not fail close. Nothing changes for leases the daemon keeps on close (retainOnClose, now recorded from allocate/heartbeat), host-allocated macos-app leases, non-proxy connections, or local mode. 6 files; the remote-proxy docs gain one sentence.

Validation

Tested commit 6e8d5d128: pnpm check:affected --run passed (format, lint, typecheck, layering, fallow, build, docs; 44 related test files, 441 tests).

New tests in cli-close.test.ts. The two release tests fail without the fix. The retain, macos-app, and non-proxy tests each fail when their guard is removed.

Live run: built CLI → logging relay → agent-device proxy → local daemon, using a private iOS simulator:

open   lease.allocate → e45eefd6…
close  command=close; lease.release e45eefd6… → {"released":false}; local lease: none
open   lease.allocate → fe83d4d1… (no heartbeat)

On origin/main the same flow sends no release after close, and the next open gets lease.heartbeat → 401 LEASE_NOT_FOUND and then allocates again.

With the change, disconnect on an open session still sends close then lease.release. Local-mode open/close works as before.