Skip to content
Open
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
2 changes: 1 addition & 1 deletion apps/server/src/mcp/McpHttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ export const layerPullRequestsToolkit = toolkitRegistration(
PullRequestsHandlers.layer,
).pipe(Layer.provide(PullRequestWatchService.layer));

export const layerEventsToolkit = toolkitRegistration(EventsToolkit, EventsHandlers.layer).pipe(
const layerEventsToolkit = toolkitRegistration(EventsToolkit, EventsHandlers.layer).pipe(
Layer.provide(PullRequestWatchService.layer),
);

Expand Down
200 changes: 115 additions & 85 deletions apps/server/src/mcp/OrchestratorMcpService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,19 @@ describe("OrchestratorMcpService provider resolution", () => {
assert.deepEqual(entry!.constraints, []);
}

providers = providers.map((provider) =>
provider.instanceId === antigravityInstanceId
? { ...provider, models: [], auth: { status: "unauthenticated" } }
: provider,
);
const signedOut = (yield* service.capabilities(scope)).providers.find(
(provider) => provider.providerInstanceId === antigravityInstanceId,
);
assert.isFalse(signedOut?.canRunChildTask);
assert.isFalse(signedOut?.canRunCrossProviderChildTask);
assert.include(signedOut?.constraints ?? [], "No models available.");
assert.include(signedOut?.constraints ?? [], "Provider is not authenticated.");

const disabled = byId.get(disabledAntigravityInstanceId);
assert.isDefined(disabled);
assert.isFalse(disabled!.canRunChildTask);
Expand Down Expand Up @@ -2239,94 +2252,111 @@ describe("OrchestratorMcpService provider resolution", () => {
);
});

it.effect.each(["already advertised", "newly advertised", "still unavailable"] as const)(
"rechecks a delegated model that is %s",
(availability) =>
Effect.gen(function* () {
const museInstanceId = ProviderInstanceId.make("muse");
const model = "muse-wonder-1.0";
const provider = (advertisedModel: string) =>
providerSnapshot({
it.effect.each([
"already advertised",
"newly advertised",
"still unavailable",
"empty catalog",
"unauthenticated",
] as const)("rechecks a delegated model that is %s", (availability) =>
Effect.gen(function* () {
const museInstanceId = ProviderInstanceId.make("muse");
const model = "muse-wonder-1.0";
const provider = (advertisedModel: string): ServerProvider => {
const snapshot = providerSnapshot({
instanceId: museInstanceId,
driver: ProviderDriverKind.make("muse"),
model: advertisedModel,
});
if (availability === "empty catalog") return { ...snapshot, models: [] };
if (availability === "unauthenticated")
return { ...snapshot, auth: { status: "unauthenticated" } };
return snapshot;
};
const commands: Array<unknown> = [];
const refreshedInstances: Array<ProviderInstanceId> = [];
const task = {
id: taskId,
threadId: parentThreadId,
origin: "app_owned",
childThreadId,
providerInstanceId: museInstanceId,
model,
status: "running",
result: null,
};
const dependencies = Layer.mergeAll(
NodeServices.layer,
NodeCrypto.layer,
Layer.mock(ThreadManagementService.ThreadManagementService)({
hasReceipt: () => Effect.succeed(false),
getThreadRecords: (threadId) =>
Effect.succeed(
threadId === parentThreadId
? parentProjection(commands.length > 0 ? [task] : [])
: childProjection,
),
dispatch: (command) =>
Effect.sync(() => {
commands.push(command);
return {
sequence: 1,
storedEvents: [{ event: { type: "subagent.updated", payload: task } }],
} as never;
}),
}),
ServerSettings.layerTest(),
Layer.mock(ProviderRegistry.ProviderRegistry)({
getProviders: Effect.succeed([
provider(availability === "already advertised" ? model : "muse-spark-1.3"),
]),
refreshInstance: (instanceId) =>
Effect.sync(() => {
refreshedInstances.push(instanceId);
return [provider(availability === "still unavailable" ? "muse-spark-1.3" : model)];
}),
}),
adapterRegistryLayer([museInstanceId]),
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 delegation = service.delegateTask(scope, {
task: "Review the change.",
target: { providerInstanceId: museInstanceId, model },
mode: "async",
clientRequestId: availability,
});
if (availability === "empty catalog" || availability === "unauthenticated") {
const error = yield* delegation.pipe(Effect.flip);
assert.equal(error.code, "provider_unavailable");
assert.include(
error.message,
availability === "empty catalog" ? "No models available" : "not authenticated",
);
assert.deepEqual(commands, []);
} else if (availability === "still unavailable") {
const error = yield* delegation.pipe(Effect.flip);
assert.equal(error.code, "model_unavailable");
assert.deepEqual(commands, []);
} else {
const result = yield* delegation;
assert.equal(result.model, model);
assert.equal(commands.length, 1);
assert.deepEqual((commands[0] as { modelSelection: unknown }).modelSelection, {
instanceId: museInstanceId,
driver: ProviderDriverKind.make("muse"),
model: advertisedModel,
model,
});
const commands: Array<unknown> = [];
const refreshedInstances: Array<ProviderInstanceId> = [];
const task = {
id: taskId,
threadId: parentThreadId,
origin: "app_owned",
childThreadId,
providerInstanceId: museInstanceId,
model,
status: "running",
result: null,
};
const dependencies = Layer.mergeAll(
NodeServices.layer,
NodeCrypto.layer,
Layer.mock(ThreadManagementService.ThreadManagementService)({
hasReceipt: () => Effect.succeed(false),
getThreadRecords: (threadId) =>
Effect.succeed(
threadId === parentThreadId
? parentProjection(commands.length > 0 ? [task] : [])
: childProjection,
),
dispatch: (command) =>
Effect.sync(() => {
commands.push(command);
return {
sequence: 1,
storedEvents: [{ event: { type: "subagent.updated", payload: task } }],
} as never;
}),
}),
ServerSettings.layerTest(),
Layer.mock(ProviderRegistry.ProviderRegistry)({
getProviders: Effect.succeed([
provider(availability === "already advertised" ? model : "muse-spark-1.3"),
]),
refreshInstance: (instanceId) =>
Effect.sync(() => {
refreshedInstances.push(instanceId);
return [provider(availability === "still unavailable" ? "muse-spark-1.3" : model)];
}),
}),
adapterRegistryLayer([museInstanceId]),
Layer.mock(ProjectService.ProjectService)({}),
Layer.mock(SecretRequests.SecretRequests)({}),
Layer.mock(RemoteDelegation.RemoteDelegation)({}),
Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
}
assert.deepEqual(
refreshedInstances,
availability === "already advertised" ? [] : [museInstanceId],
);
yield* Effect.gen(function* () {
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
const delegation = service.delegateTask(scope, {
task: "Review the change.",
target: { providerInstanceId: museInstanceId, model },
mode: "async",
clientRequestId: availability,
});
if (availability === "still unavailable") {
const error = yield* delegation.pipe(Effect.flip);
assert.equal(error.code, "model_unavailable");
assert.deepEqual(commands, []);
} else {
const result = yield* delegation;
assert.equal(result.model, model);
assert.equal(commands.length, 1);
assert.deepEqual((commands[0] as { modelSelection: unknown }).modelSelection, {
instanceId: museInstanceId,
model,
});
}
assert.deepEqual(
refreshedInstances,
availability === "already advertised" ? [] : [museInstanceId],
);
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(dependencies))));
}),
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(dependencies))));
}),
);

it.effect("rejects delegation to a provider without a registered adapter", () =>
Expand Down
42 changes: 12 additions & 30 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
CommandId,
EnvironmentId,
type RunId,
isProviderAvailable,
MessageId,
type ModelSelection,
NodeId,
Expand Down Expand Up @@ -135,7 +134,11 @@ import { isSnoozed } from "../orchestration-v2/ThreadSettlementService.ts";
import { userFacingDispatchErrorMessage } from "../orchestration-v2/UserFacingErrors.ts";
import * as ProjectService from "../project/ProjectService.ts";
import * as ProviderRegistry from "../provider/ProviderRegistry.ts";
import { findServedModel, unservedModelMessage } from "../provider/servedModel.ts";
import {
findServedModel,
providerReadinessConstraints,
unservedModelMessage,
} from "../provider/servedModel.ts";
import * as ScheduledTaskService from "../scheduledTasks/ScheduledTaskService.ts";
import * as ServerSettings from "../serverSettings.ts";
import {
Expand Down Expand Up @@ -403,9 +406,8 @@ function antigravitySuffixedModel(provider: ServerProvider, model: string) {

const withV = (version: string) => (version.startsWith("v") ? version : `v${version}`);

/** A provider that lists no models accepts any slug. */
export const requireAdvertisedModel = (provider: ServerProvider, model: string) => {
if (provider.models.length === 0 || advertisedModel(provider, model) !== undefined) {
if (advertisedModel(provider, model) !== undefined) {
return Effect.void;
}
const updateRequired = provider.updateRequiredModels?.find(
Expand Down Expand Up @@ -434,31 +436,11 @@ function capabilityModelOption(descriptor: ProviderOptionDescriptor): Orchestrat
};
}

function providerConstraints(
provider: ServerProvider | undefined,
supportsOrchestrationV2: boolean,
): ReadonlyArray<string> {
const constraints: Array<string> = [];
if (!supportsOrchestrationV2) {
constraints.push("No V2 provider adapter is registered.");
}
if (provider === undefined) return constraints;
if (!isProviderAvailable(provider)) {
constraints.push(provider.unavailableReason ?? "Provider driver is unavailable.");
}
if (!provider.enabled) {
constraints.push("Provider instance is disabled.");
// Disabled snapshots contain placeholders for installation, health, and auth.
return constraints;
}
if (!provider.installed) constraints.push("Provider executable is not installed.");
if (provider.status === "error" || provider.status === "disabled") {
constraints.push(provider.message ?? `Provider status is ${provider.status}.`);
}
if (provider.auth.status === "unauthenticated") {
constraints.push("Provider is not authenticated.");
}
return constraints;
function providerConstraints(provider: ServerProvider, supportsOrchestrationV2: boolean) {
const readiness = providerReadinessConstraints(provider);
return supportsOrchestrationV2
? readiness
: ["No V2 provider adapter is registered.", ...readiness];
}

/** t3_thread_launch keeps a selection as given, so it can hold options its model does not have. */
Expand Down Expand Up @@ -1677,7 +1659,7 @@ const make = Effect.gen(function* () {
`Provider ${instanceId} has no model available for inheritance.`,
);
}
if (requestedModel !== undefined) yield* requireAdvertisedModel(provider, model);
yield* requireAdvertisedModel(provider, model);
const advertised = advertisedModel(provider, model);
const descriptors = advertised?.capabilities?.optionDescriptors;
const requestedOptions = withLegacyUltracodeEffort(descriptors, input.target?.options);
Expand Down
54 changes: 51 additions & 3 deletions apps/server/src/mcp/toolkits/project/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,30 @@ const clientLaunchHarness = (input: {
};
const layerDependencies = Layer.mergeAll(
Layer.mock(ProviderRegistry.ProviderRegistry)({
getProviders: Effect.succeed(input.providers ?? []),
getProviders: Effect.succeed(
input.providers ?? [
{
instanceId: (input.overrideModel ?? modelSelection).instanceId,
driver: ProviderDriverKind.make((input.overrideModel ?? modelSelection).instanceId),
enabled: true,
installed: true,
status: "ready",
version: null,
auth: { status: "authenticated" },
checkedAt: "2026-01-01T00:00:00Z",
models: [
{
slug: (input.overrideModel ?? modelSelection).model,
name: "Default",
capabilities: null,
isCustom: false,
},
],
slashCommands: [],
skills: [],
},
],
),
}),
ServerSettings.layerTest({
fallbackModelSelection: input.fallbackModel ?? null,
Expand Down Expand Up @@ -309,7 +332,7 @@ it.effect("a launch steps an inherited mode down to the provider's, and refuses
version: null,
auth: { status: "authenticated" },
checkedAt: "2026-01-01T00:00:00Z",
models: [],
models: [{ slug: "pi-model", name: "Pi", capabilities: null, isCustom: false }],
slashCommands: [],
skills: [],
supportedRuntimeModes: ["approval-required", "auto-accept-edits", "full-access"],
Expand Down Expand Up @@ -408,6 +431,24 @@ it.effect("a launch with a model its provider does not advertise creates no thre
),
});
}
providers.push(
{ ...providers[0]!, instanceId: ProviderInstanceId.make("empty"), models: [] },
{
...providers[0]!,
instanceId: ProviderInstanceId.make("signed-out"),
auth: { status: "unauthenticated" },
},
);
for (const [instance, reason] of [
["missing", "not registered"],
["empty", "No models available"],
["signed-out", "not authenticated"],
] as const) {
expect(yield* launchWith(instance, "claude-opus")).toMatchObject({
code: "provider_unavailable",
message: expect.stringContaining(reason),
});
}
expect(launched).toHaveLength(0);

expect(yield* launchWith("claudeAgent", "Opus")).toMatchObject({
Expand Down Expand Up @@ -836,7 +877,14 @@ it.effect("a client launches with the fallback for an exhausted default", () =>
version: null,
auth: { status: "authenticated" },
checkedAt: "2026-01-01T00:00:00Z",
models: [],
models: [
{
slug: driver === "codex" ? fallbackModel.model : "claude-opus",
name: "Default",
capabilities: null,
isCustom: false,
},
],
slashCommands: [],
skills: [],
...(driver === "claudeAgent"
Expand Down
Loading
Loading