The best way to control Claude Code, Codex and more from any computer or phone
fix(server): browser profiles reported by one client survive another client's report (#21745)
Co-authored-by: maria-rcks <maria@kuuro.net>
Ibrahim Elkamali committed
Oct 30, 2026 at 23:29 UTC
50cdc2440afaa9a1fb3c924d823f37444587ab71
5 files changed
+106
-22
apps/server/src/preview/ServerBrowser.test.ts
+49
-2
@@ -16,6 +16,8 @@ import {
16
type PreviewAutomationStatus,
17
} from "@t3tools/contracts";
18
import * as Effect from "effect/Effect";
19
+import * as Exit from "effect/Exit";
20
+import * as Scope from "effect/Scope";
21
import * as Fiber from "effect/Fiber";
22
import * as FileSystem from "effect/FileSystem";
23
import * as Layer from "effect/Layer";
@@ -614,8 +616,9 @@ it.live.each([
616
Effect.scoped(
617
Effect.gen(function* () {
618
const { browser, broker, tabId } = yield* ready;
619
+ const reportProfiles = yield* browser.profileReporter;
620
for (const recordingFrameRate of reports) {
618
- yield* browser.reportProfiles({
621
+ yield* reportProfiles({
622
profiles: [],
623
defaultProfileId: "default",
624
...(recordingFrameRate === undefined ? {} : { recordingFrameRate }),
@@ -1453,7 +1456,8 @@ it.live(
1456
const broker = yield* Broker.PreviewAutomationBroker;
1457
const manager = yield* Manager.PreviewManager;
1458
yield* Effect.yieldNow;
1456
- yield* browser.reportProfiles({
1459
+ const reportProfiles = yield* browser.profileReporter;
1460
+ yield* reportProfiles({
1461
profiles: [{ id: "profile-work", name: "Work", kind: "persistent" }],
1462
defaultProfileId: "profile-work",
1463
});
@@ -1498,3 +1502,46 @@ it.live(
1502
}),
1503
).pipe(Effect.provide(layer)),
1504
);
1505
+
1506
+it.live("profiles reported by one client survive another client's report", () =>
1507
+ Effect.scoped(
1508
+ Effect.gen(function* () {
1509
+ const { browser, broker } = yield* ready;
1510
+ contextRequests.length = 0;
1511
+ const work = { id: "profile-work", name: "Work", kind: "persistent" } as const;
1512
+ const shared = { id: "profile-shared", name: "Shared", kind: "persistent" } as const;
1513
+ const openWork = () =>
1514
+ broker.invoke<PreviewAutomationStatus>({
1515
+ scope,
1516
+ operation: "open",
1517
+ input: { reuseExistingTab: false, show: false, profileId: work.id },
1518
+ });
1519
+ const reportFromA = yield* browser.profileReporter;
1520
+ const clientB = yield* Scope.make();
1521
+ const reportFromB = yield* browser.profileReporter.pipe(
1522
+ Effect.provideService(Scope.Scope, clientB),
1523
+ );
1524
+ yield* reportFromA({ profiles: [work, shared], defaultProfileId: work.id });
1525
+ yield* reportFromB({ profiles: [shared], defaultProfileId: shared.id });
1526
+ expect(yield* openWork()).toMatchObject({
1527
+ defaultProfileId: shared.id,
1528
+ profiles: [
1529
+ { id: "default", name: "Default" },
1530
+ { id: "incognito", name: "Incognito", incognito: true },
1531
+ { id: work.id, name: work.name },
1532
+ { id: shared.id, name: shared.name },
1533
+ ],
1534
+ });
1535
+ expect(contextRequests).toEqual([{ profileId: work.id, isolated: false }]);
1536
+ yield* Scope.close(clientB, Exit.void);
1537
+ expect(yield* openWork()).toMatchObject({ defaultProfileId: work.id });
1538
+ yield* reportFromA({ profiles: [shared], defaultProfileId: shared.id });
1539
+ const removed = yield* openWork().pipe(Effect.flip);
1540
+ expect(removed).toMatchObject({
1541
+ _tag: "PreviewAutomationExecutionError",
1542
+ reason:
1543
+ 'No browser profile is named "profile-work". Use one of: Default (id default), Incognito (id incognito), Shared (id profile-shared).',
1544
+ });
1545
+ }),
1546
+ ).pipe(Effect.provide(layer)),
1547
+);
apps/server/src/preview/ServerBrowser.ts
+45
-12
@@ -210,6 +210,8 @@ export interface ServerBrowserViewer {
210
readonly input: (message: unknown) => Effect.Effect<void>;
211
}
212
213
+export type ProfileReporter = (input: PreviewReportProfilesInput) => Effect.Effect<void>;
214
+
215
export class ServerBrowser extends Context.Service<
216
ServerBrowser,
217
{
@@ -244,7 +246,7 @@ export class ServerBrowser extends Context.Service<
246
247
readonly clearProfile: (profileId: string) => Effect.Effect<void, PreviewClearProfileError>;
248
247
- readonly reportProfiles: (input: PreviewReportProfilesInput) => Effect.Effect<void>;
249
+ readonly profileReporter: Effect.Effect<ProfileReporter, never, Scope.Scope>;
250
}
251
>()("t3/preview/ServerBrowser") {}
252
@@ -1384,6 +1386,8 @@ const make = Effect.gen(function* () {
1386
? ("agent" as const)
1387
: ("unclaimed" as const);
1388
1389
+ const reportsByClient = new Map<number, PreviewReportProfilesInput>();
1390
+ let nextClient = 0;
1391
let reportedProfiles: {
1392
readonly profiles: ReadonlyArray<BrowserProfile>;
1393
readonly defaultProfileId: string;
@@ -1392,16 +1396,45 @@ const make = Effect.gen(function* () {
1396
// last report outlives the client, which lets agents record while no client is connected.
1397
let recordingFrameRate = DEFAULT_BROWSER_RECORDING_FRAME_RATE;
1398
1395
- const reportProfiles: ServerBrowser["Service"]["reportProfiles"] = (input) =>
1396
- Effect.sync(() => {
1397
- if (input.recordingFrameRate !== undefined) recordingFrameRate = input.recordingFrameRate;
1398
- const profiles = resolveBrowserProfiles(input.profiles);
1399
- reportedProfiles = {
1400
- profiles,
1401
- defaultProfileId:
1402
- findBrowserProfile(profiles, input.defaultProfileId)?.id ?? DEFAULT_BROWSER_PROFILE_ID,
1403
- };
1404
- });
1399
+ // Each client reports only the profiles in its own settings, so the catalog is
1400
+ // their union while they stay connected. The last catalog stays usable after
1401
+ // every client disconnects, as a single report did before.
1402
+ const rebuildReportedProfiles = () => {
1403
+ const byId = new Map<string, BrowserProfile>();
1404
+ let latest: PreviewReportProfilesInput | undefined;
1405
+ for (const report of reportsByClient.values()) {
1406
+ for (const profile of report.profiles) byId.set(profile.id, profile);
1407
+ latest = report;
1408
+ }
1409
+ if (latest === undefined) return;
1410
+ const profiles = resolveBrowserProfiles([...byId.values()]);
1411
+ reportedProfiles = {
1412
+ profiles,
1413
+ defaultProfileId:
1414
+ findBrowserProfile(profiles, latest.defaultProfileId)?.id ?? DEFAULT_BROWSER_PROFILE_ID,
1415
+ };
1416
+ };
1417
+
1418
+ const profileReporter: ServerBrowser["Service"]["profileReporter"] = Effect.acquireRelease(
1419
+ Effect.sync(() => nextClient++),
1420
+ (client) =>
1421
+ Effect.sync(() => {
1422
+ reportsByClient.delete(client);
1423
+ rebuildReportedProfiles();
1424
+ }),
1425
+ ).pipe(
1426
+ Effect.map(
1427
+ (client): ProfileReporter =>
1428
+ (input) =>
1429
+ Effect.sync(() => {
1430
+ if (input.recordingFrameRate !== undefined)
1431
+ recordingFrameRate = input.recordingFrameRate;
1432
+ reportsByClient.delete(client);
1433
+ reportsByClient.set(client, input);
1434
+ rebuildReportedProfiles();
1435
+ }),
1436
+ ),
1437
+ );
1438
1439
const profileStatus = () => {
1440
const profiles = reportedProfiles?.profiles ?? BUILT_IN_BROWSER_PROFILES;
@@ -2618,7 +2651,7 @@ const make = Effect.gen(function* () {
2651
return ServerBrowser.of({
2652
attachViewer,
2653
clearProfile,
2621
- reportProfiles,
2654
+ profileReporter,
2655
openDownload,
2656
answerFileChooser,
2657
});
apps/server/src/preview/ServerBrowserStream.test.ts
+6
-6
@@ -88,7 +88,7 @@ it.effect.each([
88
});
89
const browser = ServerBrowser.ServerBrowser.of({
90
clearProfile: () => Effect.void,
91
- reportProfiles: () => Effect.void,
91
+ profileReporter: Effect.succeed(() => Effect.void),
92
openDownload: () => Effect.succeedNone,
93
answerFileChooser: () => Effect.succeed(false),
94
attachViewer: (input) =>
@@ -163,7 +163,7 @@ it.effect("sends replies ahead of stale frames and only the newest frame after a
163
});
164
const browser = ServerBrowser.ServerBrowser.of({
165
clearProfile: () => Effect.void,
166
- reportProfiles: () => Effect.void,
166
+ profileReporter: Effect.succeed(() => Effect.void),
167
openDownload: () => Effect.succeedNone,
168
answerFileChooser: () => Effect.succeed(false),
169
attachViewer: () => Effect.succeed({ output, input: () => Effect.void }),
@@ -234,7 +234,7 @@ it.effect.each([
234
let attachments = 0;
235
const browser = ServerBrowser.ServerBrowser.of({
236
clearProfile: () => Effect.void,
237
- reportProfiles: () => Effect.void,
237
+ profileReporter: Effect.succeed(() => Effect.void),
238
openDownload: () => Effect.succeedNone,
239
answerFileChooser: () => Effect.succeed(false),
240
attachViewer: () => {
@@ -275,7 +275,7 @@ it.effect("serves a tab's download only to an authorized session", () =>
275
const requests: Array<unknown> = [];
276
const browser = ServerBrowser.ServerBrowser.of({
277
clearProfile: () => Effect.void,
278
- reportProfiles: () => Effect.void,
278
+ profileReporter: Effect.succeed(() => Effect.void),
279
openDownload: (input) =>
280
Effect.sync(() => {
281
requests.push(input);
@@ -323,7 +323,7 @@ it.effect("passes uploaded files to the page's open picker and needs operate sco
323
const answers: Array<{ chooserId: string; files: Array<{ name: string; text: string }> }> = [];
324
const browser = ServerBrowser.ServerBrowser.of({
325
clearProfile: () => Effect.void,
326
- reportProfiles: () => Effect.void,
326
+ profileReporter: Effect.succeed(() => Effect.void),
327
openDownload: () => Effect.succeedNone,
328
answerFileChooser: (input) =>
329
Effect.sync(() => {
@@ -392,7 +392,7 @@ it.effect.each([
392
Effect.gen(function* () {
393
const browser = ServerBrowser.ServerBrowser.of({
394
clearProfile: () => Effect.void,
395
- reportProfiles: () => Effect.void,
395
+ profileReporter: Effect.succeed(() => Effect.void),
396
openDownload: () => Effect.succeedNone,
397
answerFileChooser: () => Effect.succeed(false),
398
attachViewer: () => Effect.fail(new ServerBrowser.ServerBrowserLaunchError({ cause: error })),
apps/server/src/ws.test.ts
+2
@@ -659,6 +659,7 @@ it.effect(
659
},
660
{},
661
yield* ServerBrowser.ServerBrowser,
662
+ () => Effect.void,
663
).pipe(Layer.provide(configRpcServices)),
664
),
665
);
@@ -826,6 +827,7 @@ it.effect("on-demand clients get provider config without workspace snapshots", (
827
},
828
{},
829
yield* ServerBrowser.ServerBrowser,
830
+ () => Effect.void,
831
).pipe(Layer.provide(configRpcServices)),
832
),
833
);
apps/server/src/ws.ts
+4
-2
@@ -1222,6 +1222,7 @@ export const layerWsRpc = (
1222
currentSession: EnvironmentAuth.AuthenticatedSession,
1223
clientAnalyticsProps: Readonly<Record<string, unknown>>,
1224
serverBrowser: ServerBrowser.ServerBrowser["Service"],
1225
+ reportProfiles: ServerBrowser.ProfileReporter,
1226
) =>
1227
Layer.effectContext(
1228
Effect.gen(function* () {
@@ -3032,7 +3033,7 @@ export const layerWsRpc = (
3033
[WS_METHODS.previewClose]: (input) => previewManager.close(input),
3034
[WS_METHODS.previewList]: (input) => previewManager.list(input),
3035
[WS_METHODS.previewClearProfile]: (input) => serverBrowser.clearProfile(input.profileId),
3035
- [WS_METHODS.previewReportProfiles]: (input) => serverBrowser.reportProfiles(input),
3036
+ [WS_METHODS.previewReportProfiles]: (input) => reportProfiles(input),
3037
[WS_METHODS.previewReportStatus]: (input) => previewManager.reportStatus(input),
3038
[WS_METHODS.subscribePreviewEvents]: (_input) => previewManager.events,
3039
[WS_METHODS.deviceConfigure]: (input) => deviceService.configure(input),
@@ -3305,6 +3306,7 @@ export const layer = Layer.unwrap(
3306
);
3307
const clientAnalyticsProps = readClientAnalyticsProps(request);
3308
yield* analytics.recordOwners(readClientOwners(request), "client");
3309
+ const reportProfiles = yield* serverBrowser.profileReporter;
3310
const rpcWebSocketHttpEffect = yield* Effect.gen(function* () {
3311
const { protocol, httpEffect } = yield* RpcServer.makeProtocolWithHttpEffectWebsocket;
3312
yield* RpcServer.make(ServerWsRpcGroup, WS_RPC_SERVER_OPTIONS).pipe(
@@ -3334,7 +3336,7 @@ export const layer = Layer.unwrap(
3336
return httpEffect;
3337
}).pipe(
3338
Effect.provide(
3337
- layerWsRpc(session, clientAnalyticsProps, serverBrowser).pipe(
3339
+ layerWsRpc(session, clientAnalyticsProps, serverBrowser, reportProfiles).pipe(
3340
Layer.provideMerge(RpcSerialization.layerJson),
3341
// Handler-context reporters see only request defects, not server-wide defects.
3342
Layer.provide(DefectReporter.layer),