fix(FN-000): restore memory compaction and log pagination
This commit is contained in:
@@ -3634,6 +3634,26 @@ Task with acceptance criteria
|
||||
expect(logs.map((entry) => entry.text)).toEqual(["chunk 3", "chunk 4"]);
|
||||
});
|
||||
|
||||
it("returns older agent log pages when offset skips recent entries", async () => {
|
||||
const task = await createTestTask();
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
await store.appendAgentLog(task.id, `chunk ${i}`, "text");
|
||||
}
|
||||
|
||||
await expect(store.getAgentLogs(task.id, { limit: 2 })).resolves.toMatchObject([
|
||||
{ text: "chunk 3" },
|
||||
{ text: "chunk 4" },
|
||||
]);
|
||||
await expect(store.getAgentLogs(task.id, { limit: 2, offset: 2 })).resolves.toMatchObject([
|
||||
{ text: "chunk 1" },
|
||||
{ text: "chunk 2" },
|
||||
]);
|
||||
await expect(store.getAgentLogs(task.id, { limit: 2, offset: 4 })).resolves.toMatchObject([
|
||||
{ text: "chunk 0" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("preserves long entry fields when returning a bounded tail", async () => {
|
||||
const task = await createTestTask();
|
||||
const longText = [
|
||||
|
||||
@@ -4054,16 +4054,15 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
|
||||
? (Number.isFinite(options.offset) ? Math.max(0, Math.floor(options.offset)) : 0)
|
||||
: 0;
|
||||
|
||||
// If limit is specified, use readAgentLogTail for efficiency
|
||||
// If limit is specified, use readAgentLogTail for efficiency.
|
||||
if (limit !== undefined) {
|
||||
if (limit === 0) return [];
|
||||
// When offset is provided, read limit + offset entries and slice off the first offset
|
||||
// Offset means "skip this many most-recent entries", so read enough
|
||||
// tail entries to include the requested older page.
|
||||
const readCount = offset > 0 ? limit + offset : limit;
|
||||
const entries = await this.readAgentLogTail(logPath, readCount);
|
||||
if (offset > 0) {
|
||||
// Slice off the first 'offset' entries (oldest in the returned batch)
|
||||
// This skips the most recent entries to get older entries
|
||||
return entries.slice(offset);
|
||||
return entries.slice(0, Math.max(0, entries.length - offset));
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user