[GH-ISSUE #3105] [Issue]: /continue with rewrite agents can overwrite instead of appending to last message #1665

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

When using /continue (or sending a blank message) in a chat with text rewrite agents enabled (prose guardian, continuity, editor), the continuation can fully replace the previous assistant message instead of appending to it. The original message content is silently destroyed.

This is a data loss bug. The merge step briefly writes the correct combined content to the database, but a later text-rewrite phase overwrites that message with rewritten continuation text only.

The bug is probabilistic: it fires only when a text rewrite agent decides the continuation needs editing (editNeeded: true for prose-guardian/continuity, or a changed result for editor). If agents judge the text acceptable, the merged content survives.

[NOTE: The initial investigation & recommendations were made by Prof. Mari, then reviewed & refined by Cursor (Composer 2.5) and me.]

Expected behavior

The continuation should append to the existing assistant message, producing: [original content][continuation content]. Text rewrite agents, if they run, should operate on and persist the full merged message.

Actual behavior

When a text rewrite agent applies an edit during a continue flow, message content is replaced entirely with [rewritten continuation text only]. The original content is lost. No error or warning is shown.

Steps to reproduce

  1. In an RP chat, enable text rewrite agents (e.g., prose-guardian, continuity, editor).
  2. Generate an assistant message (message A).
  3. Use /continue or send a blank message to trigger continuation.
  4. Repeat if needed — overwrite occurs only when a rewrite agent returns editNeeded: true (strict agents) or produces changed text (editor).

Environment

  • Marinara Engine version: 2.0.8 (also present in 2.0.6–2.0.7; not fixed in CHANGELOG or generate.routes.ts between those releases)
  • Install type: (source / installer / docker / termux / other)
  • OS + version:
  • Browser or app shell:

Additional context

Root cause trace (packages/server/src/routes/generate.routes.ts, v2.0.8)

Phase 1 — merge & save (correct): Lines 7027–7031 call appendContinuationMessageContent (defined at line 741) and persist old + new content to input.continueMessageId.

Phase 2 — combinedResponse (new text only): Line 7476 sets combinedResponse = allResponses.join("\n\n"), which contains only newly generated text, not pre-existing message content.

Phase 3 — messageId targets the continued message: Line 7895 sets messageId = lastSavedMsg.id, which resolves to input.continueMessageId.

Phase 4 — text rewrite overwrites merge (the bug): Lines 9207–9208 gate rewrite with no continueMessageId guard and seed rewrite input from combinedResponse only:

if (textRewriteRunAgents.length > 0 && messageId && !abortController.signal.aborted) {
  let currentResponseForRewrite = combinedResponse;

Line 9285 then writes rewritten new-text-only back to the same message:

await chats.updateMessageContent(messageId, editedText);

continueMessageId does not appear anywhere in the rewrite block (grep finds only 9 occurrences in the file, all outside this section).

Probabilistic firing

Lines 9263–9281 gate whether a rewrite is applied:

  • prose-guardian / continuity: rewrite runs only when editNeeded === true.
  • editor: rewrite runs when changed text is returned (less strict).
  • Additional skips: protected-markup loss (textRewriteDropsProtectedMarkup), unchanged text, empty result.

Version check (2.0.6 → 2.0.8)

CHANGELOG.md has no entry for this continue + text-rewrite overwrite path. Related fixes in 2.0.7 (#2920 empty-submit vs /continue separation, #2983+ text-rewrite markup preservation) do not address merged-content overwrite. Git history on generate.routes.ts between v2.0.6 and v2.0.8 shows no targeted fix.

Suggested fixes

Option A (quick, safest): Skip text rewrite when continueMessageId is set:

if (textRewriteRunAgents.length > 0 && messageId && !input.continueMessageId && !abortController.signal.aborted) {

Option B (proper): Feed merged content to rewrite agents:

let currentResponseForRewrite = input.continueMessageId
  ? appendContinuationMessageContent(originalExistingContent, combinedResponse)
  : combinedResponse;

Requires capturing pre-merge content before the rewrite phase overwrites it.

Client-side note (minor, separate)

use-generate.ts message_saved handler for continueMessageId may leave a __streaming__ bubble briefly; display glitch only, not data loss.

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 @spacyH on GitHub (Jun 30, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3105 Originally assigned to: @SpicyMarinara on GitHub. ## Summary When using `/continue` (or sending a blank message) in a chat with text rewrite agents enabled (prose guardian, continuity, editor), the continuation can **fully replace** the previous assistant message instead of appending to it. The original message content is silently destroyed. This is a **data loss bug**. The merge step briefly writes the correct combined content to the database, but a later text-rewrite phase overwrites that message with rewritten continuation text only. The bug is **probabilistic**: it fires only when a text rewrite agent decides the continuation needs editing (`editNeeded: true` for prose-guardian/continuity, or a changed result for editor). If agents judge the text acceptable, the merged content survives. _[NOTE: The initial investigation & recommendations were made by Prof. Mari, then reviewed & refined by Cursor (Composer 2.5) and me.]_ ## Expected behavior The continuation should append to the existing assistant message, producing: `[original content][continuation content]`. Text rewrite agents, if they run, should operate on and persist the **full merged** message. ## Actual behavior When a text rewrite agent applies an edit during a continue flow, message content is replaced entirely with `[rewritten continuation text only]`. The original content is lost. No error or warning is shown. ## Steps to reproduce 1. In an RP chat, enable text rewrite agents (e.g., prose-guardian, continuity, editor). 2. Generate an assistant message (message A). 3. Use `/continue` or send a blank message to trigger continuation. 4. Repeat if needed — overwrite occurs only when a rewrite agent returns `editNeeded: true` (strict agents) or produces changed text (editor). ## Environment - Marinara Engine version: 2.0.8 (also present in 2.0.6–2.0.7; not fixed in CHANGELOG or `generate.routes.ts` between those releases) - Install type: (source / installer / docker / termux / other) - OS + version: - Browser or app shell: ## Additional context ### Root cause trace (`packages/server/src/routes/generate.routes.ts`, v2.0.8) **Phase 1 — merge & save (correct):** Lines 7027–7031 call `appendContinuationMessageContent` (defined at line 741) and persist old + new content to `input.continueMessageId`. **Phase 2 — `combinedResponse` (new text only):** Line 7476 sets `combinedResponse = allResponses.join("\n\n")`, which contains only newly generated text, not pre-existing message content. **Phase 3 — `messageId` targets the continued message:** Line 7895 sets `messageId = lastSavedMsg.id`, which resolves to `input.continueMessageId`. **Phase 4 — text rewrite overwrites merge (the bug):** Lines 9207–9208 gate rewrite with no `continueMessageId` guard and seed rewrite input from `combinedResponse` only: ```ts if (textRewriteRunAgents.length > 0 && messageId && !abortController.signal.aborted) { let currentResponseForRewrite = combinedResponse; ``` Line 9285 then writes rewritten new-text-only back to the same message: ```ts await chats.updateMessageContent(messageId, editedText); ``` `continueMessageId` does not appear anywhere in the rewrite block (grep finds only 9 occurrences in the file, all outside this section). ### Probabilistic firing Lines 9263–9281 gate whether a rewrite is applied: - **prose-guardian / continuity:** rewrite runs only when `editNeeded === true`. - **editor:** rewrite runs when changed text is returned (less strict). - Additional skips: protected-markup loss (`textRewriteDropsProtectedMarkup`), unchanged text, empty result. ### Version check (2.0.6 → 2.0.8) `CHANGELOG.md` has no entry for this continue + text-rewrite overwrite path. Related fixes in 2.0.7 (#2920 empty-submit vs `/continue` separation, #2983+ text-rewrite markup preservation) do not address merged-content overwrite. Git history on `generate.routes.ts` between `v2.0.6` and `v2.0.8` shows no targeted fix. ### Suggested fixes **Option A (quick, safest):** Skip text rewrite when `continueMessageId` is set: ```ts if (textRewriteRunAgents.length > 0 && messageId && !input.continueMessageId && !abortController.signal.aborted) { ``` **Option B (proper):** Feed merged content to rewrite agents: ```ts let currentResponseForRewrite = input.continueMessageId ? appendContinuationMessageContent(originalExistingContent, combinedResponse) : combinedResponse; ``` Requires capturing pre-merge content before the rewrite phase overwrites it. ### Client-side note (minor, separate) `use-generate.ts` `message_saved` handler for `continueMessageId` may leave a `__streaming__` bubble briefly; display glitch only, not data loss. ## 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-21 05:41:31 +07:00
  • closed this issue
  • added the
    in-pr
    bug
    labels
Author
Owner

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

Taking this in branch codex/issue-sweep-3098-3105; I’ll patch the continue + rewrite overwrite path and close this once the fix is merged.

<!-- gh-comment-id:4845296854 --> @SpicyMarinara commented on GitHub (Jun 30, 2026): Taking this in branch `codex/issue-sweep-3098-3105`; I’ll patch the continue + rewrite overwrite path and close this once the fix is merged.
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#1665
No description provided.