[GH-ISSUE #526] [Issue]: Narrative Director leakage causes main AI double-responses #243

Closed
opened 2026-10-20 17:26:42 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @cha1latte on GitHub (May 7, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/526

Summary

Narrative Director, and potentially other text-based pre_generation agents, can leak in-character roleplay text and <committed_tracker_state> JSON into their output. That leaked text can then be converted into a user message before the main generation request, causing the main AI to respond to the leaked content instead of the actual story.

Expected behavior

Only the intended Narrative Director payload, such as the director note or structured agent output, should reach the prompt assembler. Hallucinated roleplay text, tracker JSON, or conversational filler from an agent response should not be injected into the main model prompt as user content.

Actual behavior

The Narrative Director sometimes outputs roleplay and <committed_tracker_state> JSON before or alongside its intended note. Because trailing system messages are converted to user messages for provider API safety, the leaked agent output can be read by the main AI as if the user typed it. This can produce a jarring double-response or hallucinated continuation.

Steps to reproduce

  1. Use Narrative Director or a similar text-based pre_generation agent.
  2. Run it in a chat where recent messages include a repeated pattern like User -> Assistant roleplay -> <committed_tracker_state>.
  3. Observe that the agent may mimic the recent message pattern and include roleplay or tracker JSON in its response before its intended director note.
  4. Continue to main generation.
  5. Observe the main AI responding to the leaked roleplay/tracker content rather than only the current story context.

Environment

  • Marinara Engine version: Release v1.5.8, build 7e37df8
  • Install type: Not specified.
  • OS + version: Windows 11
  • Browser or app shell: Not specified.

Logs, screenshots, or video

Discord source:

https://discord.com/channels/1417099416812392641/1501980110390169630

Reporter's root-cause summary:

  1. Pattern mimicry: the Director receives recentMessages, which are heavily patterned with User -> Assistant roleplay -> <committed_tracker_state>. The LLM may continue that pattern despite the agent prompt.
  2. System-to-user role conversion: in generate.routes.ts, trailing system messages are converted into user messages for API safety. If the Director's leaked text is returned as part of the agent output, the main AI receives that leak as user content.

Relevant area mentioned by the reporter:

  • agent-executor.ts, especially parseAgentResponse
  • generate.routes.ts, especially prepareProviderMessages

Additional context

The reporter proposed two possible fixes:

  1. Add stricter extraction in parseAgentResponse so only the intended XML/bracketed agent payload is returned and conversational filler/pattern hallucinations are discarded.
  2. Harden the Narrative Director prompt/API mode so the response is forced into a JSON-only shape, ideally starting with {, to reduce the chance of prose or roleplay leakage.

The reporter also noted that the deeper fix may be to filter <committed_tracker_state> out of recentMessages before feeding pacing/director agents, since those agents likely do not need raw tracker JSON to evaluate narrative flow.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @cha1latte on GitHub (May 7, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/526 ## Summary Narrative Director, and potentially other text-based `pre_generation` agents, can leak in-character roleplay text and `<committed_tracker_state>` JSON into their output. That leaked text can then be converted into a `user` message before the main generation request, causing the main AI to respond to the leaked content instead of the actual story. ## Expected behavior Only the intended Narrative Director payload, such as the director note or structured agent output, should reach the prompt assembler. Hallucinated roleplay text, tracker JSON, or conversational filler from an agent response should not be injected into the main model prompt as user content. ## Actual behavior The Narrative Director sometimes outputs roleplay and `<committed_tracker_state>` JSON before or alongside its intended note. Because trailing system messages are converted to user messages for provider API safety, the leaked agent output can be read by the main AI as if the user typed it. This can produce a jarring double-response or hallucinated continuation. ## Steps to reproduce 1. Use Narrative Director or a similar text-based `pre_generation` agent. 2. Run it in a chat where recent messages include a repeated pattern like `User -> Assistant roleplay -> <committed_tracker_state>`. 3. Observe that the agent may mimic the recent message pattern and include roleplay or tracker JSON in its response before its intended director note. 4. Continue to main generation. 5. Observe the main AI responding to the leaked roleplay/tracker content rather than only the current story context. ## Environment - Marinara Engine version: Release v1.5.8, build 7e37df8 - Install type: Not specified. - OS + version: Windows 11 - Browser or app shell: Not specified. ## Logs, screenshots, or video Discord source: https://discord.com/channels/1417099416812392641/1501980110390169630 Reporter's root-cause summary: 1. Pattern mimicry: the Director receives `recentMessages`, which are heavily patterned with `User -> Assistant roleplay -> <committed_tracker_state>`. The LLM may continue that pattern despite the agent prompt. 2. System-to-user role conversion: in `generate.routes.ts`, trailing system messages are converted into user messages for API safety. If the Director's leaked text is returned as part of the agent output, the main AI receives that leak as user content. Relevant area mentioned by the reporter: - `agent-executor.ts`, especially `parseAgentResponse` - `generate.routes.ts`, especially `prepareProviderMessages` ## Additional context The reporter proposed two possible fixes: 1. Add stricter extraction in `parseAgentResponse` so only the intended XML/bracketed agent payload is returned and conversational filler/pattern hallucinations are discarded. 2. Harden the Narrative Director prompt/API mode so the response is forced into a JSON-only shape, ideally starting with `{`, to reduce the chance of prose or roleplay leakage. The reporter also noted that the deeper fix may be to filter `<committed_tracker_state>` out of `recentMessages` before feeding pacing/director agents, since those agents likely do not need raw tracker JSON to evaluate narrative flow. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:26:42 +07:00
  • closed this issue
  • added the
    bug
    label
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#243
No description provided.