diff --git a/apps/server/src/mcp/OrchestratorMcpService.test.ts b/apps/server/src/mcp/OrchestratorMcpService.test.ts index 6c488afe7d989..df9a5e92e09f7 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.test.ts @@ -1948,6 +1948,76 @@ describe("OrchestratorMcpService provider resolution", () => { }), ); + // Command receipts dedupe by commandId, so a later run reusing the identity gets no card. + it.effect("opens a new secret card when a later run reuses a clientRequestId", () => + Effect.gen(function* () { + const runId = yield* Ref.make(parentRunId); + const pending = yield* Queue.unbounded<{ + readonly commandId: CommandId; + readonly turnItemId: string; + }>(); + const dependencies = Layer.mergeAll( + NodeServices.layer, + NodeCrypto.layer, + Layer.mock(ThreadManagementService.ThreadManagementService)({ + getThreadRecords: () => + Ref.get(runId).pipe( + Effect.map((id) => { + const projection = parentProjection([]); + return { + ...projection, + runs: projection.runs.map((run) => ({ ...run, id })), + turnItems: [], + }; + }), + ), + dispatch: (command) => { + if (command.type !== "secret_request.record") return Effect.die("Unexpected command"); + return ( + command.secretStatus === "pending" + ? Queue.offer(pending, { + commandId: command.commandId, + turnItemId: command.turnItemId, + }) + : Effect.void + ).pipe(Effect.as({} as never)); + }, + }), + ServerSettings.layerTest(), + providerRegistryLayer([]), + adapterRegistryLayer([]), + Layer.mock(ProjectService.ProjectService)({}), + Layer.mock(SecretRequests.SecretRequests)({}), + Layer.mock(RemoteDelegation.RemoteDelegation)({}), + Layer.mock(ScheduledTaskService.ScheduledTaskService)({}), + ); + yield* Effect.gen(function* () { + const service = yield* OrchestratorMcpService.OrchestratorMcpService; + const ask = Effect.gen(function* () { + const call = yield* service + .requestSecret(scope, { + label: "Router API key", + reason: "Reads the firewall rules.", + clientRequestId: "router-key", + timeoutMs: 1_000, + }) + .pipe(Effect.forkChild); + const card = yield* Queue.take(pending); + yield* TestClock.adjust(Duration.seconds(1)); + assert.include(yield* Fiber.join(call), { status: "timed_out" }); + return card; + }); + + const first = yield* ask; + assert.deepEqual(yield* ask, first); + yield* Ref.set(runId, RunId.make("run:mcp-providers-parent-later")); + const later = yield* ask; + assert.notEqual(later.commandId, first.commandId); + assert.notEqual(later.turnItemId, first.turnItemId); + }).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(dependencies)))); + }), + ); + it.effect( "advertises orchestration capability from registered adapters rather than a driver allowlist", () => diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 95e269c64c97f..abaed7810d83f 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -2465,7 +2465,7 @@ const make = Effect.gen(function* () { } const runId = run.id; const nodeId = run.rootNodeId; - const key = yield* requestKey(input.clientRequestId); + const key = `${runId}:${yield* requestKey(input.clientRequestId)}`; const turnItemId = TurnItemId.make( `turn-item:secret-request:${stablePart(threadId)}:${stablePart(key)}`, );