Skip to content

fix(cluster): log a removed self-hosted cluster's sign-ins out of its servers, then forget them - #1966

Merged
dawsontoth merged 8 commits into
claude/1924-full-scan-dialogfrom
claude/1954-self-hosted-logout
Oct 15, 2026
Merged

dawsontoth merged 8 commits into
claude/1924-full-scan-dialogfrom
claude/1954-self-hosted-logout

Conversation

@dawsontoth

@dawsontoth dawsontoth commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

A fuzzy otter mail carrier hands a ring of old keys back through the door of a glowing hillside cottage while a mouse unpins the matching key tags

⊙ Problem

#1954 forgets a terminated cluster's sign-ins but keeps a removed self-hosted cluster's, whose servers may still run. So removing one left its sign-ins and any stored Basic Auth credential until the next app sign-out. Separately, a logout that answered late cleared a sign-in made after it was sent.

🤔 Should removing a self-hosted cluster log its sessions out?

Yes, as decided on #1954: log out of its servers, best effort, and forget the sign-ins. Keeping them leaves live sessions and stored credentials for a cluster Studio no longer shows.

💡 Solution

  • Removing a self-hosted cluster sends a logout to its server and each instance's, and forgets those sign-ins, including ones another tab made.
  • Each logout is one attempt with a 10s timeout, as app sign-out sends them. The removal doesn't wait, and a failed logout still forgets.
  • A logout's late answer no longer clears a newer sign-in, in this tab or another. App sign-out shares the fix.
  • Fabric cluster termination is unchanged.

⚖️ Alternatives

  • Await the logouts in the removal: a slow or unreachable server would hold the Remove dialog for up to 10s, against "never block the removal".
  • Copy the app sign-out loop: a later change to its timeout or failure reporting would then reach only one of the two paths.
  • A per-tab counter for the late answer: misses another tab's sign-in.

🤔 Should a failed logout still forget the sign-in?

