[GH-ISSUE #2737] [Issue]: Continuity / Prose Guardian rewrite destroys embedded HTML/CSS formatting (gfx) — rewrite agent fed HTML-stripped input, then overwrites the message wholesale #1377

Closed
opened 2026-10-21 05:32:39 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The Continuity agent (and Prose Guardian, which shares the same rewrite path) deterministically destroys embedded HTML/CSS formatting ("gfx" — custom styled boxes, status bars, <style>/<div>/<img> blocks) in the assistant message every time it decides a rewrite is needed. This is a code bug, not a prompt/model issue — which is why users report that switching models and "rewriting the prompt" does nothing.

Two interacting defects on the post-processing rewrite path:

1. The rewrite agent is fed an HTML-stripped copy of the message

buildAgentMessages builds the <assistant_response> block the rewrite model is asked to reproduce by running the message through stripHtmlTags:

  • packages/server/src/services/agents/agent-executor.ts:1589 — finalParts.push(stripHtmlTags(context.mainResponse));
  • stripHtmlTags (agent-executor.ts:28-33) does text.replace(/<\/?[a-zA-Z][^>]*>/g, ""), deleting every HTML/XML tag.

So by the time the continuity model reads the message, all <div>/<span>/<style>/<img> markup is already gone, and a <style> open tag is removed while its raw CSS body leaks through as plain text. The model cannot reproduce gfx it was never shown.

2. The stripped rewrite overwrites the stored message wholesale

  • packages/server/src/routes/generate.routes.ts:8817 — editedText is taken raw.
  • :8823 — strictEditNeeded is true for prose-guardian and continuity.
  • :8826-8831 — when changedMessage, await chats.updateMessageContent(messageId, editedText) replaces the message with the stripped rewrite, with no diff/merge and no HTML restoration. The original is preserved only as a hidden revert snapshot (proseGuardianOriginalText, :8833-8836).
  • The retry path is identical: packages/server/src/routes/generate/retry-agents-route.ts:2204-2207.

The continuity prompt even instructs the model to "Preserve ... tags, and formatting" (packages/shared/src/constants/agent-prompts.ts:67) — but that is futile because the tags were physically removed from its input at step 1. No code anywhere re-inserts HTML after the rewrite.

How it degrades the UX

Users who use HTML/CSS "gfx" in roleplay (styled message frames, HUD/status blocks, images) and run Continuity or Prose Guardian see their formatting wiped on every turn the agent edits — the agent's "greatest joy," as one user put it. The only workaround today is turning the agent off, which users don't want to do. Prompt edits and model swaps can't help because the corruption happens in code before and after the model runs.

Steps to replicate

  1. Enable the Continuity agent (or Prose Guardian).
  2. Produce an assistant message containing an HTML/CSS block (e.g. a <div style="...">…</div> status box or a <style>…</style> block).
  3. Take a turn / trigger the agent so it returns editNeeded: true.
  4. The stored message is replaced with a version that has all HTML stripped — the styled gfx is gone.

Suggested fix

Primary (removes the deterministic corruption): do not stripHtmlTags the rewrite target for text_rewrite-type agents. In buildAgentMessages, pass the raw context.mainResponse into the <assistant_response> block when the agent's resolved result type is text_rewrite (continuity + prose-guardian), keeping the strip only for context-only agents (agent-executor.ts:1589, gate on resolveAgentResultType === "text_rewrite" or a preserveAssistantHtml flag).

Defense-in-depth:

  • Before overwriting (generate.routes.ts:8826-8831, retry-agents-route.ts:2204-2207), extract fenced ``` blocks and HTML/<style>/<div> regions from the original, replace them with placeholders before sending, and re-substitute into editedText afterward; or
  • If the original contained HTML/CSS/fences and editedText dropped all of them, reject the rewrite (treat as editNeeded:false) and log a warning, so gfx is never silently destroyed.
  • Harden the continuity/prose-guardian prompts (agent-prompts.ts:64-73) to copy HTML/CSS/<style>/<img>/code-fence markup byte-for-byte (necessary but not sufficient without the primary fix).

Note: ordinary markdown loss is normal LLM rewrite behavior and out of scope; the deterministic, code-caused damage is specifically tag-based HTML/CSS gfx.

Template checklist

  • pnpm check passes (TypeScript + ESLint)
  • Manually verify a message with a <div style>/<style> block survives a Continuity rewrite intact
  • Manually verify the same for Prose Guardian
  • Manually verify a fenced code block survives a rewrite
  • Manually verify context-only agents still receive HTML-stripped input (token savings preserved)

Reported by users in Discord ("consistency editor messing up gfx"); root-caused and verified by direct read of the staging tree at the cited file:line. Boxes left unchecked for human verification.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2737 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The **Continuity** agent (and **Prose Guardian**, which shares the same rewrite path) **deterministically destroys embedded HTML/CSS formatting** ("gfx" — custom styled boxes, status bars, `<style>`/`<div>`/`<img>` blocks) in the assistant message every time it decides a rewrite is needed. This is a **code** bug, not a prompt/model issue — which is why users report that switching models and "rewriting the prompt" does nothing. Two interacting defects on the post-processing rewrite path: ### 1. The rewrite agent is fed an HTML-stripped copy of the message `buildAgentMessages` builds the `<assistant_response>` block the rewrite model is asked to reproduce by running the message through `stripHtmlTags`: - `packages/server/src/services/agents/agent-executor.ts:1589` — `finalParts.push(stripHtmlTags(context.mainResponse));` - `stripHtmlTags` (`agent-executor.ts:28-33`) does `text.replace(/<\/?[a-zA-Z][^>]*>/g, "")`, deleting **every** HTML/XML tag. So by the time the continuity model reads the message, all `<div>/<span>/<style>/<img>` markup is already gone, and a `<style>` open tag is removed while its raw CSS body leaks through as plain text. The model cannot reproduce gfx it was never shown. ### 2. The stripped rewrite overwrites the stored message wholesale - `packages/server/src/routes/generate.routes.ts:8817` — `editedText` is taken raw. - `:8823` — `strictEditNeeded` is true for `prose-guardian` **and** `continuity`. - `:8826-8831` — when `changedMessage`, `await chats.updateMessageContent(messageId, editedText)` replaces the message with the stripped rewrite, with **no diff/merge and no HTML restoration**. The original is preserved only as a hidden revert snapshot (`proseGuardianOriginalText`, `:8833-8836`). - The retry path is identical: `packages/server/src/routes/generate/retry-agents-route.ts:2204-2207`. The continuity prompt even instructs the model to "Preserve ... tags, and formatting" (`packages/shared/src/constants/agent-prompts.ts:67`) — but that is futile because the tags were physically removed from its input at step 1. No code anywhere re-inserts HTML after the rewrite. ## How it degrades the UX Users who use HTML/CSS "gfx" in roleplay (styled message frames, HUD/status blocks, images) and run Continuity or Prose Guardian see their formatting **wiped on every turn the agent edits** — the agent's "greatest joy," as one user put it. The only workaround today is turning the agent off, which users don't want to do. Prompt edits and model swaps can't help because the corruption happens in code before and after the model runs. ## Steps to replicate 1. Enable the **Continuity** agent (or **Prose Guardian**). 2. Produce an assistant message containing an HTML/CSS block (e.g. a `<div style="...">…</div>` status box or a `<style>…</style>` block). 3. Take a turn / trigger the agent so it returns `editNeeded: true`. 4. The stored message is replaced with a version that has all HTML stripped — the styled gfx is gone. ## Suggested fix **Primary (removes the deterministic corruption):** do **not** `stripHtmlTags` the rewrite target for `text_rewrite`-type agents. In `buildAgentMessages`, pass the raw `context.mainResponse` into the `<assistant_response>` block when the agent's resolved result type is `text_rewrite` (continuity + prose-guardian), keeping the strip only for context-only agents (`agent-executor.ts:1589`, gate on `resolveAgentResultType === "text_rewrite"` or a `preserveAssistantHtml` flag). **Defense-in-depth:** - Before overwriting (`generate.routes.ts:8826-8831`, `retry-agents-route.ts:2204-2207`), extract fenced ```` ``` ```` blocks and HTML/`<style>`/`<div>` regions from the original, replace them with placeholders before sending, and re-substitute into `editedText` afterward; **or** - If the original contained HTML/CSS/fences and `editedText` dropped all of them, reject the rewrite (treat as `editNeeded:false`) and log a warning, so gfx is never silently destroyed. - Harden the continuity/prose-guardian prompts (`agent-prompts.ts:64-73`) to copy HTML/CSS/`<style>`/`<img>`/code-fence markup byte-for-byte (necessary but **not** sufficient without the primary fix). > Note: ordinary markdown loss is normal LLM rewrite behavior and out of scope; the deterministic, code-caused damage is specifically tag-based HTML/CSS gfx. ## Template checklist - [ ] `pnpm check` passes (TypeScript + ESLint) - [ ] Manually verify a message with a `<div style>`/`<style>` block survives a Continuity rewrite intact - [ ] Manually verify the same for Prose Guardian - [ ] Manually verify a fenced code block survives a rewrite - [ ] Manually verify context-only agents still receive HTML-stripped input (token savings preserved) --- _Reported by users in Discord ("consistency editor messing up gfx"); root-caused and verified by direct read of the `staging` tree at the cited file:line. Boxes left unchecked for human verification._
bsakaguchi 2026-10-21 05:32:39 +07:00
  • closed this issue
  • added the
    in-pr
    label
Author
Owner

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

Addressed in PR #2747.

<!-- gh-comment-id:4763115659 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed in PR #2747.
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#1377
No description provided.