fix(cli): display correct model for sub-agents in sessions list (#18660)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: ba54c5a351
Co-authored-by: robbyczgw-cla <239660374+robbyczgw-cla@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Robby
2026-02-18 05:59:20 +01:00
committed by GitHub
parent a69e7682c1
commit 5c69e625f5
13 changed files with 485 additions and 67 deletions

View File

@@ -6,7 +6,7 @@ import { normalizeAgentId, parseAgentSessionKey } from "../routing/session-key.j
import { normalizeDeliveryContext } from "../utils/delivery-context.js";
import { resolveAgentConfig } from "./agent-scope.js";
import { AGENT_LANE_SUBAGENT } from "./lanes.js";
import { resolveDefaultModelForAgent } from "./model-selection.js";
import { resolveSubagentSpawnModelSelection } from "./model-selection.js";
import { buildSubagentSystemPrompt } from "./subagent-announce.js";
import { getSubagentDepthFromSessionStore } from "./subagent-depth.js";
import { countActiveRunsForSession, registerSubagentRun } from "./subagent-registry.js";
@@ -49,7 +49,6 @@ export type SpawnSubagentResult = {
runId?: string;
note?: string;
modelApplied?: boolean;
warning?: string;
error?: string;
};
@@ -68,21 +67,6 @@ export function splitModelRef(ref?: string) {
return { provider: undefined, model: trimmed };
}
export function normalizeModelSelection(value: unknown): string | undefined {
if (typeof value === "string") {
const trimmed = value.trim();
return trimmed || undefined;
}
if (!value || typeof value !== "object") {
return undefined;
}
const primary = (value as { primary?: unknown }).primary;
if (typeof primary === "string" && primary.trim()) {
return primary.trim();
}
return undefined;
}
export async function spawnSubagentDirect(
params: SpawnSubagentParams,
ctx: SpawnSubagentContext,
@@ -104,7 +88,6 @@ export async function spawnSubagentDirect(
typeof params.runTimeoutSeconds === "number" && Number.isFinite(params.runTimeoutSeconds)
? Math.max(0, Math.floor(params.runTimeoutSeconds))
: 0;
let modelWarning: string | undefined;
let modelApplied = false;
const cfg = loadConfig();
@@ -166,16 +149,11 @@ export async function spawnSubagentDirect(
const childDepth = callerDepth + 1;
const spawnedByKey = requesterInternalKey;
const targetAgentConfig = resolveAgentConfig(cfg, targetAgentId);
const runtimeDefaultModel = resolveDefaultModelForAgent({
const resolvedModel = resolveSubagentSpawnModelSelection({
cfg,
agentId: targetAgentId,
modelOverride,
});
const resolvedModel =
normalizeModelSelection(modelOverride) ??
normalizeModelSelection(targetAgentConfig?.subagents?.model) ??
normalizeModelSelection(cfg.agents?.defaults?.subagents?.model) ??
normalizeModelSelection(cfg.agents?.defaults?.model?.primary) ??
normalizeModelSelection(`${runtimeDefaultModel.provider}/${runtimeDefaultModel.model}`);
const resolvedThinkingDefaultRaw =
readStringParam(targetAgentConfig?.subagents ?? {}, "thinking") ??
@@ -222,16 +200,11 @@ export async function spawnSubagentDirect(
} catch (err) {
const messageText =
err instanceof Error ? err.message : typeof err === "string" ? err : "error";
const recoverable =
messageText.includes("invalid model") || messageText.includes("model not allowed");
if (!recoverable) {
return {
status: "error",
error: messageText,
childSessionKey,
};
}
modelWarning = messageText;
return {
status: "error",
error: messageText,
childSessionKey,
};
}
}
if (thinkingOverride !== undefined) {
@@ -328,6 +301,5 @@ export async function spawnSubagentDirect(
runId: childRunId,
note: SUBAGENT_SPAWN_ACCEPTED_NOTE,
modelApplied: resolvedModel ? modelApplied : undefined,
warning: modelWarning,
};
}