[GH-ISSUE #3213] [Issue]: Editing a stopped ("unfinished") reply deletes it on save #1727

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

Originally created by @Magiwarriorx on GitHub (Jul 4, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3213

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Stopping a reply mid-generation leaves an unfinished reply that renders normally, but editing it and hitting Save makes it vanish. The stopped reply is a client-only cache row with no database record, so editing it fails silently and the message is dropped on the next cache refresh.

Expected behavior

Editing a stopped reply saves the edited text and keeps the message, the same as editing any other reply.

Actual behavior

The edited message disappears on save. The edit is silently lost.

Steps to reproduce

  1. In conversation mode, send a message so a reply begins generating.
  2. Stop the reply mid-generation (it remains on screen as a normal, unfinished reply).
  3. Edit that reply and Save.
  4. The reply disappears.

Environment

  • Marinara Engine version: 2.1.0 (Staging)
  • Install type: source (pulled from source)
  • OS + version: Termux
  • Browser or app shell: DuckDuckGo browser

Logs, screenshots, or video

None.

Additional context

Root cause (client), traced by source review:

  • When generation is stopped before the server persists anything, the client synthesizes a placeholder message with a non-database id (`__partial_${chatId}_${Date.now()}`) and inserts it into the React Query cache only — packages/client/src/hooks/use-generate.ts:2421.
  • It renders like a real reply because the post-stop refresh re-appends it as a "missing" row after the authoritative refetch — use-generate.ts:2445, via appendMissingPersistedMessages at use-generate.ts:480.
  • Editing calls useUpdateMessage, which PATCHes /chats/:chatId/messages/:messageId with the synthetic id — packages/client/src/hooks/use-chats.ts:843. No such row exists server-side, so the request fails.
  • Regardless of success, onSettled invalidates the messages query — use-chats.ts:875. The refetch reconciles the cache to the server's list (which never contained the placeholder), so the message is dropped. The onError rollback at use-chats.ts:871 does not save it, because the invalidation refetch runs afterward and wins.

Not verified: whether the server ever persists partial content on stop under some conditions (would change whether this reproduces every time), and whether delete/swipe on the same placeholder fail similarly (source suggests they would, but not confirmed).

Possible fix directions

  • Upgrade at stop time (aligned with the keep-on-stop direction of issues #2320/#2739): persist the kept partial as a real message so it has a DB id and edit/delete/swipe work like any reply.
  • Upgrade at edit time: detect the __partial_ id in the edit path and POST a new message instead of patching.
  • Downgrade / never display — NOTE: contrary to stated intent. Not rendering the partial as an editable message (or discarding it) would fix the mismatch, but this reverses the "keep visible partial" design maintainers called intentional in #426 and built in #2739. Listed for completeness; would need a maintainer's explicit reversal.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Magiwarriorx on GitHub (Jul 4, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3213 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Stopping a reply mid-generation leaves an unfinished reply that renders normally, but editing it and hitting Save makes it vanish. The stopped reply is a client-only cache row with no database record, so editing it fails silently and the message is dropped on the next cache refresh. ## Expected behavior Editing a stopped reply saves the edited text and keeps the message, the same as editing any other reply. ## Actual behavior The edited message disappears on save. The edit is silently lost. ## Steps to reproduce 1. In conversation mode, send a message so a reply begins generating. 2. Stop the reply mid-generation (it remains on screen as a normal, unfinished reply). 3. Edit that reply and Save. 4. The reply disappears. ## Environment - Marinara Engine version: 2.1.0 (Staging) - Install type: source (pulled from source) - OS + version: Termux - Browser or app shell: DuckDuckGo browser ## Logs, screenshots, or video None. ## Additional context Root cause (client), traced by source review: - When generation is stopped before the server persists anything, the client synthesizes a placeholder message with a non-database id (`` `__partial_${chatId}_${Date.now()}` ``) and inserts it into the React Query cache only — `packages/client/src/hooks/use-generate.ts:2421`. - It renders like a real reply because the post-stop refresh re-appends it as a "missing" row after the authoritative refetch — `use-generate.ts:2445`, via `appendMissingPersistedMessages` at `use-generate.ts:480`. - Editing calls `useUpdateMessage`, which `PATCH`es `/chats/:chatId/messages/:messageId` with the synthetic id — `packages/client/src/hooks/use-chats.ts:843`. No such row exists server-side, so the request fails. - Regardless of success, `onSettled` invalidates the messages query — `use-chats.ts:875`. The refetch reconciles the cache to the server's list (which never contained the placeholder), so the message is dropped. The `onError` rollback at `use-chats.ts:871` does not save it, because the invalidation refetch runs afterward and wins. Not verified: whether the server ever persists partial content on stop under some conditions (would change whether this reproduces every time), and whether delete/swipe on the same placeholder fail similarly (source suggests they would, but not confirmed). ### Possible fix directions - **Upgrade at stop time (aligned with the keep-on-stop direction of issues #2320/#2739):** persist the kept partial as a real message so it has a DB id and edit/delete/swipe work like any reply. - **Upgrade at edit time:** detect the `__partial_` id in the edit path and POST a new message instead of patching. - **Downgrade / never display — NOTE: contrary to stated intent.** Not rendering the partial as an editable message (or discarding it) would fix the mismatch, but this reverses the "keep visible partial" design maintainers called intentional in #426 and built in #2739. Listed for completeness; would need a maintainer's explicit reversal. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:42:04 +07:00
  • closed this issue
  • added the
    in-pr
    label
Author
Owner

@SpicyMarinara commented on GitHub (Jul 4, 2026):

Addressed in ready PR #3218 targeting staging.

<!-- gh-comment-id:4884071064 --> @SpicyMarinara commented on GitHub (Jul 4, 2026): Addressed in ready PR #3218 targeting staging.
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#1727
No description provided.