fix(client-runtime): connection supervisor restarts its background listeners after a defect #39431
Mergedjuliusmarmingemerged 3 commits into
main fromrefs/pull/39431/headmerged by juliusmarminge View on GitHubtanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -2631,0 +2725,21 @@2725+ : Ref.get(lanReachable).pipe(2726+ Effect.map((reachable) => (reachable ? "ready" : "silent")),2727+ ),2728+ ),2729+ ),2730+ prepare: (_attempt, target) => Effect.succeed(preparedFor(target)),2731+ });2732+ const supervisor = yield* EnvironmentSupervisor.make(LAN_THEN_RELAY_ENTRY, {2733+ initiallyDesired: true,2734+ }).pipe(Effect.provide(harness.dependencies));2735+ yield* awaitState(2736+ supervisor.state,2737+ (state) => state.phase === "connected" && state.generation === 1,2738+ );2739+ yield* TestClock.adjust("60 seconds");2740+ expect(yield* Ref.get(preflights)).toBeGreaterThanOrEqual(1);2741+2742+ yield* Ref.set(lanReachable, true);2743+ for (let minute = 0; minute < 60; minute += 1) {2744+ yield* TestClock.adjust("60 seconds");2745+ }
Pusheddb91a01
- @@ -1338,12 +1335,9 @@1338- const next = targetNetwork(network);1339- return current.network === next1340- ? [false, current]1341- : ([true, { ...current, network: next }] as const);1342- }).pipe(1343- Effect.flatMap((changed) =>1344- changed1345- ? (network === "offline" ? Effect.void : forgetSilentRoutes).pipe(1346- Effect.andThen(signal({ _tag: "NetworkChanged", network })),1347- )1348- : Effect.void,1349- ),1335+ // A defect in a background listener would otherwise end it for good, silently.1336+ // Untraced: a span here would stay open for the supervisor's whole lifetime.1337+ const keepRunning = Effect.fnUntraced(1338+ function* (task: string, effect: Effect.Effect<void>, onRestart?: Effect.Effect<void>) {1339+ let current = effect;1340+ while (true) {1341+ const exit = yield* Effect.exit(current);1342+ if (Exit.isSuccess(exit) || Cause.hasInterruptsOnly(exit.cause)) return yield* exit;1343+ yield* Effect.logError("Connection supervisor task failed; restarting it.").pipe(
juliusmarminge merged this003d53a
juliusmarminge closed this
Sign in to join this conversation.


Walkthrough
The connection supervisor now restarts its network listener, wakeup listener, and better-route checker after unexpected failures. After a network-listener restart, it reapplies the current connectivity status. New tests cover recovery after failures in all three tasks.
Changes: Supervisor task recovery
packages/client-runtime/src/connection/supervisor.ts,packages/client-runtime/src/connection/supervisor.test.tsEstimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
Suggested labels:
bugfixSuggested reviewers:
t3dotgg,maria-rcks,mr-neutr0nMerge Risk:
Low · up to
db91aThe change improves recovery of failed connection listeners. A narrow remaining case can still stop recovery if logging itself throws; otherwise no material merge-blocking failure is established. Merge with awareness of this limitation, preferably protecting the diagnostic call first.
Pre-merge checks:
3 · 
1
#39419] Requirements: (1) restart the network listener, wakeup listener, and route checker after unexpected failures, with logging of each failure and cause; (2) reread connectivity.status on network…Full details: Title check
Explanation
The title names the change: the connection supervisor restarts its background listeners after a defect. The raw summary confirms the supervisor now runs its background tasks through keepRunning, which restarts them after non-interruption failures. The title follows the conventional commit form and matches the main change.
Full details: Out of Scope Changes check
Explanation
The PR changes two files, as listed in the raw summary: packages/client-runtime/src/connection/supervisor.ts (+56/-30) and packages/client-runtime/src/connection/supervisor.test.ts (+120/-0). Both changes relate to the requirements of
#39419: the background task restart helper, its call sites, the status reread, and regression tests for the three background tasks. The summary reports no unrelated edits. The incremental change since 2d144e5 could not be read, so this verdict covers the files and changes described in the summary and PR description.Full details: Description check
Explanation
The description covers the required sections of the template. The Problem section states the defect: a background supervisor task stops silently after an unexpected failure, which leaves saved environments offline, delays wakeup checks, or keeps connections on the relay route. The Change section explains the keepRunning helper, which logs, waits one second, and restarts each task, and it explains the status reread on network-listener restart. The Scope section links the issue,
#39419(pingdotgg/t3code). The Verification section lists focused unit tests, a before-and-after comparison on main, a real-browser scenario with evidence, and the test commands with results. It also states what was not checked: wakeup-listener and better-route-checker recovery in the real app, and mobile and desktop shells. The agent attribution is present at the end. The description is thorough and mostly complete. Two points are weaker. The Scope section does not say why a fix needs no issue, but it has a linked issue, so this is not required. The description also notes that the reconnect loop in run() stays forked bare, which is a known gap and not a template violation.Full details: Linked Issues check
Explanation
[
#39419] Requirements: (1) restart the network listener, wakeup listener, and route checker after unexpected failures, with logging of each failure and cause; (2) reread connectivity.status on network-listener restart. The PR summary and description state that all three tasks run through keepRunning, which logs and restarts after a 1 s delay, and that the network listener rereads connectivity.status on restart. The reviewed head file packages/client-runtime/src/connection/supervisor.ts was readable only up to the checkBetterRoutes function (output truncated at 16000 bytes). The keepRunning body, its three call sites, and the status reread were not visible. The whole-PR diff tool failed because changed blobs are missing, so the change since the previous reviewed head (2d144e5 to db91a01) could not be read. The browser evidence covers only the network-listener path. The wakeup and route-checker paths are supported by unit tests described in the PR, but those test results were not independently checked.Resolution
Provide readable source for keepRunning in supervisor.ts at head db91a01, or a diff of the whole PR from base 38bac70 to head db91a01 that includes the keepRunning definition and its uses. Confirm that the wakeup listener and better-route checker call keepRunning, that each failure is logged with the environment and task name, and that connectivity.status is read again when the network listener restarts. Confirm that the regression tests in supervisor.test.ts ('EnvironmentSupervisor background fibers') exercise these three paths.
Finishing Touches
Generate unit tests (beta)