[PR #7373] [MERGED] fix(memory): end Decision-model scenes and add Re-scan scenes #7704

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

📋 Pull Request Information

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

Base: staging ← Head: fix/memory-scene-cuts-rescan


📝 Commits (3)

  • 5a65cf7 fix(memory): end Decision-model scenes and add a range re-scan
  • b2b5539 docs(memory): describe scene cuts and Re-scan scenes
  • a848c35 fix(memory): make re-scans safe to stop and refuse protected scenes

📊 Changes

11 files changed (+448 additions, -157 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 docs/agents/memory.md (+6 -2)
📝 packages/client/src/components/chat/AdvancedMemorySettings.tsx (+69 -0)
📝 packages/client/src/hooks/use-advanced-memory.ts (+3 -0)
📝 packages/client/src/localization/locales/en.json (+6 -0)
📝 packages/server/src/routes/advanced-memory.routes.ts (+9 -0)
📝 packages/server/src/services/advanced-memory-decisions.ts (+58 -24)
📝 packages/server/src/services/advanced-memory.ts (+147 -92)
📝 packages/shared/src/types/advanced-memory.ts (+1 -1)
📝 scripts/regressions/advanced-memory-decisions.regression.ts (+145 -32)
📝 scripts/regressions/advanced-memory-post-generation.regression.ts (+2 -6)

📄 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 #7371

Why this change

With Use Decision model on (hosted Jev), Advanced Memory never ended a scene. In the reporting chat, the open scene ran from #1162 to #1260 with no summary, while the status said Memory Ready. That range had a *** scene break with a POV switch, an out-of-character "POV switch" note and several location changes.

I replayed the production questions against hosted Jev on that chat's real messages: 158 requests, which reproduce the saved diagnostics within ±0.03. The cause was three things together, and none of it is a regression; it has been this way since #6750.

Transition old "END of X" question new "cut" question (shipped)
*** + POV switch (→1245) 0.58 / 0.70 0.98 / 0.98
OOC POV note (→1227) 0.45 / 0.54 0.87 / 0.91
Guild → gate stair (→1199) 0.23 / 0.21 0.90 / 0.67
ordinary messages 0.05–0.35 0.03–0.2 (a few cutaways 0.5–0.8)

Two numbers per row are two different check alignments.

  1. Fixed 0.8 cut-off. Scene boundaries ignored backend.calibration.defaultThreshold (0.5 for System One, 0.1 for the Open-Jev sidecar), which every other Decision gate uses. No real transition reached 0.8 with the old question.
  2. END questions are blind at the seams. The newest message of a check has nothing after it, and the message before the window was context only. So a transition between two checks was never asked about, in either check.
  3. No speakers, and no POV or scene-break cues in the question.

The maintainer's chat also needs its backlog fixed, and nothing could re-check a range while the status said Ready. A full preparation run had already marked #1162–#1199 as classified, using the 0.8 cut-off.

What changed

  • detectDecisionSceneStarts replaces detectDecisionSceneBoundaries. It asks one measured question per message: does this message cut to a new scene (another place or time, characters elsewhere, a *** line or OOC POV note)? It asks in groups of 5, each after the 3 messages before it, with speaker names. It uses the backend's own threshold. Diagnostics rows are scene_start ("Scene start").
  • Post-reply Decision check: each new message is asked as a start. A start at message index N ends the scene at message number N. When the first checked message cuts, that ending lands on the last message the previous check saw. The commit accepts endings from that message through the checked window. The checked window itself is unchanged (still the configured number of recent messages, per #6499).
  • classify() (history preparation) sends speakers and uses the new question and threshold.
  • Re-scan scenes: POST …/advanced-memory/initialize takes range: {start, end} (message numbers). The preparation run re-detects boundaries strictly inside the range, keeps every boundary outside it, and summarizes the scenes that changed. Unchanged summaries are reused. Classifier and reply-cadence checkpoints are left alone. Like Fix, it waits for running work instead of joining it. It is refused before history is prepared or for an out-of-range number. A hand-edited summary whose scene would change stops it with the existing review error.
  • UI: a Re-scan scenes box in Chat Settings → Memory Recall, pre-filled with the ongoing scene through the latest message. Six English keys.
  • Docs (docs/agents/memory.md) and CHANGELOG. Translations follow in #7372.

Out of scope, possible follow-ups: when one turn adds more messages than the scene-check interval, the oldest unchecked ones are still never candidates. The Helper scene check (SCENE_CHECK_PROMPT) keeps its own seam blind spot. Both would change the "exactly N recent messages" behaviour chosen in #6499, so I left them for a decision.

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

Automated evidence (the boxes above are for a human):

  • pnpm check passed locally (localization, formatting, lint, types, full build).
  • advanced-memory-decisions regression: an unlikely cut (0.3) leaves the scene open. A 0.6 cut is selected on a 0.5 System One threshold; the old code required 0.8. The request carries the 3 earlier messages with speakers. A cut at the first checked message closes the scene on the previous check's last message (the seam). Re-scan splits a previously missed cut into its own summarized scene, keeps outside summaries byte-identical, keeps the boundary after the range, and leaves sceneCheckMessageId alone. An out-of-range number is refused.
  • advanced-memory-post-generation regression passes; its wording assertion now expects the cut question.
  • Existing assertions changed on purpose: the 0.8 threshold and "end" semantics they pinned are the bug. The custom backend stub gained the calibration every real backend has.

Manual verification notes

  • Manually verify in the browser: Chat Settings → Memory Recall shows Re-scan scenes on a prepared chat, pre-filled with the ongoing scene's first message and the latest message. Check light and dark mode and a phone-width drawer.
  • Manually verify on the original chat (Decision on, TypeSafe Jev): Re-scan 1162–1261 splits it at about 1199, 1218, 1227, 1245 and 1250 and summarizes each closed scene. Expect a short extra scene where Maukie's blade-vision scores high (about 1259).
  • Manually verify a reply after that: Peek Prompt → Decision diagnostics shows Scene start rows, threshold 0.5.
  • Manually verify that a re-scan whose range covers a hand-edited summary with moving boundaries stops with the review error and leaves the archive intact.

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)

Two CHANGELOG entries, a new docs section, follow-up #7372 for translations.

UI evidence (if applicable)

Not captured yet; see the manual checks above.

Summary by CodeRabbit

  • New Features
    • Added a Re-scan scenes control for rescanning a selected message range. Scenes outside the range remain unchanged, and rescanning stops if it would alter an edited summary.
  • Improvements
    • Scene detection now checks for scene starts using the three preceding messages and their authors as context. Uncertain boundaries remain open rather than being treated as confirmed.
    • Decision diagnostics now displays the scene-start answer.

🔄 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/7373 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/9/2026 **Status:** ✅ Merged **Merged:** 10/9/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/memory-scene-cuts-rescan` --- ### 📝 Commits (3) - [`5a65cf7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5a65cf7236c5104a051374ffb1ce79ae79a65d20) fix(memory): end Decision-model scenes and add a range re-scan - [`b2b5539`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b2b5539df865a58fa89529574e9e2216aaf7025b) docs(memory): describe scene cuts and Re-scan scenes - [`a848c35`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a848c353eb095110e335491d382018513ac020dd) fix(memory): make re-scans safe to stop and refuse protected scenes ### 📊 Changes **11 files changed** (+448 additions, -157 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `docs/agents/memory.md` (+6 -2) 📝 `packages/client/src/components/chat/AdvancedMemorySettings.tsx` (+69 -0) 📝 `packages/client/src/hooks/use-advanced-memory.ts` (+3 -0) 📝 `packages/client/src/localization/locales/en.json` (+6 -0) 📝 `packages/server/src/routes/advanced-memory.routes.ts` (+9 -0) 📝 `packages/server/src/services/advanced-memory-decisions.ts` (+58 -24) 📝 `packages/server/src/services/advanced-memory.ts` (+147 -92) 📝 `packages/shared/src/types/advanced-memory.ts` (+1 -1) 📝 `scripts/regressions/advanced-memory-decisions.regression.ts` (+145 -32) 📝 `scripts/regressions/advanced-memory-post-generation.regression.ts` (+2 -6) </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 Closes #7371 ## Why this change With **Use Decision model** on (hosted Jev), Advanced Memory never ended a scene. In the reporting chat, the open scene ran from #1162 to #1260 with no summary, while the status said Memory Ready. That range had a `***` scene break with a POV switch, an out-of-character "POV switch" note and several location changes. I replayed the production questions against hosted Jev on that chat's real messages: 158 requests, which reproduce the saved diagnostics within ±0.03. The cause was three things together, and none of it is a regression; it has been this way since #6750. | Transition | old "END of X" question | new "cut" question (shipped) | |---|---|---| | `***` + POV switch (→1245) | 0.58 / 0.70 | **0.98 / 0.98** | | OOC POV note (→1227) | 0.45 / 0.54 | **0.87 / 0.91** | | Guild → gate stair (→1199) | 0.23 / 0.21 | **0.90 / 0.67** | | ordinary messages | 0.05–0.35 | 0.03–0.2 (a few cutaways 0.5–0.8) | Two numbers per row are two different check alignments. 1. **Fixed 0.8 cut-off.** Scene boundaries ignored `backend.calibration.defaultThreshold` (0.5 for System One, 0.1 for the Open-Jev sidecar), which every other Decision gate uses. No real transition reached 0.8 with the old question. 2. **END questions are blind at the seams.** The newest message of a check has nothing after it, and the message before the window was context only. So a transition between two checks was never asked about, in either check. 3. **No speakers, and no POV or scene-break cues** in the question. The maintainer's chat also needs its backlog fixed, and nothing could re-check a range while the status said Ready. A full preparation run had already marked #1162–#1199 as classified, using the 0.8 cut-off. ## What changed - `detectDecisionSceneStarts` replaces `detectDecisionSceneBoundaries`. It asks one measured question per message: does this message cut to a new scene (another place or time, characters elsewhere, a `***` line or OOC POV note)? It asks in groups of 5, each after the 3 messages before it, with speaker names. It uses the backend's own threshold. Diagnostics rows are `scene_start` ("Scene start"). - Post-reply Decision check: each new message is asked as a start. A start at message index N ends the scene at message number N. When the first checked message cuts, that ending lands on the last message the previous check saw. The commit accepts endings from that message through the checked window. The checked window itself is unchanged (still the configured number of recent messages, per #6499). - `classify()` (history preparation) sends speakers and uses the new question and threshold. - **Re-scan scenes**: `POST …/advanced-memory/initialize` takes `range: {start, end}` (message numbers). The preparation run re-detects boundaries strictly inside the range, keeps every boundary outside it, and summarizes the scenes that changed. Unchanged summaries are reused. Classifier and reply-cadence checkpoints are left alone. Like Fix, it waits for running work instead of joining it. It is refused before history is prepared or for an out-of-range number. A hand-edited summary whose scene would change stops it with the existing review error. - UI: a **Re-scan scenes** box in Chat Settings → Memory Recall, pre-filled with the ongoing scene through the latest message. Six English keys. - Docs (`docs/agents/memory.md`) and CHANGELOG. Translations follow in #7372. Out of scope, possible follow-ups: when one turn adds more messages than the scene-check interval, the oldest unchecked ones are still never candidates. The Helper scene check (`SCENE_CHECK_PROMPT`) keeps its own seam blind spot. Both would change the "exactly N recent messages" behaviour chosen in #6499, so I left them for a decision. ## 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` Automated evidence (the boxes above are for a human): - `pnpm check` passed locally (localization, formatting, lint, types, full build). - `advanced-memory-decisions` regression: an unlikely cut (0.3) leaves the scene open. A 0.6 cut is selected on a 0.5 System One threshold; the old code required 0.8. The request carries the 3 earlier messages with speakers. A cut at the first checked message closes the scene on the previous check's last message (the seam). Re-scan splits a previously missed cut into its own summarized scene, keeps outside summaries byte-identical, keeps the boundary after the range, and leaves `sceneCheckMessageId` alone. An out-of-range number is refused. - `advanced-memory-post-generation` regression passes; its wording assertion now expects the cut question. - Existing assertions changed on purpose: the 0.8 threshold and "end" semantics they pinned are the bug. The custom backend stub gained the `calibration` every real backend has. ### Manual verification notes - Manually verify in the browser: Chat Settings → Memory Recall shows **Re-scan scenes** on a prepared chat, pre-filled with the ongoing scene's first message and the latest message. Check light and dark mode and a phone-width drawer. - Manually verify on the original chat (Decision on, TypeSafe Jev): Re-scan 1162–1261 splits it at about 1199, 1218, 1227, 1245 and 1250 and summarizes each closed scene. Expect a short extra scene where Maukie's blade-vision scores high (about 1259). - Manually verify a reply after that: Peek Prompt → Decision diagnostics shows **Scene start** rows, threshold 0.5. - Manually verify that a re-scan whose range covers a hand-edited summary with moving boundaries stops with the review error and leaves the archive intact. ## 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) Two CHANGELOG entries, a new docs section, follow-up #7372 for translations. ## UI evidence (if applicable) Not captured yet; see the manual checks above. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a **Re-scan scenes** control for rescanning a selected message range. Scenes outside the range remain unchanged, and rescanning stops if it would alter an edited summary. * **Improvements** * Scene detection now checks for scene starts using the three preceding messages and their authors as context. Uncertain boundaries remain open rather than being treated as confirmed. * Decision diagnostics now displays the scene-start answer. <!-- 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:41 +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#7704
No description provided.