Skip to content

Commit 0de4eac

Browse files
donjor-agent[bot]rsi-pr-agent
authored andcommitted
fix(client-runtime): an attached primary no longer reconnects on every platform poll (#1477)
## What Changed The saved-connection shadow path now installs the attached primary with `retainEquivalentRuntime: true`, the same option upstream's platform path uses. An unchanged primary keeps its live connection across platform polls. ## Why A client-only desktop with a saved connection to its attached server tore down and reopened the primary WebSocket on every 3 s platform poll. The shell and thread streams never settled, so the sidebar and conversation stopped updating while the agent kept working. ```text platform poll (3 s) → reconcilePlatform → SavedConnectionPrecedence.shadow → installEntry(entry) # no retain: close service scope, reconnect ``` The new test in `registry.fork.test.ts` fails 5 of 5 runs without the fix and passes with it. ## UI Changes Both runs used the `qa-desktop` VM and the same steps: client-only desktop, attached to a guest test backend, with a saved connection to the same environment. | Signal | Before, `0.0.45-hyprws.1` | After, this branch at `eafa40241cc` | | --- | --- | --- | | Renderer `/ws` opens in 45 s | 15, one every 3.0 s | 0 | | `t3 project add` on the server | absent 15 s later | shown within 3 s | | Before | After | | --- | --- | | ![A-07-crop.png](https://github.com/user-attachments/assets/b837433e-5a85-4a19-82ae-d61eaef1e391) | ![D-07-crop.png](https://github.com/user-attachments/assets/d430d2d1-42dd-4ec9-9bec-0861735cac04) | Before: https://github.com/user-attachments/assets/f5edfb6b-12ac-4b11-957a-02af1ca949ab After: https://github.com/user-attachments/assets/ea04230c-edb7-4b63-a30d-c6900f055cc3 <details> <summary>Checks</summary> - `vp test run packages/client-runtime/src/connection/registry.fork.test.ts` → 3 passed - `vp test run packages/client-runtime/src/connection/registry.test.ts` → 28 passed - `vp run typecheck` in `packages/client-runtime` → exit 0 - `vp run fork:ci` → exit 0 - `vp run dist:desktop:linux` → exit 0; the built bundle's shadow path passes `retainEquivalentRuntime` </details> ## Checklist - [x] This PR is small and focused - [x] I explained what changed and why - [x] I included before/after screenshots for any UI changes - [x] I included a video for animation/interaction changes Closes #1469 Closes #1472 🤖 claude-opus-5-5 via Claude Code in T3 Code ## Fork trailers Squashes: - bd553c7 fix(client-runtime): an attached primary no longer reconnects on every platform poll (#1477) (#1477) - ead034c fix(fork): adapt fork seams to v0.0.46-nightly.20261005.2689 Fork-Domain: backend-attach Fork-Tier: bugfix Fork-Upstreamable: no
1 parent 49aa471 commit 0de4eac

2 files changed

Lines changed: 51 additions & 5 deletions

File tree

‎packages/client-runtime/src/connection/registry.fork.test.ts‎

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EnvironmentId } from "@t3tools/contracts";
22
import { describe, expect, it } from "@effect/vitest";
3+
import * as Deferred from "effect/Deferred";
34
import * as Effect from "effect/Effect";
45
import * as Layer from "effect/Layer";
56
import * as Option from "effect/Option";
@@ -39,6 +40,8 @@ const makeHarness = (initialTargets: ReadonlyArray<ConnectionTarget>) =>
3940
return next;
4041
});
4142
const network = yield* SubscriptionRef.make<"unknown" | "offline" | "online">("online");
43+
const connects = yield* Ref.make<ReadonlyArray<ConnectionTarget["_tag"]>>([]);
44+
const connected = yield* Deferred.make<void>();
4245
const layer = EnvironmentRegistry.layer.pipe(
4346
Layer.provide(
4447
Layer.mergeAll(
@@ -49,7 +52,13 @@ const makeHarness = (initialTargets: ReadonlyArray<ConnectionTarget>) =>
4952
Layer.succeed(Persistence.ConnectionRegistrationStore, {
5053
register: (registration) =>
5154
edit((next) => next.set(registration.target.environmentId, registration.target)),
52-
remove: (target) => edit((next) => next.delete(target.environmentId)),
55+
setRoutes: (environmentId, routes) =>
56+
edit((next) =>
57+
routes[0] === undefined
58+
? next.delete(environmentId)
59+
: next.set(environmentId, routes[0]),
60+
),
61+
remove: (environmentId) => edit((next) => next.delete(environmentId)),
5362
setEnabled: () => Effect.void,
5463
}),
5564
Layer.succeed(ConnectionProfileStore.ConnectionProfileStore, {
@@ -77,7 +86,15 @@ const makeHarness = (initialTargets: ReadonlyArray<ConnectionTarget>) =>
7786
changes: SubscriptionRef.changes(network),
7887
}),
7988
Layer.succeed(ConnectionWakeups.ConnectionWakeups, { changes: Stream.never }),
80-
Layer.succeed(ConnectionDriver.ConnectionDriver, { connect: () => Effect.never }),
89+
Layer.succeed(ConnectionDriver.ConnectionDriver, {
90+
connect: (entry) =>
91+
Ref.update(connects, (current) => [...current, entry.target._tag]).pipe(
92+
Effect.andThen(Deferred.succeed(connected, undefined)),
93+
Effect.andThen(Effect.never),
94+
),
95+
checkRoute: () => Effect.succeed("unchecked"),
96+
preflight: () => Effect.succeed(true),
97+
}),
8198
Layer.succeed(Persistence.EnvironmentCacheStore, {
8299
loadShell: () => Effect.succeedNone,
83100
saveShell: () => Effect.void,
@@ -96,7 +113,7 @@ const makeHarness = (initialTargets: ReadonlyArray<ConnectionTarget>) =>
96113
),
97114
),
98115
);
99-
return { layer, storedTargets };
116+
return { layer, storedTargets, connects, connected };
100117
});
101118

