Skip to content

Commit bc4eae8

Browse files
Gourav224claude
andcommitted
fix(server): a Claude custom model named like a built-in alias is sent under its own name
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 65b4a69 commit bc4eae8

2 files changed

Lines changed: 96 additions & 10 deletions

File tree

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,84 @@ describe("ClaudeAdapterV2 Auto-accept edits", () => {
850850
);
851851
});
852852

853+
describe("ClaudeAdapterV2 custom model names", () => {
854+
it.effect("sends a custom model that shares a built-in alias under its own name", () =>
855+
Effect.scoped(
856+
Effect.gen(function* () {
857+
const fileSystem = yield* FileSystem.FileSystem;
858+
const opened: Array<ClaudeAdapterV2.ClaudeAgentSdkQueryOptions> = [];
859+
const adapter = yield* ClaudeAdapterV2.makeClaudeAdapterV2({
860+
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
861+
settings: CUSTOM_MODEL_CLAUDE_SETTINGS,
862+
environment: {},
863+
attachmentsDir: yield* fileSystem.makeTempDirectoryScoped({
864+
prefix: "t3-claude-custom-",
865+
}),
866+
fileSystem,
867+
path: yield* Path.Path,
868+
crypto: yield* Crypto.Crypto,
869+
idAllocator: yield* IdAllocator.IdAllocatorV2,
870+
queryRunner: {
871+
allocateSessionId: Effect.succeed("native-thread-claude-custom"),
872+
open: (input) =>
873+
Effect.sync(() => {
874+
opened.push(input.options);
875+
return {
876+
messages: Stream.never,
877+
offer: () => Effect.void,
878+
setModel: () => Effect.void,
879+
applyFlagSettings: () => Effect.void,
880+
setPermissionMode: () => Effect.void,
881+
backgroundTasks: () => Effect.succeed(false),
882+
stopTask: () => Effect.void,
883+
interrupt: Effect.void,
884+
close: Effect.void,
885+
};
886+
}),
887+
forkSession: () => Effect.die("unused"),
888+
subagentLaunchToolUseId: () => Effect.succeed(null),
889+
assertComplete: Effect.void,
890+
},
891+
});
892+
// "opus" is a built-in alias, and a proxy may serve its own model of that name.
893+
const modelSelection = { ...CLAUDE_TEST_MODEL_SELECTION, model: "opus", options: [] };
894+
const threadId = ThreadId.make("thread-claude-custom");
895+
const runtime = yield* adapter.openSession({
896+
threadId,
897+
providerSessionId: ProviderSessionId.make("provider-session-claude-custom"),
898+
modelSelection,
899+
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
900+
});
901+
const providerThread = yield* runtime.ensureThread({
902+
threadId,
903+
modelSelection,
904+
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
905+
});
906+
yield* runtime
907+
.startTurn(
908+
makeClaudeTestTurnInput({
909+
threadId,
910+
providerThread,
911+
now: yield* DateTime.now,
912+
attemptId: RunAttemptId.make("attempt-claude-custom"),
913+
text: "Hello",
914+
attachments: [],
915+
modelSelection,
916+
}),
917+
)
918+
.pipe(Effect.exit);
919+
920+
assert.lengthOf(opened, 1);
921+
assert.equal(opened[0]!.model, "opus");
922+
}).pipe(
923+
Effect.provide(
924+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
925+
),
926+
),
927+
),
928+
);
929+
});
930+
853931
describe("ClaudeAdapterV2 append-system-prompt-file launch argument", () => {
854932
const startTurnWithLaunchArgs = Effect.fnUntraced(function* (launchArgs: string, cwd: string) {
855933
const fileSystem = yield* FileSystem.FileSystem;

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,9 @@ export function makeClaudeQueryOptions(input: {
14241424
readonly appendSystemPromptFileText?: string;
14251425
// Flag settings, because a user's settings.json env beats the process env in Claude Code.
14261426
readonly toolSearchOverride?: "true";
1427+
readonly modelCatalog?: ClaudeModelCatalog;
14271428
}): ClaudeAgentSdkQueryOptions {
1428-
const compiledSelection = compileClaudeModelSelection(input.modelSelection);
1429+
const compiledSelection = compileClaudeModelSelection(input.modelSelection, input.modelCatalog);
14291430
const {
14301431
"permission-mode": launchArgPermissionMode,
14311432
"dangerously-skip-permissions": launchArgSkipPermissions,
@@ -4242,7 +4243,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
42424243
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
42434244
const serverSettings = yield* Effect.serviceOption(ServerSettings.ServerSettingsService);
42444245
const { attachmentsDir, fileSystem, path, crypto, idAllocator, queryRunner } = adapterOptions;
4245-
const subagentModelCatalog = scopeClaudeModelCatalog(
4246+
const scopedModelCatalog = scopeClaudeModelCatalog(
42464247
BUNDLED_CLAUDE_MODEL_CATALOG,
42474248
adapterOptions.settings.customModels,
42484249
);
@@ -6081,7 +6082,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
60816082
existingSubagent === undefined
60826083
? (input.effort ??
60836084
input.owner?.effort ??
6084-
compileClaudeModelSelection(input.context.input.modelSelection).effort)
6085+
compileClaudeModelSelection(input.context.input.modelSelection, scopedModelCatalog)
6086+
.effort)
60856087
: existingSubagent.effort;
60866088
const model = input.model ?? priorTask?.model ?? null;
60876089
const task = {
@@ -6119,7 +6121,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
61196121
...(existingSubagent === undefined || existingSubagent.task.modelSelection !== undefined
61206122
? {
61216123
modelSelection: claudeSubagentModelSelection(
6122-
subagentModelCatalog,
6124+
scopedModelCatalog,
61236125
input.context.input.modelSelection.instanceId,
61246126
model || input.context.input.modelSelection.model,
61256127
effort,
@@ -8424,7 +8426,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
84248426
const model =
84258427
snapshotModel.length === 0 || snapshotModel === "<synthetic>"
84268428
? undefined
8427-
: canonicalClaudeSubagentModel(subagentModelCatalog, snapshotModel);
8429+
: canonicalClaudeSubagentModel(scopedModelCatalog, snapshotModel);
84288430
if (parentToolUseId !== null && model !== undefined) {
84298431
const subagent = yield* resolveSubagentByToolUseId(context, parentToolUseId);
84308432
if (subagent === undefined) {
@@ -8708,7 +8710,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
87088710
const nativeToolInput = claudeNativeToolInputFromUnknown(toolUse.input);
87098711
if (toolUse.name === "Agent") {
87108712
rememberClaudeSubagentLaunch(
8711-
subagentModelCatalog,
8713+
scopedModelCatalog,
87128714
context,
87138715
pendingSubagentLaunchesByToolUseId,
87148716
toolUse.id,
@@ -9280,7 +9282,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
92809282
const heldForEcho = context.heldRootFrames.length > 0;
92819283
if (toolName === "Agent") {
92829284
rememberClaudeSubagentLaunch(
9283-
subagentModelCatalog,
9285+
scopedModelCatalog,
92849286
context,
92859287
pendingSubagentLaunchesByToolUseId,
92869288
nativeRequestId,
@@ -9631,7 +9633,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
96319633
: { allowedTools: queryPolicy.allowedTools }),
96329634
});
96339635
const queryPolicyKey = claudeEffectiveQueryPolicyKey(queryPolicy, mcpOverrides);
9634-
const compiledSelection = compileClaudeModelSelection(turnInput.modelSelection);
9636+
const compiledSelection = compileClaudeModelSelection(
9637+
turnInput.modelSelection,
9638+
scopedModelCatalog,
9639+
);
96359640
const resumeSessionAt = yield* getNativeConversationHeadId(turnInput.providerThread);
96369641
const existing = yield* Ref.get(queryContext);
96379642
// Continuations drain existing output without prompting; retain the live process regardless of selection.
@@ -9759,6 +9764,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
97599764
supportedDialogKinds: ["resume_return"],
97609765
...(appendSystemPromptFileText === undefined ? {} : { appendSystemPromptFileText }),
97619766
...(toolSearchOverride === undefined ? {} : { toolSearchOverride }),
9767+
modelCatalog: scopedModelCatalog,
97629768
});
97639769
const querySession = yield* queryRunner
97649770
.open({
@@ -9927,7 +9933,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
99279933
: yield* makeClaudeUserMessageWithAttachments({
99289934
text: applyClaudePromptEffortPrefix(
99299935
turnInput.message.text,
9930-
compileClaudeModelSelection(turnInput.modelSelection).promptEffort,
9936+
compileClaudeModelSelection(turnInput.modelSelection, scopedModelCatalog)
9937+
.promptEffort,
99319938
),
99329939
attachments: turnInput.message.attachments,
99339940
attachmentsDir,
@@ -10380,7 +10387,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1038010387
const userMessage = yield* makeClaudeUserMessageWithAttachments({
1038110388
text: applyClaudePromptEffortPrefix(
1038210389
turnInput.message.text,
10383-
compileClaudeModelSelection(currentTurn.input.modelSelection).promptEffort,
10390+
compileClaudeModelSelection(currentTurn.input.modelSelection, scopedModelCatalog)
10391+
.promptEffort,
1038410392
),
1038510393
attachments: turnInput.message.attachments,
1038610394
priority: "now",

0 commit comments

Comments
 (0)