[PR #6618] [MERGED] fix(narration): fix translation caching and segment sync for edited messages #7256

Closed
opened 2026-10-23 04:18:00 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6618
Author: @menemorofaan
Created: 9/24/2026
Status: ✅ Merged
Merged: 9/24/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/translation-edit-cache


📝 Commits (10+)

  • 1ab31b2 fix(narration): fix translation caching and segment sync for edited messages
  • 87bb871 style: format GameNarration with prettier
  • 167694d Merge branch 'staging' into fix/translation-edit-cache
  • 00b2030 Merge branch 'staging' into fix/translation-edit-cache
  • c4689fa fix(narration): restrict raw content translation match to unedited messages
  • 541dbea Merge branch 'staging' into fix/translation-edit-cache
  • 18860b3 Merge branch 'staging' into fix/translation-edit-cache
  • 3e37ae7 Merge remote-tracking branch 'origin/staging' into codex/6618-translation-review
  • 3151034 fix(game): finish translation invalidation and segment alignment
  • b32f824 Merge remote-tracking branch 'origin/staging' into codex/6618-translation-review

📊 Changes

7 files changed (+404 additions, -36 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
➕ e2e/game-translation-edits.e2e.ts (+180 -0)
📝 e2e/roleplay-commands.e2e.ts (+25 -3)
📝 packages/client/src/components/game/GameNarration.tsx (+148 -20)
📝 packages/client/src/components/game/GameSurface.tsx (+4 -0)
📝 packages/client/src/hooks/use-translate.ts (+37 -13)
📝 packages/client/src/stores/translation.store.ts (+8 -0)

📄 Description

Linked issue #6615

Closes #6615

Why this change

In Game (GM) mode, editing a narration segment does not update its translation. The translator continues to receive the pre-edit draft, so the translation still reflects the original text. Furthermore, because the stored translation source still matches that stale draft, the outdated translation is considered fresh and remains on screen, while auto-translate is prevented from re-running.

What changed

  • Rebuild Game translation input from the existing segment edit/delete overlays, including dialogue and readables. Keep raw-message translation aliases only for untouched messages.
  • Invalidate cached and pending translations in the shared edit/delete handlers, so a request invalidated before its result arrives cannot save or display the old text.
  • Preserve the existing segment boundaries when an edit adds quoted speech, and retain deleted-segment positions for later translations.
  • Memoize the source for each message, reusing it across translation actions and display checks instead of rebuilding whole messages inside segment render loops.
  • Resolve the existing WebKit CI failure by handling the already-mocked UI settings endpoint in-page during whisper-test reloads and waiting for startup requests to settle before each reload; retain all page-error and recipient-privacy assertions.
  • Add an Unreleased changelog entry and browser regressions for manual/automatic translation, reload, deletion, saved raw-source translations, and a delayed translation completing after an edit.

Validation

Completed on the updated staging base: pnpm check. The targeted translation browser suite passed 19 cases across desktop Chromium, mobile Chromium and mobile WebKit; 2 mobile cases are deliberately skipped because the active-segment editor is a desktop control. Existing Conversation/Roleplay/Game navigation and persistence cases pass. Both whisper presentations also pass all 6 browser cases after the fixture fix, and pnpm check:e2e-types passes for that final test-only change. Before the fixes, the browser proofs reproduced raw-source alias reuse, quoted-narration misalignment, and stale-result persistence.

Local CodeRabbit completed the combined review, including all files in this PR. Its queued-request and whitespace-only-blank-line findings were reproduced with failing browser regressions and fixed. An additional suggestion to index override keys with another derived Set was not adopted: full translation sources are already memoized per message, while the remaining direct scans only inspect edit/delete keys. The follow-up local review completed across all 9 files in the combined review. It repeated optional source/override-index optimizations and suggested deleting saved translations on invalidation. The latter is not needed for correctness: every Game translation display uses current-source matching, manual translation accepts the raw-content alias only without overrides, and automatic translation compares the rebuilt source. The manual/automatic browser cases explicitly seed an obsolete saved translation, verify the edited text/retranslation, and repeat after reload and deletion. Saved values may remain cached with their old source, but cannot display as current or suppress the new request. No additional persistence writes are added. Hosted CodeRabbit completed on this head; its optional override-index suggestion has the same documented disposition.

The required hosted container build is the container validation; no local container run or live translation-provider verification is claimed.

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Manually verify narration, dialogue and readable edits with the preferred translation provider, including auto-translate, reload, deletion and switching chats during translation.

Original contributor's manual verification notes are retained below:

  1. Full client production build (npm run build) completed successfully with 0 TypeScript/build errors.
  2. Verified in real browser (Game mode):
    • Created/received a multi-paragraph assistant narration with spoken dialogue and descriptive prose.
    • Edited multiple segments in the message log/editor.
    • Verified that clicking translate (and auto-translate) sends the updated edited text to the translator.
    • Confirmed that all paragraphs/segments translate and map back 1:1 to their respective rendered segments without index drift.
  3. Verified that unedited messages and non-game modes (Conversation/Roleplay) continue to behave normally with no regressions.

Docs and release impact

Includes an Unreleased changelog entry for #6615. No settings, provider API, localization copy, storage format, or version change.

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

No UI layout changes — purely state management, translation cache invalidation, and narration segment reassembly.

Summary by CodeRabbit

  • Bug Fixes
    • Translations now use edited narration and dialogue, and reflect deleted segments.
    • Updated narration no longer displays a cached translation based on outdated text.
    • Translation requests invalidated by later edits or deletions no longer overwrite newer translations.
    • Translation matching and display now stay aligned with the current narration.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6618 **Author:** [@menemorofaan](https://github.com/menemorofaan) **Created:** 9/24/2026 **Status:** ✅ Merged **Merged:** 9/24/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/translation-edit-cache` --- ### 📝 Commits (10+) - [`1ab31b2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1ab31b29e9cb06c0b83fb96fabf61b36920bf452) fix(narration): fix translation caching and segment sync for edited messages - [`87bb871`](https://github.com/Pasta-Devs/Marinara-Engine/commit/87bb871b9ea2afd383aec3288c5e271c205af835) style: format GameNarration with prettier - [`167694d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/167694d776449426d47f64e962a7430fe371a259) Merge branch 'staging' into fix/translation-edit-cache - [`00b2030`](https://github.com/Pasta-Devs/Marinara-Engine/commit/00b20309329df64ae0951e6b460dd09b221748a2) Merge branch 'staging' into fix/translation-edit-cache - [`c4689fa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c4689fa121004d99170044fdc5337a2e46626901) fix(narration): restrict raw content translation match to unedited messages - [`541dbea`](https://github.com/Pasta-Devs/Marinara-Engine/commit/541dbea340fefc65f3e1f3db34851db7649cfe27) Merge branch 'staging' into fix/translation-edit-cache - [`18860b3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/18860b3e98c3becfdb49f56d160c108747daacbe) Merge branch 'staging' into fix/translation-edit-cache - [`3e37ae7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3e37ae73980d1d46017bb97afb23a88a70b0836c) Merge remote-tracking branch 'origin/staging' into codex/6618-translation-review - [`3151034`](https://github.com/Pasta-Devs/Marinara-Engine/commit/31510347bd6165416beba08a863f4b440bc99397) fix(game): finish translation invalidation and segment alignment - [`b32f824`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b32f82451aa6ad8ecd68b7c1cdf494b6799e3f99) Merge remote-tracking branch 'origin/staging' into codex/6618-translation-review ### 📊 Changes **7 files changed** (+404 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) ➕ `e2e/game-translation-edits.e2e.ts` (+180 -0) 📝 `e2e/roleplay-commands.e2e.ts` (+25 -3) 📝 `packages/client/src/components/game/GameNarration.tsx` (+148 -20) 📝 `packages/client/src/components/game/GameSurface.tsx` (+4 -0) 📝 `packages/client/src/hooks/use-translate.ts` (+37 -13) 📝 `packages/client/src/stores/translation.store.ts` (+8 -0) </details> ### 📄 Description ## Linked issue #6615 Closes #6615 ## Why this change In Game (GM) mode, editing a narration segment does not update its translation. The translator continues to receive the pre-edit draft, so the translation still reflects the original text. Furthermore, because the stored translation source still matches that stale draft, the outdated translation is considered fresh and remains on screen, while auto-translate is prevented from re-running. ## What changed - Rebuild Game translation input from the existing segment edit/delete overlays, including dialogue and readables. Keep raw-message translation aliases only for untouched messages. - Invalidate cached and pending translations in the shared edit/delete handlers, so a request invalidated before its result arrives cannot save or display the old text. - Preserve the existing segment boundaries when an edit adds quoted speech, and retain deleted-segment positions for later translations. - Memoize the source for each message, reusing it across translation actions and display checks instead of rebuilding whole messages inside segment render loops. - Resolve the existing WebKit CI failure by handling the already-mocked UI settings endpoint in-page during whisper-test reloads and waiting for startup requests to settle before each reload; retain all page-error and recipient-privacy assertions. - Add an Unreleased changelog entry and browser regressions for manual/automatic translation, reload, deletion, saved raw-source translations, and a delayed translation completing after an edit. ## Validation Completed on the updated staging base: `pnpm check`. The targeted translation browser suite passed 19 cases across desktop Chromium, mobile Chromium and mobile WebKit; 2 mobile cases are deliberately skipped because the active-segment editor is a desktop control. Existing Conversation/Roleplay/Game navigation and persistence cases pass. Both whisper presentations also pass all 6 browser cases after the fixture fix, and `pnpm check:e2e-types` passes for that final test-only change. Before the fixes, the browser proofs reproduced raw-source alias reuse, quoted-narration misalignment, and stale-result persistence. Local CodeRabbit completed the combined review, including all files in this PR. Its queued-request and whitespace-only-blank-line findings were reproduced with failing browser regressions and fixed. An additional suggestion to index override keys with another derived Set was not adopted: full translation sources are already memoized per message, while the remaining direct scans only inspect edit/delete keys. The follow-up local review completed across all 9 files in the combined review. It repeated optional source/override-index optimizations and suggested deleting saved translations on invalidation. The latter is not needed for correctness: every Game translation display uses current-source matching, manual translation accepts the raw-content alias only without overrides, and automatic translation compares the rebuilt source. The manual/automatic browser cases explicitly seed an obsolete saved translation, verify the edited text/retranslation, and repeat after reload and deletion. Saved values may remain cached with their old source, but cannot display as current or suppress the new request. No additional persistence writes are added. Hosted CodeRabbit completed on this head; its optional override-index suggestion has the same documented disposition. The required hosted container build is the container validation; no local container run or live translation-provider verification is claimed. - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - [ ] Manually verify narration, dialogue and readable edits with the preferred translation provider, including auto-translate, reload, deletion and switching chats during translation. Original contributor's manual verification notes are retained below: 1. Full client production build (`npm run build`) completed successfully with 0 TypeScript/build errors. 2. Verified in real browser (Game mode): - Created/received a multi-paragraph assistant narration with spoken dialogue and descriptive prose. - Edited multiple segments in the message log/editor. - Verified that clicking translate (and auto-translate) sends the updated edited text to the translator. - Confirmed that all paragraphs/segments translate and map back 1:1 to their respective rendered segments without index drift. 3. Verified that unedited messages and non-game modes (Conversation/Roleplay) continue to behave normally with no regressions. ## Docs and release impact Includes an Unreleased changelog entry for #6615. No settings, provider API, localization copy, storage format, or version change. - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) No UI layout changes — purely state management, translation cache invalidation, and narration segment reassembly. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Translations now use edited narration and dialogue, and reflect deleted segments. * Updated narration no longer displays a cached translation based on outdated text. * Translation requests invalidated by later edits or deletions no longer overwrite newer translations. * Translation matching and display now stay aligned with the current narration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:18:00 +07:00
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#7256
No description provided.