Skip to content
TypeScript

fix(server): delegated Muse tasks no longer ask approval for every command (#18065)

Theo Brownea4a1a803a3a6
diff --git a/apps/server/src/mcp/OrchestratorMcpService.test.ts b/apps/server/src/mcp/OrchestratorMcpService.test.ts
index 5b426477c24..bc9ab50276a 100644
--- a/apps/server/src/mcp/OrchestratorMcpService.test.ts
+++ b/apps/server/src/mcp/OrchestratorMcpService.test.ts
@@ -1817,4 +1817,37 @@ describe("OrchestratorMcpService provider resolution", () => {
}),
);
});
+
+ describe("resolveRuntimeMode", () => {
+ // Muse offers only these two, and runs any other mode as Supervised.
+ const muse = {
+ modelSelection: { instanceId: ProviderInstanceId.make("muse"), model: "muse-model" },
+ supportedRuntimeModes: ["approval-required", "full-access"] as const,
+ };
+
+ it.effect("refuses an explicit mode the target provider does not offer", () =>
+ Effect.gen(function* () {
+ const error = yield* OrchestratorMcpService.resolveRuntimeMode(
+ "full-access",
+ "auto-accept-edits",
+ muse,
+ ).pipe(Effect.flip);
+ assert.equal(error.code, "invalid_request");
+ assert.include(error.message, "approval-required, full-access");
+ }),
+ );
+
+ it.effect("steps an inherited mode down to the broadest one the provider offers", () =>
+ Effect.gen(function* () {
+ assert.equal(
+ yield* OrchestratorMcpService.resolveRuntimeMode("full-access", "inherit", muse),
+ "full-access",
+ );
+ assert.equal(
+ yield* OrchestratorMcpService.resolveRuntimeMode("auto", undefined, muse),
+ "approval-required",
+ );
+ }),
+ );
+ });
});
diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts
index 872163b660d..fb5153669d4 100644
--- a/apps/server/src/mcp/OrchestratorMcpService.ts
+++ b/apps/server/src/mcp/OrchestratorMcpService.ts
@@ -113,6 +113,7 @@ const DEFAULT_THREAD_ITEM_MAX_CHARS = 20_000;
interface ResolvedTarget {
readonly modelSelection: ModelSelection;
+ readonly supportedRuntimeModes: ReadonlyArray<RuntimeMode> | undefined;
}
type TerminalTaskStatus = Extract<
@@ -531,19 +532,46 @@ function interactionModeRank(mode: ProviderInteractionMode): number {
return mode === "plan" ? 0 : 1;
}
+/**
+ * The mode a new thread runs in: the requested mode, else the parent's, never
+ * broader than the parent's. Pass `target` when the thread runs on a known
+ * provider. A provider runs a mode it does not offer as Supervised, so an
+ * explicit request for one is refused, and an inherited one steps down to the
+ * broadest mode the provider offers.
+ */
export function resolveRuntimeMode(
parentMode: RuntimeMode,
requested: OrchestratorMcpRuntimeMode | undefined,
+ target?: Pick<ResolvedTarget, "modelSelection" | "supportedRuntimeModes">,
): Effect.Effect<RuntimeMode, OrchestratorMcpFailure> {
- const resolved = requested === undefined || requested === "inherit" ? parentMode : requested;
- return runtimeModeRank(resolved) > runtimeModeRank(parentMode)
- ? Effect.fail(
- failure(
- "runtime_mode_escalation_denied",
- `Child runtime mode ${resolved} is broader than parent mode ${parentMode}.`,
- ),
- )
- : Effect.succeed(resolved);
+ const inherited = requested === undefined || requested === "inherit";
+ const resolved = inherited ? parentMode : requested;
+ if (runtimeModeRank(resolved) > runtimeModeRank(parentMode)) {
+ return Effect.fail(
+ failure(
+ "runtime_mode_escalation_denied",
+ `Child runtime mode ${resolved} is broader than parent mode ${parentMode}.`,
+ ),
+ );
+ }
+ const supported = target?.supportedRuntimeModes;
+ if (supported === undefined || supported.length === 0 || supported.includes(resolved)) {
+ return Effect.succeed(resolved);
+ }
+ if (!inherited) {
+ return Effect.fail(
+ failure(
+ "invalid_request",
+ `Provider ${target?.modelSelection.instanceId} does not offer runtime mode ${resolved}, so it would run as approval-required. Use one of: ${supported.join(", ")}.`,
+ ),
+ );
+ }
+ return Effect.succeed(
+ supported
+ .filter((mode) => runtimeModeRank(mode) <= runtimeModeRank(resolved))
+ .toSorted((left, right) => runtimeModeRank(right) - runtimeModeRank(left))[0] ??
+ "approval-required",
+ );
}
export function resolveInteractionMode(
@@ -1238,6 +1266,7 @@ const make = Effect.gen(function* () {
: requestedOptions === undefined
? { instanceId, model }
: { instanceId, model, options: requestedOptions },
+ supportedRuntimeModes: provider.supportedRuntimeModes,
};
});
@@ -1844,6 +1873,10 @@ const make = Effect.gen(function* () {
? {}
: { options: model.capabilities.optionDescriptors }),
})) ?? [],
+ ...(provider.supportedRuntimeModes === undefined ||
+ provider.supportedRuntimeModes.length === 0
+ ? {}
+ : { runtimeModes: [...provider.supportedRuntimeModes] }),
canRunChildTask: constraints.length === 0,
canRunCrossProviderChildTask: constraints.length === 0,
constraints: [...constraints],
@@ -1883,7 +1916,11 @@ const make = Effect.gen(function* () {
target: input.target,
providers,
});
- const runtimeMode = yield* resolveRuntimeMode(parent.thread.runtimeMode, input.runtimeMode);
+ const runtimeMode = yield* resolveRuntimeMode(
+ parent.thread.runtimeMode,
+ input.runtimeMode,
+ target,
+ );
const interactionMode = yield* resolveInteractionMode(
parent.thread.interactionMode,
input.interactionMode,
@@ -2168,6 +2205,7 @@ const make = Effect.gen(function* () {
const runtimeMode = yield* resolveRuntimeMode(
parent.thread.runtimeMode,
request.runtimeMode,
+ target,
);
const interactionMode = yield* resolveInteractionMode(
parent.thread.interactionMode,
diff --git a/apps/server/src/mcp/toolkits/orchestrator/tools.ts b/apps/server/src/mcp/toolkits/orchestrator/tools.ts
index 33be4d24cb1..71ae2f892de 100644
--- a/apps/server/src/mcp/toolkits/orchestrator/tools.ts
+++ b/apps/server/src/mcp/toolkits/orchestrator/tools.ts
@@ -63,7 +63,7 @@ const OrchestratorCapabilitiesTool = Tool.make("orchestrator_capabilities", {
export const DelegateTaskTool = Tool.make("delegate_task", {
description:
- "Needs an agent running inside a T3 thread. Delegate one task to a T3-owned child agent/subagent of THIS thread and run it with only the supplied task prompt, without copying parent conversation history. Choose providers and models from orchestrator_capabilities, which uses the same live catalog as the composer. Prefer native subagent tools for same-provider work only when they support the chosen model. Use this for any model missing from the native tool, including same-provider work, for cross-provider work, or for explicitly T3-owned child tasks. For every T3 delegated review round, call delegate_task again with the original brief, prior findings, responses, and unresolved objections in the task prompt. Track each round by its own taskId and use a distinct clientRequestId per round, stable across retries of that round. The childThreadId is backing storage, not the target for starting another delegated review round through t3_thread_send. Provider, model, model options (see orchestrator_capabilities), runtime mode, and interaction mode inherit unless target overrides them. Prefer mode='async' for long work; mode='wait' blocks until completion or timeout. timeoutMs on mode=wait is only the parent's wait budget and does not cancel the child. waitTimedOut on that wait call means the timeout fired; keep that taskId and read status on later task_status. An async child's completion wakes this thread through a notification, steered into active turns where supported or queued otherwise, so end the turn instead of polling or spawning watchers; use task_status only when the result is needed mid-turn.",
+ "Needs an agent running inside a T3 thread. Delegate one task to a T3-owned child agent/subagent of THIS thread and run it with only the supplied task prompt, without copying parent conversation history. Choose providers and models from orchestrator_capabilities, which uses the same live catalog as the composer. Prefer native subagent tools for same-provider work only when they support the chosen model. Use this for any model missing from the native tool, including same-provider work, for cross-provider work, or for explicitly T3-owned child tasks. For every T3 delegated review round, call delegate_task again with the original brief, prior findings, responses, and unresolved objections in the task prompt. Track each round by its own taskId and use a distinct clientRequestId per round, stable across retries of that round. The childThreadId is backing storage, not the target for starting another delegated review round through t3_thread_send. Provider, model, model options (see orchestrator_capabilities), runtime mode, and interaction mode inherit unless target overrides them. A requested runtimeMode must be one the target provider lists in orchestrator_capabilities runtimeModes; an inherited one steps down to the broadest mode it offers. Prefer mode='async' for long work; mode='wait' blocks until completion or timeout. timeoutMs on mode=wait is only the parent's wait budget and does not cancel the child. waitTimedOut on that wait call means the timeout fired; keep that taskId and read status on later task_status. An async child's completion wakes this thread through a notification, steered into active turns where supported or queued otherwise, so end the turn instead of polling or spawning watchers; use task_status only when the result is needed mid-turn.",
parameters: OrchestratorMcpDelegateTaskInput,
success: OrchestratorMcpDelegateTaskResult,
failure: OrchestratorMcpFailure,
diff --git a/docs/orchestration-v2/orchestrator-mcp-server.md b/docs/orchestration-v2/orchestrator-mcp-server.md
index 14437ee7f69..20f6456b1a3 100644
--- a/docs/orchestration-v2/orchestrator-mcp-server.md
+++ b/docs/orchestration-v2/orchestrator-mcp-server.md
@@ -237,6 +237,13 @@ that driver; an explicit `providerInstanceId` is honored exactly and fails
when unavailable. Selecting a different provider without a model uses that
provider's first advertised model.
+A provider runs a runtime mode it does not offer as `approval-required`, so a
+child would ask for approval on every command. `orchestrator_capabilities`
+lists `runtimeModes` only for a provider that offers some of the modes, and
+omits it for a provider that offers all of them. When the target lists
+`runtimeModes`, an explicit `runtimeMode` outside that list is refused, and an
+inherited mode steps down to the broadest mode the target offers.
+
Each delegated review round uses a new `delegate_task` call with the original brief,
prior findings, responses, and unresolved objections. Track each round by its own `taskId` and use
a distinct `clientRequestId` per round, stable across retries of that round.
diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts
index f0ffa07bd40..61ee976e9e7 100644
--- a/packages/contracts/src/orchestratorMcp.ts
+++ b/packages/contracts/src/orchestratorMcp.ts
@@ -487,6 +487,8 @@ export const OrchestratorMcpProviderCapability = Schema.Struct({
options: Schema.optional(Schema.Array(ProviderOptionDescriptor)),
}),
),
+ /** Runtime modes the provider offers; omitted when it offers all of them. */
+ runtimeModes: Schema.optional(Schema.Array(RuntimeMode)),
canRunChildTask: Schema.Boolean,
canRunCrossProviderChildTask: Schema.Boolean,
constraints: Schema.Array(Schema.String),