From edd5993b6ecb0ef0b007f91d5ea1d052973481d2 Mon Sep 17 00:00:00 2001 From: cybersader Date: Thu, 19 Nov 2026 12:04:05 -0500 Subject: [PATCH 1/4] fix(client-runtime): an offline connection still tries when the offline report is stale A remote connection whose device reported offline waited for the report to change before it tried again. The platform report can stay wrong after the network is back, for example across VPN route changes on Android, which left the app on Offline until it was reopened or the user tapped Retry. The offline wait now ends after 30 seconds and tries once, ignoring the report, then waits again if that attempt fails. Network changes and app activation still end the wait at once. --- .../src/connection/supervisor.test.ts | 16 ++++++++++++++++ .../client-runtime/src/connection/supervisor.ts | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/client-runtime/src/connection/supervisor.test.ts b/packages/client-runtime/src/connection/supervisor.test.ts index 46b9757d0cd83..ba6115d0ae07a 100644 --- a/packages/client-runtime/src/connection/supervisor.test.ts +++ b/packages/client-runtime/src/connection/supervisor.test.ts @@ -432,6 +432,22 @@ describe("EnvironmentSupervisor", () => { }), ); + it.effect("still tries while the device keeps reporting offline", () => + Effect.gen(function* () { + const harness = yield* makeHarness({ networkStatus: "offline" }); + const supervisor = yield* EnvironmentSupervisor.make(RELAY_ENTRY, { + initiallyDesired: true, + }).pipe(Effect.provide(harness.dependencies)); + + yield* awaitState(supervisor.state, (state) => state.phase === "offline"); + expect(yield* Ref.get(harness.prepareCount)).toBe(0); + // The report never changes, but the host is reachable. + yield* TestClock.adjust("30 seconds"); + yield* awaitState(supervisor.state, (state) => state.phase === "connected"); + expect(yield* Ref.get(harness.prepareCount)).toBe(1); + }), + ); + it.effect("connects to the primary environment while the device reports offline", () => Effect.gen(function* () { const harness = yield* makeHarness({ networkStatus: "offline" }); diff --git a/packages/client-runtime/src/connection/supervisor.ts b/packages/client-runtime/src/connection/supervisor.ts index 58411d795b7fc..7ab93e1cf8438 100644 --- a/packages/client-runtime/src/connection/supervisor.ts +++ b/packages/client-runtime/src/connection/supervisor.ts @@ -45,6 +45,9 @@ import { const RETRY_BASE_DELAY_MS = 1_000; const RETRY_MAX_DELAY_MS = 300_000; +// The platform's offline report can stay wrong after the network is back, so +// an offline connection still tries this often instead of waiting for a change. +const OFFLINE_RECHECK_MS = 30_000; const SESSION_LOSS_RETRY_DELAY_MS = 250; // Someone is approving this device on the host; check back soon rather than climbing the ladder. const APPROVAL_PENDING_RETRY_DELAY_MS = 4_000; @@ -1195,6 +1198,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( pendingRetry = Option.none(); }; let replacing = false; + let offlineRecheckDue = false; for (;;) { const retryRequested = yield* Ref.getAndSet(resetRetryState, false); @@ -1216,14 +1220,15 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( } // The platform's offline report can stay wrong after the network is back, // so an explicit retry still tries instead of waiting for it to change. - const ignoreOffline = replacing || retryRequested; + const ignoreOffline = replacing || retryRequested || offlineRecheckDue; if (currentIntent.network === "offline" && !ignoreOffline) { yield* clearLease; yield* setState(offlineState(currentIntent, generation, failureCount + 1, latestFailure)); - const applicationActivated = yield* waitForSignal; + const applicationActivated = yield* waitForRetrySignal(OFFLINE_RECHECK_MS); if (applicationActivated) { resetRetryLadder(); } + offlineRecheckDue = true; continue; } @@ -1233,6 +1238,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( runAttempt(attempt, nextGeneration, latestFailure, pendingRetry, ignoreOffline), ); replacing = false; + offlineRecheckDue = false; const failedProbe = yield* Ref.getAndSet(probeUnanswered, false); if (outcome.established) { generation = nextGeneration; From 90b80bf7c05a290ef2350d852905ef35f25a9a76 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 17:23:08 +0000 Subject: [PATCH 2/4] refactor(client-runtime): fold the offline recheck note into the loop comment Co-Authored-By: Claude Opus 5.5 --- packages/client-runtime/src/connection/supervisor.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/client-runtime/src/connection/supervisor.ts b/packages/client-runtime/src/connection/supervisor.ts index 7ab93e1cf8438..a1d444ef5515c 100644 --- a/packages/client-runtime/src/connection/supervisor.ts +++ b/packages/client-runtime/src/connection/supervisor.ts @@ -45,8 +45,6 @@ import { const RETRY_BASE_DELAY_MS = 1_000; const RETRY_MAX_DELAY_MS = 300_000; -// The platform's offline report can stay wrong after the network is back, so -// an offline connection still tries this often instead of waiting for a change. const OFFLINE_RECHECK_MS = 30_000; const SESSION_LOSS_RETRY_DELAY_MS = 250; // Someone is approving this device on the host; check back soon rather than climbing the ladder. @@ -1219,7 +1217,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( continue; } // The platform's offline report can stay wrong after the network is back, - // so an explicit retry still tries instead of waiting for it to change. + // so an explicit retry, or every OFFLINE_RECHECK_MS, still tries once. const ignoreOffline = replacing || retryRequested || offlineRecheckDue; if (currentIntent.network === "offline" && !ignoreOffline) { yield* clearLease; From eff788cfb1d6a123f6e52f2337a7ac16be2a1555 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 17:25:32 +0000 Subject: [PATCH 3/4] fix(client-runtime): the offline recheck only bypasses an offline report Co-Authored-By: Claude Opus 5.5 --- packages/client-runtime/src/connection/supervisor.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/client-runtime/src/connection/supervisor.ts b/packages/client-runtime/src/connection/supervisor.ts index a1d444ef5515c..432b206b6daec 100644 --- a/packages/client-runtime/src/connection/supervisor.ts +++ b/packages/client-runtime/src/connection/supervisor.ts @@ -1218,7 +1218,8 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( } // The platform's offline report can stay wrong after the network is back, // so an explicit retry, or every OFFLINE_RECHECK_MS, still tries once. - const ignoreOffline = replacing || retryRequested || offlineRecheckDue; + const ignoreOffline = + replacing || retryRequested || (offlineRecheckDue && currentIntent.network === "offline"); if (currentIntent.network === "offline" && !ignoreOffline) { yield* clearLease; yield* setState(offlineState(currentIntent, generation, failureCount + 1, latestFailure)); From c47976ec8f66d4b8802efc122ae204451b4fe25b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 17:33:28 +0000 Subject: [PATCH 4/4] fix(client-runtime): a failed offline recheck stays offline instead of backing off Co-Authored-By: Claude Opus 5.5 --- .../src/connection/supervisor.test.ts | 17 ++++++++++++++--- .../client-runtime/src/connection/supervisor.ts | 9 +++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/client-runtime/src/connection/supervisor.test.ts b/packages/client-runtime/src/connection/supervisor.test.ts index ba6115d0ae07a..19ea686c6ee54 100644 --- a/packages/client-runtime/src/connection/supervisor.test.ts +++ b/packages/client-runtime/src/connection/supervisor.test.ts @@ -434,17 +434,28 @@ describe("EnvironmentSupervisor", () => { it.effect("still tries while the device keeps reporting offline", () => Effect.gen(function* () { - const harness = yield* makeHarness({ networkStatus: "offline" }); + const harness = yield* makeHarness({ + networkStatus: "offline", + prepare: (attempt) => + attempt === 1 ? Effect.fail(transient()) : Effect.succeed(PREPARED_CONNECTION), + }); const supervisor = yield* EnvironmentSupervisor.make(RELAY_ENTRY, { initiallyDesired: true, }).pipe(Effect.provide(harness.dependencies)); yield* awaitState(supervisor.state, (state) => state.phase === "offline"); expect(yield* Ref.get(harness.prepareCount)).toBe(0); - // The report never changes, but the host is reachable. + // A recheck that fails while still reported offline stays offline, not backoff. yield* TestClock.adjust("30 seconds"); - yield* awaitState(supervisor.state, (state) => state.phase === "connected"); + yield* awaitState( + supervisor.state, + (state) => state.phase === "offline" && state.attempt === 1 && state.lastFailure === null, + ); expect(yield* Ref.get(harness.prepareCount)).toBe(1); + // The report never changes, but the host becomes reachable. + yield* TestClock.adjust("30 seconds"); + yield* awaitState(supervisor.state, (state) => state.phase === "connected"); + expect(yield* Ref.get(harness.prepareCount)).toBe(2); }), ); diff --git a/packages/client-runtime/src/connection/supervisor.ts b/packages/client-runtime/src/connection/supervisor.ts index 432b206b6daec..2db47f8c7a5f2 100644 --- a/packages/client-runtime/src/connection/supervisor.ts +++ b/packages/client-runtime/src/connection/supervisor.ts @@ -1218,8 +1218,9 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( } // The platform's offline report can stay wrong after the network is back, // so an explicit retry, or every OFFLINE_RECHECK_MS, still tries once. - const ignoreOffline = - replacing || retryRequested || (offlineRecheckDue && currentIntent.network === "offline"); + const recheck = + offlineRecheckDue && !replacing && !retryRequested && currentIntent.network === "offline"; + const ignoreOffline = replacing || retryRequested || recheck; if (currentIntent.network === "offline" && !ignoreOffline) { yield* clearLease; yield* setState(offlineState(currentIntent, generation, failureCount + 1, latestFailure)); @@ -1257,6 +1258,10 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( } continue; } + // A failed recheck while still reported offline is not a connection failure. + if (recheck && !outcome.established && (yield* Ref.get(intent)).network === "offline") { + continue; + } const attemptSpan: Option.Option = outcome.failure.attemptSpan; const error: ConnectionAttemptError = outcome.failure.error;