refactor(agents): remove stale live model switch api

This commit is contained in:
Vincent Koc
2026-06-18 13:58:31 +08:00
parent d5d6576e06
commit a455b508a7
3 changed files with 1 additions and 107 deletions
-48
View File
@@ -2,8 +2,6 @@
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
const state = vi.hoisted(() => ({
abortEmbeddedAgentRunMock: vi.fn(),
requestEmbeddedRunModelSwitchMock: vi.fn(),
resolveDefaultModelForAgentMock: vi.fn(),
resolvePersistedSelectedModelRefMock: vi.fn(),
loadSessionStoreMock: vi.fn(),
@@ -17,12 +15,6 @@ vi.mock("./embedded-agent.js", () => {
return {};
});
vi.mock("./embedded-agent-runner/runs.js", () => ({
abortEmbeddedAgentRun: (...args: unknown[]) => state.abortEmbeddedAgentRunMock(...args),
requestEmbeddedRunModelSwitch: (...args: unknown[]) =>
state.requestEmbeddedRunModelSwitchMock(...args),
}));
vi.mock("./model-selection.js", async () => {
const actual =
await vi.importActual<typeof import("./model-selection.js")>("./model-selection.js");
@@ -81,8 +73,6 @@ describe("live model switch", () => {
});
beforeEach(() => {
state.abortEmbeddedAgentRunMock.mockReset().mockReturnValue(false);
state.requestEmbeddedRunModelSwitchMock.mockReset();
state.embeddedAgentModuleImported = false;
state.resolveDefaultModelForAgentMock
.mockReset()
@@ -339,27 +329,6 @@ describe("live model switch", () => {
});
});
it("queues a live switch only when an active run was aborted", async () => {
// Switching live runs is two-phase: abort the active run, then queue the
// selected provider/model for the restarted embedded run to consume.
state.abortEmbeddedAgentRunMock.mockReturnValue(true);
const { requestLiveSessionModelSwitch } = await loadModule();
expect(
requestLiveSessionModelSwitch({
sessionEntry: { sessionId: "session-1" },
selection: { provider: "openai", model: "gpt-5.4", authProfileId: "profile-gpt" },
}),
).toBe(true);
expect(state.abortEmbeddedAgentRunMock).toHaveBeenCalledWith("session-1");
expect(state.requestEmbeddedRunModelSwitchMock).toHaveBeenCalledWith("session-1", {
provider: "openai",
model: "gpt-5.4",
authProfileId: "profile-gpt",
});
});
it("does not import the broad embedded-agent barrel on module load", async () => {
await loadModule();
@@ -435,23 +404,6 @@ describe("live model switch", () => {
).toBe(false);
});
it("does not track persisted live selection when the run started on a transient model override", async () => {
const { shouldTrackPersistedLiveSessionModelSelection } = await loadModule();
expect(
shouldTrackPersistedLiveSessionModelSelection(
{
provider: "anthropic",
model: "claude-haiku-4-5",
},
{
provider: "anthropic",
model: "claude-sonnet-4-6",
},
),
).toBe(false);
});
describe("shouldSwitchToLiveModel", () => {
it("returns the persisted selection when liveModelSwitchPending is true and model differs", async () => {
const sessionEntry = {
+1 -34
View File
@@ -3,12 +3,7 @@
*/
import { resolveStorePath } from "../config/sessions/paths.js";
import { loadSessionStore, updateSessionStore } from "../config/sessions/store.js";
import type { SessionEntry } from "../config/sessions/types.js";
import {
abortEmbeddedAgentRun,
requestEmbeddedRunModelSwitch,
type EmbeddedRunModelSwitchRequest,
} from "./embedded-agent-runner/runs.js";
import type { EmbeddedRunModelSwitchRequest } from "./embedded-agent-runner/runs.js";
import {
normalizeStoredOverrideModel,
resolveDefaultModelForAgent,
@@ -74,22 +69,6 @@ export function resolveLiveSessionModelSelection(params: {
};
}
export function requestLiveSessionModelSwitch(params: {
sessionEntry?: Pick<SessionEntry, "sessionId">;
selection: LiveSessionModelSelection;
}): boolean {
const sessionId = normalizeOptionalString(params.sessionEntry?.sessionId);
if (!sessionId) {
return false;
}
const aborted = abortEmbeddedAgentRun(sessionId);
if (!aborted) {
return false;
}
requestEmbeddedRunModelSwitch(sessionId, params.selection);
return true;
}
function isAlreadyAppliedOpenAICodexRuntimePromotion(
current: { provider: string; model: string },
next: LiveSessionModelSelection,
@@ -126,18 +105,6 @@ export function hasDifferentLiveSessionModelSelection(
);
}
export function shouldTrackPersistedLiveSessionModelSelection(
current: {
provider: string;
model: string;
authProfileId?: string;
authProfileIdSource?: string;
},
persisted: LiveSessionModelSelection | null | undefined,
): boolean {
return !hasDifferentLiveSessionModelSelection(current, persisted);
}
/**
* Check whether a user-initiated live model switch is pending for the given
* session. Returns the persisted model selection when the session's
@@ -308,10 +308,6 @@ beforeAll(async () => {
({ parseInlineDirectives } = await import("./directive-handling.parse.js"));
({ persistInlineDirectives } = await import("./directive-handling.persist.js"));
});
const liveModelSwitchMocks = vi.hoisted(() => ({
requestLiveSessionModelSwitch: vi.fn(),
}));
const queueMocks = vi.hoisted(() => ({
refreshQueuedFollowupSession: vi.fn(),
}));
@@ -347,11 +343,6 @@ vi.mock("../../infra/system-events.js", () => ({
enqueueSystemEvent: vi.fn(),
}));
vi.mock("../../agents/live-model-switch.js", () => ({
requestLiveSessionModelSwitch: (...args: unknown[]) =>
liveModelSwitchMocks.requestLiveSessionModelSwitch(...args),
}));
vi.mock("./queue.js", () => ({
refreshQueuedFollowupSession: (...args: unknown[]) =>
queueMocks.refreshQueuedFollowupSession(...args),
@@ -439,7 +430,6 @@ beforeEach(() => {
vi.mocked(resolveAgentDir).mockReset().mockReturnValue(TEST_AGENT_DIR);
vi.mocked(resolveSessionAgentId).mockReset().mockReturnValue("main");
vi.mocked(enqueueSystemEvent).mockClear();
liveModelSwitchMocks.requestLiveSessionModelSwitch.mockReset().mockReturnValue(false);
queueMocks.refreshQueuedFollowupSession.mockReset();
clearInternalHooks();
});
@@ -1600,21 +1590,6 @@ describe("handleDirectiveOnly model persist behavior (fixes #1435)", () => {
expect(result?.text ?? "").not.toContain("xhigh not supported");
expect(sessionEntry.thinkingLevel).toBe("xhigh");
});
it("does not request a live restart when /model mutates an active session", async () => {
const directives = parseInlineDirectives("/model openai/gpt-4o");
const sessionEntry = createSessionEntry();
await handleDirectiveOnly(
createHandleParams({
directives,
sessionEntry,
}),
);
expect(liveModelSwitchMocks.requestLiveSessionModelSwitch).not.toHaveBeenCalled();
});
it("retargets queued followups when /model mutates session state", async () => {
const directives = parseInlineDirectives("/model openai/gpt-4o");
const sessionEntry = createSessionEntry();