Skip to content

Commit 4fa0222

Browse files
fix(server): leave out a subagent effort its model does not offer
A Claude subagent on a model without that effort level (claude-haiku-4-5 has none) no longer records the inherited effort on its selection, since Claude Code does not send it there. Nested subagents still inherit it. Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 4915a98 commit 4fa0222

3 files changed

Lines changed: 135 additions & 118 deletions

File tree

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

Lines changed: 105 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -7833,109 +7833,113 @@ describe("ClaudeAdapterV2 background wake turns", () => {
78337833
);
78347834

78357835
it.effect.each([
7836-
{ requested: undefined, expected: "max" },
7837-
{ requested: "low", expected: "low" },
7838-
])("records the effort a subagent runs at (Agent effort $requested)", ({ requested, expected }) =>
7839-
Effect.scoped(
7840-
Effect.gen(function* () {
7841-
const harness = yield* makeWakeHarness;
7842-
const now = yield* DateTime.now;
7843-
const toolUseId = "toolu-subagent-effort";
7844-
const parentSelection = {
7845-
instanceId: CLAUDE_TEST_MODEL_SELECTION.instanceId,
7846-
model: "claude-opus-4-6",
7847-
options: [
7848-
{ id: "effort", value: "max" },
7849-
{ id: "fastMode", value: false },
7850-
],
7851-
} satisfies ModelSelection;
7852-
yield* harness.runtime.startTurn(
7853-
makeClaudeTestTurnInput({
7854-
threadId: harness.threadId,
7855-
providerThread: harness.providerThread,
7856-
now,
7857-
attemptId: RunAttemptId.make("attempt-subagent-effort"),
7858-
text: "Spawn a subagent.",
7859-
attachments: [],
7860-
modelSelection: parentSelection,
7861-
}),
7862-
);
7863-
for (const frame of [
7864-
claudeSdkFrame({
7865-
type: "assistant",
7866-
parent_tool_use_id: null,
7867-
message: {
7868-
model: parentSelection.model,
7869-
id: "msg_subagent_effort_launch",
7870-
type: "message",
7871-
role: "assistant",
7872-
content: [
7873-
{
7874-
type: "tool_use",
7875-
id: toolUseId,
7876-
name: "Agent",
7877-
input: {
7878-
description: "Research",
7879-
subagent_type: "general-purpose",
7880-
model: "opus",
7881-
...(requested === undefined ? {} : { effort: requested }),
7882-
prompt: "Research the topic.",
7836+
{ agentModel: "opus", slug: "claude-opus-5-5", requested: undefined, expected: "max" },
7837+
{ agentModel: "opus", slug: "claude-opus-5-5", requested: "low", expected: "low" },
7838+
// claude-haiku-4-5 offers no effort, so none is sent or shown for it.
7839+
{ agentModel: "haiku-4.5", slug: "claude-haiku-4-5", requested: undefined, expected: null },
7840+
])(
7841+
"records the effort a $agentModel subagent runs at (Agent effort $requested)",
7842+
({ agentModel, slug, requested, expected }) =>
7843+
Effect.scoped(
7844+
Effect.gen(function* () {
7845+
const harness = yield* makeWakeHarness;
7846+
const now = yield* DateTime.now;
7847+
const toolUseId = "toolu-subagent-effort";
7848+
const parentSelection = {
7849+
instanceId: CLAUDE_TEST_MODEL_SELECTION.instanceId,
7850+
model: "claude-opus-4-6",
7851+
options: [
7852+
{ id: "effort", value: "max" },
7853+
{ id: "fastMode", value: false },
7854+
],
7855+
} satisfies ModelSelection;
7856+
yield* harness.runtime.startTurn(
7857+
makeClaudeTestTurnInput({
7858+
threadId: harness.threadId,
7859+
providerThread: harness.providerThread,
7860+
now,
7861+
attemptId: RunAttemptId.make("attempt-subagent-effort"),
7862+
text: "Spawn a subagent.",
7863+
attachments: [],
7864+
modelSelection: parentSelection,
7865+
}),
7866+
);
7867+
for (const frame of [
7868+
claudeSdkFrame({
7869+
type: "assistant",
7870+
parent_tool_use_id: null,
7871+
message: {
7872+
model: parentSelection.model,
7873+
id: "msg_subagent_effort_launch",
7874+
type: "message",
7875+
role: "assistant",
7876+
content: [
7877+
{
7878+
type: "tool_use",
7879+
id: toolUseId,
7880+
name: "Agent",
7881+
input: {
7882+
description: "Research",
7883+
subagent_type: "general-purpose",
7884+
model: agentModel,
7885+
...(requested === undefined ? {} : { effort: requested }),
7886+
prompt: "Research the topic.",
7887+
},
78837888
},
7884-
},
7885-
],
7886-
},
7887-
uuid: "00000000-0000-4000-8000-000000000211",
7888-
session_id: WAKE_NATIVE_SESSION,
7889-
}),
7890-
claudeSdkFrame({
7891-
type: "system",
7892-
subtype: "task_started",
7893-
task_id: "task-subagent-effort",
7894-
tool_use_id: toolUseId,
7895-
description: "Research",
7896-
task_type: "local_agent",
7897-
uuid: "00000000-0000-4000-8000-000000000212",
7898-
session_id: WAKE_NATIVE_SESSION,
7899-
}),
7900-
// The reply names the model the alias resolved to.
7901-
claudeSdkFrame({
7902-
type: "assistant",
7903-
parent_tool_use_id: toolUseId,
7904-
message: {
7905-
model: "claude-opus-5-5",
7906-
id: "msg_subagent_effort_observed",
7907-
type: "message",
7908-
role: "assistant",
7909-
content: [{ type: "text", text: "Researching." }],
7910-
},
7911-
uuid: "00000000-0000-4000-8000-000000000213",
7912-
session_id: WAKE_NATIVE_SESSION,
7913-
}),
7914-
makeResultFrame({
7915-
uuid: "00000000-0000-4000-8000-000000000214",
7916-
result: "Spawned the subagent.",
7917-
}),
7918-
]) {
7919-
yield* Queue.offer(harness.sdkMessages, frame);
7920-
}
7921-
yield* Queue.take(harness.terminalReceipts);
7889+
],
7890+
},
7891+
uuid: "00000000-0000-4000-8000-000000000211",
7892+
session_id: WAKE_NATIVE_SESSION,
7893+
}),
7894+
claudeSdkFrame({
7895+
type: "system",
7896+
subtype: "task_started",
7897+
task_id: "task-subagent-effort",
7898+
tool_use_id: toolUseId,
7899+
description: "Research",
7900+
task_type: "local_agent",
7901+
uuid: "00000000-0000-4000-8000-000000000212",
7902+
session_id: WAKE_NATIVE_SESSION,
7903+
}),
7904+
// The reply names the model the alias resolved to.
7905+
claudeSdkFrame({
7906+
type: "assistant",
7907+
parent_tool_use_id: toolUseId,
7908+
message: {
7909+
model: slug,
7910+
id: "msg_subagent_effort_observed",
7911+
type: "message",
7912+
role: "assistant",
7913+
content: [{ type: "text", text: "Researching." }],
7914+
},
7915+
uuid: "00000000-0000-4000-8000-000000000213",
7916+
session_id: WAKE_NATIVE_SESSION,
7917+
}),
7918+
makeResultFrame({
7919+
uuid: "00000000-0000-4000-8000-000000000214",
7920+
result: "Spawned the subagent.",
7921+
}),
7922+
]) {
7923+
yield* Queue.offer(harness.sdkMessages, frame);
7924+
}
7925+
yield* Queue.take(harness.terminalReceipts);
79227926

7923-
// The alias is stored as its slug, so the reply is no model change,
7924-
// and the parent's fast mode stays with the parent.
7925-
const subagentSelection = {
7926-
instanceId: parentSelection.instanceId,
7927-
model: "claude-opus-5-5",
7928-
options: [{ id: "effort", value: expected }],
7929-
};
7930-
const child = harness.events.find((event) => event.type === "app_thread.created");
7931-
assert.deepEqual(child?.appThread.modelSelection, subagentSelection);
7932-
const subagents = harness.events.filter((event) => event.type === "subagent.updated");
7933-
assert.deepEqual(
7934-
subagents.map((event) => event.subagent.modelSelection),
7935-
subagents.map(() => subagentSelection),
7936-
);
7937-
}).pipe(Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
7938-
),
7927+
// The alias is stored as its slug, so the reply is no model change,
7928+
// and the parent's fast mode stays with the parent.
7929+
const subagentSelection = {
7930+
instanceId: parentSelection.instanceId,
7931+
model: slug,
7932+
...(expected === null ? {} : { options: [{ id: "effort", value: expected }] }),
7933+
};
7934+
const child = harness.events.find((event) => event.type === "app_thread.created");
7935+
assert.deepEqual(child?.appThread.modelSelection, subagentSelection);
7936+
const subagents = harness.events.filter((event) => event.type === "subagent.updated");
7937+
assert.deepEqual(
7938+
subagents.map((event) => event.subagent.modelSelection),
7939+
subagents.map(() => subagentSelection),
7940+
);
7941+
}).pipe(Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
7942+
),
79397943
);
79407944

79417945
it.effect("gives a nested subagent its own effort, else the one its owner runs at", () =>

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import {
9898
import {
9999
BUNDLED_CLAUDE_MODEL_CATALOG,
100100
resolveClaudeCatalogContextWindowTokens,
101+
getClaudeCatalogModelCapabilities,
101102
resolveClaudeModelSlug,
102103
} from "../../provider/ClaudeModelCatalog.ts";
103104
import {
@@ -2856,6 +2857,26 @@ function canonicalClaudeSubagentModel(model: string): string {
28562857
return resolveClaudeModelSlug(BUNDLED_CLAUDE_MODEL_CATALOG, model);
28572858
}
28582859

2860+
/**
2861+
* The selection a subagent's thread shows. An effort its model does not offer
2862+
* is not sent for it, so it is left out (a nested subagent still inherits it).
2863+
*/
2864+
function claudeSubagentModelSelection(
2865+
instanceId: ModelSelection["instanceId"],
2866+
model: string,
2867+
effort: string | undefined,
2868+
): ModelSelection {
2869+
const descriptor = getClaudeCatalogModelCapabilities(
2870+
BUNDLED_CLAUDE_MODEL_CATALOG,
2871+
model,
2872+
).optionDescriptors?.find((candidate) => candidate.id === "effort");
2873+
const offered =
2874+
effort !== undefined &&
2875+
descriptor?.type === "select" &&
2876+
descriptor.options.some((option) => option.id === effort);
2877+
return { instanceId, model, ...(offered ? { options: [{ id: "effort", value: effort }] } : {}) };
2878+
}
2879+
28592880
const PENDING_CLAUDE_SUBAGENT_CAP = 64;
28602881
// Per-subagent bound on frames held while waiting for task_started.
28612882
const PENDING_CLAUDE_SUBAGENT_FRAME_CAP = 256;
@@ -4305,11 +4326,11 @@ export function makeClaudeAdapterV2(
43054326
// restart. The parent's other options belong to the parent's session.
43064327
...(existingSubagent === undefined || existingSubagent.task.modelSelection !== undefined
43074328
? {
4308-
modelSelection: {
4309-
instanceId: input.context.input.modelSelection.instanceId,
4310-
model: model || input.context.input.modelSelection.model,
4311-
...(effort === undefined ? {} : { options: [{ id: "effort", value: effort }] }),
4312-
},
4329+
modelSelection: claudeSubagentModelSelection(
4330+
input.context.input.modelSelection.instanceId,
4331+
model || input.context.input.modelSelection.model,
4332+
effort,
4333+
),
43134334
}
43144335
: {}),
43154336
...(input.progress === undefined ? {} : { progress: input.progress }),

‎apps/server/src/orchestration-v2/testkit/fixtures/claude_nested_subagent_model/output.ts‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,10 @@ export function assertClaudeNestedSubagentModelOutput(
4646
// only that snapshot can say who launched it and on which model.
4747
assert.equal(nested.parentNodeId, outer.id, "a nested subagent hangs off its owner");
4848
assert.equal(nested.model, SUBAGENT_MODEL, "a nested subagent runs on its owner's model");
49-
// No Agent call names an effort, so both run at the one the session sends
50-
// (claude-sonnet-4-6's default).
51-
assert.deepEqual(outer.modelSelection, {
52-
instanceId: outer.providerInstanceId,
53-
model: SUBAGENT_MODEL,
54-
options: [{ id: "effort", value: "high" }],
55-
});
56-
assert.deepEqual(
57-
nested.modelSelection,
58-
outer.modelSelection,
59-
"a nested subagent with no effort of its own runs at its owner's",
60-
);
49+
// The session's effort is not sent for claude-haiku-4-5, which offers none.
50+
const subagentSelection = { instanceId: outer.providerInstanceId, model: SUBAGENT_MODEL };
51+
assert.deepEqual(outer.modelSelection, subagentSelection);
52+
assert.deepEqual(nested.modelSelection, subagentSelection);
6153
const nestedNode = projection.nodes.find((node) => node.id === nested.id);
6254
assert.isDefined(nestedNode);
6355
assert.equal(nestedNode.parentNodeId, outer.id);

0 commit comments

Comments
 (0)