[GH-ISSUE #6066] [Issue]: Bug Report: Conversation Identity Fallback Incorrectly Suppressed by Macro Alias Detection #3361

Closed
opened 2026-10-21 06:02:19 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @Mr-Ken-1102 on GitHub (Sep 12, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6066

Originally assigned to: @SpicyMarinara on GitHub.

Bug Report: Conversation Identity Fallback Incorrectly Suppressed by Macro Alias Detection

Summary

In Marinara Engine 2.4.4, Conversation-mode identity fallback can incorrectly omit Character and Persona fields when a custom Conversation prompt contains ordinary prose words such as personality, description, or persona.

The issue is not in the Conversation fallback gate. The fallback gate behaves as intended and always enables identity fallback in Conversation mode.

The defect is in the macro alias detector used by the fallback suppression logic. Its current regular expression can match text across }} macro boundaries, causing normal prose following a macro such as {{charName}} to be misinterpreted as if it contained explicit identity macros.

This causes populated Character and Persona fields to be silently suppressed from the final model request.


Environment

  • Marinara Engine: 2.4.4
  • Audited HEAD: 1a299369a
  • Relevant TypeScript and compiled JavaScript contain the same logic.
  • Mode affected: Conversation
  • Reproduced with:
    • Built-in Conversation preset
    • Saved custom Conversation preset
    • Existing compiled fallback injector invoked in memory
  • No source files were modified during reproduction.

Severity / Impact

This is a prompt-construction regression that can materially alter model behavior.

A custom Conversation prompt may appear valid in the UI but cause Character or Persona identity fields to disappear from the final model request simply because ordinary prose contains alias words after another macro.

Affected data can include:

Character

  • Description
  • Personality
  • Backstory
  • Appearance
  • Scenario
  • Advanced System Prompt
  • Example Dialogue

Persona

  • Description
  • Personality
  • Backstory
  • Appearance
  • Scenario

In the reproduced case, the custom prompt caused:

  • Character Description: missing
  • Character Personality: missing
  • Persona Description: missing
  • Persona Personality: missing
  • Persona Backstory: missing
  • Persona Appearance: missing
  • Persona Scenario: missing

while Character Backstory, Appearance, and Scenario remained present.


Minimal Reproduction

A normal Conversation instruction such as:

{{charName}} follows their personality and description.
Respond as {{charName}}.

contains no {{personality}} or {{description}} macro.

However, the current alias detector reports references to both personality and description.

A similar issue occurs when ordinary prose contains the word persona.

For the tested saved preset, three false positives were observed:

Detected alias Actual occurrence Effect
description Ordinary prose after {{charName}} Suppresses Character Description
personality Ordinary prose after {{charName}} Suppresses Character Personality
persona Ordinary prose containing user/persona Suppresses all five Persona fallback fields

Root Cause

The relevant detector currently constructs a pattern equivalent to:

return new RegExp(
  `\\{\\{[\\s\\S]*?\\b${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b[\\s\\S]*?\\}\\}`,
  "i"
);

The problem is the use of:

[\s\S]*?

before and after the alias.

Although non-greedy, these expressions are not constrained to a single macro token. They can cross a closing }}, continue through ordinary prompt prose, and terminate at a later }}.

Conceptually, the detector can therefore interpret text like:

{{charName}} follows their personality and description.
Respond as {{charName}}

as one large apparent macro span.

This makes personality and description look like macro aliases even though they are plain prose.


Why the Conversation Fallback Gate Is Not the Problem

The current implementation is:

export function shouldInjectIdentityFallback({
  chatMode,
  presetId,
}: {
  chatMode: string;
  presetId: string | null | undefined;
}): boolean {
  if (chatMode === "game") return false;
  if (chatMode === "conversation") return true;
  return !presetId;
}

Observed behavior:

Chat mode Preset ID Result
conversation Any ID true
conversation null / undefined / empty true
game Any false
roleplay Non-empty false
roleplay Empty / missing true
Other modes Any !presetId

