[PR #7387] [MERGED] fix(roleplay): keep model whispers in place after the reply is edited #7710

Closed
opened 2026-10-24 04:06:45 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7387
Author: @SpicyMarinara
Created: 10/10/2026
Status: ✅ Merged
Merged: 10/10/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/whisper-position


📝 Commits (7)

  • a8d5049 fix(roleplay): keep model whispers in place after the reply is edited
  • 337f938 fix(roleplay): follow the unchanged text around a whisper through an edit
  • 6ada138 fix(roleplay): move whispers only when their saved text no longer places them
  • fe42b2f fix(roleplay): keep a whisper's first place and prefer it while its text is there
  • 001f0d9 fix(roleplay): re-anchor the active swipe's activity from its own text
  • e8522c1 fix(roleplay): re-anchor each saved activity list on its own
  • cd5d04f fix(roleplay): trust an anchor in its place over one found elsewhere

📊 Changes

5 files changed (+246 additions, -24 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/services/storage/chats.storage.ts (+31 -6)
📝 packages/shared/src/types/roleplay-command.ts (+92 -16)
📝 packages/shared/src/utils/quote-format.ts (+2 -1)
📝 scripts/regressions/roleplay-whisper-generation.regression.ts (+120 -1)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7386

Why this change

  • In Roleplay, a whisper the model writes mid-reply showed at the bottom of the message once the reply was edited. Mari saw it as "always at the bottom".
  • A whisper keeps its place with contentOffset and contentAnchor, the 80 characters before it. getRoleplayCommandContentOffset uses the offset if the anchor still matches there, then the anchor's only match, then the end.
  • Saving an edit applies the Typographic quote setting to the whole message. Anchors kept straight quotes and stopped matching, even for an edit far from the whisper. An edit near the whisper, a text-rewrite agent (Prose Guardian) or a continuation also changed the text without moving any anchor.
  • In Mari's live chat, 13 of 19 model whispers no longer matched their anchors. Four were mid-text whispers whose anchors differ only in quote style. The other mismatches had the anchor text itself edited away or cut, and stay at the end.

What changed

  • getRoleplayCommandContentOffset (shared) compares the text and the anchor with straight quotes (toStraightQuotes, now exported). Curling keeps the text length, so offsets still line up. This puts whispers in replies that were already edited back in place, with no data migration. Dice-roll results and whisper placement in prompts use the same function.
  • reanchorRoleplayCommandActivity (shared) runs from updateMessageContent on every content change: manual edits, rewrite agents, retries, continuations and corrections. It works on the message row and the active swipe, each from its own list, and leaves commands typed into the edit as prepared. It moves a result only when its saved text no longer places it:
    • text before or after the changed part keeps it exactly in place;
    • inside the changed part, it follows the unchanged text right before or after it (the longest match of 80, 40 or 20 characters that appears once in both the old and the new text);
    • with no such text it stays as it was and shows at the end, as on staging.
  • The place a result was first anchored is kept for good (originalContentOffset / originalContentAnchor). Placement tries saved anchors at their saved offsets first (original, then current), and only then searches the text for them. Undoing an edit and toggling Prose Guardian back both restore the original place, and editing away one copy of a repeated phrase no longer pulls the whisper to the other copy.
  • Each saved list (the message row and the active swipe) is re-anchored from the text it was anchored to, and is written only when it changes.
  • Regression (roleplay-whisper-generation): a real model reply edited through the PATCH route (the sentence before the whisper reworded, all quotes curled), straight-quote anchors on curled text, and these cases: two typos around a whisper, edits on both sides, a deleted sentence before it, an insertion right after it, a full rewrite (stays at the end), rewrite and toggle back, delete and restore, two edits and restore, a repeated phrase (stays at the end), and one copy of a repeated phrase edited away.

Review

  • Local CodeRabbit (8 runs; the last found nothing) and four rounds of adversarial review. Two of them fuzzed about 18,000 edit sequences per category against a model of staging. The first designs were rejected: one remapped every change as a single region and put whispers mid-word, one pinned whispers that couldn't be placed, and one let a newer anchor beat the original after an undo. CodeRabbit's "keep the first previous position" was taken. Its "A whisper" to "A A whisper" case was declined: it is ambiguous and staging places it the same way. Its later per-swipe and repeated-phrase findings were fixed.
  • Final fuzz (3 seeds): 0 crashes and 0 cases worse than staging in every undo, revert and Prose Guardian toggle category. Typo, insert, delete, rewrite and quote-curling edits are better than staging in about 2,000 to 3,500 sequences per category and seed. The few left (at most 0.8% in any category) are ambiguous: duplicate sentences, a word inserted exactly at the whisper, or an undo of a deletion right after a whisper at the very end. There, staging's fallback to the end happens to match. None split a word.

Validation

  • 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

Commands run by the agent: pnpm check; node ./scripts/run-regressions.mjs --filter for roleplay-whisper-generation, roleplay-whisper-hidden-recipient, roleplay-user-private-generation, roleplay-user-private-storage, roleplay-commands, roleplay-interrupt-storage, roleplay-interrupt-generation, roleplay-streaming, roleplay-swipe-media, roleplay-regeneration-context, roleplay-vn-paragraphs, dice-display, message-edit-delete-races, message-trash, regeneration-context, manual-agent-retry-resolution, character-id-macro-modes, open-issues, advanced-memory-core, advanced-memory-post-generation and prompt (all pass on the final head or the commit before it).

Manual verification notes

  • Manually verify in a Roleplay chat with Typographic quotes: have a character whisper mid-reply, edit a word in the sentence before the whisper, save, and check the whisper still shows in the same place.
  • Manually verify that an older reply whose whisper had dropped to the bottom after an edit shows it back in place (when only the quotes changed).
  • Manually verify that a reply rewritten by Prose Guardian keeps its whisper in place.

Docs and release impact

  • 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)

CHANGELOG [Unreleased] has an entry. No user docs change.

Summary by CodeRabbit

  • Bug Fixes
    • Whispers in roleplay replies retain their intended position when nearby text is edited or quote styles change.
    • Existing whispers are repositioned when edits shift their text, including when a reply is restored or updated again.
    • When text contains repeated or ambiguous matches, a whisper may be placed at the end of the reply rather than at an uncertain location.

🔄 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/7387 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/10/2026 **Status:** ✅ Merged **Merged:** 10/10/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/whisper-position` --- ### 📝 Commits (7) - [`a8d5049`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a8d5049df255ce2a9c98dd9529501f75ca229f1a) fix(roleplay): keep model whispers in place after the reply is edited - [`337f938`](https://github.com/Pasta-Devs/Marinara-Engine/commit/337f938a3310c38992cb70b203b35dedae9272f4) fix(roleplay): follow the unchanged text around a whisper through an edit - [`6ada138`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6ada13807b9d79826818a153a5922cbaba952d4d) fix(roleplay): move whispers only when their saved text no longer places them - [`fe42b2f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fe42b2fb937164c34170925574711f415dd93054) fix(roleplay): keep a whisper's first place and prefer it while its text is there - [`001f0d9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/001f0d91b73fc12956b08bbd8709538959c3011f) fix(roleplay): re-anchor the active swipe's activity from its own text - [`e8522c1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e8522c15b574849c4b9c2de73dd19517bcae98d2) fix(roleplay): re-anchor each saved activity list on its own - [`cd5d04f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cd5d04f5bb2be5c68bfd5874b5c16ec4f70424db) fix(roleplay): trust an anchor in its place over one found elsewhere ### 📊 Changes **5 files changed** (+246 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/services/storage/chats.storage.ts` (+31 -6) 📝 `packages/shared/src/types/roleplay-command.ts` (+92 -16) 📝 `packages/shared/src/utils/quote-format.ts` (+2 -1) 📝 `scripts/regressions/roleplay-whisper-generation.regression.ts` (+120 -1) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7386 ## Why this change - In Roleplay, a whisper the model writes mid-reply showed at the bottom of the message once the reply was edited. Mari saw it as "always at the bottom". - A whisper keeps its place with `contentOffset` and `contentAnchor`, the 80 characters before it. `getRoleplayCommandContentOffset` uses the offset if the anchor still matches there, then the anchor's only match, then the end. - Saving an edit applies the **Typographic** quote setting to the whole message. Anchors kept straight quotes and stopped matching, even for an edit far from the whisper. An edit near the whisper, a text-rewrite agent (Prose Guardian) or a continuation also changed the text without moving any anchor. - In Mari's live chat, 13 of 19 model whispers no longer matched their anchors. Four were mid-text whispers whose anchors differ only in quote style. The other mismatches had the anchor text itself edited away or cut, and stay at the end. ## What changed - `getRoleplayCommandContentOffset` (shared) compares the text and the anchor with straight quotes (`toStraightQuotes`, now exported). Curling keeps the text length, so offsets still line up. This puts whispers in replies that were already edited back in place, with no data migration. Dice-roll results and whisper placement in prompts use the same function. - `reanchorRoleplayCommandActivity` (shared) runs from `updateMessageContent` on every content change: manual edits, rewrite agents, retries, continuations and corrections. It works on the message row and the active swipe, each from its own list, and leaves commands typed into the edit as prepared. It moves a result only when its saved text no longer places it: - text before or after the changed part keeps it exactly in place; - inside the changed part, it follows the unchanged text right before or after it (the longest match of 80, 40 or 20 characters that appears once in both the old and the new text); - with no such text it stays as it was and shows at the end, as on staging. - The place a result was first anchored is kept for good (`originalContentOffset` / `originalContentAnchor`). Placement tries saved anchors at their saved offsets first (original, then current), and only then searches the text for them. Undoing an edit and toggling Prose Guardian back both restore the original place, and editing away one copy of a repeated phrase no longer pulls the whisper to the other copy. - Each saved list (the message row and the active swipe) is re-anchored from the text it was anchored to, and is written only when it changes. - Regression (`roleplay-whisper-generation`): a real model reply edited through the PATCH route (the sentence before the whisper reworded, all quotes curled), straight-quote anchors on curled text, and these cases: two typos around a whisper, edits on both sides, a deleted sentence before it, an insertion right after it, a full rewrite (stays at the end), rewrite and toggle back, delete and restore, two edits and restore, a repeated phrase (stays at the end), and one copy of a repeated phrase edited away. ## Review - Local CodeRabbit (8 runs; the last found nothing) and four rounds of adversarial review. Two of them fuzzed about 18,000 edit sequences per category against a model of staging. The first designs were rejected: one remapped every change as a single region and put whispers mid-word, one pinned whispers that couldn't be placed, and one let a newer anchor beat the original after an undo. CodeRabbit's "keep the first previous position" was taken. Its "A whisper" to "A A whisper" case was declined: it is ambiguous and staging places it the same way. Its later per-swipe and repeated-phrase findings were fixed. - Final fuzz (3 seeds): 0 crashes and 0 cases worse than staging in every undo, revert and Prose Guardian toggle category. Typo, insert, delete, rewrite and quote-curling edits are better than staging in about 2,000 to 3,500 sequences per category and seed. The few left (at most 0.8% in any category) are ambiguous: duplicate sentences, a word inserted exactly at the whisper, or an undo of a deletion right after a whisper at the very end. There, staging's fallback to the end happens to match. None split a word. ## Validation - [ ] `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` Commands run by the agent: `pnpm check`; `node ./scripts/run-regressions.mjs --filter` for roleplay-whisper-generation, roleplay-whisper-hidden-recipient, roleplay-user-private-generation, roleplay-user-private-storage, roleplay-commands, roleplay-interrupt-storage, roleplay-interrupt-generation, roleplay-streaming, roleplay-swipe-media, roleplay-regeneration-context, roleplay-vn-paragraphs, dice-display, message-edit-delete-races, message-trash, regeneration-context, manual-agent-retry-resolution, character-id-macro-modes, open-issues, advanced-memory-core, advanced-memory-post-generation and prompt (all pass on the final head or the commit before it). ### Manual verification notes - Manually verify in a Roleplay chat with Typographic quotes: have a character whisper mid-reply, edit a word in the sentence before the whisper, save, and check the whisper still shows in the same place. - Manually verify that an older reply whose whisper had dropped to the bottom after an edit shows it back in place (when only the quotes changed). - Manually verify that a reply rewritten by Prose Guardian keeps its whisper in place. ## Docs and release impact - [ ] 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) CHANGELOG `[Unreleased]` has an entry. No user docs change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Whispers in roleplay replies retain their intended position when nearby text is edited or quote styles change. * Existing whispers are repositioned when edits shift their text, including when a reply is restored or updated again. * When text contains repeated or ambiguous matches, a whisper may be placed at the end of the reply rather than at an uncertain location. <!-- 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-24 04:06:45 +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#7710
No description provided.