[GH-ISSUE #7407] [Issue]: Professor Mari's lorebook.entries ignores offset, so entries past the first page are unreachable #4128

Closed
opened 2026-10-21 06:11:16 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @bahaynes on GitHub (Oct 11, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7407

Originally assigned to: @SpicyMarinara on GitHub.

Summary

app_data lorebook.entries accepts limit but never reads offset, and it returns a bare array with no total or nextOffset. On a large lorebook Mari gets the same first page every time she asks for "the rest", so she cannot see, review, or edit entries beyond it. instruction.list and skill.list were already paged for this exact reason; lorebook.entries was left out.

Expected behavior

lorebook.entries pages like instruction.list: it honors offset and returns { items, total, offset, nextOffset }, with a page size that keeps the result under MARI_READ_OUTPUT_BUDGET, so Mari can walk every entry of any lorebook.

Actual behavior

packages/server/src/services/mari-db/mari-db.service.ts, executeLorebookAction → case "entries" (line 3718 on b19bfbd9f):

const limit = normalizeLimit(firstNumber(args, ["limit"]), 100, 2000);
const entries = (await this.rawRows("lorebook_entries"))
  .filter((entry) => entry.lorebookId === lorebookId)
  .filter((entry) => !entryId || entry.id === entryId)
  .sort((a, b) => Number(a.order ?? 100) - Number(b.order ?? 100))
  .slice(0, limit)            // offset is never read
  .map(summarizeLorebookEntryRow);
return { ok: true, mode: "read", command: context.command, output: entries };

With 190 entries (the lorebook this was found on):

Call Entries returned Serialized size
lorebook.entries {} Session 1 … Session 100 52,284 chars
lorebook.entries { offset: 100 } Session 1 … Session 100 (same page) 52,284 chars
lorebook.entries { limit: 50, offset: 150 } Session 1 … Session 50 26,133 chars

The default page is also more than twice the 24k read budget, so in a real run the tail of even the first page is cut before Mari sees it. The instruction.list comment (line ~3536) describes the same hazard: an unbounded list "hid[es] every id and mak[es] the tail unfetchable".

Steps to reproduce

Save as scripts/regressions/mari/repro-lorebook-entries-offset.regression.ts and run node ./scripts/run-regressions.mjs --filter scripts/regressions/mari/repro-lorebook-entries-offset.regression.ts:

import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
process.env.FILE_STORAGE_DIR = mkdtempSync(join(tmpdir(), "repro-entries-"));
const { createFileNativeDB } = await import("../../../packages/server/src/db/file-backed-store.js");
const { MariDbService } = await import("../../../packages/server/src/services/mari-db/mari-db.service.js");
const mari = new MariDbService(await createFileNativeDB());
const created = await mari.executeAction({
  action: "lorebook.create",
  lorebookId: "book",
  data: {
    name: "Campaign",
    entries: Array.from({ length: 190 }, (_, i) => ({
      name: `Session ${i + 1}`,
      content: `Revelation ${i + 1}. `.repeat(60).trim(),
      order: i,
    })),
  },
  apply: true,
});
await mari.keepAppliedReview(created.approval?.id ?? "");
for (const args of [{}, { offset: 100 }, { limit: 50, offset: 150 }]) {
  const result = await mari.executeAction({ action: "lorebook.entries", lorebookId: "book", ...args });
  const names = (result.output as Array<{ name: string }>).map((entry) => entry.name);
  console.log(JSON.stringify({ args, first: names[0], last: names.at(-1), chars: JSON.stringify(result.output, null, 2).length }));
}

Output on staging b19bfbd9f: every call starts at Session 1.

Environment

  • Marinara Engine version: 2.5.0 (staging at b19bfbd9f)
  • Install type: source / docker
  • OS + version: Linux
  • Browser or app shell: n/a (server-side)

Logs, screenshots, or video

See the table above; reproduced with the script against the current staging tip.

Additional context

Suggested direction, mirroring instruction.list and skill.list:

  • Read offset with normalizeOffset, return { items, total, offset, nextOffset }, and size the page so its pretty-printed form stays under MARI_READ_OUTPUT_BUDGET.
  • Update the app_data tool description and the lorebook guidance in MARI_SYSTEM_PROMPT ("call it again with offset: nextOffset").
  • Pin it with a regression that walks a 190-entry lorebook to the end.

We carry a fix in a fork. It is available as a reference if useful.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @bahaynes on GitHub (Oct 11, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7407 Originally assigned to: @SpicyMarinara on GitHub. ## Summary `app_data` `lorebook.entries` accepts `limit` but never reads `offset`, and it returns a bare array with no `total` or `nextOffset`. On a large lorebook Mari gets the same first page every time she asks for "the rest", so she cannot see, review, or edit entries beyond it. `instruction.list` and `skill.list` were already paged for this exact reason; `lorebook.entries` was left out. ## Expected behavior `lorebook.entries` pages like `instruction.list`: it honors `offset` and returns `{ items, total, offset, nextOffset }`, with a page size that keeps the result under `MARI_READ_OUTPUT_BUDGET`, so Mari can walk every entry of any lorebook. ## Actual behavior `packages/server/src/services/mari-db/mari-db.service.ts`, `executeLorebookAction` → `case "entries"` (line 3718 on `b19bfbd9f`): ```ts const limit = normalizeLimit(firstNumber(args, ["limit"]), 100, 2000); const entries = (await this.rawRows("lorebook_entries")) .filter((entry) => entry.lorebookId === lorebookId) .filter((entry) => !entryId || entry.id === entryId) .sort((a, b) => Number(a.order ?? 100) - Number(b.order ?? 100)) .slice(0, limit) // offset is never read .map(summarizeLorebookEntryRow); return { ok: true, mode: "read", command: context.command, output: entries }; ``` With 190 entries (the lorebook this was found on): | Call | Entries returned | Serialized size | | --- | --- | --- | | `lorebook.entries {}` | Session 1 … Session 100 | 52,284 chars | | `lorebook.entries { offset: 100 }` | Session 1 … Session 100 (same page) | 52,284 chars | | `lorebook.entries { limit: 50, offset: 150 }` | Session 1 … Session 50 | 26,133 chars | The default page is also more than twice the 24k read budget, so in a real run the tail of even the first page is cut before Mari sees it. The `instruction.list` comment (line ~3536) describes the same hazard: an unbounded list "hid[es] every id and mak[es] the tail unfetchable". ## Steps to reproduce Save as `scripts/regressions/mari/repro-lorebook-entries-offset.regression.ts` and run `node ./scripts/run-regressions.mjs --filter scripts/regressions/mari/repro-lorebook-entries-offset.regression.ts`: ```ts import { mkdtempSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; process.env.FILE_STORAGE_DIR = mkdtempSync(join(tmpdir(), "repro-entries-")); const { createFileNativeDB } = await import("../../../packages/server/src/db/file-backed-store.js"); const { MariDbService } = await import("../../../packages/server/src/services/mari-db/mari-db.service.js"); const mari = new MariDbService(await createFileNativeDB()); const created = await mari.executeAction({ action: "lorebook.create", lorebookId: "book", data: { name: "Campaign", entries: Array.from({ length: 190 }, (_, i) => ({ name: `Session ${i + 1}`, content: `Revelation ${i + 1}. `.repeat(60).trim(), order: i, })), }, apply: true, }); await mari.keepAppliedReview(created.approval?.id ?? ""); for (const args of [{}, { offset: 100 }, { limit: 50, offset: 150 }]) { const result = await mari.executeAction({ action: "lorebook.entries", lorebookId: "book", ...args }); const names = (result.output as Array<{ name: string }>).map((entry) => entry.name); console.log(JSON.stringify({ args, first: names[0], last: names.at(-1), chars: JSON.stringify(result.output, null, 2).length })); } ``` Output on `staging` `b19bfbd9f`: every call starts at `Session 1`. ## Environment - Marinara Engine version: 2.5.0 (`staging` at `b19bfbd9f`) - Install type: source / docker - OS + version: Linux - Browser or app shell: n/a (server-side) ## Logs, screenshots, or video See the table above; reproduced with the script against the current `staging` tip. ## Additional context Suggested direction, mirroring `instruction.list` and `skill.list`: - Read `offset` with `normalizeOffset`, return `{ items, total, offset, nextOffset }`, and size the page so its pretty-printed form stays under `MARI_READ_OUTPUT_BUDGET`. - Update the `app_data` tool description and the lorebook guidance in `MARI_SYSTEM_PROMPT` ("call it again with `offset: nextOffset`"). - Pin it with a regression that walks a 190-entry lorebook to the end. We carry a fix in a fork. It is available as a reference if useful. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 06:11:16 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Oct 11, 2026):

Working on this in branch fix/mari-lorebook-entries-offset (Claude Code agent for @SpicyMarinara).

<!-- gh-comment-id:6107054450 --> @SpicyMarinara commented on GitHub (Oct 11, 2026): Working on this in branch fix/mari-lorebook-entries-offset (Claude Code agent for @SpicyMarinara).
Author
Owner

@SpicyMarinara commented on GitHub (Oct 11, 2026):

Fixed on staging by #7413. lorebook.entries now honors offset and returns { items, total, offset, nextOffset } in pages that fit the read budget. Professor Mari is told to keep paging until nextOffset is null, and mari lorebooks entries --offset pages the same way. Thanks for the detailed report and repro, @bahaynes!

<!-- gh-comment-id:6107724266 --> @SpicyMarinara commented on GitHub (Oct 11, 2026): Fixed on staging by #7413. `lorebook.entries` now honors `offset` and returns `{ items, total, offset, nextOffset }` in pages that fit the read budget. Professor Mari is told to keep paging until `nextOffset` is null, and `mari lorebooks entries --offset` pages the same way. Thanks for the detailed report and repro, @bahaynes!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4128
No description provided.