fix(webui): preserve session caches during history revalidation (#6636)
This commit is contained in:
1 parent
1046a37be1
commit
0ce10533d3
7 files changed
+68
-43
No files matched your search
@@ -6,15 +6,19 @@ it.each([
|
||||
{ collection: "Map keys", small: new Map([["turn", "source"]]), large: new Map([["x".repeat(64), "source"]]) },
|
||||
{ collection: "Map values", small: new Map([["turn", "source"]]), large: new Map([["turn", "x".repeat(64)]]) },
|
||||
{ collection: "Set members", small: new Set(["turn"]), large: new Set(["x".repeat(64)]) },
|
||||
])("counts nested $collection toward the byte budget", ({ small, large }) => {
|
||||
const cache = new MemoryLruCache<{ members: typeof large }>(160, 2);
|
||||
const snapshot = { members: small };
|
||||
])("counts shared nested $collection once and re-estimates changed snapshots", ({ small, large }) => {
|
||||
const cache = new MemoryLruCache<{ members: typeof large }>(110, 2);
|
||||
const snapshot = { members: small, alias: small };
|
||||
cache.set("small", snapshot);
|
||||
expect(cache.get("small")).toBe(snapshot);
|
||||
|
||||
cache.set("large", { members: large });
|
||||
expect(cache.get("large")).toBeUndefined();
|
||||
|
||||
cache.set("small", snapshot);
|
||||
expect(cache.get("small")).toBe(snapshot);
|
||||
|
||||
// A saved transcript can share mutable collections with its next snapshot.
|
||||
if (small instanceof Map) small.set("turn", "x".repeat(64));
|
||||
else small.add("x".repeat(64));
|
||||
cache.set("small", snapshot);
|
||||
expect(cache.get("small")).toBeUndefined();
|
||||
});
|
||||
@@ -15,13 +15,25 @@ it("keeps recently visited chats within the entry budget", () => {
|
||||
.toEqual([rows, undefined, rows]);
|
||||
});
|
||||
|
||||
it("bounds large replay snapshots while retaining temporary chats", () => {
|
||||
it("bounds large replay snapshots without charging temporary chats to the reusable budget", () => {
|
||||
const cache = new ThreadMessageCache((key) => key === "temporary", 4096, 2);
|
||||
cache.set("temporary", snapshot);
|
||||
cache.set("large", new ThreadTranscript([{ ...rows[0], content: "x".repeat(4096) }]).save());
|
||||
cache.set("ordinary-a", snapshot);
|
||||
cache.set("ordinary-b", snapshot);
|
||||
const large = new ThreadTranscript([{ ...rows[0], content: "x".repeat(4096) }]).save();
|
||||
cache.set("large", large);
|
||||
expect(cache.get("large")).toBeUndefined();
|
||||
expect(cache.get("temporary")?.projection.messages).toBe(rows);
|
||||
cache.delete("temporary");
|
||||
expect(cache.peek("ordinary-a")).toBe(snapshot);
|
||||
expect(cache.peek("ordinary-b")).toBe(snapshot);
|
||||
|
||||
cache.set("temporary", large);
|
||||
expect(cache.get("temporary")).toBe(large);
|
||||
expect(cache.get("ordinary-a")).toBe(snapshot);
|
||||
expect(cache.peek("ordinary-b")).toBe(snapshot);
|
||||
|
||||
cache.set("small", snapshot);
|
||||
expect(cache.get("small")?.projection.messages).toBe(rows);
|
||||
expect(cache.peek("ordinary-a")).toBe(snapshot);
|
||||
expect(cache.peek("ordinary-b")).toBeUndefined();
|
||||
expect(cache.get("small")).toBe(snapshot);
|
||||
cache.delete("temporary");
|
||||
expect(cache.get("small")).toBe(snapshot);
|
||||
});
|
||||
@@ -3263,7 +3263,7 @@ describe("ThreadShell", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("recovers an uncommitted reset lineage on the next canonical hydrate", async () => {
|
||||
it("adopts a disjoint latest window immediately when returning to a cached session", async () => {
|
||||
const client = makeClient();
|
||||
let chatACalls = 0;
|
||||
vi.stubGlobal(
|
||||
@@ -3309,8 +3309,8 @@ describe("ThreadShell", () => {
|
||||
rerender(view("lineage-chat-a"));
|
||||
await waitFor(() => expect(chatACalls).toBe(2));
|
||||
|
||||
expect(screen.getByText("committed old lineage")).toBeInTheDocument();
|
||||
expect(screen.queryByText("disjoint new lineage")).not.toBeInTheDocument();
|
||||
expect(await screen.findByText("disjoint new lineage")).toBeInTheDocument();
|
||||
expect(screen.queryByText("committed old lineage")).not.toBeInTheDocument();
|
||||
|
||||
act(() => client._emitSessionUpdate("lineage-chat-a", "thread"));
|
||||
|
||||
|
||||
Reference in new issue
Block a user