Skip to content

Commit a1fd17a

Browse files
committed
fix(server): retain inherited Claude subagent options
1 parent 3a19fd0 commit a1fd17a

2 files changed

Lines changed: 86 additions & 23 deletions

File tree

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

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12383,12 +12383,22 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1238312383
"synthetic-after",
1238412384
"inherit",
1238512385
"unknown",
12386+
"requested-parent",
12387+
"configured-default",
12388+
"configured-extended",
1238612389
] as const)(
1238712390
"records the subagent model from %s without inheriting the parent override",
1238812391
(source) =>
1238912392
Effect.scoped(
1239012393
Effect.gen(function* () {
12391-
const harness = yield* makeWakeHarness;
12394+
const harness = yield* makeWakeHarnessWithOptions({
12395+
environment:
12396+
source === "configured-default"
12397+
? { CLAUDE_CODE_SUBAGENT_MODEL: "claude-opus-4-6" }
12398+
: source === "configured-extended"
12399+
? { CLAUDE_CODE_SUBAGENT_MODEL: "claude-opus-4-6[1m]" }
12400+
: {},
12401+
});
1239212402
const now = yield* DateTime.now;
1239312403
const toolUseId = "toolu-subagent-model";
1239412404
const parentModel = "claude-opus-4-6";
@@ -12403,7 +12413,14 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1240312413
attemptId: RunAttemptId.make("attempt-subagent-model"),
1240412414
text: "Spawn a Haiku subagent.",
1240512415
attachments: [],
12406-
modelSelection: { ...CLAUDE_TEST_MODEL_SELECTION, model: parentModel },
12416+
modelSelection: {
12417+
...CLAUDE_TEST_MODEL_SELECTION,
12418+
model: parentModel,
12419+
options: [
12420+
...CLAUDE_TEST_MODEL_SELECTION.options,
12421+
{ id: "contextWindow", value: "1m" },
12422+
],
12423+
},
1240712424
}),
1240812425
);
1240912426
const observed = claudeSdkFrame({
@@ -12438,9 +12455,16 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1243812455
input: {
1243912456
description: "Haiku puzzle",
1244012457
subagent_type: "general-purpose",
12441-
...(source === "unknown"
12458+
...(source === "unknown" || source.startsWith("configured-")
1244212459
? {}
12443-
: { model: source === "inherit" ? "inherit" : "haiku" }),
12460+
: {
12461+
model:
12462+
source === "inherit"
12463+
? "inherit"
12464+
: source === "requested-parent"
12465+
? parentModel
12466+
: "haiku",
12467+
}),
1244412468
prompt: "Solve the puzzle.",
1244512469
},
1244612470
},
@@ -12479,18 +12503,31 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1247912503
const initialModel =
1248012504
source === "observed-before"
1248112505
? observedSlug
12482-
: source === "inherit"
12483-
? parentModel
12484-
: source === "unknown"
12485-
? null
12486-
: "claude-haiku-5-5";
12506+
: source === "configured-extended"
12507+
? `${parentModel}[1m]`
12508+
: source === "inherit" ||
12509+
source === "requested-parent" ||
12510+
source === "configured-default"
12511+
? parentModel
12512+
: source === "unknown"
12513+
? null
12514+
: "claude-haiku-5-5";
1248712515
assert.equal(subagents[0]?.subagent.model, initialModel);
1248812516
assert.equal(
1248912517
subagents.at(-1)?.subagent.model,
1249012518
source.startsWith("observed") ? observedSlug : initialModel,
1249112519
);
1249212520
const child = harness.events.find((event) => event.type === "app_thread.created");
12493-
assert.equal(child?.appThread.modelSelection?.model, initialModel ?? parentModel);
12521+
assert.equal(
12522+
child?.appThread.modelSelection?.model,
12523+
source === "configured-extended" ? parentModel : (initialModel ?? parentModel),
12524+
);
12525+
assert.equal(
12526+
getModelSelectionStringOptionValue(child?.appThread.modelSelection, "contextWindow"),
12527+
source === "inherit" || source === "unknown" || source === "configured-extended"
12528+
? "1m"
12529+
: undefined,
12530+
);
1249412531
}).pipe(
1249512532
Effect.provide(
1249612533
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
@@ -12678,7 +12715,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1267812715
),
1267912716
);
1268012717

