fix(daemon): require the session lease id on every request to a leased session

Merged
TH
5d ago
+1195-185

Summary

Targets 0.22. A request on a leased session must send that lease's id. The daemon filled a missing lease id from the session, so any holder of a shared proxy token who knew a session name could read, drive and close another client's session. Now a missing id fails with UNAUTHORIZED, LEASE_SESSION_MISMATCH, field: leaseId. Labels are checked when present and never grant access. Nested daemon requests (find, batch, replay) carry the parent's lease scope without overriding their own. Active provider-session artifact lookup needs the lease id. Caller-chosen allocate ids need 128 bits. Health reports session-lease-id. ADR 0007 states the trust model.

Breaking for older clients and direct RPC/SDK callers that relied on inheritance. The current CLI already sends the saved lease id.

Follow-ups: #4908, #4909, #4910, #4912, #4913. #4171 was fixed by #4177.

Before / after

raw --tenant e2b --session-isolation tenant --session agentA (proxy token, no lease id)
snapshot | press @e7 | close
base: succeed on agentA's device   head: UNAUTHORIZED LEASE_SESSION_MISMATCH (field leaseId)

Value

basehead
Same-token attacks admitted (proxy test: snapshot, press, close, artifacts)4/40/4
Minimum caller-chosen lease id64 bits128 bits

Validation

At 6eef3a85f9: full unit-core and provider-integration pass; lint, typecheck, layering and wire-compat clean. New tests fail at base; the find, batch and replay tests guard the nested hand-down. check:affected --run passed at cecfae508b (exactCommit).

Live, iOS 26.2 simulator, checkout proxy, three state dirs: C's snapshot/press/close refused. B's open got DEVICE_IN_USE. A's connect, open, snapshot, press, close and disconnect passed.