perf(gateway): avoid cloning live switch store reads

This commit is contained in:
Peter Steinberger
2026-05-27 06:15:12 +01:00
parent 586a6ce03b
commit b75f70bc04
2 changed files with 17 additions and 11 deletions

View File

@@ -398,12 +398,13 @@ describe("live model switch", () => {
describe("shouldSwitchToLiveModel", () => {
it("returns the persisted selection when liveModelSwitchPending is true and model differs", async () => {
const sessionEntry = {
liveModelSwitchPending: true,
providerOverride: "openai",
modelOverride: "gpt-5.4",
};
state.loadSessionStoreMock.mockReturnValue({
main: {
liveModelSwitchPending: true,
providerOverride: "openai",
modelOverride: "gpt-5.4",
},
main: sessionEntry,
});
const { shouldSwitchToLiveModel } = await loadModule();
@@ -431,15 +432,20 @@ describe("live model switch", () => {
const result = shouldSwitchToLiveModel(makeShouldSwitchParams());
expect(result).toBeUndefined();
expect(state.loadSessionStoreMock).toHaveBeenCalledWith("/tmp/session-store.json", {
skipCache: true,
clone: false,
});
});
it("returns undefined when liveModelSwitchPending is true but models match", async () => {
const sessionEntry = {
liveModelSwitchPending: true,
providerOverride: "anthropic",
modelOverride: "claude-opus-4-6",
};
state.loadSessionStoreMock.mockReturnValue({
main: {
liveModelSwitchPending: true,
providerOverride: "anthropic",
modelOverride: "claude-opus-4-6",
},
main: sessionEntry,
});
const { shouldSwitchToLiveModel } = await loadModule();

View File

@@ -159,7 +159,7 @@ export function shouldSwitchToLiveModel(params: {
const storePath = resolveStorePath(cfg.session?.store, {
agentId: params.agentId?.trim(),
});
const entry = loadSessionStore(storePath, { skipCache: true })[sessionKey];
const entry = loadSessionStore(storePath, { skipCache: true, clone: false })[sessionKey];
if (!entry?.liveModelSwitchPending) {
return undefined;
}