fix(web): WSL backend recovers from a revoked bootstrap session #22992
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelsvia-triage
- @@ -698,3 +701,5 @@698701 credential,699702 }),700703 })),704+ wasRejected: (connectionId, credential) =>705+ Effect.sync(() => Equal.equals(rejectedCredentials.get(connectionId), credential)),
- @@ -363,4 +363,6 @@363363 learnRoutes: (input) => learnRoutes({ environmentId, ...input }),364364 }).pipe(365365 Effect.provideService(Connectivity.Connectivity, connectivity),366- Effect.provideService(ConnectionDriver.ConnectionDriver, driver),366+ Effect.provideService(ConnectionDriver.ConnectionDriver, {367+ ...driver,368+ connect: Effect.fn(function* (current, reportProgress) {
juliusmarminge added labelsvia-triage:needs-julius
juliusmarminge removed labelsvia-triage
juliusmarminge removed labelsvia-triage:needs-julius
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:needs-julius
- @@ -668,9 +699,10 @@668699 // token instead of the primary's same-origin cookie. Stash it where669700 // the resolver's bearer broker looks it up.670701 let bearerChanged = false;702+ let bearerRejected = false;671703 if (registration._tag === "BearerConnectionRegistration") {672- const stored = yield* credentials673- .get(registration.target.connectionId)674- .pipe(Effect.orElseSucceed(() => Option.none<ConnectionCredential>()));675- bearerChanged =676- Option.isSome(stored) && !Equal.equals(stored.value, registration.credential);704+ bearerRejected = yield* (705+ credentials706+ .wasRejected?.(registration.target.connectionId, registration.credential)707+ .pipe(Effect.orElseSucceed(() => false)) ?? Effect.succeed(false)708+ );
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
tanstack-source added labelsbug
juliusmarminge linked this to fix #22951
Pushed7d1b288
- @@ -744,5 +750,20 @@744750 for (const bootstrap of topologyRead.bootstraps) {745751 // Token rotation only controls exchange retries; dropping endpoint bearers also clears drafts.746752 const endpointSignature = `${bootstrap.httpBaseUrl}|${bootstrap.wsBaseUrl}`;747753 const signature = `${endpointSignature}|${bootstrap.bootstrapToken ?? ""}`;748- const cached = previous.get(bootstrap.id);754+ let cached = previous.get(bootstrap.id);755+ if (cached?.registration._tag === "BearerConnectionRegistration" && !cached.stale) {756+ const invalidated = yield* (757+ credentials758+ .wasRejected?.(759+ cached.registration.target.connectionId,760+ cached.registration.credential,761+ )762+ .pipe(Effect.orElseSucceed(() => undefined)) ?? Effect.undefined763+ );764+ if (invalidated) {765+ cached = { ...cached, stale: true };766+ if (cached.recoverySignature === signature) {767+ rejected.set(768+ bootstrap.id,769+ nextRejectedSecondaryBootstrap(rejected.get(bootstrap.id), signature, nowEpochMs),@@ -749,3 +780,21 @@780+ )781+ ) {782+ // A slow connection can reject a bearer after several clean polls.783+ // Require sustained survival before treating a revocation as independent.784+ const {785+ recoverySignature: _recoverySignature,786+ recoveryStartedAtEpochMs: _recoveryStartedAtEpochMs,787+ ...healthy788+ } = cached;789+ cached = healthy;790+ rejected.delete(bootstrap.id);791+ }792+ }793+ const priorRejection = rejected.get(bootstrap.id);794+ if (cached?.recoverySignature === signature && priorRejection?.signature === signature) {795+ nextRejected.set(bootstrap.id, priorRejection);796+ }749797 // Rotation may mean a restart; retain the old bearer if the new exchange fails.750798 if (751799 cached !== undefined &&800+ !cached.stale &&@@ -838,3 +841,9 @@838841 credential,839842 }),840843 })),844+ wasRejected: (connectionId, credential) =>845+ Effect.sync(() => Equal.equals(rejectedCredentials.get(connectionId), credential)),846+ removeIfMatches: Effect.fn("ConnectionCredentialStore.removeIfMatches")(847+ function* (connectionId, credential) {848+ let removed = false;849+ yield* catalog.update((document) => {@@ -838,3 +841,21 @@838841 credential,839842 }),840843 })),844+ wasRejected: (connectionId, credential) =>845+ Effect.sync(() => Equal.equals(rejectedCredentials.get(connectionId), credential)),846+ removeIfMatches: Effect.fn("ConnectionCredentialStore.removeIfMatches")(847+ function* (connectionId, credential) {848+ let removed = false;849+ yield* catalog.update((document) => {850+ const credentials = document.credentials.filter((entry) => {851+ if (852+ entry.connectionId !== connectionId ||853+ !Equal.equals(entry.credential, credential)854+ )855+ return true;856+ removed = true;857+ return false;858+ });859+ return { ...document, credentials };860+ });861+ if (removed) rejectedCredentials.set(connectionId, credential);@@ -1416,0 +1453,21 @@1453+ storedCredentials = harness.storedCredentials;1454+ yield* Effect.gen(function* () {1455+ const registry = yield* EnvironmentRegistry.EnvironmentRegistry;1456+ const registration = new BearerConnectionRegistration({1457+ target: BEARER_TARGET,1458+ profile: BEARER_PROFILE,1459+ credential: new BearerConnectionCredential({ token: "revoked-bearer" }),1460+ });1461+ yield* registry.reconcilePlatform([registration]);1462+ yield* awaitConnectionState(1463+ registry,1464+ BEARER_TARGET.environmentId,1465+ (state) => state.phase === "blocked",1466+ );1467+ expect((yield* Ref.get(harness.storedCredentials)).has(BEARER_TARGET.connectionId)).toBe(1468+ false,1469+ );1470+ yield* TestClock.adjust("3 seconds");1471+ yield* registry.reconcilePlatform([registration]);1472+ yield* TestClock.adjust("3 seconds");1473+ yield* registry.reconcilePlatform([registration]);
juliusmarminge added labelstakeover:blocked
juliusmarminge removed labelstakeover:in-progress
Sign in to join this conversation.
Walkthrough
The connection registry now tracks rejected platform bearer credentials and conditionally removes a credential only when it matches the failed value. The platform connection source detects stale registrations, applies retry backoff, and requests a new bearer during recovery.
Changes: Bearer Credential Recovery
packages/client-runtime/src/connection/credentialStore.ts,apps/web/src/connection/storage.ts,apps/web/src/connection/storage.test.tspackages/client-runtime/src/connection/registry.ts,packages/client-runtime/src/connection/registry.test.ts,packages/client-runtime/src/connection/index.ts,packages/client-runtime/src/connection/onboarding.test.tsConnectionDriver; the onboarding test mock implementswasRejected.apps/web/src/connection/platform.ts,apps/web/src/connection/platform.test.tsEstimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
Possibly related issues
Possibly related PRs
EnvironmentRegistry.Merge Risk:
Moderate · up to
7d1b2The change lets a WSL backend replace a revoked bearer automatically, but with two runtimes sharing a backend, recovery can still disconnect or overwrite the other runtime's credentials and connections. A failed credential-storage write can also leave a revoked bearer in use. These cases should be fixed or accepted before merge.
Pre-merge checks:
4
#22951. The Change secti…#22951] offers two alternative remedies, and the issue states that either one would help: (1) prevent duplicate registration builds or share one in-flight exchange per backend, or (2) evict the cache…#22951].credentialStore.tsadds the two optional operations.storage.tsimplements in-memory rejection tracking and condit…Full details: Title check
Explanation
The title names the main change: the WSL backend recovers when its bootstrap session is revoked. The changeset adds recovery logic that evicts rejected bearer credentials, retries exchange on later polls, and adds backoff. The title is conventional and specific. It does not describe the out-of-scope duplicate-exchange fix, and the title does not claim that fix.
Full details: Description check
Explanation
The description follows the template sections (Problem, Change, Scope, Verification) and fills each one. The Problem section explains the revoked cached bearer and links issue
#22951. The Change section describes the recovery mechanism. The Scope section links the issue and states that the PR is a bug fix. The Verification section lists test runs, the fake-endpoint sequence, and the limits of the evidence, including the missing live WSL test. Minor gaps: the Scope section cites an automated triage flow rather than explaining why the fix needs no issue, and the Change section is long and includes investigation detail that the template does not request. The required information is present, so the check passes.Full details: Linked Issues check
Explanation
[
#22951] offers two alternative remedies, and the issue states that either one would help: (1) prevent duplicate registration builds or share one in-flight exchange per backend, or (2) evict the cached secondary registration after a revoked or invalid session so the next poll exchanges again. This PR implements remedy (2).ConnectionCredentialStoregains optionalwasRejectedandremoveIfMatches(credentialStore.ts, storage.ts).EnvironmentRegistry.createServiceScopewraps the driver so an authenticationConnectionBlockedErroron a platform-managed bearer removes that credential only when the stored value still matches.platform.tschecks the cached secondary bearer for rejection, marks the registration stale, retries on later polls, and applies backoff. Registry and platform tests cover re-exchange after rejection, retention of the registration on failed refresh, atomic preservation of a replacement credential, healthy bearer reuse, and backoff. The issue's expected behavior of re-exchanging after a later rejection is covered. Startup duplicate exchange (remedy 1) is not changed, and the PR says so explicitly. The issue permits that. Live WSL behavior is not verified, per the PR description. Those limits do not block a PASS for the stated remedy.Full details: Out of Scope Changes check
Explanation
The changed production files support the eviction and recovery path for [
#22951].credentialStore.tsadds the two optional operations.storage.tsimplements in-memory rejection tracking and conditional removal.registry.tswires eviction into the connection failure path and excludes rejected credentials from replacement.platform.tsimplements recovery and backoff.isRejectedSecondaryBootstrapchanges from a type predicate tobooleanto support the rejection check.layerPlatformConnectionSourceis exported so tests can exercise the production layer.connection/index.tsre-exportsConnectionDriver, which the registry wrapper uses.onboarding.test.tsadds awasRejectedstub to match the new interface. Test files cover the new paths. No unrelated product behavior change is shown in the summary. The public-declaration changes are small and tied to this work.Finishing Touches
Generate unit tests (beta)