fix: use summary checkpoints for all compaction triggers (#5694)

* fix: exclude archived history after manual compaction

* refactor: share summary checkpoints across compaction paths

* fix: use summary checkpoints for every compaction trigger

* test: assert replay starts at the archived boundary

* fix: preserve nothing summaries without raw fallback

* test: assert compaction results positively

* test: verify checkpoint continuation after session reload
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-08 13:16:45 +08:00
1 parent c039a7052a
commit 3548aec576
18 files changed
+335 -271

No files matched your search

@@ -92,6 +92,9 @@ function sameMessageShape(a: MessageShape, b: MessageShape): boolean {
function latestComposerContextUsage(messages: UIMessage[]): ComposerContextUsage | null {
for (let index = messages.length - 1; index >= 0; index -= 1) {
const message = messages[index];
if (message.kind === "compaction" && message.compaction?.phase === "succeeded") {
return null;
}
const contextTokens = message.usage?.context_tokens;
if (
message.role !== "assistant"
+47
View File
@@ -497,6 +497,53 @@ describe("ThreadShell", () => {
expect(screen.getByRole("img", {
name: /input tokens 16,400.*KV cache hit rate 99%.*output tokens 236/i,
})).toBeInTheDocument();
expect(screen.getByTestId("composer-context-meter")).toBeInTheDocument();
for (const phase of ["started", "failed"] as const) {
act(() => client._emitChat("usage-chart", {
event: "context_compaction", chat_id: "usage-chart", compaction_id: "failed", phase,
}));
expect(screen.getByTestId("composer-context-meter")).toBeInTheDocument();
}
act(() => client._emitChat("usage-chart", {
event: "context_compaction", chat_id: "usage-chart",
compaction_id: "success", phase: "succeeded",
}));
expect(trigger).toHaveAccessibleName("Open context usage");
expect(screen.getAllByTestId("round-usage-bar")).toHaveLength(4);
});
it.each([false, true])("restores context after compaction only with newer usage (%s)", async (newReply) => {
const client = makeClient();
const messages: UIMessage[] = [
{
id: "old", role: "assistant", content: "Before compact", createdAt: 1_000,
contextWindowTokens: 1_000_000, usage: { context_tokens: 170_000 },
roundUsages: [{ prompt_tokens: 170_000 }],
},
{
id: "compact", role: "assistant", kind: "compaction", content: "", createdAt: 2_000,
compaction: { id: "compact", phase: "succeeded" },
},
];
if (newReply) messages.push({
id: "new", role: "assistant", content: "After compact", createdAt: 3_000,
contextWindowTokens: 1_000_000, usage: { context_tokens: 20_700 },
});
vi.stubGlobal("fetch", vi.fn((input: RequestInfo | URL) => Promise.resolve(
String(input).includes("websocket%3Acompact-usage/webui-thread")
? httpJson({ schemaVersion: 3, messages })
: { ok: false, status: 404, json: async () => ({}) },
)));
render(wrap(client, <ThreadShell
session={session("compact-usage")} title="Compact usage" onToggleSidebar={() => {}}
settingsSnapshot={modelSettings("test-model", "deepseek")}
/>));
const trigger = await screen.findByTestId("composer-context-usage");
if (newReply) {
expect(trigger).toHaveAccessibleName("Context 2%. Open context usage");
} else {
expect(trigger).toHaveAccessibleName("Open context usage");
}
});
it("moves the session handle into the pane only when the workbench is split", () => {