[PR #7507] [MERGED] feat(memory): rewrite every part of a split POV reply (#7504) #7764

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

📋 Pull Request Information

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

Base: staging ← Head: fix/pov-split-rewrite-every-part


📝 Commits (5)

  • f745991 feat(memory): rewrite every part of a split POV reply (#7504)
  • da6e05b fix(memory): release an earlier responder's held split parts (#7504)
  • f33ddb4 Merge branch 'staging' into fix/pov-split-rewrite-every-part
  • d98745f fix(memory): keep text-rewrite persistence on the sanitized text for split parts
  • 8ec24ab Merge branch 'staging' into fix/pov-split-rewrite-every-part

📊 Changes

7 files changed (+458 additions, -194 deletions)

View changed files

📝 docs/agents/memory.md (+2 -1)
📝 packages/client/src/hooks/use-generate.ts (+27 -21)
📝 packages/client/src/lib/message-rewrite-versions.ts (+25 -0)
📝 packages/server/src/routes/generate.routes.ts (+184 -160)
📝 packages/shared/src/utils/scene-breaks.ts (+11 -0)
📝 scripts/regressions/advanced-memory-post-generation.regression.ts (+172 -9)
📝 scripts/regressions/roleplay-streaming.regression.ts (+37 -3)

📄 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.

Merge after #7497. This branch is built on feat/advanced-memory-pov-split, so until #7497 lands the diff against staging also shows its commits. The two commits of this PR are the last two (f74599116, da6e05b62).

Linked issue

Closes #7504

Follow-up to #7497 / #7481.

Why this change

  • With Advanced Memory on, #7497 saves a new Roleplay reply as one message per scene or POV break (***, ---, ___), so each part can have its own audience.
  • Prose Guardian, Continuity and Immersive HTML only rewrote the last part. The earlier parts kept the unedited text, so one reply came out half polished.
  • Maintainer decision (2026-10-12): rewrite every part, one rewrite call per part, through the existing pipeline.

What changed

  • Server, rewrite step (generate.routes.ts): the existing text-rewrite block now runs once per part of the last reply, in order. A reply that wasn't split takes exactly the old path, as one target. Each part gets the same agents, settings and context as a normal reply.
    • Break line: the part's leading break line is held aside, the agents rewrite the text under it, and it is put back as the first line. The new shared helper leadingSceneBreak (next to splitAtSceneBreaks) finds that line.
    • Whispers: each part is saved through chats.updateMessageContent on its own row, which re-anchors that part's whisper positions within it, as for any rewrite.
    • Failures: a failed or refused rewrite leaves its part as written, and the loop goes on to the next part.
  • Events: every text_rewrite event now carries messageId.
  • Hold Message Until Rewrite: earlier parts are now sent with the same placeholder as the last part (heldForRewrite, shared by both). Each part is released by its own text_rewrite: the rewrite, or its unchanged text after a failure.
  • Individual groups: rewrites still cover only the last reply, as before. When a later responder's reply takes over, an earlier responder's held parts are released with their text, so they don't stay on the placeholder.
  • Client (use-generate.ts):
    • A text_rewrite whose messageId is an earlier split part updates that row in the cache. The live reply, which belongs to the last part, isn't touched.
    • An earlier part that arrives with the placeholder stays its own row and never becomes the held live message.
    • The shared step "apply a rewrite to a message" moved to applyMessageTextRewrite in lib/message-rewrite-versions.ts. The held-reply path uses it too, so both paths behave the same.
  • Docs (docs/agents/memory.md): the split-reply bullet now says each part is rewritten on its own. Translation follow-up: #7506.

Not changed: visibility decisions, swipes/regenerate (still one message), where attachments go, Continue/Impersonate (never split), and the rewrite of a reply that wasn't split.

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

Agent-run checks (not a substitute for the boxes above):

  • pnpm check: passed (exit 0) on the head da6e05b62. The only ESLint warning is the existing one in HomeProfessorMariChat.tsx, which this PR doesn't touch.
  • node ./scripts/run-regressions.mjs --filter advanced-memory: 16/16 passed on da6e05b62.
  • node ./scripts/run-regressions.mjs --filter roleplay: 14/14 passed.
  • node ./scripts/run-regressions.mjs --filter regeneration-context: 2/2 passed.
  • Local CodeRabbit (coderabbit review --agent --committed --base-commit <merge-base with staging>), run once on the first commit f74599116 (not rate limited; it also covered #7497's commits on this branch): 2 findings.
    • docs/agents/memory.md, minor: open a [docs-i18n] follow-up. Fixed by opening #7506.
    • ChatArea.tsx, trivial: run speaker extraction for split parts in parallel. Not changed here: that code is #7497's autoplay path, and this PR doesn't touch it. It's a latency suggestion, not a defect, so it belongs with #7497 if wanted.
    • The second commit da6e05b62 (earlier-responder release) wasn't reviewed by the local run.

New proof:

  • advanced-memory-post-generation.regression.ts, run through the real /api/generate route with a fake Prose Guardian:
    • A 2-part reply gets one rewrite call per part, and the agent never sees the break line. Both parts are rewritten, and the second part still starts with ***. Each text_rewrite names its part.
    • With hold on, both parts' message_saved carry the placeholder. With hold off, they carry the written text.
    • A failing rewrite of part 1 leaves part 1 as written. A release event carries its text, and part 2 is still rewritten.
    • A whisper in part 2 moves by exactly the inserted text.
    • In an individual group, the first responder's held part is released, and only the last reply's parts are rewritten.
  • roleplay-streaming.regression.ts: applyMessageTextRewrite (placeholder removed, the built-in original kept and toggleable, cleared otherwise), plus the client routing of a part's rewrite to its own row. #7497's source check on the earlier part's message_saved now also requires the placeholder. It keeps the remainingContent: "" requirement unchanged.
  • Fails without the change: with this PR's source files reverted to #7497 and the new regression kept, advanced-memory-post-generation fails at held: one rewrite per part, without its break: only '***\n\nMARI_AND_MAUKIE run through the rain.' reached the agent. With the earlier-responder release disabled, the group assertion fails. With #7497's use-generate.ts, roleplay-streaming fails at "an earlier part's rewrite must update its own row before anything touches the live reply".

Manual verification notes

Needs a person in a browser (not done by the agent):

  • Manually verify, in a one-character Roleplay chat with Advanced Memory and Prose Guardian on and Hold Message Until Rewrite on, a reply with a *** line:
    • both parts show "Prose Guardian is working!" until their own rewrite arrives;
    • both end up rewritten;
    • the second part still starts with ***.
  • Manually verify the same with Hold Message Until Rewrite off: both parts appear as written, then each changes in place to its rewrite. Nothing is duplicated, and the live reply never shows the first part again.
  • Manually verify that the shield button on each rewritten part toggles between that part's original and rewritten text.
  • Manually verify that speech autoplay reads the rewritten text of every part.
  • Manually verify, in an individual group with two characters and hold on, that a first responder's split reply never stays on the placeholder.

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)

docs/agents/memory.md updated; translation follow-up #7506. No CHANGELOG entry (compiled at release time).

Risks

  • More calls: a split reply now makes one rewrite call per part, so an N-part reply costs N rewrite calls, run one after another. With hold on, the last part waits for all of them.
  • Group scope: in an individual group, only the last reply's parts are rewritten, which is unchanged in scope. An earlier responder's reply that wasn't split still goes through the existing joined-text rewrite of the last message, as on staging.

Summary by CodeRabbit

  • Bug Fixes
    • Split roleplay replies are rewritten part by part, with scene-break markers preserved. If rewriting one part fails, its original text remains while other parts can still be rewritten.
    • Held replies display a placeholder until each part’s rewrite is ready. Completed rewrites update the correct saved part without altering the live reply.
    • Rewriting preserves original text for restoration and keeps whisper offsets aligned with updated text.
  • Documentation
    • Updated guidance to reflect how rewrite agents handle split replies and individual rewrite failures.

🔄 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/7507 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/12/2026 **Status:** ✅ Merged **Merged:** 10/12/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/pov-split-rewrite-every-part` --- ### 📝 Commits (5) - [`f745991`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f7459911619448405f322d915fb2aa9f38b17a3f) feat(memory): rewrite every part of a split POV reply (#7504) - [`da6e05b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/da6e05b62f4fe52f86cdb8de657421d29971dde1) fix(memory): release an earlier responder's held split parts (#7504) - [`f33ddb4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f33ddb4f271bcba4ebf5bc7e84f7194971b84975) Merge branch 'staging' into fix/pov-split-rewrite-every-part - [`d98745f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d98745f14c7cd56bc14bce7d23b57daca2e56f94) fix(memory): keep text-rewrite persistence on the sanitized text for split parts - [`8ec24ab`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8ec24ab5a267aea33a1848c5eea17ee4831e081e) Merge branch 'staging' into fix/pov-split-rewrite-every-part ### 📊 Changes **7 files changed** (+458 additions, -194 deletions) <details> <summary>View changed files</summary> 📝 `docs/agents/memory.md` (+2 -1) 📝 `packages/client/src/hooks/use-generate.ts` (+27 -21) 📝 `packages/client/src/lib/message-rewrite-versions.ts` (+25 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+184 -160) 📝 `packages/shared/src/utils/scene-breaks.ts` (+11 -0) 📝 `scripts/regressions/advanced-memory-post-generation.regression.ts` (+172 -9) 📝 `scripts/regressions/roleplay-streaming.regression.ts` (+37 -3) </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. --> **Merge after #7497.** This branch is built on `feat/advanced-memory-pov-split`, so until #7497 lands the diff against `staging` also shows its commits. The two commits of this PR are the last two (`f74599116`, `da6e05b62`). ## Linked issue Closes #7504 Follow-up to #7497 / #7481. ## Why this change - With Advanced Memory on, #7497 saves a new Roleplay reply as one message per scene or POV break (`***`, `---`, `___`), so each part can have its own audience. - Prose Guardian, Continuity and Immersive HTML only rewrote the **last** part. The earlier parts kept the unedited text, so one reply came out half polished. - Maintainer decision (2026-10-12): rewrite **every** part, one rewrite call per part, through the existing pipeline. ## What changed - **Server, rewrite step** (`generate.routes.ts`): the existing text-rewrite block now runs once per part of the last reply, in order. A reply that wasn't split takes exactly the old path, as one target. Each part gets the same agents, settings and context as a normal reply. - **Break line:** the part's leading break line is held aside, the agents rewrite the text under it, and it is put back as the first line. The new shared helper `leadingSceneBreak` (next to `splitAtSceneBreaks`) finds that line. - **Whispers:** each part is saved through `chats.updateMessageContent` on its own row, which re-anchors that part's whisper positions within it, as for any rewrite. - **Failures:** a failed or refused rewrite leaves its part as written, and the loop goes on to the next part. - **Events:** every `text_rewrite` event now carries `messageId`. - **Hold Message Until Rewrite:** earlier parts are now sent with the same placeholder as the last part (`heldForRewrite`, shared by both). Each part is released by its own `text_rewrite`: the rewrite, or its unchanged text after a failure. - **Individual groups:** rewrites still cover only the last reply, as before. When a later responder's reply takes over, an earlier responder's held parts are released with their text, so they don't stay on the placeholder. - **Client** (`use-generate.ts`): - A `text_rewrite` whose `messageId` is an earlier split part updates that row in the cache. The live reply, which belongs to the last part, isn't touched. - An earlier part that arrives with the placeholder stays its own row and never becomes the held live message. - The shared step "apply a rewrite to a message" moved to `applyMessageTextRewrite` in `lib/message-rewrite-versions.ts`. The held-reply path uses it too, so both paths behave the same. - **Docs** (`docs/agents/memory.md`): the split-reply bullet now says each part is rewritten on its own. Translation follow-up: #7506. Not changed: visibility decisions, swipes/regenerate (still one message), where attachments go, Continue/Impersonate (never split), and the rewrite of a reply that wasn't split. ## 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` Agent-run checks (not a substitute for the boxes above): - `pnpm check`: passed (exit 0) on the head `da6e05b62`. The only ESLint warning is the existing one in `HomeProfessorMariChat.tsx`, which this PR doesn't touch. - `node ./scripts/run-regressions.mjs --filter advanced-memory`: 16/16 passed on `da6e05b62`. - `node ./scripts/run-regressions.mjs --filter roleplay`: 14/14 passed. - `node ./scripts/run-regressions.mjs --filter regeneration-context`: 2/2 passed. - Local CodeRabbit (`coderabbit review --agent --committed --base-commit <merge-base with staging>`), run once on the first commit `f74599116` (not rate limited; it also covered #7497's commits on this branch): 2 findings. - `docs/agents/memory.md`, minor: open a `[docs-i18n]` follow-up. Fixed by opening #7506. - `ChatArea.tsx`, trivial: run speaker extraction for split parts in parallel. Not changed here: that code is #7497's autoplay path, and this PR doesn't touch it. It's a latency suggestion, not a defect, so it belongs with #7497 if wanted. - The second commit `da6e05b62` (earlier-responder release) wasn't reviewed by the local run. New proof: - `advanced-memory-post-generation.regression.ts`, run through the real `/api/generate` route with a fake Prose Guardian: - A 2-part reply gets one rewrite call per part, and the agent never sees the break line. Both parts are rewritten, and the second part still starts with `***`. Each `text_rewrite` names its part. - With hold on, both parts' `message_saved` carry the placeholder. With hold off, they carry the written text. - A failing rewrite of part 1 leaves part 1 as written. A release event carries its text, and part 2 is still rewritten. - A whisper in part 2 moves by exactly the inserted text. - In an individual group, the first responder's held part is released, and only the last reply's parts are rewritten. - `roleplay-streaming.regression.ts`: `applyMessageTextRewrite` (placeholder removed, the built-in original kept and toggleable, cleared otherwise), plus the client routing of a part's rewrite to its own row. #7497's source check on the earlier part's `message_saved` now also requires the placeholder. It keeps the `remainingContent: ""` requirement unchanged. - **Fails without the change:** with this PR's source files reverted to #7497 and the new regression kept, `advanced-memory-post-generation` fails at `held: one rewrite per part, without its break`: only `'***\n\nMARI_AND_MAUKIE run through the rain.'` reached the agent. With the earlier-responder release disabled, the group assertion fails. With #7497's `use-generate.ts`, `roleplay-streaming` fails at "an earlier part's rewrite must update its own row before anything touches the live reply". ### Manual verification notes Needs a person in a browser (not done by the agent): - Manually verify, in a one-character Roleplay chat with Advanced Memory and Prose Guardian on and **Hold Message Until Rewrite** on, a reply with a `***` line: - both parts show "Prose Guardian is working!" until their own rewrite arrives; - both end up rewritten; - the second part still starts with `***`. - Manually verify the same with **Hold Message Until Rewrite** off: both parts appear as written, then each changes in place to its rewrite. Nothing is duplicated, and the live reply never shows the first part again. - Manually verify that the shield button on each rewritten part toggles between that part's original and rewritten text. - Manually verify that speech autoplay reads the rewritten text of every part. - Manually verify, in an individual group with two characters and hold on, that a first responder's split reply never stays on the placeholder. ## 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) `docs/agents/memory.md` updated; translation follow-up #7506. No CHANGELOG entry (compiled at release time). ## Risks - **More calls:** a split reply now makes one rewrite call per part, so an N-part reply costs N rewrite calls, run one after another. With hold on, the last part waits for all of them. - **Group scope:** in an individual group, only the last reply's parts are rewritten, which is unchanged in scope. An earlier responder's reply that wasn't split still goes through the existing joined-text rewrite of the last message, as on `staging`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Split roleplay replies are rewritten part by part, with scene-break markers preserved. If rewriting one part fails, its original text remains while other parts can still be rewritten. * Held replies display a placeholder until each part’s rewrite is ready. Completed rewrites update the correct saved part without altering the live reply. * Rewriting preserves original text for restoration and keeps whisper offsets aligned with updated text. * **Documentation** * Updated guidance to reflect how rewrite agents handle split replies and individual rewrite failures. <!-- 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:07:18 +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#7764
No description provided.