[GH-ISSUE #3052] [Issue]: Custom impersonate prompt drops a whole line (including co-located text) when a placeholder has an empty value #1621

Closed
opened 2026-10-21 05:40:56 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3052

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

The impersonate-instruction renderer removes placeholders with an empty value at the whole-line level: if {{persona_description}} (and the persona has no description) or {{impersonate_direction}} (and there is no steering direction) appears anywhere on a line, that ENTIRE line is dropped — including any other instruction text or other placeholders the user put on the same line. With a custom impersonate prompt that places a placeholder inline with meaningful text (e.g. Stay in character as {{user}} ({{persona_description}}) and reply.), an empty persona description silently deletes the whole "Stay in character as … and reply." instruction. The default prompt is unaffected (its placeholders sit on their own lines), so this only bites user-authored custom impersonate prompts.

How to reproduce (try it yourself)

  1. Set a custom Impersonate prompt whose template has a placeholder inline with text on the same line, e.g. a line: Write {{user}}'s reply ({{persona_description}}) staying in character.
  2. Use a persona with an empty Description (so personaDescription is empty), and impersonate without a steering direction.
  3. Trigger an impersonate generation and inspect the assembled impersonate instruction.

You'll see: the entire line — including Write {{user}}'s reply … staying in character. — is gone, because the empty {{persona_description}} caused the whole line to be filtered out.
Expected: only the empty placeholder is removed; the surrounding instruction text (and the resolved {{user}}) is preserved.

Where it is

packages/server/src/services/conversation/impersonate-prompt.ts:48-62 — renderImpersonateTemplate splits the template into lines and, in the .filter at lines 50-53, drops any whole line containing {{persona_description}} when personaDescription is empty (line 51) or {{impersonate_direction}} when direction is empty (line 52), BEFORE the placeholder replacement at lines 55-60. Reached via the custom-prompt path in buildImpersonateInstruction (lines 76-84).

What's happening

The empty-value cleanup is line-granular, not placeholder-granular. It was written assuming each removable placeholder occupies its own line (true for DEFAULT_IMPERSONATE_PROMPT), but a custom template can legitimately put a placeholder inline with other content, and the filter removes that content along with the empty placeholder.

Suggested fix

Drop a line only when an empty-valued placeholder was its sole meaningful content; otherwise keep the line and let the replacement turn the empty placeholder into an empty string. Replace renderImpersonateTemplate's body (lines 48-62):

  const lineIsEmptyPlaceholderOnly = (line: string): boolean => {
    let stripped = line;
    let removedEmpty = false;
    if (!personaDescription && stripped.includes("{{persona_description}}")) {
      stripped = stripped.replaceAll("{{persona_description}}", "");
      removedEmpty = true;
    }
    if (!direction && stripped.includes("{{impersonate_direction}}")) {
      stripped = stripped.replaceAll("{{impersonate_direction}}", "");
      removedEmpty = true;
    }
    // Resolve {{user}} too, so a line that is only "{{user}}" + an empty placeholder
    // is judged on its real rendered content.
    return removedEmpty && stripped.replaceAll("{{user}}", personaName).trim() === "";
  };

  return template
    .split(/\r?\n/)
    .filter((line) => !lineIsEmptyPlaceholderOnly(line))
    .map((line) =>
      line
        .replaceAll("{{user}}", personaName)
        .replaceAll("{{persona_description}}", personaDescription)
        .replaceAll("{{impersonate_direction}}", direction),
    )
    .join("\n")
    .trim();

This preserves the previous behavior for placeholder-only lines (a bare {{persona_description}}/{{impersonate_direction}} line with an empty value is still removed, so no blank line is left), while a line that also carries instruction text or {{user}} is now kept and the empty placeholder simply renders as "". The default prompt round-trips identically (its removable placeholders are alone on their lines). When the value is non-empty, the line was never filtered before and still isn't.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3052 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The impersonate-instruction renderer removes placeholders with an empty value at the **whole-line** level: if `{{persona_description}}` (and the persona has no description) or `{{impersonate_direction}}` (and there is no steering direction) appears anywhere on a line, that ENTIRE line is dropped — including any other instruction text or other placeholders the user put on the same line. With a **custom impersonate prompt** that places a placeholder inline with meaningful text (e.g. `Stay in character as {{user}} ({{persona_description}}) and reply.`), an empty persona description silently deletes the whole "Stay in character as … and reply." instruction. The default prompt is unaffected (its placeholders sit on their own lines), so this only bites user-authored custom impersonate prompts. **How to reproduce (try it yourself)** 1. Set a custom Impersonate prompt whose template has a placeholder inline with text on the same line, e.g. a line: `Write {{user}}'s reply ({{persona_description}}) staying in character.` 2. Use a persona with an empty Description (so `personaDescription` is empty), and impersonate without a steering direction. 3. Trigger an impersonate generation and inspect the assembled impersonate instruction. You'll see: the entire line — including `Write {{user}}'s reply … staying in character.` — is gone, because the empty `{{persona_description}}` caused the whole line to be filtered out. Expected: only the empty placeholder is removed; the surrounding instruction text (and the resolved `{{user}}`) is preserved. **Where it is** `packages/server/src/services/conversation/impersonate-prompt.ts:48-62` — `renderImpersonateTemplate` splits the template into lines and, in the `.filter` at lines 50-53, drops any whole line containing `{{persona_description}}` when `personaDescription` is empty (line 51) or `{{impersonate_direction}}` when `direction` is empty (line 52), BEFORE the placeholder replacement at lines 55-60. Reached via the custom-prompt path in `buildImpersonateInstruction` (lines 76-84). **What's happening** The empty-value cleanup is line-granular, not placeholder-granular. It was written assuming each removable placeholder occupies its own line (true for `DEFAULT_IMPERSONATE_PROMPT`), but a custom template can legitimately put a placeholder inline with other content, and the filter removes that content along with the empty placeholder. **Suggested fix** Drop a line only when an empty-valued placeholder was its **sole** meaningful content; otherwise keep the line and let the replacement turn the empty placeholder into an empty string. Replace `renderImpersonateTemplate`'s body (lines 48-62): ```ts const lineIsEmptyPlaceholderOnly = (line: string): boolean => { let stripped = line; let removedEmpty = false; if (!personaDescription && stripped.includes("{{persona_description}}")) { stripped = stripped.replaceAll("{{persona_description}}", ""); removedEmpty = true; } if (!direction && stripped.includes("{{impersonate_direction}}")) { stripped = stripped.replaceAll("{{impersonate_direction}}", ""); removedEmpty = true; } // Resolve {{user}} too, so a line that is only "{{user}}" + an empty placeholder // is judged on its real rendered content. return removedEmpty && stripped.replaceAll("{{user}}", personaName).trim() === ""; }; return template .split(/\r?\n/) .filter((line) => !lineIsEmptyPlaceholderOnly(line)) .map((line) => line .replaceAll("{{user}}", personaName) .replaceAll("{{persona_description}}", personaDescription) .replaceAll("{{impersonate_direction}}", direction), ) .join("\n") .trim(); ``` This preserves the previous behavior for placeholder-only lines (a bare `{{persona_description}}`/`{{impersonate_direction}}` line with an empty value is still removed, so no blank line is left), while a line that also carries instruction text or `{{user}}` is now kept and the empty placeholder simply renders as "". The default prompt round-trips identically (its removable placeholders are alone on their lines). When the value is non-empty, the line was never filtered before and still isn't. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Claiming this for the current staging sweep in draft PR #3053 (branch codex/issue-sweep-3033-3052).

<!-- gh-comment-id:4834991314 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Claiming this for the current staging sweep in draft PR #3053 (branch `codex/issue-sweep-3033-3052`).
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in PR #3053 on branch codex/issue-sweep-3033-3052 (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.

<!-- gh-comment-id:4835091802 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in PR #3053 on branch `codex/issue-sweep-3033-3052` (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.
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#1621
No description provided.