There is no built-in/custom whitelist or special Conversation preset distinction here.

Therefore, changing shouldInjectIdentityFallback() would address the wrong subsystem.


Built-in vs Custom Conversation Preset Control Flow

Built-in and custom Conversation prompts use the same identity fallback path.

The high-level flow is:

  1. Resolve Persona and its identity fields.
  2. Resolve the selected preset.
  3. Skip the normal preset section assembler for Conversation/Game.
  4. Select Conversation instructions in this priority:
    1. nonblank chat-local customSystemPrompt
    2. nonblank preset conversationPrompt
    3. DEFAULT_CONVERSATION_PROMPT
  5. Save the raw selected template as an identity-fallback template source.
  6. Render instructions and construct finalMessages.
  7. Resolve Character card fields.
  8. shouldInjectIdentityFallback(...) returns true in Conversation mode.
  9. injectIdentityFallbackMessages(...) decides which fields to suppress or inject.

The built-in and custom paths diverge only when the injector analyzes the selected template.

The built-in prompt produces no false alias matches.

The tested custom prompt does.


Actual Behavior

With the affected custom Conversation prompt:

Field Built-in preset Custom preset
Character Description Injected Missing
Character Personality Injected Missing
Character Backstory Injected Injected
Character Appearance Injected Injected
Character Scenario Injected Injected
Persona Description Injected Missing
Persona Personality Injected Missing
Persona Backstory Injected Missing
Persona Appearance Injected Missing
Persona Scenario Injected Missing

The missing-field pattern was reproduced directly with the existing compiled injector.


Expected Behavior

Ordinary prose inside a Conversation prompt must not suppress identity fallback fields.

Only actual supported identity macro references or explicitly supported suppression constructs should cause a field to be omitted from fallback injection.

For example:

{{charName}} follows their personality and description.

must not suppress Character Personality or Character Description.

By contrast:

{{personality}}
{{description}}
{{persona}}

should retain the intended deduplication behavior and prevent duplicate fallback insertion.


Current Suppression Logic

The fallback injector currently suppresses fields under several conditions:

  1. A named Character/Persona profile already exists in XML/Markdown form.
  2. The resolved field is empty.
  3. The raw selected Conversation template is considered to reference the field macro.
  4. A field-content marker is already found in existing messages.

The third condition is where this regression occurs.

Other relevant implementation characteristics:

  • Template inspection uses the raw selected Conversation template.
  • Existing-content checks scan all message roles, including history.
  • The content duplication marker uses only the first trimmed line, capped at 80 characters.
  • Template alias detection is not character-scoped.
  • allContent is captured before injection and is not refreshed after blocks are inserted.

These are not necessarily defects by themselves, but they should remain unchanged unless intentionally redesigned.


Regression History / Intent

Repository history indicates that Conversation identity fallback is intentional.

Relevant history:

  • Commit c7558d96c (June 24) changed the Conversation behavior so Character/Persona identity fallback remains enabled even when a preset is selected.
  • Commit fc673c17d (July 8) introduced template alias detection to prevent duplication and allow intentional field suppression.
  • The changelog documents the later deduplication work under issues #3380 / #3377.
  • The existing regression suite explicitly expects Conversation with a preset to return true from the fallback gate.

This strongly suggests the current behavior is a regression in deduplication detection, not an intended limitation of custom Conversation presets.


Preferred: constrain alias detection to one macro token

The safest patch is to change alias detection so that it cannot cross {{ ... }} boundaries.

The detector should inspect only the contents of an individual macro expression.

This preserves:

  • the Conversation fallback gate;
  • the existing field list;
  • current insertion order;
  • existing built-in/custom flow;
  • intentional suppression when a real identity macro is present;
  • existing Conversation architecture.

This is the smallest targeted correction.

Important compatibility requirement

Before accepting the patch, verify that the revised detection still handles any supported conditional/comment macro syntax that is intentionally allowed to suppress fields.


Alternative Fixes

Ranked from safest to riskiest:

