[PR #8007] [MERGED] fix(scene): start from the starred Roleplay profile, repair loose planner JSON, write the opening in the right voice #8052

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

📋 Pull Request Information

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

Base: staging ← Head: fix/scene-chat-fixes


📝 Commits (10+)

  • 530f456 fix(scene): a new Scene starts from the starred Roleplay settings profile
  • da84426 fix(scene): the opening follows the starred profile's writing rules
  • 0396f6e fix(scene): repair slightly broken JSON from the scene planner
  • c2658eb fix(json): repair dialogue quotes inside one-line JSON string values
  • 01bcbd0 fix(json): escape dialogue quotes before jsonrepair, only on invalid lines
  • 30b03ad style: format the JSON repair and scene regression
  • b80bbff fix(scene): the opening message is written in its poster's voice
  • 4c6adad fix(scene): quote spoken words in the opening, and post the description as narration
  • 378cbc5 fix(scene): write the opening for the scene's group mode
  • f7ae393 test(scene): check the starred profile after the opening-speaker cases

📊 Changes

6 files changed (+616 additions, -32 deletions)

View changed files

📝 docs/roleplay/scenes.md (+7 -1)
📝 packages/client/src/lib/scene-generation.ts (+2 -0)
📝 packages/server/src/lib/json-repair.ts (+128 -1)
📝 packages/server/src/routes/scene.routes.ts (+126 -30)
📝 packages/shared/src/types/scene.ts (+2 -0)
📝 scripts/regressions/scene-participants.regression.ts (+351 -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

Closes #8006
@SpicyMarinara

Why this change

  • A Scene is a new Roleplay chat, but it never got the starred Roleplay settings profile that every other new Roleplay chat gets, and its opening was planned with a different prompt preset than the scene then used.
  • Plan Scene failed with "Model didn't return valid JSON" on small JSON slips that the rest of the app already repairs.
  • The opening message could be written in the wrong character's voice, with the scene description glued onto its front.

What changed

The starred Roleplay profile

  • /scene/create applies the starred Roleplay settings profile before writing the scene's own settings, as a new Roleplay chat does. The connection is the one the request named, else the profile's, else the Conversation's; a prompt preset picked for the scene stays; scene settings, background and lorebooks go on top. The built-in Default profile is left out, as it is for new chats.
  • With no preset picked, the scene planner applies the starred profile's prompt preset (its writing sections, with that preset's default choices), so the opening follows the same writing rules as every reply after it.

Broken JSON from the planner

  • The planner uses the shared tryParseJsonRecord (jsonrepair), as agents, memory and summaries do, instead of two regex repairs. It still fails clearly when nothing can be read.
  • The shared repairJsonText keeps jsonrepair's reading first, as before, unless it holds a key that was never a quoted key in the model's text (keys are collected once and decoded as JSON reads them): that is how jsonrepair mangles dialogue quotes inside a value ("So. You came back.", The librarian smiles. "Again?" becomes a The librarian smiles. key). Only then does it escape the quotes inside each "key": "value" of a line that isn't valid on its own, splitting a line with several properties at each , "key": first. Every caller of tryParseJsonRecord / repairJsonText gets this, and only for text that failed to parse. Dialogue that itself holds , "key": "value" can't be told from a property, so there jsonrepair's reading stands.

The opening message

  • The plan request takes initiatorCharId. The planner is told the opening character by name and to write only as them, and a cast the model picks always keeps that character, so /scene/create credits the same one.
  • In a group scene in merged mode (the default), the opening is written by one narrating voice for every character; in Individual mode it stays the opening character's own. The mode is the starred Roleplay profile's, else merged.
  • Words spoken aloud go in double quotes, with narration, actions and thoughts outside them, unless the scene's writing instructions set another dialogue style.
  • The scene description is its own narrator message after the participation guide, instead of the start of the opening. The guide and the description are marked (extra.sceneParticipationGuide, extra.sceneDescriptionMessage), so a scene fork that leaves the guide out drops exactly it, even in a scene that had none; scenes made before keep the old rule.

Docs: docs/roleplay/scenes.md (leaving Prompt preset on None uses the starred profile's preset; what the new scene starts from and how its opening is written).

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 runs on 2026-10-21 on staging 5e7468ab4, Node 24.21.0:

  • pnpm check: passes. Its one lint warning, in HomeProfessorMariChat.tsx, is not from this PR.
  • pnpm localization:check: passes.
  • scene-participants, through the real routes with a fake model: the starred profile applied to a new scene with its own settings and connection; its writing rules in the planner prompt; plans from JSON with an unquoted key, single quotes and a trailing comma, and with unescaped dialogue quotes (kept as text); two properties on one valid line kept apart; the opening character named in the planner prompt and kept in a model-picked cast; the quote rule; the opening as only the character's text with the guide and description as separate narrator messages; a fork without the guide; Individual and merged group modes. Five of the fix commits record that their check fails without the fix.
  • Full pnpm regression on f7ae3938f: 960/960 pass. The two later commits (docs, and the description marker below) were checked with scene-participants and a server type check.
  • Local CodeRabbit (CLI) on the whole branch: 1 finding, fixed in bb05b61be: a scene whose plan had no participation guide lost its description in a fork without the guide, because nothing was marked and the old "first narrator message" rule took the description. The description is now marked too (extra.sceneDescriptionMessage); scene-participants covers it and fails without the fix. A review of the docs and that fix: 0 findings.
  • Not run: pnpm smoke:ui and pnpm regression:ui (no client UI changes beyond the plan request's new field).

Manual verification notes

  • Manually verify a scene from a Conversation chat picks up the starred Roleplay profile's settings (for example its Illustrator interval or connection).
  • Manually verify that with Prompt preset on None, the opening follows the starred profile's writing rules (POV, tense, dialogue style).
  • Manually verify a two-character scene opened by the second character: in Individual mode the opening is that character's own; in merged mode it is one narrating voice.
  • Manually verify the scene description shows as its own narrator message before the opening.
  • Manually verify Plan Scene with a model that writes loose JSON now plans the scene.

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)

English docs updated: docs/roleplay/scenes.md. Translations: #8008

UI evidence (if applicable)

No UI changes.

🤖 Generated with Claude Code


🔄 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/8007 **Author:** [@JamesMowery](https://github.com/JamesMowery) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/scene-chat-fixes` --- ### 📝 Commits (10+) - [`530f456`](https://github.com/Pasta-Devs/Marinara-Engine/commit/530f456367fc6709763a7b7678f7b3d35d6f0da4) fix(scene): a new Scene starts from the starred Roleplay settings profile - [`da84426`](https://github.com/Pasta-Devs/Marinara-Engine/commit/da8442614707d2a2a152a2f1ba5515258b4b1a00) fix(scene): the opening follows the starred profile's writing rules - [`0396f6e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0396f6ed3cf4c938d49bac9cc457506fb04454c8) fix(scene): repair slightly broken JSON from the scene planner - [`c2658eb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c2658eb5a698659c5dc4212c6ffcced2a4df6b7d) fix(json): repair dialogue quotes inside one-line JSON string values - [`01bcbd0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/01bcbd0702affb8653bbd194e64be743d8b1f61b) fix(json): escape dialogue quotes before jsonrepair, only on invalid lines - [`30b03ad`](https://github.com/Pasta-Devs/Marinara-Engine/commit/30b03add2893d9a306e0fc05f02c13926b316cb3) style: format the JSON repair and scene regression - [`b80bbff`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b80bbff9fa82cdb6b55c708d20eee1da379fb682) fix(scene): the opening message is written in its poster's voice - [`4c6adad`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4c6adad0e75f5a3202c1ffbb97b5d24587fe2a9d) fix(scene): quote spoken words in the opening, and post the description as narration - [`378cbc5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/378cbc5a47438c1f5c270ba61bc2ccf571191caf) fix(scene): write the opening for the scene's group mode - [`f7ae393`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f7ae3938fd310bfe288ed55e820d6801a718d998) test(scene): check the starred profile after the opening-speaker cases ### 📊 Changes **6 files changed** (+616 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `docs/roleplay/scenes.md` (+7 -1) 📝 `packages/client/src/lib/scene-generation.ts` (+2 -0) 📝 `packages/server/src/lib/json-repair.ts` (+128 -1) 📝 `packages/server/src/routes/scene.routes.ts` (+126 -30) 📝 `packages/shared/src/types/scene.ts` (+2 -0) 📝 `scripts/regressions/scene-participants.regression.ts` (+351 -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`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #8006 @SpicyMarinara ## Why this change - A Scene is a new Roleplay chat, but it never got the starred Roleplay settings profile that every other new Roleplay chat gets, and its opening was planned with a different prompt preset than the scene then used. - **Plan Scene** failed with "Model didn't return valid JSON" on small JSON slips that the rest of the app already repairs. - The opening message could be written in the wrong character's voice, with the scene description glued onto its front. ## What changed **The starred Roleplay profile** - `/scene/create` applies the starred Roleplay settings profile before writing the scene's own settings, as a new Roleplay chat does. The connection is the one the request named, else the profile's, else the Conversation's; a prompt preset picked for the scene stays; scene settings, background and lorebooks go on top. The built-in Default profile is left out, as it is for new chats. - With no preset picked, the scene planner applies the starred profile's prompt preset (its writing sections, with that preset's default choices), so the opening follows the same writing rules as every reply after it. **Broken JSON from the planner** - The planner uses the shared `tryParseJsonRecord` (jsonrepair), as agents, memory and summaries do, instead of two regex repairs. It still fails clearly when nothing can be read. - The shared `repairJsonText` keeps `jsonrepair`'s reading first, as before, unless it holds a key that was never a quoted key in the model's text (keys are collected once and decoded as JSON reads them): that is how `jsonrepair` mangles dialogue quotes inside a value (`"So. You came back.", The librarian smiles. "Again?"` becomes a `The librarian smiles.` key). Only then does it escape the quotes inside each `"key": "value"` of a line that isn't valid on its own, splitting a line with several properties at each `, "key":` first. Every caller of `tryParseJsonRecord` / `repairJsonText` gets this, and only for text that failed to parse. Dialogue that itself holds `, "key": "value"` can't be told from a property, so there `jsonrepair`'s reading stands. **The opening message** - The plan request takes `initiatorCharId`. The planner is told the opening character by name and to write only as them, and a cast the model picks always keeps that character, so `/scene/create` credits the same one. - In a group scene in merged mode (the default), the opening is written by one narrating voice for every character; in Individual mode it stays the opening character's own. The mode is the starred Roleplay profile's, else merged. - Words spoken aloud go in double quotes, with narration, actions and thoughts outside them, unless the scene's writing instructions set another dialogue style. - The scene description is its own narrator message after the participation guide, instead of the start of the opening. The guide and the description are marked (`extra.sceneParticipationGuide`, `extra.sceneDescriptionMessage`), so a scene fork that leaves the guide out drops exactly it, even in a scene that had none; scenes made before keep the old rule. **Docs**: `docs/roleplay/scenes.md` (leaving **Prompt preset** on **None** uses the starred profile's preset; what the new scene starts from and how its opening is written). ## Validation <!-- Required: include commands run and/or manual checks performed --> - [x] `pnpm check` passes locally - [x] 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` Automated runs on 2026-10-21 on `staging` `5e7468ab4`, Node 24.21.0: - `pnpm check`: passes. Its one lint warning, in `HomeProfessorMariChat.tsx`, is not from this PR. - `pnpm localization:check`: passes. - `scene-participants`, through the real routes with a fake model: the starred profile applied to a new scene with its own settings and connection; its writing rules in the planner prompt; plans from JSON with an unquoted key, single quotes and a trailing comma, and with unescaped dialogue quotes (kept as text); two properties on one valid line kept apart; the opening character named in the planner prompt and kept in a model-picked cast; the quote rule; the opening as only the character's text with the guide and description as separate narrator messages; a fork without the guide; Individual and merged group modes. Five of the fix commits record that their check fails without the fix. - Full `pnpm regression` on `f7ae3938f`: 960/960 pass. The two later commits (docs, and the description marker below) were checked with `scene-participants` and a server type check. - Local CodeRabbit (CLI) on the whole branch: 1 finding, fixed in `bb05b61be`: a scene whose plan had no participation guide lost its description in a fork without the guide, because nothing was marked and the old "first narrator message" rule took the description. The description is now marked too (`extra.sceneDescriptionMessage`); `scene-participants` covers it and fails without the fix. A review of the docs and that fix: 0 findings. - Not run: `pnpm smoke:ui` and `pnpm regression:ui` (no client UI changes beyond the plan request's new field). ### Manual verification notes - Manually verify a scene from a Conversation chat picks up the starred Roleplay profile's settings (for example its Illustrator interval or connection). - Manually verify that with **Prompt preset** on **None**, the opening follows the starred profile's writing rules (POV, tense, dialogue style). - Manually verify a two-character scene opened by the second character: in Individual mode the opening is that character's own; in merged mode it is one narrating voice. - Manually verify the scene description shows as its own narrator message before the opening. - Manually verify **Plan Scene** with a model that writes loose JSON now plans the scene. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README) as needed - [x] 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) English docs updated: `docs/roleplay/scenes.md`. Translations: #8008 ## UI evidence (if applicable) No UI changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi changed title from [PR #8007] fix(scene): start from the starred Roleplay profile, repair loose planner JSON, write the opening in the right voice to [PR #8007] [MERGED] fix(scene): start from the starred Roleplay profile, repair loose planner JSON, write the opening in the right voice 2026-10-25 04:03:44 +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#8052
No description provided.