[GH-ISSUE #2034] Generation and autonomous checks still load full chat histories #996

Closed
opened 2026-10-21 05:24:58 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Xelvanis on GitHub (Jun 3, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2034

Originally assigned to: @cha1latte on GitHub.

Problem

Several hot paths still load a full chat transcript when they only need recent or summary-shaped data.

Current refactor evidence on origin/refactor:

  • src/engine/generation/start-generation.ts:846 defines generationMessageLoadOptions, but :851 returns no cap unless contextMessageLimit or request historyLimit is set. Normal chats with default metadata call loadChatMessages without options at :2447, :2461, :2463, and :2548.
  • src/engine/generation/context.ts:75 wraps storage.listChatMessages; without options it reads the full chat.
  • src/engine/generation/start-generation.ts:2372 and :2414 use full transcript reads for retry/lorebook-keeper paths.
  • src/engine/modes/chat/autonomous/autonomous.service.ts:66-67 loads all messages for a chat, then :147-148 only uses them to initialize recent activity state.
  • src/features/modes/conversation/hooks/autonomous/use-background-autonomous.ts:77 scans chats every poll and :108 calls the autonomous check for each eligible background chat.

Scratch large-profile timing on the current Target 2 batch 4 base, using synthetic JSON collections:

  • Timeline page projection, 20 rows from an 8,000-message chat: 8.87ms cold / 8.18ms warm, 130,221 payload bytes.
  • Full generation-style chat message read, same 8,000-message chat: 3069.33ms cold / 2983.80ms warm, 101,686,891 payload bytes.
  • Message count, same chat: 129.76ms cold / 128.60ms warm.

This makes normal generation, retry, lorebook keeper backfill, and autonomous background checks scale with total transcript size instead of the context window they actually need.

Expected

High-frequency generation and polling paths should not full-read message history by default. Full transcript reads should be reserved for explicit export, branch, summary range, or other workflows that really need all rows.

Suggested Fix

  • Give normal generation a bounded default message load matching prompt assembly's default history window plus margin, instead of returning undefined when contextMessageLimit is absent.
  • Keep regenerate/old-target flows correct without full reads, using cursor/page or an indexed lookup where possible.
  • Change autonomous activity initialization to request only recent projected fields needed for timing: role, createdAt, and characterId.
  • Add cold/warm large-chat proof covering normal generation, retry/lorebook-keeper, and background autonomous checks.
Originally created by @Xelvanis on GitHub (Jun 3, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2034 Originally assigned to: @cha1latte on GitHub. ## Problem Several hot paths still load a full chat transcript when they only need recent or summary-shaped data. Current refactor evidence on `origin/refactor`: - `src/engine/generation/start-generation.ts:846` defines `generationMessageLoadOptions`, but `:851` returns no cap unless `contextMessageLimit` or request `historyLimit` is set. Normal chats with default metadata call `loadChatMessages` without options at `:2447`, `:2461`, `:2463`, and `:2548`. - `src/engine/generation/context.ts:75` wraps `storage.listChatMessages`; without options it reads the full chat. - `src/engine/generation/start-generation.ts:2372` and `:2414` use full transcript reads for retry/lorebook-keeper paths. - `src/engine/modes/chat/autonomous/autonomous.service.ts:66-67` loads all messages for a chat, then `:147-148` only uses them to initialize recent activity state. - `src/features/modes/conversation/hooks/autonomous/use-background-autonomous.ts:77` scans chats every poll and `:108` calls the autonomous check for each eligible background chat. Scratch large-profile timing on the current Target 2 batch 4 base, using synthetic JSON collections: - Timeline page projection, 20 rows from an 8,000-message chat: `8.87ms` cold / `8.18ms` warm, `130,221` payload bytes. - Full generation-style chat message read, same 8,000-message chat: `3069.33ms` cold / `2983.80ms` warm, `101,686,891` payload bytes. - Message count, same chat: `129.76ms` cold / `128.60ms` warm. This makes normal generation, retry, lorebook keeper backfill, and autonomous background checks scale with total transcript size instead of the context window they actually need. ## Expected High-frequency generation and polling paths should not full-read message history by default. Full transcript reads should be reserved for explicit export, branch, summary range, or other workflows that really need all rows. ## Suggested Fix - Give normal generation a bounded default message load matching prompt assembly's default history window plus margin, instead of returning `undefined` when `contextMessageLimit` is absent. - Keep regenerate/old-target flows correct without full reads, using cursor/page or an indexed lookup where possible. - Change autonomous activity initialization to request only recent projected fields needed for timing: `role`, `createdAt`, and `characterId`. - Add cold/warm large-chat proof covering normal generation, retry/lorebook-keeper, and background autonomous checks.
bsakaguchi 2026-10-21 05:24:58 +07:00
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#996
No description provided.