Rank Option Assessment
1 Confine alias detection to a single macro token Recommended. Small, targeted, preserves architecture.
2 Replace regex detection with syntax-aware macro parsing More precise long-term design, but larger semantic change.
3 Remove template-source suppression and rely on rendered-content checks Fixes this symptom but may reintroduce duplicates or break intentional suppression.
4 Always inject identity fields or route Conversation through the full preset assembler Broad behavioral change with unnecessary duplication, placement, and cross-mode risk.

Changing the custom prompt to avoid words such as description, personality, or persona is only a workaround and should not be treated as the fix.


Suggested Regression Tests

The existing prompt regression suite should add focused coverage for this case.

Test Required result
Exact affected custom Conversation template, no identity macros All populated identity fields appear via native fallback
Built-in template with same cards Same identity coverage
{{charName}} ... personality ... {{charName}} Personality remains injected
Same pattern with description Description remains injected
Same pattern with persona / user/persona Persona remains injected
Cross-newline occurrence No false macro detection
Explicit {{description}} Description appears once
Explicit {{personality}} Personality appears once
Explicit {{persona}} Persona fields appear once according to current semantics
Explicit individual Persona macro Only the referenced field is suppressed
Supported conditional/comment constructs Existing intentional suppression still works
Existing named Character profile Existing suppression contract remains
Existing named Persona profile Existing Persona suppression contract remains
XML output Correct coverage and placement
Markdown output Correct coverage and placement
Unwrapped output Correct coverage and placement
Targeted/group generation No unrelated Character injection
Conversation built-in/custom/chat-local override Same fallback semantics
Roleplay mode Existing gate behavior unchanged
Game mode Existing gate behavior unchanged

After the patch:

  1. Use identical Character card, Persona, chat history, and model settings.
  2. Switch only the Conversation instruction source:
    • built-in prompt
    • affected custom prompt
  3. Inspect the exact final model request.
  4. Verify each field by content and occurrence count.
  5. Do not rely only on approximate token totals.
  6. Confirm explicit identity macros still prevent duplication.
  7. Confirm ordinary prose alias words do not suppress fields.

Verification Already Performed

The following verification has already been completed:

  • TypeScript source inspection
  • Compiled JavaScript inspection
  • Conversation fallback gate inspection
  • Built-in vs custom control-flow tracing
  • Relevant repository history / regression review
  • In-memory reproduction using the existing compiled identity fallback injector
  • Comparison of injected field presence between built-in and affected custom presets

Not performed:

  • Source patch
  • Rebuild
  • Full regression suite
  • End-to-end model generation after a patch

No files were modified during the investigation.


Conclusion

The Conversation-mode identity fallback architecture is functioning as intended.

The regression is caused by the identity macro alias detector allowing its regex match to cross }} boundaries. As a result, ordinary prose following macros can be mistaken for explicit identity references, and Character/Persona fields are incorrectly suppressed.

The recommended fix is therefore narrowly scoped:

Constrain identity alias detection to a single macro token and add regression coverage for prose containing description, personality, and persona after unrelated macros.

This resolves the observed failure without changing the Conversation fallback gate or broader prompt assembly behavior.

