[PR #7678] [MERGED] refactor(generate): move the reply save step into generate/save-generated-reply.ts #7877

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

📋 Pull Request Information

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

Base: staging ← Head: chore/7573-save-generated-reply


📝 Commits (4)

  • d95d7f6 refactor(generate): move the reply save step into save-generated-reply.ts
  • e35a340 Merge remote-tracking branch 'origin/staging' into chore/7573-save-generated-reply
  • 9b2ebd6 test(generate): pin repeated split offsets, continue fallback, impersonate and owner-turn commit
  • ef860f9 Merge remote-tracking branch 'origin/staging' into chore/7573-save-generated-reply

📊 Changes

3 files changed (+403 additions, -133 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+22 -133)
➕ packages/server/src/routes/generate/save-generated-reply.ts (+187 -0)
➕ scripts/regressions/generate-save-generated-reply.regression.ts (+194 -0)

📄 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

Part of #7573 (seventh slice).

Why this change

The route saved a generated reply in one long inline block: as a new swipe on regenerate, appended to the continued message, as the owner's turn of a pending spatial transition (with recovery of an already applied turn), or as new messages, split at scene breaks with Advanced Memory and saved whole or not at all. That block mixed storage, SSE events and multiplayer extras with the rest of the route. As saveGeneratedReply it has one input, one result and a direct test of each path.

No behaviour change.

What changed

  • New packages/server/src/routes/generate/save-generated-reply.ts with saveGeneratedReply(ctx, fullResponse). It returns the saved message, the swipe index, the reply parts, the reply as saved, the continued content and whether an owner turn was recovered.
  • generate.routes.ts calls it and writes the results back to its locals. The order of storage calls and SSE events is the same.
  • New scripts/regressions/generate-save-generated-reply.regression.ts (temp DB): new reply, regenerate swipe, continue (and its fallback to the message read before generation), impersonate, Advanced Memory split (including start offsets of repeated parts), the rollback of a failed split save, the rejected, committed and recovered owner turn with their SSE events.

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 results (not a substitute for the boxes above):

  • pnpm check: passed. Server typecheck passed again after the last test commit.
  • Regressions: the new one passed, plus the regressions that read generate.routes.ts.
  • Local CodeRabbit: 0 findings. A separate review compared the helper with the old block line by line and found no behaviour change; its one low test-coverage note is fixed by the added asserts.

Manual verification notes

  • Manually verify a new reply, a regenerate (new swipe) and a continue in a roleplay chat.
  • Manually verify an Advanced Memory chat: a reply with a scene break is saved as two messages.
  • Manually verify an impersonated reply with a World Maps move: the move commits and the location updates.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

Summary by CodeRabbit

  • Improvements
    • Replies are saved consistently when starting a new reply, regenerating one, or continuing an existing message.
    • When Advanced Memory is enabled, eligible replies are organized at scene breaks, with repeated parts placed correctly.
    • Replies associated with spatial transitions are handled more reliably, including recovery when a transition has already been applied and clear handling of rejected transitions.
    • If saving a multi-part reply fails, any parts already saved are removed to avoid leaving incomplete content.

🔄 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/7678 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `staging` ← **Head:** `chore/7573-save-generated-reply` --- ### 📝 Commits (4) - [`d95d7f6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d95d7f64d4550f980ebc060d2956dcc56ddca062) refactor(generate): move the reply save step into save-generated-reply.ts - [`e35a340`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e35a34045f2ed62cad08df518617cb0f33f07f28) Merge remote-tracking branch 'origin/staging' into chore/7573-save-generated-reply - [`9b2ebd6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9b2ebd6c68c191a48e819a8c9cdac93a4ab553eb) test(generate): pin repeated split offsets, continue fallback, impersonate and owner-turn commit - [`ef860f9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ef860f97a19aa229928c95c0acc2bbbc621ee35f) Merge remote-tracking branch 'origin/staging' into chore/7573-save-generated-reply ### 📊 Changes **3 files changed** (+403 additions, -133 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+22 -133) ➕ `packages/server/src/routes/generate/save-generated-reply.ts` (+187 -0) ➕ `scripts/regressions/generate-save-generated-reply.regression.ts` (+194 -0) </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`. ## Linked issue Part of #7573 (seventh slice). ## Why this change The route saved a generated reply in one long inline block: as a new swipe on regenerate, appended to the continued message, as the owner's turn of a pending spatial transition (with recovery of an already applied turn), or as new messages, split at scene breaks with Advanced Memory and saved whole or not at all. That block mixed storage, SSE events and multiplayer extras with the rest of the route. As `saveGeneratedReply` it has one input, one result and a direct test of each path. No behaviour change. ## What changed - New `packages/server/src/routes/generate/save-generated-reply.ts` with `saveGeneratedReply(ctx, fullResponse)`. It returns the saved message, the swipe index, the reply parts, the reply as saved, the continued content and whether an owner turn was recovered. - `generate.routes.ts` calls it and writes the results back to its locals. The order of storage calls and SSE events is the same. - New `scripts/regressions/generate-save-generated-reply.regression.ts` (temp DB): new reply, regenerate swipe, continue (and its fallback to the message read before generation), impersonate, Advanced Memory split (including start offsets of repeated parts), the rollback of a failed split save, the rejected, committed and recovered owner turn with their SSE events. ## 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 results (not a substitute for the boxes above): - `pnpm check`: passed. Server typecheck passed again after the last test commit. - Regressions: the new one passed, plus the regressions that read `generate.routes.ts`. - Local CodeRabbit: 0 findings. A separate review compared the helper with the old block line by line and found no behaviour change; its one low test-coverage note is fixed by the added asserts. ### Manual verification notes - Manually verify a new reply, a regenerate (new swipe) and a continue in a roleplay chat. - Manually verify an Advanced Memory chat: a reply with a scene break is saved as two messages. - Manually verify an impersonated reply with a World Maps move: the move commits and the location updates. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Replies are saved consistently when starting a new reply, regenerating one, or continuing an existing message. * When Advanced Memory is enabled, eligible replies are organized at scene breaks, with repeated parts placed correctly. * Replies associated with spatial transitions are handled more reliably, including recovery when a transition has already been applied and clear handling of rejected transitions. * If saving a multi-part reply fails, any parts already saved are removed to avoid leaving incomplete content. <!-- 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:08:24 +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#7877
No description provided.