Skip to content

Commit d05ac07

Browse files
fix(server): resolve subagent models against the instance's custom models
Subagent model names and effort levels now resolve against the Claude instance's catalog, custom models included. A custom model keeps its own effort levels, and a bare custom slug that shadows a built-in alias keeps its name instead of being mapped to the built-in model. Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 7a14b52 commit d05ac07

2 files changed

Lines changed: 152 additions & 10 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ const DEFAULT_CLAUDE_SETTINGS = Schema.decodeSync(ClaudeSettings)({});
7474
const AUTO_COMPACT_CLAUDE_SETTINGS = Schema.decodeSync(ClaudeSettings)({
7575
autoCompactWindow: "300000",
7676
});
77+
const CUSTOM_MODEL_CLAUDE_SETTINGS = Schema.decodeSync(ClaudeSettings)({
78+
customModels: [
79+
// A bare custom slug that shadows the built-in "opus" alias.
80+
"opus",
81+
{
82+
slug: "claude-custom-tuned",
83+
name: "Tuned",
84+
capabilities: {
85+
optionDescriptors: [
86+
{
87+
id: "effort",
88+
label: "Reasoning",
89+
type: "select",
90+
options: [
91+
{ id: "gentle", label: "Gentle", isDefault: true },
92+
{ id: "brutal", label: "Brutal" },
93+
],
94+
},
95+
],
96+
},
97+
},
98+
],
99+
});
77100
const CLAUDE_TEST_MODEL_SELECTION = {
78101
instanceId: ProviderInstanceId.make(ClaudeAdapterV2.CLAUDE_PROVIDER),
79102
model: "claude-sonnet-4-6",
@@ -2108,6 +2131,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
21082131
readonly close?: (sdkMessages: Queue.Queue<SDKMessage>) => Effect.Effect<void>;
21092132
readonly interrupt?: Effect.Effect<void>;
21102133
readonly environment?: NodeJS.ProcessEnv;
2134+
readonly settings?: ClaudeSettings;
21112135
// A CLI process opened after the first streams from its own queue, so the
21122136
// first one can exit (Queue.shutdown) and a later turn can start another.
21132137
readonly freshQueueOnReopen?: boolean;
@@ -2142,7 +2166,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
21422166
let openedOptions: ClaudeAdapterV2.ClaudeAgentSdkQueryOptions | undefined;
21432167
const adapter = yield* ClaudeAdapterV2.makeClaudeAdapterV2({
21442168
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
2145-
settings: DEFAULT_CLAUDE_SETTINGS,
2169+
settings: options?.settings ?? DEFAULT_CLAUDE_SETTINGS,
21462170
environment: options?.environment ?? {},
21472171
attachmentsDir,
21482172
fileSystem,
@@ -8221,6 +8245,110 @@ describe("ClaudeAdapterV2 background wake turns", () => {
82218245
),
82228246
);
82238247

8248+
it.effect("resolves a subagent's model and effort against the instance's custom models", () =>
8249+
Effect.scoped(
8250+
Effect.gen(function* () {
8251+
const TUNED_TOOL_USE_ID = "toolu-effort-custom-tuned";
8252+
const SHADOW_TOOL_USE_ID = "toolu-effort-custom-shadow";
8253+
const harness = yield* makeWakeHarnessWithOptions({
8254+
settings: CUSTOM_MODEL_CLAUDE_SETTINGS,
8255+
});
8256+
const now = yield* DateTime.now;
8257+
yield* harness.runtime.startTurn(
8258+
makeClaudeTestTurnInput({
8259+
threadId: harness.threadId,
8260+
providerThread: harness.providerThread,
8261+
now,
8262+
attemptId: RunAttemptId.make("attempt-subagent-custom-effort"),
8263+
text: "Spawn subagents on custom models.",
8264+
attachments: [],
8265+
}),
8266+
);
8267+
for (const frame of [
8268+
claudeSdkFrame({
8269+
type: "assistant",
8270+
parent_tool_use_id: null,
8271+
message: {
8272+
model: CLAUDE_TEST_MODEL_SELECTION.model,
8273+
id: "msg_custom_effort_launch",
8274+
type: "message",
8275+
role: "assistant",
8276+
content: [
8277+
{
8278+
type: "tool_use",
8279+
id: TUNED_TOOL_USE_ID,
8280+
name: "Agent",
8281+
input: {
8282+
description: "Tuned",
8283+
subagent_type: "general-purpose",
8284+
model: "claude-custom-tuned",
8285+
effort: "brutal",
8286+
prompt: "Check one thing.",
8287+
},
8288+
},
8289+
{
8290+
type: "tool_use",
8291+
id: SHADOW_TOOL_USE_ID,
8292+
name: "Agent",
8293+
input: {
8294+
description: "Shadow",
8295+
subagent_type: "general-purpose",
8296+
model: "opus",
8297+
prompt: "Check another thing.",
8298+
},
8299+
},
8300+
],
8301+
},
8302+
uuid: "00000000-0000-4000-8000-000000000231",
8303+
session_id: WAKE_NATIVE_SESSION,
8304+
}),
8305+
...[TUNED_TOOL_USE_ID, SHADOW_TOOL_USE_ID].map((id, index) =>
8306+
claudeSdkFrame({
8307+
type: "system",
8308+
subtype: "task_started",
8309+
task_id: `task-${id}`,
8310+
tool_use_id: id,
8311+
description: id,
8312+
task_type: "local_agent",
8313+
uuid: `00000000-0000-4000-8000-00000000023${index + 2}`,
8314+
session_id: WAKE_NATIVE_SESSION,
8315+
}),
8316+
),
8317+
makeResultFrame({
8318+
uuid: "00000000-0000-4000-8000-000000000234",
8319+
result: "Spawned the subagents.",
8320+
}),
8321+
]) {
8322+
yield* Queue.offer(harness.sdkMessages, frame);
8323+
}
8324+
yield* Queue.take(harness.terminalReceipts);
8325+
8326+
const selections = Object.fromEntries(
8327+
harness.events.flatMap((event) =>
8328+
event.type === "subagent.updated"
8329+
? [[event.subagent.nativeTaskRef?.nativeId, event.subagent.modelSelection] as const]
8330+
: [],
8331+
),
8332+
);
8333+
const instanceId = CLAUDE_TEST_MODEL_SELECTION.instanceId;
8334+
assert.deepEqual(selections, {
8335+
// The custom model's own effort levels apply.
8336+
[`task-${TUNED_TOOL_USE_ID}`]: {
8337+
instanceId,
8338+
model: "claude-custom-tuned",
8339+
options: [{ id: "effort", value: "brutal" }],
8340+
},
8341+
// The custom slug is not resolved to the built-in model it shadows.
8342+
[`task-${SHADOW_TOOL_USE_ID}`]: { instanceId, model: "opus" },
8343+
});
8344+
}).pipe(
8345+
Effect.provide(
8346+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
8347+
),
8348+
),
8349+
),
8350+
);
8351+
82248352
it.effect("gives a nested subagent its own effort, else the one its owner runs at", () =>
82258353
Effect.scoped(
82268354
Effect.gen(function* () {

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ import {
9999
import {
100100
BUNDLED_CLAUDE_MODEL_CATALOG,
101101
resolveClaudeCatalogContextWindowTokens,
102+
type ClaudeModelCatalog,
102103
getClaudeCatalogModelCapabilities,
103104
resolveClaudeModelSlug,
105+
scopeClaudeModelCatalog,
104106
} from "../../provider/ClaudeModelCatalog.ts";
105107
import {
106108
boundProviderEventForLogging,
@@ -2879,25 +2881,26 @@ interface PendingClaudeSubagentLaunch {
28792881
* Agent calls name aliases ("opus") and replies name dated ids; both resolve
28802882
* to the catalog slug. A subagent's thread then keeps one model name across
28812883
* its launch, its replies and a resume after a restart, so a later report of
2882-
* the same model never reads as a model change that drops its effort.
2884+
* the same model never reads as a model change that drops its effort. The
2885+
* catalog is the instance's, so a custom model keeps its own name.
28832886
*/
2884-
function canonicalClaudeSubagentModel(model: string): string {
2885-
return resolveClaudeModelSlug(BUNDLED_CLAUDE_MODEL_CATALOG, model);
2887+
function canonicalClaudeSubagentModel(catalog: ClaudeModelCatalog, model: string): string {
2888+
return resolveClaudeModelSlug(catalog, model);
28862889
}
28872890

28882891
/**
28892892
* The selection a subagent's thread shows. An effort its model does not offer
28902893
* is not sent for it, so it is left out (a nested subagent still inherits it).
28912894
*/
28922895
function claudeSubagentModelSelection(
2896+
catalog: ClaudeModelCatalog,
28932897
instanceId: ModelSelection["instanceId"],
28942898
model: string,
28952899
effort: string | undefined,
28962900
): ModelSelection {
2897-
const descriptor = getClaudeCatalogModelCapabilities(
2898-
BUNDLED_CLAUDE_MODEL_CATALOG,
2899-
model,
2900-
).optionDescriptors?.find((candidate) => candidate.id === "effort");
2901+
const descriptor = getClaudeCatalogModelCapabilities(catalog, model).optionDescriptors?.find(
2902+
(candidate) => candidate.id === "effort",
2903+
);
29012904
const offered =
29022905
effort !== undefined &&
29032906
descriptor?.type === "select" &&
@@ -2931,6 +2934,7 @@ function rememberPendingClaudeSubagentLaunch(
29312934
* starts back to it.
29322935
*/
29332936
function rememberClaudeSubagentLaunch(
2937+
catalog: ClaudeModelCatalog,
29342938
context: ActiveClaudeTurnContext,
29352939
pending: Map<string, PendingClaudeSubagentLaunch>,
29362940
toolUseId: string,
@@ -2943,7 +2947,7 @@ function rememberClaudeSubagentLaunch(
29432947
// task_started resolves it.
29442948
const model =
29452949
requested !== "inherit"
2946-
? requested && canonicalClaudeSubagentModel(requested)
2950+
? requested && canonicalClaudeSubagentModel(catalog, requested)
29472951
: ownerToolUseId === null
29482952
? context.input.modelSelection.model
29492953
: undefined;
@@ -3103,6 +3107,11 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
31033107
) {
31043108
const mcpSessions = yield* McpProviderSessions.McpProviderSessions;
31053109
const { attachmentsDir, fileSystem, path, crypto, idAllocator, queryRunner } = adapterOptions;
3110+
// Subagent model names and effort levels, including the instance's custom models.
3111+
const subagentModelCatalog = scopeClaudeModelCatalog(
3112+
BUNDLED_CLAUDE_MODEL_CATALOG,
3113+
adapterOptions.settings.customModels,
3114+
);
31063115
const continuationRequests = adapterOptions.continuationRequests ?? {
31073116
offer: () => Effect.void,
31083117
};
@@ -4355,6 +4364,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
43554364
...(existingSubagent === undefined || existingSubagent.task.modelSelection !== undefined
43564365
? {
43574366
modelSelection: claudeSubagentModelSelection(
4367+
subagentModelCatalog,
43584368
input.context.input.modelSelection.instanceId,
43594369
model || input.context.input.modelSelection.model,
43604370
effort,
@@ -6230,7 +6240,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
62306240
const snapshotModel =
62316241
typeof message.message.model === "string" ? message.message.model.trim() : "";
62326242
const model =
6233-
snapshotModel.length === 0 ? undefined : canonicalClaudeSubagentModel(snapshotModel);
6243+
snapshotModel.length === 0
6244+
? undefined
6245+
: canonicalClaudeSubagentModel(subagentModelCatalog, snapshotModel);
62346246
if (parentToolUseId !== null && model !== undefined) {
62356247
const subagent = yield* resolveSubagentByToolUseId(context, parentToolUseId);
62366248
if (subagent === undefined) {
@@ -6439,6 +6451,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
64396451
const nativeToolInput = claudeNativeToolInputFromUnknown(toolUse.input);
64406452
if (toolUse.name === "Agent") {
64416453
rememberClaudeSubagentLaunch(
6454+
subagentModelCatalog,
64426455
context,
64436456
pendingSubagentLaunchesByToolUseId,
64446457
toolUse.id,
@@ -7037,6 +7050,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
70377050
const heldForEcho = context.heldRootFrames.length > 0;
70387051
if (toolName === "Agent") {
70397052
rememberClaudeSubagentLaunch(
7053+
subagentModelCatalog,
70407054
context,
70417055
pendingSubagentLaunchesByToolUseId,
70427056
nativeRequestId,

0 commit comments

Comments
 (0)