12681-
it.effect("gives a nested subagent its own effort, else the one its owner runs at", () =>
12718+
it.effect("keeps nested subagent context while allowing their own effort", () =>
1268212719
Effect.scoped(
1268312720
Effect.gen(function* () {
1268412721
const OUTER_TOOL_USE_ID = "toolu-effort-outer";
@@ -12689,7 +12726,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1268912726
const parentSelection = {
1269012727
instanceId: CLAUDE_TEST_MODEL_SELECTION.instanceId,
1269112728
model: "claude-opus-4-6",
12692-
options: [{ id: "effort", value: "high" }],
12729+
options: [
12730+
{ id: "contextWindow", value: "1m" },
12731+
{ id: "effort", value: "high" },
12732+
],
1269312733
} satisfies ModelSelection;
1269412734
yield* harness.runtime.startTurn(
1269512735
makeClaudeTestTurnInput({
@@ -12789,6 +12829,12 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1278912829
: [],
1279012830
);
1279112831
assert.deepEqual(childEfforts, ["low", "low", "max"]);
12832+
const childContexts = harness.events.flatMap((event) =>
12833+
event.type === "app_thread.created" && event.appThread.id !== harness.threadId
12834+
? [getModelSelectionStringOptionValue(event.appThread.modelSelection, "contextWindow")]
12835+
: [],
12836+
);
12837+
assert.deepEqual(childContexts, ["1m", "1m", "1m"]);
1279212838
}).pipe(
1279312839
Effect.provide(
1279412840
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),

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

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4135,6 +4135,7 @@ function isClaudeTranscriptConversationLine(
41354135
interface PendingClaudeSubagentLaunch {
41364136
readonly model?: string;
41374137
readonly effort?: string;
4138+
readonly inheritModel?: boolean;
41384139
readonly ownerToolUseId?: string;
41394140
}
41404141

@@ -4147,8 +4148,15 @@ function claudeSubagentModelSelection(
41474148
instanceId: ModelSelection["instanceId"],
41484149
model: string,
41494150
effort: string | undefined,
4151+
inheritedSelection?: ModelSelection,
41504152
): ModelSelection {
41514153
const selection = resolveClaudeCatalogModelSelection(catalog, instanceId, model);
4154+
const options = new Map(
4155+
[
4156+
...(inheritedSelection?.model === selection.model ? (inheritedSelection.options ?? []) : []),
4157+
...(selection.options ?? []),
4158+
].map((option) => [option.id, option] as const),
4159+
);
41524160
const descriptor = getClaudeCatalogModelCapabilities(
41534161
catalog,
41544162
selection.model,
@@ -4157,15 +4165,11 @@ function claudeSubagentModelSelection(
41574165
effort !== undefined &&
41584166
descriptor?.type === "select" &&
41594167
descriptor.options.some((option) => option.id === effort);
4160-
return offered
4161-
? {
4162-
...selection,
4163-
options: [
4164-
...(selection.options?.filter((option) => option.id !== "effort") ?? []),
4165-
{ id: "effort", value: effort },
4166-
],
4167-
}
4168-
: selection;
4168+
if (offered) {
4169+
options.delete("effort");
4170+
options.set("effort", { id: "effort", value: effort });
4171+
}
4172+
return { ...selection, ...(options.size > 0 ? { options: [...options.values()] } : {}) };
41694173
}
41704174

41714175
const PENDING_CLAUDE_SUBAGENT_CAP = 64;
@@ -4193,9 +4197,10 @@ function rememberClaudeSubagentLaunch(
41934197
toolUseId: string,
41944198
input: ClaudeNativeToolInput,
41954199
ownerToolUseId: string | null,
4200+
defaultModel: string | undefined,
41964201
): void {
41974202
if (context.subagentsByToolUseId.has(toolUseId)) return;
4198-
const requested = firstStringInputField(input, ["model"]);
4203+
const requested = firstStringInputField(input, ["model"]) ?? (defaultModel?.trim() || undefined);
41994204
const model =
42004205
requested !== "inherit"
42014206
? requested && canonicalClaudeSubagentModel(catalog, requested)
@@ -4206,11 +4211,13 @@ function rememberClaudeSubagentLaunch(
42064211
const launch: PendingClaudeSubagentLaunch = {
42074212
...(model === undefined || pending.get(toolUseId)?.model !== undefined ? {} : { model }),
42084213
...(effort === undefined ? {} : { effort }),
4214+
inheritModel: requested === undefined || requested === "inherit",
42094215
...(ownerToolUseId === null ? {} : { ownerToolUseId }),
42104216
};
42114217
if (
42124218
launch.model !== undefined ||
42134219
launch.effort !== undefined ||
4220+
launch.inheritModel === true ||
42144221
launch.ownerToolUseId !== undefined
42154222
) {
42164223
rememberPendingClaudeSubagentLaunch(pending, toolUseId, launch);
@@ -6305,6 +6312,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
63056312
readonly title?: string;
63066313
readonly model?: string;
63076314
readonly effort?: string;
6315+
readonly inheritModel?: boolean;
63086316
readonly owner?: ActiveClaudeSubagent;
63096317
readonly nativeTaskType?: string;
63106318
readonly progress?: string;
@@ -6406,6 +6414,11 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
64066414
.effort)
64076415
: existingSubagent.effort;
64086416
const model = input.model ?? priorTask?.model ?? null;
6417+
const inheritedSelection =
6418+
existingSubagent?.task.modelSelection ??
6419+
(input.inheritModel
6420+
? (input.owner?.task.modelSelection ?? input.context.input.modelSelection)
6421+
: undefined);
64096422
const task = {
64106423
...(priorTask ?? {
64116424
id: nodeId,
@@ -6443,8 +6456,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
64436456
modelSelection: claudeSubagentModelSelection(
64446457
modelCatalog,
64456458
input.context.input.modelSelection.instanceId,
6446-
model || input.context.input.modelSelection.model,
6459+
model || inheritedSelection?.model || input.context.input.modelSelection.model,
64476460
effort,
6461+
inheritedSelection,
64486462
),
64496463
}
64506464
: {}),
@@ -8925,6 +8939,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
89258939
...(message.prompt === undefined ? {} : { prompt: message.prompt }),
89268940
...(model === undefined ? {} : { model }),
89278941
...(launch?.effort === undefined ? {} : { effort: launch.effort }),
8942+
...(launch?.inheritModel === true ? { inheritModel: true } : {}),
89288943
...(owner === undefined ? {} : { owner }),
89298944
...(isWorkflow
89308945
? {
@@ -9069,6 +9084,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
90699084
toolUse.id,
90709085
nativeToolInput,
90719086
parentToolUseIdFromSdkMessage(message),
9087+
adapterOptions.environment.CLAUDE_CODE_SUBAGENT_MODEL,
90729088
);
90739089
continue;
90749090
}
@@ -9643,6 +9659,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
96439659
nativeRequestId,
96449660
nativeToolInput,
96459661
null,
9662+
adapterOptions.environment.CLAUDE_CODE_SUBAGENT_MODEL,
96469663
);
96479664
} else if (startToolCall && !heldForEcho) {
96489665
yield* ensureToolCallStarted({

0 commit comments

Comments
 (0)