Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
No provider sign-in required. The focused test took 80 seconds after dependency installation. Use Git and Vite+ with the checkout's pinned Node 26.13.1 and pnpm 12.14.0.
git clone https://github.com/pingdotgg/t3code.git
cd t3code
git checkout --detach f17114b2c2a2a06f4628522dde4ea8b92dd7129b
vp install --frozen-lockfileSave the full diff below as queued-provider-switch.patch in the checkout root.
git apply queued-provider-switch.patch
cd apps/server
vp test run src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts -t 'keeps a busy previous session running when a queued hand-off starts' --reporter=verbosequeued-provider-switch.patch
diff --git a/apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts b/apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts
index ccd4c69710..b98e8e4a38 100644
--- a/apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts
+++ b/apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts
@@ -25,6 +25,7 @@ import * as ServerSettings from "../../serverSettings.ts";
import * as ManagedPolicy from "../../policy/ManagedPolicy.ts";
import * as ThreadManagementService from "../ThreadManagementService.ts";
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
+import * as McpSessionRegistry from "../../mcp/McpSessionRegistry.ts";
import * as McpSessionRegistryTestkit from "../../mcp/McpSessionRegistry.testkit.ts";
import * as VcsDriverRegistry from "../../vcs/VcsDriverRegistry.ts";
import * as GitVcsDriver from "../../vcs/GitVcsDriver.ts";
@@ -286,6 +287,7 @@ export function layerWithRegistry<Error>(
McpProviderSessions.McpProviderSessions
>,
options: {
+ readonly mcpRegistryLayer?: Layer.Layer<McpSessionRegistry.McpSessionRegistry>;
readonly databaseLayer?: Layer.Layer<
SqlClient.SqlClient,
MigrationError | PlatformError.PlatformError | SqlError
@@ -442,7 +444,7 @@ export function layerWithRegistry<Error>(
Layer.provide(Layer.merge(layerEventSinkProvided, layerStores)),
);
const layerProviderSessionManagerProvided = ProviderSessionManager.layerWithOptions({
- configureMcp: false,
+ configureMcp: options.mcpRegistryLayer !== undefined,
}).pipe(
Layer.provide(
Layer.mergeAll(
@@ -451,7 +453,7 @@ export function layerWithRegistry<Error>(
layerEventSinkProvided,
IdAllocator.layer,
McpProviderSessions.layer,
- McpSessionRegistryTestkit.layer,
+ options.mcpRegistryLayer ?? McpSessionRegistryTestkit.layer,
layerProviderEventIngestorProvided,
layerStores,
ProviderInstallationGate.layer,
diff --git a/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts b/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts
index 811279357d..9729097d2c 100644
--- a/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts
+++ b/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts
@@ -1,3 +1,9 @@
+import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
+import * as NetAddress from "effect/net/NetAddress";
+import { HttpServer } from "effect/http";
+import { EnvironmentId } from "@t3tools/contracts";
+import * as McpSessionRegistry from "../../mcp/McpSessionRegistry.ts";
+import * as ServerEnvironment from "../../environment/ServerEnvironment.ts";
import { vi } from "vite-plus/test";
import { historyResponseItems } from "@t3tools/provider-core/server/handoffBudget";
import { assert, describe, it } from "@effect/vitest";
@@ -69,6 +75,49 @@ import * as ProviderReplayHarness from "./ProviderReplayHarness.ts";
import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace";
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
+const makeReproMcpRegistry = (issued: Ref.Ref<ReadonlyMap<ProviderInstanceId, string>>) =>
+ Layer.effect(
+ McpSessionRegistry.McpSessionRegistry,
+ McpSessionRegistry.__testing.make().pipe(
+ Effect.map((registry) =>
+ McpSessionRegistry.McpSessionRegistry.of({
+ ...registry,
+ issue: (input) =>
+ registry.issue(input).pipe(
+ Effect.tap(({ config }) =>
+ Ref.update(issued, (tokens) =>
+ new Map(tokens).set(
+ input.providerInstanceId,
+ config.authorizationHeader.replace(/^Bearer\s+/, ""),
+ ),
+ ),
+ ),
+ ),
+ }),
+ ),
+ ),
+ ).pipe(
+ Layer.provide(
+ Layer.succeed(
+ HttpServer.HttpServer,
+ HttpServer.HttpServer.of({
+ address: NetAddress.inetAddressFromIpStringUnsafe("127.0.0.1", 43123),
+ serve: (() => Effect.void) as HttpServer.HttpServer["Service"]["serve"],
+ }),
+ ),
+ ),
+ Layer.provide(
+ Layer.succeed(
+ ServerEnvironment.ServerEnvironment,
+ ServerEnvironment.ServerEnvironment.of({
+ getEnvironmentId: Effect.succeed(EnvironmentId.make("environment:mcp-repro")),
+ getDescriptor: Effect.die("unused"),
+ }),
+ ),
+ ),
+ Layer.provide(NodeCrypto.layer),
+ );
+
const encodeJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
const threadId = ThreadId.make("thread:provider-switch");
@@ -4400,6 +4449,8 @@ describe("orchestration v2 provider switching", () => {
const capturedTurns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
const backgroundWork = yield* Ref.make(background);
const closedSessions = yield* Ref.make<ReadonlyArray<string>>([]);
+ const issued = yield* Ref.make<ReadonlyMap<ProviderInstanceId, string>>(new Map());
+ const layerMcpRegistryRepro = makeReproMcpRegistry(issued);
const firstStarted = yield* Deferred.make<void>();
const releaseFirst = yield* Deferred.make<void>();
const secondSelection: ModelSelection = {
@@ -4487,7 +4538,14 @@ describe("orchestration v2 provider switching", () => {
yield* send(1, CLAUDE_MODEL_SELECTION);
if (queued) {
+ const registry = yield* McpSessionRegistry.McpSessionRegistry;
yield* Deferred.await(firstStarted);
+ const tokenA = (yield* Ref.get(issued)).get(CLAUDE_MODEL_SELECTION.instanceId);
+ assert.isDefined(tokenA);
+ assert.equal(
+ (yield* registry.resolve(tokenA!))?.thread.providerInstanceId,
+ CLAUDE_MODEL_SELECTION.instanceId,
+ );
yield* send(2, secondSelection);
const queuedRunId = (yield* orchestrator.getThreadProjection(handoffThreadId)).runs[1]
?.id;
@@ -4518,6 +4576,17 @@ describe("orchestration v2 provider switching", () => {
[secondSelection.instanceId, "completed"],
],
);
+ const tokenB = (yield* Ref.get(issued)).get(secondSelection.instanceId);
+ assert.isDefined(tokenB);
+ assert.equal(
+ (yield* registry.resolve(tokenB!))?.thread.providerInstanceId,
+ secondSelection.instanceId,
+ );
+ assert.equal(
+ (yield* registry.resolve(tokenA!))?.thread.providerInstanceId,
+ CLAUDE_MODEL_SELECTION.instanceId,
+ "The Claude session kept alive for background work must retain MCP access",
+ );
return;
}
// Resuming the native thread beside the busy session would fork its history.
@@ -4594,20 +4663,24 @@ describe("orchestration v2 provider switching", () => {
assert.deepEqual(yield* Ref.get(closedSessions), [firstSession!.id]);
}).pipe(
Effect.provide(
- ProviderReplayHarness.layerWithRegistry(
- {
- name: "handoff-releases-session",
- runtimePolicyOverride: {
- cwd,
- approvalPolicy: "never",
- sandboxPolicy: {
- type: "readOnly",
- access: { type: "fullAccess" },
- networkAccess: false,
+ Layer.mergeAll(
+ layerMcpRegistryRepro,
+ ProviderReplayHarness.layerWithRegistry(
+ {
+ name: "handoff-releases-session",
+ runtimePolicyOverride: {
+ cwd,
+ approvalPolicy: "never",
+ sandboxPolicy: {
+ type: "readOnly",
+ access: { type: "fullAccess" },
+ networkAccess: false,
+ },
},
},
- },
- layerRegistry,
+ layerRegistry,
+ { mcpRegistryLayer: layerMcpRegistryRepro },
+ ),
),
),
);- The test starts a turn on Claude instance A and verifies the registry accepts A's MCP credential.
- While that turn is running, it queues a message on Claude instance B, which has separate native history. A still reports background work when its turn ends.
- The queued message runs on B. The existing integration test verifies that A remains ready and its provider process has not closed. The added checks exercise both credentials through the real MCP registry.
Expected behavior
The MCP registry still accepts A’s credential while A remains alive with background work. B receives its own working credential.
Actual behavior
B receives a working credential. A remains ready with background work, but the registry returns undefined for A’s original credential as soon as B opens.
Impact
Major degradation or frequent failure
Version or commit
Upstream f17114b2c2a2a06f4628522dde4ea8b92dd7129b.
Environment
Offline reproduction on Windows 11 with Node 26.13.1, pnpm 12.14.0, two fake Claude adapters and the production MCP credential registry. No provider launches or HTTP listener.
Logs or stack traces
× keeps a busy previous session running when a queued hand-off starts
AssertionError: The Claude session kept alive for background work must retain MCP access:
expected undefined to equal 'claudeAgent'
Tests 1 failed | 98 skipped (99)
Duration 79.57s
Follows #36453, closed as not reproducible. The maintainer’s test of immediate switches found that A was released before switching or that its background work caused the switch to be refused. This case exercises a queued handoff that is accepted while A is live. ProviderSessionManager revokes the thread’s existing credential when issuing B’s, even though the handoff keeps A running.
The offline test establishes the rejection in the real credential registry. A live check would confirm the subsequent tool error from the retained Claude process. I did not run that live case on this commit.
Posted by GPT-6.2 Sol on behalf of Alb11747.
Activity
juliusmarminge commentedon Nov 23, 2026
This is the same problem as #37000, so I'm closing it in favour of that one. If it is different, say how and it will be reopened.