Originally created by @Mr-Ken-1102 on GitHub (Sep 12, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6066 Originally assigned to: @SpicyMarinara on GitHub. # Bug Report: Conversation Identity Fallback Incorrectly Suppressed by Macro Alias Detection ## Summary In Marinara Engine 2.4.4, Conversation-mode identity fallback can incorrectly omit Character and Persona fields when a custom Conversation prompt contains ordinary prose words such as `personality`, `description`, or `persona`. The issue is **not** in the Conversation fallback gate. The fallback gate behaves as intended and always enables identity fallback in Conversation mode. The defect is in the macro alias detector used by the fallback suppression logic. Its current regular expression can match text **across `}}` macro boundaries**, causing normal prose following a macro such as `{{charName}}` to be misinterpreted as if it contained explicit identity macros. This causes populated Character and Persona fields to be silently suppressed from the final model request. --- ## Environment - Marinara Engine: **2.4.4** - Audited HEAD: `1a299369a` - Relevant TypeScript and compiled JavaScript contain the same logic. - Mode affected: **Conversation** - Reproduced with: - Built-in Conversation preset - Saved custom Conversation preset - Existing compiled fallback injector invoked in memory - No source files were modified during reproduction. --- ## Severity / Impact This is a prompt-construction regression that can materially alter model behavior. A custom Conversation prompt may appear valid in the UI but cause Character or Persona identity fields to disappear from the final model request simply because ordinary prose contains alias words after another macro. Affected data can include: ### Character - Description - Personality - Backstory - Appearance - Scenario - Advanced System Prompt - Example Dialogue ### Persona - Description - Personality - Backstory - Appearance - Scenario In the reproduced case, the custom prompt caused: - Character Description: **missing** - Character Personality: **missing** - Persona Description: **missing** - Persona Personality: **missing** - Persona Backstory: **missing** - Persona Appearance: **missing** - Persona Scenario: **missing** while Character Backstory, Appearance, and Scenario remained present. --- ## Minimal Reproduction A normal Conversation instruction such as: ```text {{charName}} follows their personality and description. Respond as {{charName}}. ``` contains no `{{personality}}` or `{{description}}` macro. However, the current alias detector reports references to both `personality` and `description`. A similar issue occurs when ordinary prose contains the word `persona`. For the tested saved preset, three false positives were observed: | Detected alias | Actual occurrence | Effect | |---|---|---| | `description` | Ordinary prose after `{{charName}}` | Suppresses Character Description | | `personality` | Ordinary prose after `{{charName}}` | Suppresses Character Personality | | `persona` | Ordinary prose containing `user/persona` | Suppresses all five Persona fallback fields | --- ## Root Cause The relevant detector currently constructs a pattern equivalent to: ```ts return new RegExp( `\\{\\{[\\s\\S]*?\\b${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b[\\s\\S]*?\\}\\}`, "i" ); ``` The problem is the use of: ```regex [\s\S]*? ``` before and after the alias. Although non-greedy, these expressions are **not constrained to a single macro token**. They can cross a closing `}}`, continue through ordinary prompt prose, and terminate at a later `}}`. Conceptually, the detector can therefore interpret text like: ```text {{charName}} follows their personality and description. Respond as {{charName}} ``` as one large apparent macro span. This makes `personality` and `description` look like macro aliases even though they are plain prose. --- ## Why the Conversation Fallback Gate Is Not the Problem The current implementation is: ```ts export function shouldInjectIdentityFallback({ chatMode, presetId, }: { chatMode: string; presetId: string | null | undefined; }): boolean { if (chatMode === "game") return false; if (chatMode === "conversation") return true; return !presetId; } ``` Observed behavior: | Chat mode | Preset ID | Result | |---|---|---| | `conversation` | Any ID | `true` | | `conversation` | `null` / `undefined` / empty | `true` | | `game` | Any | `false` | | `roleplay` | Non-empty | `false` | | `roleplay` | Empty / missing | `true` | | Other modes | Any | `!presetId` | There is no built-in/custom whitelist or special Conversation preset distinction here. Therefore, changing `shouldInjectIdentityFallback()` would address the wrong subsystem. --- ## Built-in vs Custom Conversation Preset Control Flow Built-in and custom Conversation prompts use the same identity fallback path. The high-level flow is: 1. Resolve Persona and its identity fields. 2. Resolve the selected preset. 3. Skip the normal preset section assembler for Conversation/Game. 4. Select Conversation instructions in this priority: 1. nonblank chat-local `customSystemPrompt` 2. nonblank preset `conversationPrompt` 3. `DEFAULT_CONVERSATION_PROMPT` 5. Save the raw selected template as an identity-fallback template source. 6. Render instructions and construct `finalMessages`. 7. Resolve Character card fields. 8. `shouldInjectIdentityFallback(...)` returns `true` in Conversation mode. 9. `injectIdentityFallbackMessages(...)` decides which fields to suppress or inject. The built-in and custom paths diverge only when the injector analyzes the selected template. The built-in prompt produces no false alias matches. The tested custom prompt does. --- ## Actual Behavior With the affected custom Conversation prompt: | Field | Built-in preset | Custom preset | |---|---|---| | Character Description | Injected | **Missing** | | Character Personality | Injected | **Missing** | | Character Backstory | Injected | Injected | | Character Appearance | Injected | Injected | | Character Scenario | Injected | Injected | | Persona Description | Injected | **Missing** | | Persona Personality | Injected | **Missing** | | Persona Backstory | Injected | **Missing** | | Persona Appearance | Injected | **Missing** | | Persona Scenario | Injected | **Missing** | The missing-field pattern was reproduced directly with the existing compiled injector. --- ## Expected Behavior Ordinary prose inside a Conversation prompt must not suppress identity fallback fields. Only actual supported identity macro references or explicitly supported suppression constructs should cause a field to be omitted from fallback injection. For example: ```text {{charName}} follows their personality and description. ``` must **not** suppress Character Personality or Character Description. By contrast: ```text {{personality}} {{description}} {{persona}} ``` should retain the intended deduplication behavior and prevent duplicate fallback insertion. --- ## Current Suppression Logic The fallback injector currently suppresses fields under several conditions: 1. A named Character/Persona profile already exists in XML/Markdown form. 2. The resolved field is empty. 3. The raw selected Conversation template is considered to reference the field macro. 4. A field-content marker is already found in existing messages. The third condition is where this regression occurs. Other relevant implementation characteristics: - Template inspection uses the **raw selected Conversation template**. - Existing-content checks scan all message roles, including history. - The content duplication marker uses only the first trimmed line, capped at 80 characters. - Template alias detection is not character-scoped. - `allContent` is captured before injection and is not refreshed after blocks are inserted. These are not necessarily defects by themselves, but they should remain unchanged unless intentionally redesigned. --- ## Regression History / Intent Repository history indicates that Conversation identity fallback is intentional. Relevant history: - Commit `c7558d96c` (June 24) changed the Conversation behavior so Character/Persona identity fallback remains enabled even when a preset is selected. - Commit `fc673c17d` (July 8) introduced template alias detection to prevent duplication and allow intentional field suppression. - The changelog documents the later deduplication work under issues `#3380 / #3377`. - The existing regression suite explicitly expects Conversation with a preset to return `true` from the fallback gate. This strongly suggests the current behavior is a **regression in deduplication detection**, not an intended limitation of custom Conversation presets. --- ## Recommended Fix ### Preferred: constrain alias detection to one macro token The safest patch is to change alias detection so that it cannot cross `{{ ... }}` boundaries. The detector should inspect only the contents of an individual macro expression. This preserves: - the Conversation fallback gate; - the existing field list; - current insertion order; - existing built-in/custom flow; - intentional suppression when a real identity macro is present; - existing Conversation architecture. This is the smallest targeted correction. ### Important compatibility requirement Before accepting the patch, verify that the revised detection still handles any supported conditional/comment macro syntax that is intentionally allowed to suppress fields. --- ## Alternative Fixes Ranked from safest to riskiest: | Rank | Option | Assessment | |---:|---|---| | 1 | Confine alias detection to a single macro token | **Recommended.** Small, targeted, preserves architecture. | | 2 | Replace regex detection with syntax-aware macro parsing | More precise long-term design, but larger semantic change. | | 3 | Remove template-source suppression and rely on rendered-content checks | Fixes this symptom but may reintroduce duplicates or break intentional suppression. | | 4 | Always inject identity fields or route Conversation through the full preset assembler | Broad behavioral change with unnecessary duplication, placement, and cross-mode risk. | Changing the custom prompt to avoid words such as `description`, `personality`, or `persona` is only a workaround and should not be treated as the fix. --- ## Suggested Regression Tests The existing prompt regression suite should add focused coverage for this case. | Test | Required result | |---|---| | Exact affected custom Conversation template, no identity macros | All populated identity fields appear via native fallback | | Built-in template with same cards | Same identity coverage | | `{{charName}} ... personality ... {{charName}}` | Personality remains injected | | Same pattern with `description` | Description remains injected | | Same pattern with `persona` / `user/persona` | Persona remains injected | | Cross-newline occurrence | No false macro detection | | Explicit `{{description}}` | Description appears once | | Explicit `{{personality}}` | Personality appears once | | Explicit `{{persona}}` | Persona fields appear once according to current semantics | | Explicit individual Persona macro | Only the referenced field is suppressed | | Supported conditional/comment constructs | Existing intentional suppression still works | | Existing named Character profile | Existing suppression contract remains | | Existing named Persona profile | Existing Persona suppression contract remains | | XML output | Correct coverage and placement | | Markdown output | Correct coverage and placement | | Unwrapped output | Correct coverage and placement | | Targeted/group generation | No unrelated Character injection | | Conversation built-in/custom/chat-local override | Same fallback semantics | | Roleplay mode | Existing gate behavior unchanged | | Game mode | Existing gate behavior unchanged | --- ## Recommended End-to-End Verification After the patch: 1. Use identical Character card, Persona, chat history, and model settings. 2. Switch only the Conversation instruction source: - built-in prompt - affected custom prompt 3. Inspect the exact final model request. 4. Verify each field by content and occurrence count. 5. Do not rely only on approximate token totals. 6. Confirm explicit identity macros still prevent duplication. 7. Confirm ordinary prose alias words do not suppress fields. --- ## Verification Already Performed The following verification has already been completed: - TypeScript source inspection - Compiled JavaScript inspection - Conversation fallback gate inspection - Built-in vs custom control-flow tracing - Relevant repository history / regression review - In-memory reproduction using the existing compiled identity fallback injector - Comparison of injected field presence between built-in and affected custom presets Not performed: - Source patch - Rebuild - Full regression suite - End-to-end model generation after a patch No files were modified during the investigation. --- ## Conclusion The Conversation-mode identity fallback architecture is functioning as intended. The regression is caused by the identity macro alias detector allowing its regex match to cross `}}` boundaries. As a result, ordinary prose following macros can be mistaken for explicit identity references, and Character/Persona fields are incorrectly suppressed. The recommended fix is therefore narrowly scoped: > **Constrain identity alias detection to a single macro token and add regression coverage for prose containing `description`, `personality`, and `persona` after unrelated macros.** This resolves the observed failure without changing the Conversation fallback gate or broader prompt assembly behavior.
bsakaguchi 2026-10-21 06:02:19 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Sep 12, 2026):

