mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3024] [Issue]: Chat-history marker assigned to a group is collapsed into one block, destroying message boundaries and mis-anchoring all depth/post-history injection #1595
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#1595
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/3024
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
If the Chat History marker section is assigned to a group in the preset editor (the UI permits it), the assembler routes it through
buildGroupMessages, which collapses the entire chat history into one block (or one block per role-run) and overwrites each message'scontextKindfrom"history"to"prompt". The per-message structure and the history anchor are lost, so depth-injected sections, depth lorebook entries, character depth prompts, and post-history instructions get placed relative to the end of the WHOLE prompt instead of the end of chat history.How to reproduce (try it yourself)
You'll see: chat history collapsed into a single block (or per-role blocks) wrapped in the group tag,
contextKind "history"gone, and depth/post-history blocks landing after the whole prompt instead of after the last chat message.Expected: chat history preserved as discrete messages and depth/post-history blocks anchored to the end of chat history.
Where it is
packages/server/src/services/prompt/assembler.ts— group routing at line 398 (if (section.groupId)) is checked BEFORE theisChatHistorybranch at line 424 (inside theelse), and the inner member-collection loop at line 405 (if (next.groupId === section.groupId)) also absorbs chat-history sections.buildGroupMessages(692-738) flattens and re-tags as"prompt"(lines 705/720).findHistoryBounds(750-760) then returns null, and Phase-5 inject (499-507) callsinjectAtDepthwith no bounds, defaulting the anchor to the end of the whole prompt (packages/server/src/services/lorebook/prompt-injector.ts:95-96). UI reachability:packages/client/src/components/presets/PresetEditor.tsx:1575-1601(Group selector, no marker guard).What's happening
The group-routing condition takes precedence over the history-preserving branch, and
buildGroupMessageshas no chat-history awareness, so a grouped chat-history section is flattened and itscontextKind: "history"markers are overwritten — which removes the anchorfindHistoryBoundsneeds.Suggested fix
Exclude chat-history sections from group collection in BOTH the outer head check and the inner member-collection loop in
assembler.ts:if (section.groupId) {toif (section.groupId && !section.isChatHistory) {.if (next.groupId === section.groupId) {toif (next.groupId === section.groupId && !next.isChatHistory) {.With both guards, a chat-history section is never routed to or absorbed by
buildGroupMessages; it falls into the existingelse/isChatHistorypath (lines 424-426) and emitssection.messagesverbatim, preserving each message'scontextKind: "history"sofindHistoryBoundsfinds the anchor and depth injection is placed correctly.Note on the obvious one-guard version: guarding only the outer head check (line 398) is INSUFFICIENT — if any non-chat-history section sharing the same groupId is ordered before the chat-history section, that earlier section becomes the group head and the inner loop still pulls the chat-history section in. Both guards are required. Optionally also hide the Group selector for the chat_history marker in
PresetEditor.tsxas defense-in-depth, but the two-line server guard is the load-bearing fix.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed on staging in PR #3031 (merged as
f542e282). Closing manually because GitHub auto-close keywords only close issues when merged into the default branch (main), not staging.