Skip to content

Commit 4bd4f72

Browse files
shivamhwpclaude
andcommitted
fix(connection): keep the post-wake retry through an offline period
A long wake armed the one 3 second retry, but the offline branch cleared it, so when the socket died with the network the first attempt after the network came back had no retry and could wait out the full setup timeout. A long wake received while already offline or blocked never armed it. The offline branch now leaves the flag alone, and waiting there or while blocked arms it on a long wake, as waiting in backoff already did. An explicit disconnect and a healthy probe still clear it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 77f057c commit 4bd4f72

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎packages/client-runtime/src/connection/supervisor.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ describe("EnvironmentSupervisor", () => {
550550
it.effect.each([
551551
{ from: "connected", stall: "handshake" },
552552
{ from: "backoff", stall: "preparation" },
553+
{ from: "connected, then offline", stall: "preparation" },
554+
{ from: "offline", stall: "handshake" },
553555
] as const)(
554556
"retries a $stall that stalls after a long resume from $from once, at 3 seconds",
555557
({ from, stall }) =>
@@ -570,13 +572,26 @@ describe("EnvironmentSupervisor", () => {
570572
initiallyDesired: true,
571573
}).pipe(Effect.provide(harness.dependencies));
572574
yield* awaitState(supervisor.state, (state) => state.phase === "connected");
575+
// The socket dies with the network, so the supervisor waits offline.
576+
const goOffline = harness
577+
.setNetworkStatus("offline")
578+
.pipe(
579+
Effect.andThen(harness.closeLatestSession()),
580+
Effect.andThen(awaitState(supervisor.state, (state) => state.phase === "offline")),
581+
);
573582
if (from === "backoff") {
574583
yield* harness.closeLatestSession();
575584
yield* awaitState(supervisor.state, (state) => state.phase === "backoff");
576585
}
586+
if (from === "offline") yield* goOffline;
577587

578588
yield* harness.wake("application-active-long");
579589
if (from === "connected") yield* TestClock.adjust("3 seconds");
590+
if (from === "connected, then offline" || from === "offline") {
591+
yield* TestClock.adjust("0 millis");
592+
if (from === "connected, then offline") yield* goOffline;
593+
yield* harness.setNetworkStatus("online");
594+
}
580595
yield* Deferred.await(stalled);
581596
yield* TestClock.adjust("2999 millis");
582597
expect(yield* Ref.get(harness.prepareCount)).toBe(2);

‎packages/client-runtime/src/connection/supervisor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* (
11151115

11161116
const waitForSignal = Queue.take(signals).pipe(
11171117
Effect.repeat({ while: (next) => next._tag === "BetterRouteAvailable" }),
1118+
Effect.tap((next) => (isLongResume(next) ? Ref.set(wakeRecoveryPending, true) : Effect.void)),
11181119
Effect.map(
11191120
(next) => next._tag === "Wakeup" && ConnectionWakeups.resetsRetryBackoff(next.reason),
11201121
),
@@ -1148,7 +1149,6 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* (
11481149
continue;
11491150
}
11501151
if (currentIntent.network === "offline" && !replacing) {
1151-
yield* Ref.set(wakeRecoveryPending, false);
11521152
yield* clearLease;
11531153
yield* setState(offlineState(currentIntent, generation, failureCount + 1, latestFailure));
11541154
const applicationActivated = yield* waitForSignal;

0 commit comments

Comments
 (0)