Owner: @SpicyMarinara (Codex). The maintainer has requested that this issue be completed in the assigned issue sweep, tracked in draft PR #6072. Existing contributor patches and previously completed translations will be reviewed and reused with attribution; the final PR will document the implementation and verification before this issue is closed.

<!-- gh-comment-id:5644875071 --> @SpicyMarinara commented on GitHub (Sep 12, 2026): Owner: @SpicyMarinara (Codex). The maintainer has requested that this issue be completed in the assigned issue sweep, tracked in draft PR #6072. Existing contributor patches and previously completed translations will be reviewed and reused with attribution; the final PR will document the implementation and verification before this issue is closed.
Author
Owner

@SpicyMarinara commented on GitHub (Sep 12, 2026):

Fixed in #6072, merged into staging.

Identity alias detection now stays inside one macro. Ordinary prose containing “alias” between separate macros no longer suppresses Backstory, Appearance, or Personality. The regression covers all three identity fields and deliberate aliases.

<!-- gh-comment-id:5645730910 --> @SpicyMarinara commented on GitHub (Sep 12, 2026): Fixed in #6072, merged into `staging`. Identity alias detection now stays inside one macro. Ordinary prose containing “alias” between separate macros no longer suppresses Backstory, Appearance, or Personality. The regression covers all three identity fields and deliberate aliases.
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#3361
No description provided.