Skip to content

Commit bd0e3ad

Browse files
only21milclaude
andcommitted
fix(client-runtime): an offline report no longer cancels an explicit retry
When retryNow interrupts a running attempt and the platform then reports offline, the queued NetworkChanged reached the new attempt's interrupt waiter and cancelled it, even though that attempt ignores the offline report. The loop went back to the offline wait, so the retry never connected. The interrupt waiter now gets the attempt's offline bypass and ignores an offline report only when the bypass is on; other attempts still stop on it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 55bc1bb commit bd0e3ad

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,39 @@ describe("EnvironmentSupervisor", () => {
359359
}),
360360
);
361361

362+
it.effect.each([
363+
{ label: "cancels connection setup", retry: false, phase: "offline", sessions: 0 },
364+
{ label: "does not cancel an explicit retry", retry: true, phase: "connected", sessions: 1 },
365+
])("an offline report during setup $label", ({ retry, phase, sessions }) =>
366+
Effect.gen(function* () {
367+
const firstAttemptStarted = yield* Deferred.make<void>();
368+
const harness = yield* makeHarness({
369+
prepare: () =>
370+
Deferred.succeed(firstAttemptStarted, undefined).pipe(
371+
Effect.andThen(Effect.sleep("1 second")),
372+
Effect.as(PREPARED_CONNECTION),
373+
),
374+
});
375+
const supervisor = yield* EnvironmentSupervisor.make(RELAY_ENTRY, {
376+
initiallyDesired: true,
377+
}).pipe(Effect.provide(harness.dependencies));
378+
379+
yield* Deferred.await(firstAttemptStarted);
380+
if (retry) {
381+
yield* supervisor.retryNow;
382+
}
383+
yield* harness.setNetworkStatus("offline");
384+
yield* TestClock.adjust("1 second");
385+
const settled = yield* awaitState(
386+
supervisor.state,
387+
(state) => state.phase === "connected" || state.phase === "offline",
388+
);
389+
390+
expect(settled.phase).toBe(phase);
391+
expect(yield* Ref.get(harness.sessionCount)).toBe(sessions);
392+
}),
393+
);
394+
362395
it.effect("keeps the latest failure visible throughout the next connection attempt", () =>
363396
Effect.gen(function* () {
364397
const harness = yield* makeHarness({

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* (
505505
);
506506
});
507507

508-
const waitForEstablishmentInterrupt = Effect.fnUntraced(function* () {
508+
const waitForEstablishmentInterrupt = Effect.fnUntraced(function* (ignoreOffline: boolean) {
509509
for (;;) {
510510
const next = yield* Queue.take(signals);
511511
switch (next._tag) {
@@ -519,7 +519,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* (
519519
}
520520
break;
521521
case "NetworkChanged":
522-
if (next.network === "offline") {
522+
if (next.network === "offline" && !ignoreOffline) {
523523
return false;
524524
}
525525
break;
@@ -695,7 +695,7 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* (
695695
exit,
696696
})),
697697
),
698-
waitForEstablishmentInterrupt().pipe(
698+
waitForEstablishmentInterrupt(ignoreOffline).pipe(
699699
Effect.map((resetRetry): EstablishmentEvent => ({
700700
_tag: "Interrupted",
701701
resetRetry,

0 commit comments

Comments
 (0)