Repository navigation
fix(server): let CloseSession clear a stale lost-lease tombstone - #1266
Merged
Merged
Conversation
The engine/provider engine-version and x/sync bumps merged via dependabot (#1246, #1247, #1248, #1249, #1250) left root's go.mod/go.sum out of sync with what GOWORK=off resolution needs, breaking `task e2e:k8s` the same way 9991e54 fixed previously: `go: updates to go.mod needed, disabled by -mod=readonly`. Re-run `task tidy` to bring go.mod/go.sum back in sync. Co-Authored-By: Claude Sonnet 5 <[email protected]>
4 of 5 tasks
closeSessionAuthorized always reaffirmed the session lease before tearing down local state, but a process that already lost its lease (lostOwnership set by onLeaseLost) fails that reaffirm the same way every time, so closeSessionLocal — the only place that clears the tombstone — was never reached. CloseSession is the documented recovery path for a lost lease (ADR 0027 Phase 4), so once a process ever lost a session's lease it could never touch that session again without a restart, even after the lease became free. Skip the impossible reaffirm/settle step when lostOwnership[id] is already set and go straight to closeSessionLocal, which is already safe to call in that state. A subsequent run then goes through the normal reaffirmLease path and re-acquires cleanly if the lease is actually free. Co-Authored-By: Claude Sonnet 5 <[email protected]>
jhrozek
force-pushed
the
fix/session-lease-tombstone
branch
from
September 8, 2026 20:09
16c4c0c to
8b749ec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Service.onLeaseLostsetslostOwnership[id]) could never use that session again, even after the lease was actually free.CloseSessionis the documented recovery path, butcloseSessionAuthorizedalways tried to reaffirm the lease first — which fails the exact same way every time oncelostOwnership[id]is set — socloseSessionLocal(the only place that clears the tombstone) was never reached.lostOwnership[id]is already set,closeSessionAuthorizedskips the impossible reaffirm/settle step and goes straight tocloseSessionLocal, which is already safe to call in that state. A subsequent run then goes through the normalreaffirmLeasepath and acquires cleanly if the lease is genuinely free (or is correctly refused again if someone else really holds it).Development stage
Contract linkage
CloseSessionrecovery path actually workInterface conformance
port.SessionLease, all backends (flocklease/k8slease/grpcdriver/memlease), and every other lease code path (reaffirmLease,onLeaseLost,renewLoop) are untouched.Issue relationship
Relates to a live bug found while investigating a "session is leased by another process" report on a local mecatui instance whose renewer missed ticks (host sleep) past the lease TTL.
Type of change
Test plan
Baseline checks
task lintscoped tointernal/adapter/serverviagolangci-lint run ./internal/adapter/server/... --config .golangci.yml— 0 issues)go test ./internal/adapter/server/... -racepasses except one pre-existing, unrelated failure (TestSDKTypescriptRelease_Scenario2_HTTPCodecParity), confirmed present onmainbefore this change too (stashed the diff and re-ran to verify)go run ./cmd/mecademo) — not run; change is scoped tointernal/adapter/server, no engine/demo path touchedengine/change)Changes
internal/adapter/server/service.gocloseSessionAuthorizedskips reaffirm/settle whenlostOwnership[id]is already set, going straight tocloseSessionLocalso the tombstone actually clearsinternal/adapter/server/lease_test.goTestCloseSessionClearsLostOwnershipAndReacquires(proves the fix) andTestCloseSessionStillRefusedWhileLeaseHeldElsewhere(regression guard: a lease genuinely held elsewhere must still be refused)internal/adapter/server/session_mutation_inventory.gocloseSessionLocal's rationale comment to note the new direct call path fromcloseSessionAuthorizedUser-facing change
None directly — but a mecatui/mecated process that ever loses a session's local flock-backed lease (e.g. due to the host sleeping past the lease TTL) can now recover it via
CloseSessioninstead of requiring a full process restart.Special notes for reviewers
The tombstone's permanence-until-explicit-close is intentional (an existing pinned test,
TestADR_0294_AwaitingLeaseLossRetractsLocalAskPreservesSnapshot, requires a lost lease to stay refused absent an explicit close) — this PR does not weaken that. It only fixes the fact that the explicit-close path itself was unreachable once the tombstone was set.