Skip to content

Commit c334e78

Browse files
Mezzleclaude
andcommitted
fix(mcp): a scheduled task's target sets a runtime mode its provider offers
A target could pick a provider that lacks the caller's runtime mode, so runs fell back to approval-required and waited. The mode now steps down the way delegate_task's does, on create and update. A complete target also no longer needs a project default model when the caller has no thread. Shortens the target description to trim the tool list. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5ae3de4 commit c334e78

4 files changed

Lines changed: 97 additions & 30 deletions

File tree

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

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
OrchestratorMcpTarget,
1414
type OrchestrationV2ThreadShell,
1515
type ScheduledTask,
16+
type ScheduledTaskUpsertInput,
1617
ScheduledTaskId,
1718
ProjectId,
1819
ProviderDriverKind,
@@ -2989,6 +2990,7 @@ describe("OrchestratorMcpService provider resolution", () => {
29892990
instanceId: codexInstanceId,
29902991
driver: ProviderDriverKind.make("codex"),
29912992
}),
2993+
supportedRuntimeModes: ["approval-required", "auto-accept-edits"],
29922994
models: ["gpt-5", "gpt-5-mini"].map((slug) => ({
29932995
slug,
29942996
name: slug,
@@ -3022,9 +3024,10 @@ describe("OrchestratorMcpService provider resolution", () => {
30223024
threadId: ThreadId.make("thread:scheduled-model-bound"),
30233025
};
30243026
const service = (
3025-
saved: Ref.Ref<ReadonlyArray<ScheduledTask["modelSelection"]>>,
3027+
saved: Ref.Ref<ReadonlyArray<ScheduledTaskUpsertInput>>,
30263028
stored: ScheduledTask = existing,
30273029
enabledForProject = true,
3030+
defaultModelSelection: ScheduledTask["modelSelection"] | null = existing.modelSelection,
30283031
) =>
30293032
OrchestratorMcpService.layer.pipe(
30303033
Layer.provide(Layer.mock(ThreadLaunchService.ThreadLaunchService)({})),
@@ -3051,15 +3054,15 @@ describe("OrchestratorMcpService provider resolution", () => {
30513054
Effect.succeedSome({
30523055
id: projectId,
30533056
workspaceRoot: "/repo/scheduled-model",
3054-
defaultModelSelection: existing.modelSelection,
3057+
defaultModelSelection,
30553058
} as never),
30563059
}),
30573060
Layer.mock(SecretRequests.SecretRequests)({}),
30583061
Layer.mock(RemoteDelegation.RemoteDelegation)({}),
30593062
Layer.mock(ScheduledTaskService.ScheduledTaskService)({
30603063
list: () => Effect.succeed({ tasks: [stored] }),
30613064
upsert: (input) =>
3062-
Ref.update(saved, (selections) => [...selections, input.modelSelection]).pipe(
3065+
Ref.update(saved, (inputs) => [...inputs, input]).pipe(
30633066
Effect.as({
30643067
task: {
30653068
...stored,
@@ -3072,18 +3075,27 @@ describe("OrchestratorMcpService provider resolution", () => {
30723075
),
30733076
),
30743077
);
3075-
const savedSelections = <E>(
3078+
const savedInputs = <E>(
30763079
run: (mcp: OrchestratorMcpService.OrchestratorMcpServiceShape) => Effect.Effect<unknown, E>,
30773080
stored: ScheduledTask = existing,
3081+
defaultModelSelection?: ScheduledTask["modelSelection"] | null,
30783082
) =>
30793083
Effect.gen(function* () {
3080-
const saved = yield* Ref.make<ReadonlyArray<ScheduledTask["modelSelection"]>>([]);
3084+
const saved = yield* Ref.make<ReadonlyArray<ScheduledTaskUpsertInput>>([]);
30813085
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe(
3082-
Effect.provide(service(saved, stored)),
3086+
Effect.provide(service(saved, stored, true, defaultModelSelection)),
30833087
);
30843088
yield* run(mcp);
30853089
return yield* Ref.get(saved);
30863090
});
3091+
const savedSelections = <E>(
3092+
run: (mcp: OrchestratorMcpService.OrchestratorMcpServiceShape) => Effect.Effect<unknown, E>,
3093+
stored: ScheduledTask = existing,
3094+
defaultModelSelection?: ScheduledTask["modelSelection"] | null,
3095+
) =>
3096+
savedInputs(run, stored, defaultModelSelection).pipe(
3097+
Effect.map((inputs) => inputs.map((input) => input.modelSelection)),
3098+
);
30873099

30883100
it.effect("saves a new task with the target's model and options", () =>
30893101
Effect.gen(function* () {
@@ -3109,6 +3121,52 @@ describe("OrchestratorMcpService provider resolution", () => {
31093121
}),
31103122
);
31113123

3124+
it.effect("takes a complete target when the project has no default model", () =>
3125+
Effect.gen(function* () {
3126+
const saved = yield* savedSelections(
3127+
(mcp) =>
3128+
mcp.scheduleTask(client, {
3129+
projectId,
3130+
prompt: "Check the build",
3131+
schedule: { type: "interval", everyMs: 3_600_000 },
3132+
target: { providerInstanceId: codexInstanceId, model: "gpt-5-mini" },
3133+
}),
3134+
existing,
3135+
null,
3136+
);
3137+
assert.deepEqual(saved, [{ instanceId: codexInstanceId, model: "gpt-5-mini" }]);
3138+
}),
3139+
);
3140+
3141+
it.effect("steps the runtime mode down to one the target's provider offers", () =>
3142+
Effect.gen(function* () {
3143+
const fullAccess: McpInvocationScope = {
3144+
...client,
3145+
client: { sessionId: "scheduled-model", label: "Claude Code", access: "full-access" },
3146+
};
3147+
const stored: ScheduledTask = { ...existing, runtimeMode: "full-access" };
3148+
const target = { providerInstanceId: codexInstanceId };
3149+
const saved = yield* savedInputs(
3150+
(mcp) =>
3151+
Effect.all([
3152+
mcp.scheduleTask(fullAccess, {
3153+
projectId,
3154+
prompt: "Check the build",
3155+
schedule: { type: "interval", everyMs: 3_600_000 },
3156+
target,
3157+
}),
3158+
mcp.updateScheduledTask(fullAccess, { scheduledTaskId: stored.id, target }),
3159+
mcp.updateScheduledTask(fullAccess, { scheduledTaskId: stored.id, prompt: "Again" }),
3160+
]),
3161+
stored,
3162+
);
3163+
assert.deepEqual(
3164+
saved.map((input) => input.runtimeMode),
3165+
["auto-accept-edits", "auto-accept-edits", "full-access"],
3166+
);
3167+
}),
3168+
);
3169+
31123170
it.effect("merges an update's options into the stored selection", () =>
31133171
Effect.gen(function* () {
31143172
const saved = yield* savedSelections((mcp) =>
@@ -3141,7 +3199,7 @@ describe("OrchestratorMcpService provider resolution", () => {
31413199

31423200
it.effect("reports the saved model and options", () =>
31433201
Effect.gen(function* () {
3144-
const saved = yield* Ref.make<ReadonlyArray<ScheduledTask["modelSelection"]>>([]);
3202+
const saved = yield* Ref.make<ReadonlyArray<ScheduledTaskUpsertInput>>([]);
31453203
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe(
31463204
Effect.provide(service(saved)),
31473205
);
@@ -3156,7 +3214,7 @@ describe("OrchestratorMcpService provider resolution", () => {
31563214

31573215
it.effect("refuses a target for a bound task, whose runs use the thread's model", () =>
31583216
Effect.gen(function* () {
3159-
const saved = yield* Ref.make<ReadonlyArray<ScheduledTask["modelSelection"]>>([]);
3217+
const saved = yield* Ref.make<ReadonlyArray<ScheduledTaskUpsertInput>>([]);
31603218
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe(
31613219
Effect.provide(service(saved, bound)),
31623220
);
@@ -3190,7 +3248,7 @@ describe("OrchestratorMcpService provider resolution", () => {
31903248

31913249
it.effect("refuses a provider the project has disabled, which every run would fail on", () =>
31923250
Effect.gen(function* () {
3193-
const saved = yield* Ref.make<ReadonlyArray<ScheduledTask["modelSelection"]>>([]);
3251+
const saved = yield* Ref.make<ReadonlyArray<ScheduledTaskUpsertInput>>([]);
31943252
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe(
31953253
Effect.provide(service(saved, existing, false)),
31963254
);
@@ -3214,7 +3272,7 @@ describe("OrchestratorMcpService provider resolution", () => {
32143272
},
32153273
] as const)("refuses $name and saves nothing", ({ target, code }) =>
32163274
Effect.gen(function* () {
3217-
const saved = yield* Ref.make<ReadonlyArray<ScheduledTask["modelSelection"]>>([]);
3275+
const saved = yield* Ref.make<ReadonlyArray<ScheduledTaskUpsertInput>>([]);
32183276
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService.pipe(
32193277
Effect.provide(service(saved)),
32203278
);

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,13 +1998,11 @@ const make = Effect.gen(function* () {
19981998
return task;
19991999
});
20002000

2001-
/** A given target resolves against `base`, the selection the task would otherwise keep. */
2002-
const scheduledTaskModelSelection = Effect.fn(
2003-
"OrchestratorMcpService.scheduledTaskModelSelection",
2004-
)(function* (
2001+
/** A given target resolves against `base`, the selection and mode the task would otherwise keep. */
2002+
const scheduledTaskTarget = Effect.fn("OrchestratorMcpService.scheduledTaskTarget")(function* (
20052003
projectId: ProjectId,
20062004
bound: boolean,
2007-
base: ModelSelection,
2005+
base: { readonly modelSelection: ModelSelection; readonly runtimeMode: RuntimeMode },
20082006
target: OrchestratorMcpScheduledTaskTarget | undefined,
20092007
) {
20102008
if (target === undefined) return base;
@@ -2016,7 +2014,7 @@ const make = Effect.gen(function* () {
20162014
);
20172015
}
20182016
const resolved = yield* resolveTargetRechecking({
2019-
parent: { thread: { modelSelection: base, projectId } },
2017+
parent: { thread: { modelSelection: base.modelSelection, projectId } },
20202018
target,
20212019
providers: yield* loadProviders,
20222020
});
@@ -2028,7 +2026,10 @@ const make = Effect.gen(function* () {
20282026
`Provider instance ${instanceId} is not enabled for this project.`,
20292027
);
20302028
}
2031-
return resolved.modelSelection;
2029+
return {
2030+
modelSelection: resolved.modelSelection,
2031+
runtimeMode: yield* resolveRuntimeMode(base.runtimeMode, undefined, resolved),
2032+
};
20322033
});
20332034

20342035
return OrchestratorMcpService.of({
@@ -2048,10 +2049,18 @@ const make = Effect.gen(function* () {
20482049
: "bindToCurrentThread binds to this thread, which belongs to a different project.",
20492050
);
20502051
}
2051-
const modelSelection = yield* scheduledTaskModelSelection(
2052+
const { modelSelection, runtimeMode } = yield* scheduledTaskTarget(
20522053
projectId,
20532054
bindToCurrentThread,
2054-
parent?.thread.modelSelection ?? (yield* projectDefaultModelSelection(project)),
2055+
{
2056+
modelSelection:
2057+
parent?.thread.modelSelection ??
2058+
project.defaultModelSelection ??
2059+
(input.target?.providerInstanceId !== undefined && input.target.model !== undefined
2060+
? { instanceId: input.target.providerInstanceId, model: input.target.model }
2061+
: yield* projectDefaultModelSelection(project)),
2062+
runtimeMode: limits.runtimeMode,
2063+
},
20552064
input.target,
20562065
);
20572066
const derivedTitle = input.prompt.split("\n")[0]?.trim() ?? "";
@@ -2066,7 +2075,7 @@ const make = Effect.gen(function* () {
20662075
threadId: bindToCurrentThread && parent !== undefined ? parent.thread.id : null,
20672076
workspaceStrategy: yield* scheduledTaskWorkspaceStrategy(bindToCurrentThread, projectId),
20682077
modelSelection,
2069-
runtimeMode: limits.runtimeMode,
2078+
runtimeMode,
20702079
interactionMode: limits.interactionMode,
20712080
createdBy: "agent",
20722081
creationSource: "mcp",
@@ -2137,6 +2146,12 @@ const make = Effect.gen(function* () {
21372146
input.bindToCurrentThread === undefined
21382147
? existing.workspaceStrategy
21392148
: yield* scheduledTaskWorkspaceStrategy(input.bindToCurrentThread, existing.projectId);
2149+
const { modelSelection, runtimeMode } = yield* scheduledTaskTarget(
2150+
existing.projectId,
2151+
threadId !== null,
2152+
existing,
2153+
input.target,
2154+
);
21402155
const upsertInput: ScheduledTaskUpsertInput = {
21412156
id: existing.id,
21422157
title: input.title ?? existing.title,
@@ -2146,13 +2161,8 @@ const make = Effect.gen(function* () {
21462161
projectId: existing.projectId,
21472162
threadId,
21482163
workspaceStrategy,
2149-
modelSelection: yield* scheduledTaskModelSelection(
2150-
existing.projectId,
2151-
threadId !== null,
2152-
existing.modelSelection,
2153-
input.target,
2154-
),
2155-
runtimeMode: existing.runtimeMode,
2164+
modelSelection,
2165+
runtimeMode,
21562166
interactionMode: existing.interactionMode,
21572167
createdBy: existing.createdBy,
21582168
creationSource: existing.creationSource,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"claudeSystemAppendBytes": 5133,
33
"codexAdditionalContextBytes": 6863,
4-
"mcpToolListJsonBytes": 48159
4+
"mcpToolListJsonBytes": 48103
55
}

‎packages/contracts/src/orchestratorMcp.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,7 @@ export const OrchestratorMcpScheduleTaskInput = Schema.Struct({
670670
),
671671
target: Schema.optional(
672672
OrchestratorMcpScheduledTaskTarget.annotate({
673-
description:
674-
"Model and options, as in `delegate_task`. Unbound tasks only: a bound run uses its thread's model.",
673+
description: "As in `delegate_task`. Unbound tasks only.",
675674
}),
676675
),
677676
clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),

0 commit comments

Comments
 (0)