Skip to content

Commit e05be9f

Browse files
author
root
committed
perf(sessions): avoid redundant clone on skipCache loads
1 parent df83374 commit e05be9f

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/config/sessions.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,4 +761,31 @@ describe("sessions", () => {
761761
expect(store[mainSessionKey]?.providerOverride).toBe("anthropic");
762762
expect(store[mainSessionKey]?.thinkingLevel).toBe("high");
763763
});
764+
765+
it("loadSessionStore skipCache returns a fresh mutable store without tainting cached reads", async () => {
766+
const mainSessionKey = "agent:main:main";
767+
const { storePath } = await createSessionStoreFixture({
768+
prefix: "loadSessionStore-skip-cache-fresh",
769+
entries: {
770+
[mainSessionKey]: {
771+
sessionId: "sess-1",
772+
updatedAt: 123,
773+
thinkingLevel: "low",
774+
},
775+
},
776+
});
777+
778+
const fresh = loadSessionStore(storePath, { skipCache: true });
779+
expect(fresh[mainSessionKey]?.thinkingLevel).toBe("low");
780+
781+
fresh[mainSessionKey] = {
782+
...fresh[mainSessionKey],
783+
thinkingLevel: "high",
784+
};
785+
786+
expect(loadSessionStore(storePath)[mainSessionKey]?.thinkingLevel).toBe("low");
787+
expect(loadSessionStore(storePath, { skipCache: true })[mainSessionKey]?.thinkingLevel).toBe(
788+
"low",
789+
);
790+
});
764791
});

src/config/sessions/store-load.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,12 @@ export function loadSessionStore(
129129
});
130130
}
131131

132+
// `skipCache` callers already forced a fresh disk load, so there is no shared
133+
// cached object to protect here. Returning the parsed store directly avoids an
134+
// extra full-store clone on hot read-modify-write paths.
135+
if (opts.skipCache) {
136+
return store;
137+
}
138+
132139
return structuredClone(store);
133140
}

0 commit comments

Comments
 (0)