102119
const withAuth = (savedConnectionsOutrankPrimary: boolean) =>
@@ -137,6 +154,30 @@ describe("EnvironmentRegistry saved-connection precedence RSI-Software/t3code-hy
137154
}),
138155
);
139156

157+
it.effect("an unchanged attached primary keeps its connection across platform polls", () =>
158+
Effect.gen(function* () {
159+
const harness = yield* makeHarness([savedTarget]);
160+
yield* Effect.gen(function* () {
161+
const registry = yield* EnvironmentRegistry.EnvironmentRegistry;
162+
// Each poll builds fresh objects, as the platform poll does in production.
163+
const poll = Effect.suspend(() =>
164+
registry.reconcilePlatform([
165+
new PrimaryConnectionRegistration({
166+
target: new PrimaryConnectionTarget({ ...TARGET }),
167+
}),
168+
]),
169+
);
170+
yield* poll;
171+
yield* Deferred.await(harness.connected);
172+
yield* poll;
173+
yield* poll;
174+
// A reinstalled entry connects from a forked fiber on the next turn.
175+
yield* Effect.yieldNow;
176+
expect(yield* Ref.get(harness.connects)).toEqual(["PrimaryConnectionTarget"]);
177+
}).pipe(Effect.provide(harness.layer), withAuth(true), Effect.scoped);
178+
}),
179+
);
180+
140181
it.effect("without the flag the platform primary still shadows the saved connection", () =>
141182
Effect.gen(function* () {
142183
const harness = yield* makeHarness([savedTarget]);

‎packages/client-runtime/src/connection/savedConnectionPrecedence.fork.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export const savedConnectionsOutrankPrimary = Effect.map(
2020
export const make = Effect.fn("SavedConnectionPrecedence.make")(function* (
2121
enabled: boolean,
2222
platformEnvironmentIds: Ref.Ref<ReadonlySet<EnvironmentId>>,
23-
installEntry: (entry: ConnectionCatalogEntry) => Effect.Effect<void>,
23+
installEntry: (
24+
entry: ConnectionCatalogEntry,
25+
options?: { readonly retainEquivalentRuntime?: boolean },
26+
) => Effect.Effect<void>,
2427
) {
2528
const shadowed = yield* Ref.make<ReadonlyMap<EnvironmentId, ConnectionCatalogEntry>>(new Map());
2629

@@ -41,7 +44,9 @@ export const make = Effect.fn("SavedConnectionPrecedence.make")(function* (
4144
yield* Ref.update(shadowed, (current) => new Map(current).set(environmentId, previous));
4245
}
4346
yield* Ref.update(platformEnvironmentIds, (current) => new Set(current).add(environmentId));
44-
yield* installEntry(entry);
47+
// The platform re-reports the primary on every poll; an unchanged one keeps
48+
// its live connection instead of reconnecting (RSI-Software/t3code-hyprws#1472).
49+
yield* installEntry(entry, { retainEquivalentRuntime: true });
4550
return true;
4651
});
4752

0 commit comments

Comments
 (0)