I chose yes, as decided. The cost: a server unreachable at removal keeps its session, and no later app sign-out retries it (#1967). Keeping the marker until a logout succeeds would trade that for leaving the sign-in remembered.

🔧 Changes

✅ Verification

End-to-end route: (d). A real logout needs a running self-hosted server; the flows run in unit tests.

Mutation checks and a flaky unrelated file
  • Each makes a test fail: no logouts; forgetting after the logouts answer; the self-hosted path forgetting locally only; the removal awaiting the logouts; no late-answer check; skipping the late clear always; dropping the stored Basic Auth, the Fabric Connect flag or the connection generation from the snapshot; not reading stored markers; not dropping another tab's marker.
  • Keeping the logout client's response interceptors passes tests: a logout is a write, and curryRetryGatewayErrors (retryGatewayErrors.ts) replays reads only.
  • Some full runs report an unhandled Radix focus-scope timer after teardown, in cardLinksDuringPendingNavigation.test.tsx or SecretsManager.delivery.test.tsx. Neither file runs this code, and both pass alone. The pre-commit run on the final commit was clean.

Follow-up to #1954 (#1931).

🤖 Generated with Claude Code

Related PRs: #1954 overlaps (merged; this builds on its terminate and DESIGN.md lines), #1956 independent
Complexity: medium

Deferred findings

Review-Coverage: authored=claude; ran=codex,gemini,cursor-grok,cursor-muse; adjudicated=domain; declined=cursor-composer,cursor-kimi,muse; rounds=11; full=7 @ e61ed02

Review-Attention: study ~20m (sensitive: authStore.ts, onInstanceLogoutSubmit.ts; decisions: forget-before-logout-answer, self-hosted-removal-logs-out, removal-not-awaiting-logouts, late-answer-guard-shape, managed-vs-self-hosted-split, do-less-alternative, forget-before-answer, snapshot-guard-shape, logout-only-on-studio-removal) @ e61ed02

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability to sign out of self-hosted cluster entities when they are removed or terminated, ensuring their active sessions are closed. It adds a new signOutEntities method to AuthStore to perform concurrent, best-effort logouts, along with comprehensive unit tests and updated design documentation. Feedback on these changes highlights a potential race condition in terminateCluster.ts where concurrent deletion and retrieval can cause both reads to fail with a 404, preventing logouts from being sent. Additionally, it is recommended to unconditionally clear stored credentials and to improve type safety in Promise.all by returning Promise.resolve() instead of falsy values.

Comment thread src/features/clusters/mutations/terminateCluster.ts
Comment thread src/features/auth/store/authStore.ts
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 79.99% 14915 / 18645
🔵 Statements 79.94% 15829 / 19799
🔵 Functions 75.43% 3977 / 5272
🔵 Branches 74.66% 11569 / 15495
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/features/auth/handlers/clearAuthStateLocally.ts 100% 100% 100% 100%
src/features/auth/queries/getCurrentUser.ts 90% 100% 66.66% 90% 37-41
src/features/auth/store/authStore.ts 94.74% 85.37% 97.16% 94.61% 138, 281-282, 291-294, 342, 363, 394-405, 413, 418-421, 528-531, 843, 963, 968, 1097, 1122
src/features/auth/store/signInMarkers.ts 98.36% 100% 100% 98.33% 58
src/features/auth/store/signInMarkersTestHelpers.ts 100% 100% 100% 100%
src/features/cluster/terminatedClusterSignIns.ts 100% 75% 100% 100%
src/features/clusters/mutations/terminateCluster.ts 86.66% 87.5% 66.66% 86.66% 45-46
src/integrations/api/instance/auth/onInstanceLogoutSubmit.ts 85.71% 75% 100% 85.71% 21
Generated in workflow #2386 for commit e7ae19f by the Vitest Coverage Report Action

dawsontoth and others added 8 commits October 15, 2026 09:31
… servers, then forget them

A self-hosted cluster's servers may outlive its removal from Fabric, so
#1954 kept its remembered sign-ins rather than forget them with no logout.
Removing one from Studio now ends those sessions instead.

authStore.signOutEntities(ids) starts one best-effort logout per
remembered id, built the way app sign-out builds them (the remembered
credential, a 10s timeout, no response interceptors), forgets every id
locally whatever the servers answer, and never rejects. terminateCluster
calls it for a self-hosted cluster's own sign-in and each instance's once
the DELETE succeeds, without making the removal wait. A Fabric cluster's
terminate is unchanged, and a removed self-hosted cluster is still never
cleared on render.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
onInstanceLogoutSubmit clears the entity's Basic Auth credential and
Fabric Connect state once the logout answers. App sign-out and cluster
removal forget the entity before they send, so by the time a late answer
lands, anything recorded for it is a newer sign-in, and the clear wiped
it: a new Basic Auth credential (from this tab or another), a new Fabric
Connect flag, or the token of a Fabric Connect still verifying.

sendBestEffortLogout now snapshots what the answer would clear when it
sends: the stored Basic Auth credential and Fabric Connect flag, read raw
from localStorage so another tab's writes count, and the connection
generation, which moves when a Fabric Connect token is claimed. It hands
onInstanceLogoutSubmit a signedInSince check, which skips the clear once
the snapshot has changed and clears again otherwise. Explicit sign-outs
pass no check and clear as before.

signOutEntities also reads the sign-in markers from storage, not only
this tab's copy, so removing a self-hosted cluster logs out a sign-in
another tab made after this one loaded, and drops that sign-in's marker
from storage too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arkers

Each tab read Studio:PotentiallyAuthenticated once at startup and wrote
that whole copy back on every sign-in and sign-out. That erased every
marker another tab had added since. An app sign-out from the stale tab
then sent those sign-ins no logout, and a sign-out of an entity only
another tab held left its marker behind.

- flagKeyAsSignedIn and flagKeyAsSignedOut now change one entity in
  the record as stored now, and leave the rest alone. A sign-in updates
  this tab's copy only once its write lands, so a refused write is
  retried at the next sign-in.
- A passing check of a sign-in this tab already marked still writes
  nothing, and a failing one removes the marker only when it still
  holds the URL it checked. Neither undoes another tab's change.
- When storage refuses to take a signed-out entity out of the record,
  this tab's later writes leave it out until one lands, instead of
  trusting or discarding the whole record.
- App sign-out, the local full sign-out and signOutEntities act on this
  tab's markers and every stored one, and log out each URL an entity
  is marked at, since another tab may have signed in again at a newer
  one.
- signOutEntities' forgetStoredMarkers is gone: flagKeyAsSignedOut now
  drops another tab's marker for the entity it signs out, so managed
  cluster termination, which signs out locally, reaches it too.
- A stored record that is not an object is treated as unreadable.
- DESIGN.md records what remains: storage has no atomic
  read-modify-write, so two tabs writing at once can still lose one
  change, and a marker removed elsewhere stays removed.

Closes #1968

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The markers lived in one shared Studio:PotentiallyAuthenticated record,
so every write read and rewrote the whole of it. Two tabs writing at once
could still lose a change, a refused write could take every marker with
it, and a full sign-out rewrote the record once per entity.

- Each marker now has its own key, Studio:PotentiallyAuthenticated:<id>,
  holding the URL signed into. A sign-in or sign-out touches only its
  entity's key, and sweeps enumerate the keys by prefix.
- On load, the legacy record is copied into per-entity keys once per
  storage, and a marker already stored per entity wins. A record that is
  not one (an array, or not JSON) is removed at every load, since the
  previous release cannot start on it.
- For one release, every marker change is mirrored into the legacy
  record, and sign-out sweeps read it. A tab still on the previous
  release, or a rollback, then still sees this release's sign-ins and
  sign-outs, and an app sign-out here reaches a sign-in only such a tab
  recorded. The copy is never repeated: that tab writes its whole
  load-time record back, which would bring back what this release
  signed out.
- A sign-in storage refuses to record no longer throws out of
  setUserForIdAndKey or a check. Its next sign-in or check records it.
  A marker storage would not remove is retried at every marker write.
- A check's answer is dropped when this tab signed in again at another
  URL while the check was out.
- Unit tests seed and read markers through signInMarkersTestHelpers,
  and the e2e anon specs through e2e/tests/signInMarkers.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng silently

- The sign-out wipe keeps the migration flag, so a previous-release tab
  writing its record back after a full sign-out isn't migrated again.
- Until a migration lands, as when a full quota refuses it, the legacy
  record also seeds this tab's markers, so its sign-ins still check out.
- Migration decides from one read, and also drops entries that aren't
  markers from the legacy record. A sign-in leaves a legacy record it
  can't read alone instead of replacing other tabs' markers.
- A sign-in always records itself, so signing in again restores a
  marker another tab removed; only a check's passing answer skips it.
- A check's answer is dropped when this tab signed in again while it was
  out, at the same URL or another, using a per-entity sign-in revision.
- A marker storage refused to remove is retried only while it still
  holds the value it had, so another tab's sign-in there survives, and a
  marker that couldn't be read at sign-out is still removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A failed check is a probe, not a sign-out: when it can't read the
  marker it leaves it, and a mirror write it can't make no longer takes
  the whole legacy record.
- For the app sign-in, which every /User/current answer re-signs, those
  answers no longer write the marker, so they can't put back one
  another tab's failed check dropped.
- A failing app check that was out during a new app sign-in is dropped,
  as an entity's already was.
- This tab's own sign-in cancels a removal of its marker still owed
  from a refused write.
- Migration checks its flag before the best-effort cleanup, so a
  refused cleanup on a migrated storage can't seed signed-out entities.
  The sign-out wipe marks the storage migrated, as nothing of the legacy
  record survives it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A page-load app check still out when the user signed in again applied
its answer for the old session over the new sign-in: getCurrentUser
synced it into the store, and loadUser applied it again.

- The store's app check now fetches through fetchCurrentUser, which
  doesn't sync, so loadUser applies the answer itself, and the sign-in
  revision guard drops a stale passing answer as it drops a failing one.
- getCurrentUser syncs its answer only if no sign-in landed while it was
  in flight, using the store's new getSignInRevision.
- DESIGN.md links #1970 for removing the legacy mirror.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- getCurrentUser syncs through the new syncAppUser, which writes no
  marker this tab already holds and leaves the sign-in revision alone.
  A sync landing during the store's own app check therefore no longer
  makes that check drop its answer and skip its sign-out re-ask.
- setUserForIdAndKey treats every sign-in, the app's included, as one
  that always records itself.
- A removal storage still owes is cancelled up front only when the kept
  marker already holds the URL being signed in, and otherwise once the
  new marker is written.
- A migration flag that can't be read is reported as migrated, so a
  previous-release write-back can't seed that load.
- getSignInRevision sits under its own doc comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dawsontoth
dawsontoth force-pushed the claude/1954-self-hosted-logout branch from e61ed02 to 0b14c61 Compare October 15, 2026 13:33
@dawsontoth
dawsontoth changed the base branch from stage to claude/1924-full-scan-dialog October 15, 2026 13:34
@dawsontoth
dawsontoth merged commit e7ae19f into claude/1924-full-scan-dialog Oct 15, 2026
5 checks passed
@dawsontoth
dawsontoth deleted the claude/1954-self-hosted-logout branch October 15, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant