mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2691] [Issue]: At-depth lorebook entries (role=system) are hoisted to the front by strictRoleFormatting; embedded-book round-trip flattens at-depth placement #1335
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#1335
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 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2691
Originally assigned to: @SpicyMarinara on GitHub.
Summary
Lorebook entries configured for at-depth injection (
position = at-depth,depth = N,role = system) are moved out of their computed depth slot to the front of the prompt — so an at-depth note meant to sit N messages from the end of history is collapsed into the leading system block. Becauseroledefaults tosystem, this is the common case, not an edge case. A separate embedded-character-book round-trip path also flattens at-depth placement tobefore_char.Expected behavior
An at-depth lorebook entry (
position=2,depth=N,role=system) should land as an in-chat message N messages from the history end (SillyTavern@Dparity), not as a global system prompt at the top.Actual behavior
enforceStrictRoleshoists at-depth system entries. Assembler Phase 5 injects lorebook depth entries viainjectAtDepth, preserving role andcontextKind:'injection'. Phase 6 (enforceStrictRoles, run whenstrictRoleFormattingis true — the default) unconditionally takes everyrole==='system'message after the leading block and merges/unshifts it to the front. There is no guard forcontextKind==='injection', so a depth-injected system entry is yanked to the top. Sinceroledefaults tosystem, most at-depth entries are affected.position>=2(at-depth/AN/EM) entry tobefore_char, silently moving@D/AN/EM content to the top of context.How it breaks the pipeline
Code trace (staging @
b826f8f4):packages/server/src/services/prompt/assembler.ts:429-465(injectAtDepth, role preserved,contextKind:'injection'). Hoist:assembler.ts:749-760(enforceStrictRolesmerges/unshifts every trailingrole==='system'with nocontextKindguard).strictRoleFormattingdefaults true (shared/constants/defaults.ts:38, shippeddefault-preset.json).roledefaultssystem(lorebook.schema.ts:182).packages/server/src/services/lorebook/character-book-sync.ts(position>=2 → before_char on sync).Steps to reproduce
position=at-depth,depth=2,role=system(defaults), with a keyword present in the last message; default preset (strictRoleFormatting=true), aworld_infomarker, and >2 history messages.positionflatten tobefore_char.Suggested fix
enforceStrictRoles(assembler.ts:749-760), skip hoisting for depth-injected content: whenmsg.contextKind === 'injection'(or a dedicatedisDepthInjectedflag), leave it in place — or runenforceStrictRolesbefore Phase 5 depth injection. Mirror ST, which keeps@Dsystem entries at their depth.position(and depth/role) through the embedded-character-book round-trip incharacter-book-sync.tsinstead of flatteningposition>=2tobefore_char.Environment
b826f8f4)Additional context
Found via a systematic multi-agent audit of conditional prompt insertion. The lorebook-specific sibling of the post-history hoist (#2676), but it affects native and imported at-depth entries at the default
role=system. Related to the ST position-import mismap filed separately.Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@SpicyMarinara commented on GitHub (Jun 21, 2026):
Addressed in branch
codex/spicy-issue-sweep-2026-06-21.Verification/fix notes:
enforceStrictRolesno longer unshifts later system messages into the leading system block, so depth-injected system messages are not collapsed to the front there.position: 4with depth/role preserved.Final repo checks will run after the full issue sweep.