From 58d1c1c58689d06cabe421577051ba1cd982f7ca Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 2 Nov 2026 13:31:32 +0000 Subject: [PATCH 1/5] test(client-runtime): reproduce #29323, primary environment parks offline These tests reproduce #29323: a supervisor for the primary connection target, created while the browser reports offline, parks in `offline` instead of connecting to the server that served the page. The existing offline-wait test now runs against a relay entry, which keeps waiting. Co-Authored-By: Claude Opus 5.5 --- .../src/connection/supervisor.test.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/client-runtime/src/connection/supervisor.test.ts b/packages/client-runtime/src/connection/supervisor.test.ts index 66d151043b11..f9e2db57aeca 100644 --- a/packages/client-runtime/src/connection/supervisor.test.ts +++ b/packages/client-runtime/src/connection/supervisor.test.ts @@ -312,7 +312,7 @@ describe("EnvironmentSupervisor", () => { it.effect("waits while offline and connects immediately when the network returns", () => Effect.gen(function* () { const harness = yield* makeHarness({ networkStatus: "offline" }); - const supervisor = yield* EnvironmentSupervisor.make(TARGET_ENTRY, { + const supervisor = yield* EnvironmentSupervisor.make(RELAY_ENTRY, { initiallyDesired: true, }).pipe(Effect.provide(harness.dependencies)); @@ -334,6 +334,23 @@ describe("EnvironmentSupervisor", () => { }), ); + it.effect("connects to the primary environment while the device reports offline", () => + Effect.gen(function* () { + const harness = yield* makeHarness({ networkStatus: "offline" }); + const supervisor = yield* EnvironmentSupervisor.make(TARGET_ENTRY, { + initiallyDesired: true, + }).pipe(Effect.provide(harness.dependencies)); + + const settled = yield* awaitState( + supervisor.state, + (state) => state.phase === "connected" || state.phase === "offline", + ); + + expect(settled).toMatchObject({ phase: "connected", attempt: 1, lastFailure: null }); + expect(yield* Ref.get(harness.prepareCount)).toBe(1); + }), + ); + it.effect("keeps the latest failure visible throughout the next connection attempt", () => Effect.gen(function* () { const harness = yield* makeHarness({ From b40319a24c1e07b386bd0710f569b43905dbc098 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 2 Nov 2026 13:35:04 +0000 Subject: [PATCH 2/5] fix(client-runtime): connect to the primary environment while the device reports offline The supervisor gated every target on the browser's network report, so a wrong `navigator.onLine === false` parked the primary environment (the server that served the page, or desktop's loopback backend) in offline, Reconnect did nothing, and the diagnosis blamed the device. The primary target's intent now reads an offline report as unknown, so it connects and retries regardless, while the report itself still probes its live session as before. Relay, bearer and SSH targets keep waiting while offline. Fixes pingdotgg/t3code#29323 Co-Authored-By: Claude Opus 5.5 --- .../src/connection/supervisor.test.ts | 23 +++++++++++++++++++ .../src/connection/supervisor.ts | 16 +++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/packages/client-runtime/src/connection/supervisor.test.ts b/packages/client-runtime/src/connection/supervisor.test.ts index f9e2db57aeca..90444f312ac5 100644 --- a/packages/client-runtime/src/connection/supervisor.test.ts +++ b/packages/client-runtime/src/connection/supervisor.test.ts @@ -768,6 +768,29 @@ describe("EnvironmentSupervisor", () => { }).pipe(Effect.provide(TestClock.layer())), ); + it.effect("checks the primary environment's socket when the device reports offline", () => + Effect.gen(function* () { + const harness = yield* makeSilentSocketHarness(); + const target = new PrimaryConnectionTarget({ + ...TARGET, + httpBaseUrl: "http://127.0.0.1:3773", + wsBaseUrl: "ws://127.0.0.1:3773", + }); + const supervisor = yield* EnvironmentSupervisor.make( + { ...TARGET_ENTRY, target }, + { initiallyDesired: true }, + ).pipe(Effect.provide(harness.dependencies)); + + yield* awaitState(supervisor.state, (state) => state.phase === "connected"); + yield* harness.setNetworkStatus("offline"); + yield* TestClock.adjust("500 millis"); + yield* awaitState( + supervisor.state, + (state) => state.phase === "connected" && state.generation === 2, + ); + }).pipe(Effect.provide(TestClock.layer())), + ); + it.effect("replaces a remote socket after a long resume while the network reports offline", () => Effect.gen(function* () { const harness = yield* makeSilentSocketHarness(); diff --git a/packages/client-runtime/src/connection/supervisor.ts b/packages/client-runtime/src/connection/supervisor.ts index 212381921961..f5c20859349c 100644 --- a/packages/client-runtime/src/connection/supervisor.ts +++ b/packages/client-runtime/src/connection/supervisor.ts @@ -283,9 +283,14 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( const connectivity = yield* Connectivity.Connectivity; const driver = yield* ConnectionDriver.ConnectionDriver; const wakeups = yield* ConnectionWakeups.ConnectionWakeups; + // The primary environment served this client, so the device reporting + // offline (often wrongly) never parks it. The report still probes its live + // session, like any other network change. + const targetNetwork = (network: NetworkStatus): NetworkStatus => + network === "offline" && target._tag === "PrimaryConnectionTarget" ? "unknown" : network; const initialIntent: SupervisorIntent = { desired: options?.initiallyDesired ?? false, - network: yield* connectivity.status, + network: targetNetwork(yield* connectivity.status), }; const intent = yield* Ref.make(initialIntent); const signals = yield* Queue.unbounded(); @@ -1152,9 +1157,12 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( yield* connectivity.changes.pipe( Stream.runForEach((network) => - Ref.modify(intent, (current) => - current.network === network ? [false, current] : ([true, { ...current, network }] as const), - ).pipe( + Ref.modify(intent, (current) => { + const next = targetNetwork(network); + return current.network === next + ? [false, current] + : ([true, { ...current, network: next }] as const); + }).pipe( Effect.flatMap((changed) => changed ? (network === "offline" ? Effect.void : forgetSilentRoutes).pipe( From a0a30f9615cd6c5f93a1d4818f00587a4bc70b6e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 2 Nov 2026 13:50:24 +0000 Subject: [PATCH 3/5] test(client-runtime): primary state does not report the device offline Co-Authored-By: Claude Opus 5.5 --- packages/client-runtime/src/connection/supervisor.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/client-runtime/src/connection/supervisor.test.ts b/packages/client-runtime/src/connection/supervisor.test.ts index 90444f312ac5..7e3d37e9b636 100644 --- a/packages/client-runtime/src/connection/supervisor.test.ts +++ b/packages/client-runtime/src/connection/supervisor.test.ts @@ -346,7 +346,12 @@ describe("EnvironmentSupervisor", () => { (state) => state.phase === "connected" || state.phase === "offline", ); - expect(settled).toMatchObject({ phase: "connected", attempt: 1, lastFailure: null }); + expect(settled).toMatchObject({ + phase: "connected", + network: "unknown", + attempt: 1, + lastFailure: null, + }); expect(yield* Ref.get(harness.prepareCount)).toBe(1); }), ); From 37441e905194b062345c76d81caacd00d77ef5e5 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 2 Nov 2026 13:57:34 +0000 Subject: [PATCH 4/5] test(client-runtime): long-resume offline probe runs on a non-primary entry Co-Authored-By: Claude Opus 5.5 --- packages/client-runtime/src/connection/supervisor.test.ts | 2 +- packages/client-runtime/src/connection/supervisor.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/client-runtime/src/connection/supervisor.test.ts b/packages/client-runtime/src/connection/supervisor.test.ts index 7e3d37e9b636..bdc64f8ab5f2 100644 --- a/packages/client-runtime/src/connection/supervisor.test.ts +++ b/packages/client-runtime/src/connection/supervisor.test.ts @@ -1004,7 +1004,7 @@ describe("EnvironmentSupervisor", () => { const harness = yield* makeHarness({ probe: (attempt) => (attempt === 1 ? Effect.never : Effect.void), }); - const supervisor = yield* EnvironmentSupervisor.make(TARGET_ENTRY, { + const supervisor = yield* EnvironmentSupervisor.make(LAN_ENTRY, { initiallyDesired: true, }).pipe(Effect.provide(harness.dependencies)); diff --git a/packages/client-runtime/src/connection/supervisor.ts b/packages/client-runtime/src/connection/supervisor.ts index f5c20859349c..d025cfb24e2d 100644 --- a/packages/client-runtime/src/connection/supervisor.ts +++ b/packages/client-runtime/src/connection/supervisor.ts @@ -283,9 +283,9 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( const connectivity = yield* Connectivity.Connectivity; const driver = yield* ConnectionDriver.ConnectionDriver; const wakeups = yield* ConnectionWakeups.ConnectionWakeups; - // The primary environment served this client, so the device reporting - // offline (often wrongly) never parks it. The report still probes its live - // session, like any other network change. + // The primary environment served this client or runs beside it on loopback, + // so the device reporting offline (often wrongly) never parks it. The report + // still probes its live session, like any other network change. const targetNetwork = (network: NetworkStatus): NetworkStatus => network === "offline" && target._tag === "PrimaryConnectionTarget" ? "unknown" : network; const initialIntent: SupervisorIntent = { From 9122df29a18e12524db7853684333b4f4de14b14 Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Mon, 2 Nov 2026 18:07:12 -0800 Subject: [PATCH 5/5] fix(client-runtime): primary setup survives an offline report and restarts when the network returns Co-Authored-By: Claude Opus 5.5 --- .../src/connection/supervisor.test.ts | 26 +++++++++++++++++++ .../src/connection/supervisor.ts | 13 ++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/client-runtime/src/connection/supervisor.test.ts b/packages/client-runtime/src/connection/supervisor.test.ts index b6b5fe8c89af..b4fc6955366a 100644 --- a/packages/client-runtime/src/connection/supervisor.test.ts +++ b/packages/client-runtime/src/connection/supervisor.test.ts @@ -368,6 +368,32 @@ describe("EnvironmentSupervisor", () => { }), ); + it.effect( + "keeps a primary attempt through an offline report and restarts it when the network returns", + () => + Effect.gen(function* () { + const started = yield* Deferred.make(); + const harness = yield* makeHarness({ + prepare: (attempt) => + attempt === 1 + ? Deferred.succeed(started, undefined).pipe(Effect.andThen(Effect.never)) + : Effect.succeed(PREPARED_CONNECTION), + }); + const supervisor = yield* EnvironmentSupervisor.make(TARGET_ENTRY, { + initiallyDesired: true, + }).pipe(Effect.provide(harness.dependencies)); + + yield* Deferred.await(started); + yield* harness.setNetworkStatus("offline"); + yield* TestClock.adjust("1 second"); + expect(yield* Ref.get(harness.prepareCount)).toBe(1); + + yield* harness.setNetworkStatus("online"); + yield* awaitState(supervisor.state, (state) => state.phase === "connected"); + expect(yield* Ref.get(harness.prepareCount)).toBe(2); + }).pipe(Effect.provide(TestClock.layer())), + ); + it.effect("keeps the latest failure visible throughout the next connection attempt", () => Effect.gen(function* () { const harness = yield* makeHarness({ diff --git a/packages/client-runtime/src/connection/supervisor.ts b/packages/client-runtime/src/connection/supervisor.ts index f7f1b1a069ba..5f279edf568c 100644 --- a/packages/client-runtime/src/connection/supervisor.ts +++ b/packages/client-runtime/src/connection/supervisor.ts @@ -575,6 +575,9 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( }); const waitForEstablishmentInterrupt = Effect.fnUntraced(function* () { + // A primary attempt keeps running through an offline report, so the + // network returning restarts it in case it stalled meanwhile. + let deviceOffline = (yield* connectivity.status) === "offline"; for (;;) { const next = yield* Queue.take(signals); switch (next._tag) { @@ -582,8 +585,14 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* ( case "RetryRequested": return false; case "NetworkChanged": - if (next.network === "offline") { - return false; + if (target._tag !== "PrimaryConnectionTarget") { + if (next.network === "offline") { + return false; + } + } else if (next.network === "offline") { + deviceOffline = true; + } else if (deviceOffline) { + return true; } break; case "ConnectRequested":