Repository navigation
Description
Bug description
When Service.onLeaseLost (internal/adapter/server/service.go) declares a
cross-process session-lease loss, it sets a permanent lostOwnership[id] tombstone.
Every normal caller of acquireLease/reaffirmLease (StartRunContent,
resumeFromAwaiting/ApproveRun, RenameSession, DeleteSession, etc.) fails fast
on that tombstone forever — by design, per the field's own doc comment. The only two
things that clear it are:
CloseSession(unconditionally deletes it) — not something a normal client
resuming a session calls on its own.- The stale-session reconcile sweep's
bypassTombstone=truepath
(SettleIfStale/SessionStale, added in fix(server): let the stale-session sweep re-acquire a lost lease #1302 / commit0841e8eb9) — but this is
gated onstaleMaintenanceCandidate/staleMaintenanceSessionCandidate
(internal/adapter/server/stale_maintenance.go), which only ever consider
sessions persisted assession.StateRunning.
The problem: onLeaseLost itself drives the session out of StateRunning as
part of handling the loss — either to awaiting (the preserveAwaiting branch, e.g.
a session parked on a permission ask) or eventually to cancelled (via
run.Cancel()). By the time the sweep would look at it, it's no longer a
StateRunning candidate, so the sweep never finds it and the tombstone is
permanent — regardless of whether the original loss was a genuine takeover or a
false positive (see #1333).
Steps to reproduce
- Wire a
SessionLeasebackend (flock, k8s, or Redis/gRPC-driver). - Cause a lease loss to be declared while a session is parked
awaitinga
permission approval, or shortly after a run is in flight (e.g. via
flocklease.Renew declares definitive loss on process suspend (laptop sleep), even with no competitor #1333's laptop-sleep repro, or by killing/network-partitioning the
lease backend briefly). - Wait past the point the session settles into
awaiting/cancelled. - Try to resume/continue the session (
ApproveRun, or a new prompt).
Expected behavior
A session whose lease was lost should be recoverable without manual intervention
once the underlying lease is verifiably free again — the existing self-held-lease
correction (SessionStale's trial-Acquire logic) already proves this safely for
StateRunning sessions; it should apply to awaiting/cancelled sessions too.
Actual behavior
The session is readable (GetSession/history load doesn't touch leasing) but
permanently un-writable: every attempt to add to it returns
rpc error: code = FailedPrecondition desc = server: session is leased by another process: "<id>"
Clients surface this as a read-only session. The only recovery is CloseSession
(an editor/ACP disconnect path most clients never call on purpose) or restarting the
process (which clears the in-memory tombstone map).
Environment (if relevant)
- Any deployment with a
SessionLeasebackend wired (--session-lease-dir,
--session-lease-k8s-namespace,--session-lease-url).
Additional context
Reviewed by a go-architect + kubernetes-operator-expert panel alongside
#1333. This is a separate, orthogonal issue: #1333 stops one
specific trigger (laptop suspend on the flock backend) from ever declaring a false
loss; this issue is about the fact that any declared loss — false positive or a
genuine takeover on k8s/Redis — currently wedges the session's write path
permanently instead of self-healing once the lease is actually free again.
Proposed direction: widen staleMaintenanceCandidate/staleMaintenanceSessionCandidate
(and the corresponding checks inside SettleIfStale) to also consider
session.StateAwaiting (and possibly StateCancelled) sessions whose lease this
process previously lost, not only StateRunning ones — reusing the same
age-horizon-first, self-held-lease-correction trial-Acquire logic
SessionStale/SettleIfStale already implement, so a stranded tombstone clears once
the backend confirms the lease is genuinely free (or genuinely held by a live peer,
in which case it correctly stays refused).
Activity
fix(server): clear lease-loss tombstones for awaiting/cancelled sessi…
fix(server): address panel findings on the #1334 lease-tombstone fix
fix(server): clear lease-loss tombstones for awaiting/cancelled sessi…
fix(server): address panel findings on the #1334 lease-tombstone fix