fix: prevent Infinity anchorTimestamp ghost block spiral

The root cause of the compression spiral (101 failures, 2 hours):
resolveAnchorTimestamp returned Infinity when no message followed the
compression range. Infinity corrupted JSON serialization (became null),
and null timestamps in JS overlap checks coerced to 0, making every
range appear to overlap the ghost block b7.

Fixes:
- resolveAnchorTimestamp returns endTimestamp + 1 instead of Infinity
- Validate all timestamps are finite before creating a block (fail fast)
- Skip blocks with non-finite timestamps in overlap checks and compression
- Include existing block range in overlap error messages (diagnostic)
- Filter out corrupted blocks on session restore
- Guard synthetic message timestamp creation against non-finite values
- Add regression tests for Infinity anchor and null-timestamp blocks
This commit is contained in:
wassname
2026-04-10 20:28:22 +00:00
parent 8681bd833b
commit a0d9945830
5 changed files with 3953 additions and 12 deletions
+10 -1
View File
@@ -81,7 +81,16 @@ export default function (pi: ExtensionAPI) {
const data = entry.data as any
if (data?.compressionBlocks) {
state.compressionBlocks = data.compressionBlocks
// Filter out blocks with corrupted (null/NaN/Infinity) timestamps —
// these were caused by Infinity anchorTimestamp values that became
// null after JSON round-trip.
const validBlocks = data.compressionBlocks.filter(
(b: any) =>
Number.isFinite(b.startTimestamp) &&
Number.isFinite(b.endTimestamp) &&
Number.isFinite(b.anchorTimestamp),
)
state.compressionBlocks = validBlocks
state.nextBlockId = data.nextBlockId ?? state.compressionBlocks.length
state.tokensSaved = data.tokensSaved ?? 0
state.totalPruneCount = data.totalPruneCount ?? 0