Skip to content

Lease-loss tombstone (lostOwnership) is permanent for awaiting/cancelled sessions; stale-sweep only covers StateRunning #1334

Closed

Description

@jhrozek

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:

  1. CloseSession (unconditionally deletes it) — not something a normal client
    resuming a session calls on its own.
  2. The stale-session reconcile sweep's bypassTombstone=true path
    (SettleIfStale/SessionStale, added in fix(server): let the stale-session sweep re-acquire a lost lease #1302 / commit 0841e8eb9) — but this is
    gated on staleMaintenanceCandidate/staleMaintenanceSessionCandidate
    (internal/adapter/server/stale_maintenance.go), which only ever consider
    sessions persisted as session.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

  1. Wire a SessionLease backend (flock, k8s, or Redis/gRPC-driver).
  2. Cause a lease loss to be declared while a session is parked awaiting a
    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).
  3. Wait past the point the session settles into awaiting/cancelled.
  4. 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 SessionLease backend 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

  1. self-assigned this
    on Sep 10, 2026
  2. added 4 commits that reference this issue on Sep 14, 2026
    cc312a4
    e5be498
    174576a
    824b643
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions