[GH-ISSUE #4196] [Issue]: First sent-message edit appears to revert after stopping generation #2272

Closed
opened 2026-10-21 05:46:52 +07:00 by bsakaguchi · 3 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

After sending a message and stopping generation before the response finishes, editing that sent user message appears to revert on the first save attempt. Editing the same message a second time succeeds.

Static investigation strongly indicates this is the same client-side cache race reported in #4115, rather than a failure in the server-side message update.

Expected behavior

The edited text should be shown and remain saved on the first attempt, including immediately after a generation is stopped or fails.

Actual behavior

The first edit appears not to persist. Repeating the edit after generation cleanup has settled saves and displays the new text correctly. Clearing leftover text from the chat composer beforehand does not change the behavior.

Steps to reproduce

  1. Open a Roleplay chat.
  2. Send a message.
  3. Click Stop Generation before the response finishes.
  4. Edit the sent user message and save the change.
  5. Observe that the new text appears to revert.
  6. Edit the same message again and save it.
  7. Observe that the second edit succeeds.

Environment

  • Marinara Engine version: 2.3.4
  • Install type: installer (.exe)
  • OS + version: Windows 10
  • Browser or app shell: Windows installer app shell (exact shell not provided)
  • Mode: Roleplay

Logs, screenshots, or video

The reporter supplied a screenshot of the original report. No logs or browser network trace were provided.

Root cause investigation

Static comparison of v2.3.4 with current staging strongly indicates a race between message-edit cache handling and generation cleanup:

  1. Saving exits the message editor immediately and starts useUpdateMessage().
  2. In v2.3.4, useUpdateMessage().onMutate first awaits cancellation of the in-flight messages query.
  3. Stopping or failing generation concurrently completes its cleanup and refreshes the same messages query.
  4. Query cancellation can restore the older cached snapshot before the optimistic edit is painted, so the UI renders the original text and the first save appears to have been lost.
  5. A second edit occurs after generation cleanup has settled, so there is no competing refresh/cancellation window.

The server path does not have the same ordering problem: PATCH /api/chats/:chatId/messages/:messageId directly updates the message content and synchronizes the active swipe. This makes a client-side stale-cache overwrite the more likely explanation.

Likely fix and current status

Current staging already changes the mutation ordering in packages/client/src/hooks/use-chats.ts:

  • Start message-query cancellation with { revert: false }.
  • Paint the optimistic message content into the cache immediately.
  • Await cancellation only after the edit is visible.
  • Continue preserving recent message edits when authoritative generation snapshots are merged.

The ordering fix landed in commit 5d849e4fc and is present in current origin/staging. Merged PR #4122 added regression guards for this behavior while resolving the closely matching #4115.

This report is therefore likely already fixed on staging but remains reproducible in the 2.3.4 release. Before closing it as a duplicate/resolved issue, manually verify the exact stop-generation sequence on a current staging build:

  1. Test the first edit after Stop Generation with composer text left in place.
  2. Repeat with the composer cleared.
  3. Reload the chat after the first save to confirm the server-persisted value.
  4. If it still fails, capture the message PATCH response and the following messages GET response to distinguish a persistence failure from a display-cache rollback.

Additional context

Related issue: #4115 — user reply edits in Roleplay mode fail while an assistant response is generating.

The original report described the title as occurring after a generation failure, while its reproduction specifically uses Stop Generation. Both paths converge on the same generation cleanup and message-refresh lifecycle.

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 @Xelvanis on GitHub (Jul 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4196 Originally assigned to: @SpicyMarinara on GitHub. ## Summary After sending a message and stopping generation before the response finishes, editing that sent user message appears to revert on the first save attempt. Editing the same message a second time succeeds. Static investigation strongly indicates this is the same client-side cache race reported in #4115, rather than a failure in the server-side message update. ## Expected behavior The edited text should be shown and remain saved on the first attempt, including immediately after a generation is stopped or fails. ## Actual behavior The first edit appears not to persist. Repeating the edit after generation cleanup has settled saves and displays the new text correctly. Clearing leftover text from the chat composer beforehand does not change the behavior. ## Steps to reproduce 1. Open a Roleplay chat. 2. Send a message. 3. Click **Stop Generation** before the response finishes. 4. Edit the sent user message and save the change. 5. Observe that the new text appears to revert. 6. Edit the same message again and save it. 7. Observe that the second edit succeeds. ## Environment - Marinara Engine version: 2.3.4 - Install type: installer (`.exe`) - OS + version: Windows 10 - Browser or app shell: Windows installer app shell (exact shell not provided) - Mode: Roleplay ## Logs, screenshots, or video The reporter supplied a screenshot of the original report. No logs or browser network trace were provided. ## Root cause investigation Static comparison of v2.3.4 with current `staging` strongly indicates a race between message-edit cache handling and generation cleanup: 1. Saving exits the message editor immediately and starts `useUpdateMessage()`. 2. In v2.3.4, `useUpdateMessage().onMutate` first awaits cancellation of the in-flight messages query. 3. Stopping or failing generation concurrently completes its cleanup and refreshes the same messages query. 4. Query cancellation can restore the older cached snapshot before the optimistic edit is painted, so the UI renders the original text and the first save appears to have been lost. 5. A second edit occurs after generation cleanup has settled, so there is no competing refresh/cancellation window. The server path does not have the same ordering problem: `PATCH /api/chats/:chatId/messages/:messageId` directly updates the message content and synchronizes the active swipe. This makes a client-side stale-cache overwrite the more likely explanation. ## Likely fix and current status Current `staging` already changes the mutation ordering in `packages/client/src/hooks/use-chats.ts`: - Start message-query cancellation with `{ revert: false }`. - Paint the optimistic message content into the cache immediately. - Await cancellation only after the edit is visible. - Continue preserving recent message edits when authoritative generation snapshots are merged. The ordering fix landed in commit `5d849e4fc` and is present in current `origin/staging`. Merged PR #4122 added regression guards for this behavior while resolving the closely matching #4115. This report is therefore likely already fixed on `staging` but remains reproducible in the 2.3.4 release. Before closing it as a duplicate/resolved issue, manually verify the exact stop-generation sequence on a current staging build: 1. Test the first edit after **Stop Generation** with composer text left in place. 2. Repeat with the composer cleared. 3. Reload the chat after the first save to confirm the server-persisted value. 4. If it still fails, capture the message `PATCH` response and the following messages `GET` response to distinguish a persistence failure from a display-cache rollback. ## Additional context Related issue: #4115 — user reply edits in Roleplay mode fail while an assistant response is generating. The original report described the title as occurring after a generation failure, while its reproduction specifically uses **Stop Generation**. Both paths converge on the same generation cleanup and message-refresh lifecycle. <!-- task-id: first-message-edit-after-stopped-generation --> ## 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:46:52 +07:00
Author
Owner

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

Regression verification is claimed by @SpicyMarinara on agent/assigned-issues-4195-4198. I’m verifying the exact stop-generation/first-edit sequence against the current staging cache fix and will attach the shared draft PR here once the proof guard is pushed.

<!-- gh-comment-id:5100727315 --> @SpicyMarinara commented on GitHub (Jul 28, 2026): Regression verification is claimed by @SpicyMarinara on `agent/assigned-issues-4195-4198`. I’m verifying the exact stop-generation/first-edit sequence against the current staging cache fix and will attach the shared draft PR here once the proof guard is pushed.
Author
Owner

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

Draft regression-verification PR: #4199

<!-- gh-comment-id:5100766317 --> @SpicyMarinara commented on GitHub (Jul 28, 2026): Draft regression-verification PR: #4199
Author
Owner

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

Verified and guarded on staging via #4199 (a97cc55d6). The stop-generation path now has exact browser coverage for the first saved edit with retained and cleared composer drafts, followed by reload persistence. The existing staging cache behavior remains intact.

<!-- gh-comment-id:5101518962 --> @SpicyMarinara commented on GitHub (Jul 28, 2026): Verified and guarded on `staging` via #4199 (`a97cc55d6`). The stop-generation path now has exact browser coverage for the first saved edit with retained and cleared composer drafts, followed by reload persistence. The existing staging cache behavior remains intact.
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#2272
No description provided.