mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3012] [Issue]: append_chat_summary grows persisted summaryEntries unbounded; only the compiled summary is byte-capped #1584
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1584
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3012
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
Every
append_chat_summarycall adds a new entry tometadata.summaryEntriesviaappendChatSummaryEntryToMetadata, which doessortChatSummaryEntries([...entries, entry])with NO cap on entry count and no pruning. The compiledsummarystring is byte-limited (to 64 KB), so the prompt-injected text stays bounded, but the underlyingsummaryEntriesarray — persisted in chat metadata and re-serialized to JSON on every metadata write — accumulates forever. An agent that callsappend_chat_summaryon most turns will steadily inflate the chat row's metadata blob with entries that no longer contribute to the already byte-capped compiled summary, growing JSON parse/stringify cost on every subsequentpatchMetadatafor that chat.How to reproduce (try it yourself)
append_chat_summaryand have it append summary text every turn over a long chat.metadata.summaryEntries.You'll see: the array grows by one per append with no upper bound, while the compiled
summarysaturates at ~64 KB and discards older entries' contribution. Each subsequentpatchMetadata(any metadata write for the chat) parses/stringifies the ever-larger array.Expected: the persisted entries array is bounded (mirroring the 64 KB compile cap) so metadata size and per-write JSON cost stay bounded.
Where it is
Writer at
packages/server/src/services/tools/tool-executor.ts:536-549; the unbounded append atpackages/shared/src/utils/chat-summary-entries.ts:267-283(appendChatSummaryEntryToMetadata); persistence (JSON.stringify on every write) atpackages/server/src/services/storage/chats.storage.ts:467-489.What's happening
appendChatSummaryEntryToMetadataappends to the entries array with no maximum-count or total-bytes pruning; the only size guard (compileChatSummaryEntries→ 64 KB) is applied to the derived compiled string, not to the persisted source array. The append path has no back-pressure on the stored entry list.Suggested fix
Cap the count of
automatedsummary entries inside the sharedappendChatSummaryEntryToMetadataso all unbounded callers (the agent tool plus the auto-rolling-summary route) are fixed at once, while preserving user-authored and user-disabled content.In
packages/shared/src/utils/chat-summary-entries.ts:export const MAX_AUTOMATED_CHAT_SUMMARY_ENTRIES = 200;.automatedentries first (the sorted array is oldest-to-newest), never touching manual/legacy entries and never an automated entry that hid messages (hiddenMessageIds), since this side-effect-free helper cannot unhide them the way the delete route does:appendChatSummaryEntryToMetadata:Regression avoided: the original suggestion ("prune entries whose content no longer survives compilation" / "drop oldest disabled") would delete user-disabled entries — but
summaryEntriesis user-facing (the SummaryPopover renders disabled entries via a "show inactive" toggle and lets the user re-enable/edit/delete them), and disabled entries never survive compilation BY DESIGN. It would also break message-hiding consistency if it pruned an entry carryinghiddenMessageIds(leaving messages hidden with no entry to justify them; only the delete route unhides first). And the cap belongs in the shared helper, not just the tool path — three of its four callers produce unbounded automated entries (the tool, the automatedchats.routespath, and the auto-rolling-summarygenerate.routespath); the fourth is user-initiatedmanual. The corrected fix caps ONLY automated entries, preserves all manual/legacy and disabled entries, and never prunes an automated entry that hid messages.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in merged staging PR #3018.