[PR #8703] [MERGED] fix(generate): every request ends on the Assistant Prefill #8755

Closed
opened 2026-11-07 17:39:28 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8703
Author: @SpicyMarinara
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/assistant-prefill-ends-the-prompt


📝 Commits (3)

  • db86c2c fix(generate): end every request on the Assistant Prefill
  • 5c3a2a5 fix(generate): keep the prefill one request on Apply and Claude Subscription
  • b63a215 fix(generate): with no reply to open, send the prefill as a user message

📊 Changes

8 files changed (+639 additions, -76 deletions)

View changed files

📝 docs/prompts/generation-parameters.md (+2 -0)
📝 packages/server/src/routes/generate.routes.ts (+36 -20)
📝 packages/server/src/routes/generate/dry-run-route.ts (+25 -12)
📝 packages/server/src/routes/generate/generate-route-utils.ts (+104 -39)
📝 packages/server/src/services/generation/generation-parameters.ts (+12 -0)
📝 packages/server/src/services/llm/providers/claude-subscription/jsonl-entries.ts (+5 -4)
➕ scripts/regressions/assistant-prefill-ends-prompt.regression.ts (+452 -0)
📝 scripts/regressions/provider-compat.regression.ts (+3 -1)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #8692

Why this change

The maintainer wants the Assistant Prefill setting to work like this:

  • Normally: the request sent to the model ends on an assistant message that is exactly the prefill, after everything else, including the user's depth 0 prompts and post-history instructions.
  • Models that refuse a final assistant message: in their words, "apply it before the assistant's last message in the chat history… we want to show the model the last turn it used it."
  • No assistant reply in the chat yet: the prefill goes in as a user message.

Before this change the prefill was pushed into the shared prompt early, by appendGenerationTailMessages. Everything added per responder after that landed after it:

  • the generation guide;
  • @mention and regeneration instructions;
  • in individual groups, earlier in-turn replies, the turn instruction and the "@Name" hint;
  • notes and whispers.

So many requests did not end on the prefill.

What changed

  • Built, not pushed. appendGenerationTailMessages now only builds the prefill turn (the visible text, plus the reasoning prefill where supported). The exception is Gemini user-message regeneration, which still puts the prefill before the rewrite instruction (#7558).
  • Added last, per responder. New endPromptOnAssistantPrefill runs in generateForCharacter after every per-responder addition. It resolves macros in the prefill and pushes it as the final message, trimmed at the end for Anthropic.
  • Safe from post-processing. Single User Message never folds the final prefill turn into the user message. Apply merges it into an assistant reply right before it, as on staging, so a chat ending on the AI's own reply sends one assistant message ending with the prefill, never two in a row (llama.cpp refuses two). Don't Apply never merged it.
  • Models that refuse a final assistant message, detected by rejectsFinalAssistantMessage(model), which reuses the existing capability helpers:
    • Models: Claude Opus 5.5 and Sonnet 5.5; Gemini 4 Argon, 3.5 Flash-Lite and 3.6 to 3.8 Flash. This applies on any provider, and on the Claude subscription with every model.
    • Where the prefill goes: at the start of the last assistant reply in the history, right before the reply's own text: after any timestamp, speaker name or <chat_history>/<last_message> wrapper. It's joined the way a streamed reply is.
    • No trailing turn: no assistant turn is added, so the providers' continuation prompt never fires.
    • Gemini parts: a reply's saved Gemini parts are dropped, so the edited text is what gets sent.
    • No assistant reply in the history (a first turn, or a group responder with no reply of their own): the prefill goes in as a user message at the end, the maintainer's choice.
    • Reasoning prefill: a reasoning-only prefill still ends the prompt, as before.
  • Kept:
    • the reply is streamed and saved with the prefill;
    • an echoed prefill is stripped from the saved reply, only when the prefill really ends the prompt;
    • the Anthropic trailing-whitespace trim;
    • impersonation (no prefill), continue, follow-up iterations, and the tool-round and Game-planner placement.
  • Peek Prompt (the dry-run route) shows all of this.
  • Docs: the Assistant Prefill section of docs/prompts/generation-parameters.md. Translations follow in #8700.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

What the agent ran locally, rebased on staging:

  • node ./scripts/pnpm-runner.mjs check: exits 0.

  • New regression assistant-prefill-ends-prompt. It builds the final provider payload through the real route for:

    • Anthropic, Gemini and an OpenAI-compatible endpoint;
    • Roleplay and Conversation, single and individual-group chats;
    • Apply, Don't Apply and Single User Message;
    • depth-0 prompts and post-history instructions;
    • models that refuse a trailing assistant message, and the Claude subscription.

    It asserts the last message, or the prefixed last reply, and the user-message case with no reply. It fails with the source change reverted.

  • Existing regressions: provider-compat, gemini-user-regeneration and roleplay-regeneration-context pass.

  • Review: an independent review found three defects, all fixed:

    • Apply sent two assistant turns at the end;
    • the Claude subscription wasn't treated as refusing a final assistant message;
    • the fallback's text placement after a regex-changed reply.

For a human to verify:

  • In a Roleplay chat on an accepting model (for example Claude Sonnet 4.5) with Assistant Prefill set and Post-Processing at Don't Apply, open Peek Prompt. Manually verify the prefill is the last [assistant] block, after the post-history section and any guide, and the streamed reply starts with it.
  • In a Conversation group chat with Assistant Prefill set, manually verify Peek Prompt ends on the prefill after the <output_format> block.
  • On a Claude Opus 5.5 or Gemini 3.8 Flash connection, manually verify:
    • the request has no trailing assistant message;
    • the AI's last reply in Peek Prompt starts with the prefill, after its timestamp or speaker name;
    • the new reply is saved without it.
  • On the same kind of connection, in a new chat with no AI reply yet, manually verify the prefill goes last as your message.
  • Manually verify Gemini user-message regeneration still ends on the rewrite instruction, impersonation sends no prefill, and Continue works as before.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

The English Assistant Prefill section of docs/prompts/generation-parameters.md is updated. The translations follow in #8700.

UI evidence (if applicable)

No UI change. Peek Prompt shows the new order.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/8703 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/assistant-prefill-ends-the-prompt` --- ### 📝 Commits (3) - [`db86c2c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/db86c2c8e1612bcec5a99e3df5d2fd94bfdb3b08) fix(generate): end every request on the Assistant Prefill - [`5c3a2a5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5c3a2a53defecb805eec587d2ecbac0734e622b5) fix(generate): keep the prefill one request on Apply and Claude Subscription - [`b63a215`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b63a215996e7caf5e8a9a370047f1998cb848907) fix(generate): with no reply to open, send the prefill as a user message ### 📊 Changes **8 files changed** (+639 additions, -76 deletions) <details> <summary>View changed files</summary> 📝 `docs/prompts/generation-parameters.md` (+2 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+36 -20) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+25 -12) 📝 `packages/server/src/routes/generate/generate-route-utils.ts` (+104 -39) 📝 `packages/server/src/services/generation/generation-parameters.ts` (+12 -0) 📝 `packages/server/src/services/llm/providers/claude-subscription/jsonl-entries.ts` (+5 -4) ➕ `scripts/regressions/assistant-prefill-ends-prompt.regression.ts` (+452 -0) 📝 `scripts/regressions/provider-compat.regression.ts` (+3 -1) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #8692 ## Why this change The maintainer wants the Assistant Prefill setting to work like this: - **Normally:** the request sent to the model ends on an assistant message that is exactly the prefill, after everything else, including the user's depth 0 prompts and post-history instructions. - **Models that refuse a final assistant message:** in their words, "apply it before the assistant's last message in the chat history… we want to show the model the last turn it used it." - **No assistant reply in the chat yet:** the prefill goes in as a user message. Before this change the prefill was pushed into the shared prompt early, by `appendGenerationTailMessages`. Everything added per responder after that landed after it: - the generation guide; - @mention and regeneration instructions; - in individual groups, earlier in-turn replies, the turn instruction and the "@Name" hint; - notes and whispers. So many requests did not end on the prefill. ## What changed - **Built, not pushed.** `appendGenerationTailMessages` now only builds the prefill turn (the visible text, plus the reasoning prefill where supported). The exception is Gemini user-message regeneration, which still puts the prefill before the rewrite instruction (#7558). - **Added last, per responder.** New `endPromptOnAssistantPrefill` runs in `generateForCharacter` after every per-responder addition. It resolves macros in the prefill and pushes it as the final message, trimmed at the end for Anthropic. - **Safe from post-processing.** Single User Message never folds the final prefill turn into the user message. Apply merges it into an assistant reply right before it, as on staging, so a chat ending on the AI's own reply sends one assistant message ending with the prefill, never two in a row (llama.cpp refuses two). Don't Apply never merged it. - **Models that refuse a final assistant message**, detected by `rejectsFinalAssistantMessage(model)`, which reuses the existing capability helpers: - **Models:** Claude Opus 5.5 and Sonnet 5.5; Gemini 4 Argon, 3.5 Flash-Lite and 3.6 to 3.8 Flash. This applies on any provider, and on the Claude subscription with every model. - **Where the prefill goes:** at the start of the last assistant reply in the history, right before the reply's own text: after any timestamp, speaker name or `<chat_history>`/`<last_message>` wrapper. It's joined the way a streamed reply is. - **No trailing turn:** no assistant turn is added, so the providers' continuation prompt never fires. - **Gemini parts:** a reply's saved Gemini parts are dropped, so the edited text is what gets sent. - **No assistant reply in the history** (a first turn, or a group responder with no reply of their own): the prefill goes in as a user message at the end, the maintainer's choice. - **Reasoning prefill:** a reasoning-only prefill still ends the prompt, as before. - **Kept:** - the reply is streamed and saved with the prefill; - an echoed prefill is stripped from the saved reply, only when the prefill really ends the prompt; - the Anthropic trailing-whitespace trim; - impersonation (no prefill), continue, follow-up iterations, and the tool-round and Game-planner placement. - **Peek Prompt** (the dry-run route) shows all of this. - **Docs:** the Assistant Prefill section of `docs/prompts/generation-parameters.md`. Translations follow in #8700. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes What the agent ran locally, rebased on staging: - **`node ./scripts/pnpm-runner.mjs check`:** exits 0. - **New regression `assistant-prefill-ends-prompt`.** It builds the final provider payload through the real route for: - Anthropic, Gemini and an OpenAI-compatible endpoint; - Roleplay and Conversation, single and individual-group chats; - Apply, Don't Apply and Single User Message; - depth-0 prompts and post-history instructions; - models that refuse a trailing assistant message, and the Claude subscription. It asserts the last message, or the prefixed last reply, and the user-message case with no reply. It fails with the source change reverted. - **Existing regressions:** provider-compat, gemini-user-regeneration and roleplay-regeneration-context pass. - **Review:** an independent review found three defects, all fixed: - Apply sent two assistant turns at the end; - the Claude subscription wasn't treated as refusing a final assistant message; - the fallback's text placement after a regex-changed reply. For a human to verify: - In a Roleplay chat on an accepting model (for example Claude Sonnet 4.5) with Assistant Prefill set and Post-Processing at Don't Apply, open Peek Prompt. Manually verify the prefill is the last `[assistant]` block, after the post-history section and any guide, and the streamed reply starts with it. - In a Conversation group chat with Assistant Prefill set, manually verify Peek Prompt ends on the prefill after the `<output_format>` block. - On a Claude Opus 5.5 or Gemini 3.8 Flash connection, manually verify: - the request has no trailing assistant message; - the AI's last reply in Peek Prompt starts with the prefill, after its timestamp or speaker name; - the new reply is saved without it. - On the same kind of connection, in a new chat with no AI reply yet, manually verify the prefill goes last as your message. - Manually verify Gemini user-message regeneration still ends on the rewrite instruction, impersonation sends no prefill, and Continue works as before. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) The English Assistant Prefill section of `docs/prompts/generation-parameters.md` is updated. The translations follow in #8700. ## UI evidence (if applicable) No UI change. Peek Prompt shows the new order. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:39:28 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8755
No description provided.