Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions apps/server/src/mcp/OrchestratorMcpService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
() =>
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`,
);
Expand Down
Loading