mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #6219] [Issue]: Depth-injected system entries are hoisted into the Anthropic system block and break the cached prefix #3468
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#3468
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 (Sep 15, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6219
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The Anthropic adapter collects every
role: "system"message in the whole array into the top-levelsystemfield. A depth-injected entry authored as system (a depth prompt section, a lorebook depth entry, a character advanced-prompt entry) therefore lands in the system block instead of at its depth, and anything that changes inside it invalidates the cached prefix for the whole system block.Expected behavior
A depth entry sits at its configured depth in the message history on Anthropic, as it does on other providers, and a lorebook entry near the end of history changing does not throw away the cached system prefix.
Actual behavior
packages/server/src/services/llm/providers/anthropic.provider.ts:369and:682filterm.role === "system"across the entire array and hoist the result intosystem. The injector places each entry with its authored role (packages/server/src/services/prompt/assembler.ts:696-707, slot computed atpackages/server/src/services/lorebook/prompt-injector.ts:105). Nothing checks where the entry ended up.Steps to reproduce
{{time}}).system, not inmessages, and the next turn reports a cache write where a cache read was expected.Environment
29ee24fc2)Logs, screenshots, or video
Not applicable; the hoist is visible at the cited lines.
Additional context
The fix has API constraints. A system message inside
messagesis accepted only on some models, must follow a user turn (or an assistant turn ending in server tool use), and must be the last entry or be followed by an assistant turn, otherwise the request is a 400. The injector's slot math does not check neighbours, so the safe shape is to keep the entry inmessagesonly when the slot satisfies the rule and otherwise convert it to a user-role entry at the same depth, which is also what unsupported models get.CHANGELOG.mdline 825 records an earlier fix of the same class (volatile name lists moved out of the system prompt to keep caching stable).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 (Sep 15, 2026):
Owner: @SpicyMarinara, with Codex implementing this issue as part of the requested sweep in draft PR #6230 against
staging. I checked the open PRs and issue-linked work before starting; no competing open PR was found.@SpicyMarinara commented on GitHub (Sep 15, 2026):
Merged in #6230 to staging (
c6685f7034).Only leading system instructions enter Anthropic’s top-level system prefix. Depth instructions retain their history position, using supported history-level system messages or a compatible user-context fallback. Provider regressions cover both request paths, placement controls, and empty tool-result pairing.