Skip to content

Commit 5c0b8bb

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 3e250a8 commit 5c0b8bb

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
@@ -750,6 +750,84 @@ describe("ClaudeAdapterV2 Auto-accept edits", () => {
750750
);
751751
});
752752

753+
describe("ClaudeAdapterV2 custom model names", () => {
754+
it.effect("sends a custom model that shares a built-in alias under its own name", () =>
755+
Effect.scoped(
756+
Effect.gen(function* () {
757+
const fileSystem = yield* FileSystem.FileSystem;
758+
const opened: Array<ClaudeAdapterV2.ClaudeAgentSdkQueryOptions> = [];
759+
const adapter = yield* ClaudeAdapterV2.makeClaudeAdapterV2({
760+
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
761+
settings: CUSTOM_MODEL_CLAUDE_SETTINGS,
762+
environment: {},
763+
attachmentsDir: yield* fileSystem.makeTempDirectoryScoped({
764+
prefix: "t3-claude-custom-",
765+
}),
766+
fileSystem,
767+
path: yield* Path.Path,
768+
crypto: yield* Crypto.Crypto,
769+
idAllocator: yield* IdAllocator.IdAllocatorV2,
770+
queryRunner: {
771+
allocateSessionId: Effect.succeed("native-thread-claude-custom"),
772+
open: (input) =>
773+
Effect.sync(() => {
774+
opened.push(input.options);
775+
return {
776+
messages: Stream.never,
777+
offer: () => Effect.void,
778+
setModel: () => Effect.void,
779+
applyFlagSettings: () => Effect.void,
780+
setPermissionMode: () => Effect.void,
781+
backgroundTasks: () => Effect.succeed(false),
782+
stopTask: () => Effect.void,
783+
interrupt: Effect.void,
784+
close: Effect.void,
785+
};
786+
}),
787+
forkSession: () => Effect.die("unused"),
788+
subagentLaunchToolUseId: () => Effect.succeed(null),
789+
assertComplete: Effect.void,
790+
},
791+
});
792+
// "opus" is a built-in alias, and a proxy may serve its own model of that name.
793+
const modelSelection = { ...CLAUDE_TEST_MODEL_SELECTION, model: "opus", options: [] };
794+
const threadId = ThreadId.make("thread-claude-custom");
795+
const runtime = yield* adapter.openSession({
796+
threadId,
797+
providerSessionId: ProviderSessionId.make("provider-session-claude-custom"),
798+
modelSelection,
799+
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
800+
});
801+
const providerThread = yield* runtime.ensureThread({
802+
threadId,
803+
modelSelection,
804+
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
805+
});
806+
yield* runtime
807+
.startTurn(
808+
makeClaudeTestTurnInput({
809+
threadId,
810+
providerThread,
811+
now: yield* DateTime.now,
812+
attemptId: RunAttemptId.make("attempt-claude-custom"),
813+
text: "Hello",
814+
attachments: [],
815+
modelSelection,
816+
}),
817+
)
818+
.pipe(Effect.exit);
819+
820+
assert.lengthOf(opened, 1);
821+
assert.equal(opened[0]!.model, "opus");
822+
}).pipe(
823+
Effect.provide(
824+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
825+
),
826+
),
827+
),
828+
);
829+
});
830+
753831
describe("ClaudeAdapterV2 append-system-prompt-file launch argument", () => {
754832
const startTurnWithLaunchArgs = Effect.fnUntraced(function* (launchArgs: string, cwd: string) {
755833
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
@@ -1264,8 +1264,9 @@ export function makeClaudeQueryOptions(input: {
12641264
readonly supportedDialogKinds?: ClaudeQueryOptions["supportedDialogKinds"];
12651265
readonly allowDangerouslySkipPermissions?: boolean;
12661266
readonly appendSystemPromptFileText?: string;
1267+
readonly modelCatalog?: ClaudeModelCatalog;
12671268
}): ClaudeAgentSdkQueryOptions {
1268-
const compiledSelection = compileClaudeModelSelection(input.modelSelection);
1269+
const compiledSelection = compileClaudeModelSelection(input.modelSelection, input.modelCatalog);
12691270
const {
12701271
"permission-mode": launchArgPermissionMode,
12711272
"dangerously-skip-permissions": launchArgSkipPermissions,
@@ -3816,7 +3817,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
38163817
) {
38173818
const mcpSessions = yield* McpProviderSessions.McpProviderSessions;
38183819
const { attachmentsDir, fileSystem, path, crypto, idAllocator, queryRunner } = adapterOptions;
3819-
const subagentModelCatalog = scopeClaudeModelCatalog(
3820+
const scopedModelCatalog = scopeClaudeModelCatalog(
38203821
BUNDLED_CLAUDE_MODEL_CATALOG,
38213822
adapterOptions.settings.customModels,
38223823
);
@@ -5538,7 +5539,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
55385539
existingSubagent === undefined
55395540
? (input.effort ??
55405541
input.owner?.effort ??
5541-
compileClaudeModelSelection(input.context.input.modelSelection).effort)
5542+
compileClaudeModelSelection(input.context.input.modelSelection, scopedModelCatalog)
5543+
.effort)
55425544
: existingSubagent.effort;
55435545
const model = input.model ?? priorTask?.model ?? null;
55445546
const task = {
@@ -5576,7 +5578,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
55765578
...(existingSubagent === undefined || existingSubagent.task.modelSelection !== undefined
55775579
? {
55785580
modelSelection: claudeSubagentModelSelection(
5579-
subagentModelCatalog,
5581+
scopedModelCatalog,
55805582
input.context.input.modelSelection.instanceId,
55815583
model || input.context.input.modelSelection.model,
55825584
effort,
@@ -7865,7 +7867,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
78657867
const model =
78667868
snapshotModel.length === 0 || snapshotModel === "<synthetic>"
78677869
? undefined
7868-
: canonicalClaudeSubagentModel(subagentModelCatalog, snapshotModel);
7870+
: canonicalClaudeSubagentModel(scopedModelCatalog, snapshotModel);
78697871
if (parentToolUseId !== null && model !== undefined) {
78707872
const subagent = yield* resolveSubagentByToolUseId(context, parentToolUseId);
78717873
if (subagent === undefined) {
@@ -8150,7 +8152,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
81508152
const nativeToolInput = claudeNativeToolInputFromUnknown(toolUse.input);
81518153
if (toolUse.name === "Agent") {
81528154
rememberClaudeSubagentLaunch(
8153-
subagentModelCatalog,
8155+
scopedModelCatalog,
81548156
context,
81558157
pendingSubagentLaunchesByToolUseId,
81568158
toolUse.id,
@@ -8708,7 +8710,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
87088710
const heldForEcho = context.heldRootFrames.length > 0;
87098711
if (toolName === "Agent") {
87108712
rememberClaudeSubagentLaunch(
8711-
subagentModelCatalog,
8713+
scopedModelCatalog,
87128714
context,
87138715
pendingSubagentLaunchesByToolUseId,
87148716
nativeRequestId,
@@ -9047,7 +9049,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
90479049
: { allowedTools: queryPolicy.allowedTools }),
90489050
});
90499051
const queryPolicyKey = claudeEffectiveQueryPolicyKey(queryPolicy, mcpOverrides);
9050-
const compiledSelection = compileClaudeModelSelection(turnInput.modelSelection);
9052+
const compiledSelection = compileClaudeModelSelection(
9053+
turnInput.modelSelection,
9054+
scopedModelCatalog,
9055+
);
90519056
const resumeSessionAt = yield* getNativeConversationHeadId(turnInput.providerThread);
90529057
const existing = yield* Ref.get(queryContext);
90539058
// A continuation prompts nothing: it drains output the live process
@@ -9172,6 +9177,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
91729177
onUserDialog,
91739178
supportedDialogKinds: ["resume_return"],
91749179
...(appendSystemPromptFileText === undefined ? {} : { appendSystemPromptFileText }),
9180+
modelCatalog: scopedModelCatalog,
91759181
});
91769182
const querySession = yield* queryRunner
91779183
.open({
@@ -9335,7 +9341,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
93359341
: yield* makeClaudeUserMessageWithAttachments({
93369342
text: applyClaudePromptEffortPrefix(
93379343
turnInput.message.text,
9338-
compileClaudeModelSelection(turnInput.modelSelection).promptEffort,
9344+
compileClaudeModelSelection(turnInput.modelSelection, scopedModelCatalog)
9345+
.promptEffort,
93399346
),
93409347
attachments: turnInput.message.attachments,
93419348
attachmentsDir,
@@ -9772,7 +9779,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
97729779
const userMessage = yield* makeClaudeUserMessageWithAttachments({
97739780
text: applyClaudePromptEffortPrefix(
97749781
turnInput.message.text,
9775-
compileClaudeModelSelection(currentTurn.input.modelSelection).promptEffort,
9782+
compileClaudeModelSelection(currentTurn.input.modelSelection, scopedModelCatalog)
9783+
.promptEffort,
97769784
),
97779785
attachments: turnInput.message.attachments,
97789786
priority: "now",

0 commit comments

Comments
 (0)