Skip to content

Commit 0ce4cbe

Browse files
TDanks2000claude
andauthored
fix(preview): isolate tabs for threads sharing a provider session (pingdotgg#18146)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 6670dc7 commit 0ce4cbe

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎apps/server/src/mcp/PreviewAutomationBroker.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,3 +1500,43 @@ it.effect("keeps the host connected when a background status read times out", ()
15001500
}),
15011501
),
15021502
);
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‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,13 @@ const selectorDiagnosticsFromInput = (
166166
return {};
167167
};
168168

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+
*/
169174
const hostAssignmentKey = (scope: McpInvocationContext.McpThreadInvocationScope): string =>
170-
`${scope.environmentId}\u0000${scope.thread.providerSessionId}`;
175+
`${scope.environmentId}\u0000${scope.thread.providerSessionId}\u0000${scope.thread.threadId}`;
171176

172177
const isPreviewTabId = Schema.is(PreviewTabId);
173178
const decodeControlReason = Schema.decodeUnknownOption(PreviewAutomationControlReason);

0 commit comments

Comments
 (0)