mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2673] [Issue]: Assistant prefill sent to Anthropic with trailing whitespace → HTTP 400 (perceived as a refusal/block) #1320
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#1320
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 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2673
Originally assigned to: @kolacheee on GitHub.
Summary
A preset's assistant prefill is pushed as the trailing assistant message untrimmed, while the trimmed value is used only as a presence guard. Anthropic's Messages API rejects a final assistant message that ends in whitespace with HTTP 400 ("final assistant content cannot end with trailing whitespace"), which users perceive as a content block/refusal. Prefills ending in
\nor a space are common, so this breaks many Anthropic generations that work fine in SillyTavern.Expected behavior
A prefill that ends in whitespace (e.g.
<thinking>\n) should still produce a successful Anthropic generation — the trailing edge should be stripped from what is sent to the API (the user-facing prefill rendering is separate), matching SillyTavern's behavior.Actual behavior
appendGenerationTailMessagescomputesconst assistantPrefill = options.assistantPrefill.trim()(used only as the guard) but pushes the untrimmedoptions.assistantPrefillas the final assistant message. On Anthropic that trailing assistant turn ends in whitespace → HTTP 400 → the generation fails and looks like a refusal/block.How it breaks the pipeline
Code trace (staging @
b826f8f4):packages/server/src/routes/generate/generate-route-utils.ts:540-543—appendGenerationTailMessages: trims to a local for the guard, but pushescontent: options.assistantPrefill(untrimmed).packages/server/src/services/llm/providers/anthropic.provider.tsemits the trailing assistant content untrimmed (formatAnthropicPayloadMessages~line 194 text block; the string-content path), andmergeAnthropicPayloadMessagesdoes not trim.400"final assistant content cannot end with trailing whitespace".dry-run-route.ts:1438-1439), so the preview would not reveal it.Steps to reproduce
<thinking>\norSure,(trailing space).400; the generation fails and appears to the user as a block/refusal. The same prefill works in SillyTavern (which strips the trailing edge).Suggested fix
Push
options.assistantPrefill.trimEnd()as the trailing assistant message content (strip the trailing edge Anthropic rejects; leading whitespace is fine and preserved). Mirror the same in the dry-run preview (dry-run-route.ts) so the preview matches what is sent. Harmless for OpenAI/Google (they do not reject trailing whitespace), and the user-facing prefill rendering is unaffected.Environment
b826f8f4)Additional context
Identified via a source-level audit of the prompt-assembly / prefill path on staging, prompted by reports of presets that work on SillyTavern producing blocks/refusals on Marinara. This is one concrete cause; a broader prompt-ordering audit (e.g. system-message placement under
strictRoleFormatting) is ongoing.Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@kolacheee commented on GitHub (Jun 20, 2026):
assign me pls