Repository navigation
Host lease survives clock skew and fails closed; sign-out confirms the session is gone - #991
Merged
Merged
Conversation
…ms revocation (#978, #979, #980) Host lease (core joinHostLease, shared by store, auth and audit): - Liveness never compares two hosts' wall clocks. Each renewal writes a strictly larger heartbeat_at; an observer judges another host's row by whether that value changes, timed on its own monotonic clock (dead after 20 s unchanged). Rows of this host are also dropped once expires_at passed. - Joining watches another host's row: refuses once it advances, deletes it and joins once it stays silent for the TTL. A joiner whose clock is ahead no longer evicts a live holder; a crashed host whose clock was ahead blocks for 20 s, not the skew. - Every heartbeat re-reads the table. Another host's row loses the lease: delete the own row, log, never re-insert beside it, rejoin by itself once no other host's row is left. Heartbeat failures are logged. - Writes fail closed: HostLease.verify() runs inside each store write transaction and audit ingest (503 storage_unavailable / audit_unavailable); auth checks renew() once per request (503 auth_unavailable). #979: auth releases the lease when activation fails after joining; audit releases it when close races the first activation. #980: the auth mount confirms against the database that a successful /sign-out removed the session, and that a 401 from the session endpoints means no session (Better Auth's getSessionFromCtx reads a storage failure as no session, pinned by a test); otherwise 503 with no Set-Cookie. Docs: STORE, OPERATIONS, CAPACITY, EXTENSIONS, FRAMEWORK, the RIM card, package READMEs, SECURITY and CHANGELOGs. Package budgets raised per the package-audit policy with measurements. Co-Authored-By: Claude Opus 5.5 <[email protected]>
jimhoyd
enabled auto-merge (squash)
September 29, 2026 22:36
…regenerate references Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 29, 2026
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.
Fixes #978
Fixes #979
Fixes #980
Problem
auth_serversrow and a heartbeat timer running against a closed connection./sign-outswallows a failed session delete. It answers200 {"success":true}and clears the cookie while the session stays valid.Design
heartbeat_at. A process judges another host's row only by whether that value changes, timed on its own monotonic clock: a row unchanged for 20 s is dead. Rows from this host (same kernel, same clock) are also dropped onceexpires_atpasses. Everything stays inside the extension's own SQLite database, with no schema change.lease.verify()under the write lock, throughStoreDatabase.writeGuard. Host transactions go through the same guard.ingestcallslease.verify()the same way.verify()allows: a write goes ahead if the last committed heartbeat began less than 10 s ago. After that it goes ahead only if the process's own row is present and no other host's row is. A peer needs 20 s of silence before it can take over, so no write from the old holder can land after the take-over.503 storage_unavailable; audit answers503 audit_unavailable, and producers keep their events. Auth cannot wrap Better Auth's statements, so it callslease.renew()once per request and answers503 auth_unavailable.close()races the first activation./sign-out, the mount reads the session back from the database (disableCookieCache,disableRefresh). It answers 503 with noSet-Cookieunless the session is gone.getSessionFromCtxturns a storage error into "no session", so its session endpoints answer 401. A test now pins that upstream behavior. The mount confirms a 401 from/list-sessions, the revoke endpoints and/change-passwordthe same way./revoke-session(s)and/revoke-other-sessionsalready fail with a 500, which the mount turns into a 503.Remaining limits (documented in STORE.md)
Validation
npm run verifypasses. It includestest:multiprocess, lint and typecheck.npm run test:packagepasses.sleep):test/host-lease.test.ts: stalled holder, joiner with a clock a day ahead, crashed host with a clock a day ahead.scripts/package-audit.ts, following its policy.This is not an independent security review.
🤖 Generated with Claude Code