Agent pages: the blocks of older history begin on multiples of 8,000 offsets, so the mind answers them from its kept files
Jonas Templestein, 2026-11-28 17:08 UTC · 375e5d4dc2f785a6dd3b0ecbe5fa30500164e50d · parent fe8f9d8
2 files changed
M src/agent-kind-view/chat-history.test.ts
@@ -40,25 +40,23 @@ // the first older window: a block of 8,000 offsets that ends where the window ends const first = await held.readEvents(49_000, 1000); - expect(asked).toEqual(["chat 42000 50000"]); expect(first.events).toHaveLength(100); expect(first).toMatchObject({ scannedThroughOffset: 50_000, atHead: false, version: 3 }); - // the next windows come from the block: no call + // the reader is in the lower half of that block: the whole block below was read ahead, once + expect(asked).toEqual(["chat 48000 50000", "chat 40000 48000"]); + + // the next windows come from what is held: no call const second = await held.readEvents(47_000, 1000); expect(second.events).toHaveLength(300); - expect(asked).toEqual(["chat 42000 50000"]); - - // half through the block: the block below is read ahead, once const third = await held.readEvents(45_000, 250); expect(third.events).toHaveLength(250); expect(third.scannedThroughOffset).toBe(47_500); - await held.readEvents(43_000, 1000); - expect(asked).toEqual(["chat 42000 50000", "chat 34000 42000"]); - // below the first block, from what was read ahead - const fourth = await held.readEvents(40_000, 1000); - expect(fourth.events[0]).toEqual({ offset: 40_010 }); expect(asked).toHaveLength(2); + // in the lower half again: the next whole block + await held.readEvents(43_000, 1000); + await held.readEvents(41_000, 1000); + expect(asked).toEqual(["chat 48000 50000", "chat 40000 48000", "chat 32000 40000"]); }); test("a mind with no such read: one refusal, then the context's own read", async () => { @@ -70,7 +68,7 @@ await held.readEvents(9000, 1000); await held.readEvents(8000, 100); await held.readEvents(7000, 100); - expect(asked).toEqual(["plain 9000 1000", "chat 100", "plain 8000 100", "plain 7000 100"]); + expect(asked).toEqual(["plain 9000 1000", "chat 8000", "plain 8000 100", "plain 7000 100"]); }); test("an answer that is not the whole block: the window is read as a page", async () => { @@ -82,6 +80,6 @@ }); await held.readEvents(9000, 1000); const page = await held.readEvents(8000, 100); - expect(asked).toEqual(["plain 9000 1000", "chat 100 8100", "chat 8000 x100"]); + expect(asked).toEqual(["plain 9000 1000", "chat 8000 8100", "chat 8000 x100"]); expect(page.events).toHaveLength(5); });
M src/agent-kind-view/chat-history.ts
@@ -70,8 +70,12 @@ // over the block: a window's rest, which the log's reader asks for after a full answer if (block && after >= block.hi) return read(after, limit); if (!block || after + limit < block.lo) { - // the first older page, or a jump far below: a block that ends where this window ends - const fresh = await span(Math.max(0, after + limit - BLOCK), after + limit); + // the first older page, or a jump far below: a block that ends where this window ends and + // begins on a multiple of BLOCK, so that every block below it is a whole one that the mind + // keeps (it answers a kept block from a file, with no scan of the log) + const top = after + limit; + const aligned = Math.floor((top - 1) / BLOCK) * BLOCK; + const fresh = await span(Math.max(0, aligned > after ? aligned - BLOCK : aligned), top); if (!fresh || after < fresh.lo) return read(after, limit); block = fresh; } else if (after < block.lo) {