mirror of
https://github.com/wassname/pi-dynamic-context-pruning.git
synced 2026-06-27 16:46:12 +08:00
fix: Infinity anchorTimestamp ghost block, prompt tag name, test cleanup
- resolveAnchorTimestamp returns endTimestamp + 1 instead of Infinity - Validate timestamps are finite before creating blocks - Skip corrupted blocks in overlap checks and compression application - Include block timestamp range in overlap error messages - Filter out corrupted blocks on session restore - Fix prompt tag name: dcp-message-id → dcp-id to match injected tags - Remove duplicate test, keep corrupted-block resilience test
This commit is contained in:
+18
-37
@@ -709,38 +709,30 @@ function findOrphanedToolUse(result: any[]): string | null {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Test 10 — INFINITY ANCHOR BUG (regression test)
|
||||
// Test 10 — CORRUPTED BLOCK WITH NULL/INFINITY TIMESTAMPS (resilience)
|
||||
//
|
||||
// Previously, when a compression block's range extended to the end of the
|
||||
// conversation, resolveAnchorTimestamp returned Infinity. This caused:
|
||||
// 1. JSON serialization turned Infinity into null, corrupting saved state
|
||||
// 2. Null timestamps in overlap checks caused false positives (every range
|
||||
// appeared to overlap the ghost block)
|
||||
// 3. The model entered a compression spiral, unable to consolidate blocks
|
||||
//
|
||||
// Fix: resolveAnchorTimestamp returns endTimestamp + 1 instead of Infinity.
|
||||
// Blocks from older sessions may have null/Infinity timestamps due to JSON
|
||||
// round-trip corruption. These blocks should be skipped during compression
|
||||
// application and should not block new compress operations.
|
||||
// ---------------------------------------------------------------------------
|
||||
{
|
||||
console.log("TEST 10: Infinity anchor timestamp regression");
|
||||
console.log("TEST 10: corrupted block with null/Infinity timestamps is skipped");
|
||||
|
||||
// Conversation where the last message is at timestamp 4000.
|
||||
// Compression block covers up to the end, so anchor should be 4001, not Infinity.
|
||||
const messages: any[] = [
|
||||
{ role: "user", content: [{ type: "text", text: "read file" }], timestamp: 1000 },
|
||||
{ role: "assistant", content: [{ type: "toolCall", id: "toolu_1", name: "read", arguments: {} }], timestamp: 2000 },
|
||||
{ role: "toolResult", toolCallId: "toolu_1", toolName: "read", isError: false, content: [{ type: "text", text: "file data" }], timestamp: 3000 },
|
||||
{ role: "user", content: [{ type: "text", text: "thanks" }], timestamp: 4000 },
|
||||
{ role: "user", content: [{ type: "text", text: "hello" }], timestamp: 1000 },
|
||||
{ role: "assistant", content: [{ type: "text", text: "hi" }], timestamp: 2000 },
|
||||
{ role: "user", content: [{ type: "text", text: "bye" }], timestamp: 3000 },
|
||||
];
|
||||
|
||||
// Block that extends to the end of conversation
|
||||
// Block with corrupted timestamps (null from JSON round-trip)
|
||||
const state = makeState([
|
||||
{
|
||||
id: 1,
|
||||
topic: "file read",
|
||||
summary: "File was read.",
|
||||
startTimestamp: 1000,
|
||||
endTimestamp: 4000,
|
||||
anchorTimestamp: 4001, // Fixed: was Infinity before the bugfix
|
||||
topic: "ghost block",
|
||||
summary: "This block has corrupted timestamps.",
|
||||
startTimestamp: null as any, // null from JSON deserialization of Infinity
|
||||
endTimestamp: null as any,
|
||||
anchorTimestamp: null as any,
|
||||
active: true,
|
||||
summaryTokenEstimate: 5,
|
||||
createdAt: Date.now(),
|
||||
@@ -757,23 +749,12 @@ function findOrphanedToolUse(result: any[]): string | null {
|
||||
console.log(` role="${m.role}" ts=${m.timestamp} content="${preview}"`);
|
||||
}
|
||||
|
||||
// The synthetic message timestamp must be finite (not Infinity)
|
||||
const synthetic = result.find(
|
||||
(m: any) => m.role === "user" && typeof m.content?.[0]?.text === "string" && m.content[0].text.includes("Compressed section")
|
||||
);
|
||||
assert.ok(synthetic, "FAIL — no synthetic compressed message found");
|
||||
assert.ok(
|
||||
Number.isFinite(synthetic.timestamp),
|
||||
`FAIL — synthetic message has non-finite timestamp: ${synthetic.timestamp}`
|
||||
);
|
||||
console.log(` PASS: synthetic message has finite timestamp (${synthetic.timestamp})`);
|
||||
// All 3 original messages should survive (ghost block was skipped)
|
||||
assert.strictEqual(result.length, 3, `FAIL — expected 3 messages, got ${result.length}`);
|
||||
console.log(" PASS: corrupted block skipped, all original messages preserved");
|
||||
|
||||
console.log("TEST 10 PASSED\n");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Test 11 — CORRUPTED BLOCK WITH NULL/INFINITY TIMESTAMPS (resilience)
|
||||
//
|
||||
}//
|
||||
// Blocks from older sessions may have null/Infinity timestamps due to JSON
|
||||
// round-trip corruption. These blocks should be skipped during compression
|
||||
// application and should not block new compress operations.
|
||||
|
||||
Reference in New Issue
Block a user