From f545eb986cedad16eb42d92905ca9fdd0ed633f5 Mon Sep 17 00:00:00 2001 From: HugoLopes45 Date: Wed, 11 Nov 2026 20:13:41 +0100 Subject: [PATCH 1/2] Test that replacing old reads alone does not trigger a shake When replacing superseded reads brings the context under the threshold but not to progressRatio of it, turn_end keeps only those edits and does not shake, so the context breaks the prompt cache once instead of twice. The test pins this and fails with the gate on Pi's raw token count. --- test/extension.test.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/extension.test.ts b/test/extension.test.ts index 7e2f78d..63247e6 100644 --- a/test/extension.test.ts +++ b/test/extension.test.ts @@ -1026,6 +1026,40 @@ describe("pi-context-kit inside Pi", () => { ); }); + it("does not shake when replacing old reads alone brings the context under the threshold", async () => { + const { session } = await start( + [ + fauxAssistantMessage([ + { + type: "text", + text: ["```ts", "x = 1;".repeat(2_800), "```"].join("\n"), + }, + fauxToolCall("read", { path: "b.ts" }), + ]), + fauxAssistantMessage(fauxToolCall("read", { path: "b.ts" })), + fauxAssistantMessage("done"), + ], + 200_000, + true, + { + thresholdTokens: 11_000, + asyncEnabled: false, + prune: { enabled: false }, + shake: { protectTokens: 0, minSavings: 1, blockMinTokens: 10 }, + }, + ); + await session.prompt("Read b.ts twice"); + const replacements = session.sessionManager + .getBranch() + .flatMap((entry) => + entry.type === "context_edit" + ? [JSON.stringify(entry.replacement)] + : [], + ); + expect(replacements).toHaveLength(1); + expect(replacements[0]).toContain("Superseded by a newer read"); + }); + it("does not shake before soft when methodOrder puts soft first", async () => { const { session } = await start( [ From e0f57ca19960290e95ce27a1c9ef171e32748306 Mon Sep 17 00:00:00 2001 From: HugoLopes45 Date: Wed, 11 Nov 2026 20:19:12 +0100 Subject: [PATCH 2/2] Assert the stale-only test runs no handoff compaction A regression that keeps the planned tokens above the threshold would run a handoff compaction and still pass the edit-count assertion. --- test/extension.test.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/extension.test.ts b/test/extension.test.ts index 63247e6..6937a17 100644 --- a/test/extension.test.ts +++ b/test/extension.test.ts @@ -1049,15 +1049,16 @@ describe("pi-context-kit inside Pi", () => { }, ); await session.prompt("Read b.ts twice"); - const replacements = session.sessionManager - .getBranch() - .flatMap((entry) => - entry.type === "context_edit" - ? [JSON.stringify(entry.replacement)] - : [], - ); + const branch = session.sessionManager.getBranch(); + const replacements = branch.flatMap((entry) => + entry.type === "context_edit" ? [JSON.stringify(entry.replacement)] : [], + ); expect(replacements).toHaveLength(1); expect(replacements[0]).toContain("Superseded by a newer read"); + expect(branch.filter((entry) => entry.type === "compaction")).toHaveLength( + 0, + ); + expect(JSON.stringify(session.messages.at(-1))).toContain("done"); }); it("does not shake before soft when methodOrder puts soft first", async () => {