@devries-cameron20 / t3code-1 / commits / 0ce4cbec47
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(preview): isolate tabs for threads sharing a provider session (#18146)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Tdanks2000 committed Oct 18, 2026 at 20:33 UTC 0ce4cbec47dce32e4de1b38e50f2758a7609501c
2 files changed +46 -1
apps/server/src/mcp/PreviewAutomationBroker.test.ts
+40
@@ -1500,3 +1500,43 @@ it.effect("keeps the host connected when a background status read times out", ()
1500 }),
1501 ),
1502 );
1503 +
1504 +it.effect("keeps each thread's current tab when threads share a provider session", () =>
1505 + Effect.scoped(
1506 + Effect.gen(function* () {
1507 + const broker = yield* makeBroker;
1508 + const routed: Array<RoutedRequest> = [];
1509 + const requests = requestsFrom(yield* broker.connect(makeHost(), { preferred: true }));
1510 + yield* Stream.runForEach(requests, (request) => {
1511 + routed.push(request);
1512 + return broker.respond({
1513 + clientId: "client-1",
1514 + connectionId: request.connectionId,
1515 + requestId: request.requestId,
1516 + ok: true,
1517 + result: { tabId: request.tabId ?? `tab-${request.threadId}` },
1518 + });
1519 + }).pipe(Effect.forkScoped);
1520 + yield* Effect.yieldNow;
1521 + // Codex runs every thread of an instance in one provider session.
1522 + const otherThread = {
1523 + ...scope,
1524 + thread: { ...scope.thread, threadId: ThreadId.make("thread-2") },
1525 + };
1526 +
1527 + yield* broker.invoke({ scope, operation: "open", input: {} });
1528 + yield* broker.invoke({ scope: otherThread, operation: "snapshot", input: {} });
1529 + yield* broker.invoke({ scope, operation: "snapshot", input: {} });
1530 + yield* broker.invoke({ scope: otherThread, operation: "snapshot", input: {} });
1531 +
1532 + expect(routed.map(({ threadId, tabId }) => [threadId, tabId])).toEqual([
1533 + ["thread-1", undefined],
1534 + ["thread-2", undefined],
1535 + ["thread-1", "tab-thread-1"],
1536 + ["thread-2", "tab-thread-2"],
1537 + ]);
1538 + // Each thread's agent owns its own tabs and tab budget.
1539 + expect(routed[0]!.agentSessionId).not.toBe(routed[1]!.agentSessionId);
1540 + }),
1541 + ),
1542 +);
apps/server/src/mcp/PreviewAutomationBroker.ts
+6 -1
@@ -166,8 +166,13 @@ const selectorDiagnosticsFromInput = (
166 return {};
167 };
168
169 +/**
170 + * One agent: a provider session on one thread. Codex and OpenCode run every
171 + * thread of a provider instance in one session, so the session alone would
172 + * share one current tab, tab budget, and tab ownership across chats.
173 + */
174 const hostAssignmentKey = (scope: McpInvocationContext.McpThreadInvocationScope): string =>
170 - `${scope.environmentId}\u0000${scope.thread.providerSessionId}`;
175 + `${scope.environmentId}\u0000${scope.thread.providerSessionId}\u0000${scope.thread.threadId}`;
176
177 const isPreviewTabId = Schema.is(PreviewTabId);
178 const decodeControlReason = Schema.decodeUnknownOption(PreviewAutomationControlReason);