[PR #8091] [MERGED] fix(mari): refuse sections in preset.update so the section order survives #8094

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8091
Author: @ylli-selmani
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @ylli-selmani

Base: staging ← Head: fix/mari-preset-update-sections


📝 Commits (2)

  • 32d290d fix(mari): refuse sections in preset.update so the order survives
  • fc26ae1 fix(mari): check the section_order alias for quoted ids

📊 Changes

3 files changed (+239 additions, -1 deletions)

View changed files

📝 packages/server/src/assets/mari-skills/presets.md (+1 -1)
📝 packages/server/src/services/mari-db/mari-db.service.ts (+60 -0)
➕ scripts/regressions/mari/preset-update-sections.regression.ts (+178 -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

No issue yet: a user hit this live with Professor Mari. An issue should be opened and linked before merge.

Why this change

  • Data loss in a user's preset. Professor Mari edited one section of a preset with preset.update and data.sections: [<that section>]. normalizePromptPresetChildInserts rebuilds sectionOrder from whatever sections are sent, so the preset was left with a one-section order. Every other section dropped out of the prompt while its row survived, so the editor still listed them and nothing looked wrong until the replies changed.
  • The same call sent the id as "\"YZuq…\"", a JSON-encoded id with literal quotes inside. Ids like that never match a real section, so the path wrote a new row instead of editing the existing one.
  • Mari's raw delete of a preset (or a lorebook) left the deleted id in library_folders.itemIds. #7977 added this cleanup to the HTTP routes and a startup prune; Mari's delete path didn't do it.

What changed

preset.update refuses sections (mari-db.service.ts)

  • sections / promptSections (top-level or inside data/patch) are refused before anything is planned. The refusal follows tool-error.ts: what was refused and what arrived, that nothing was changed, and the exact preset.updateSection / preset.addSection calls to make instead. A complete sectionOrder still reorders.
  • preset.create keeps taking sections: there's no existing order to lose when the preset is new.

Quoted section ids are refused

  • preset.create and preset.update refuse a section id (in sections or sectionOrder) that contains " or ', saying nothing was changed and to send the id exactly as preset.sections returns it.

Library folders are pruned on Mari's deletes

  • planDelete adds an update of each library_folders row that lists a deleted preset (scope presets) or lorebook (scope lorebooks). It's part of the same plan, so the review card shows it and Restore puts the id back. I used plan changes instead of #7977's removeItemReferences, because a direct write would happen outside Mari's journal and survive a Restore.
  • The task brief said Mari's lorebook delete already pruned folders. It didn't: nothing in mari-db.service.ts touched library_folders.itemIds. The fix covers both scopes, since it's the same few lines.

Handbook (mari-skills/presets.md)

  • The paragraph that told Mari to send sections through preset.update (with the complete sectionOrder) now says preset.update takes none and names addSection / updateSection / deleteSection.

Regression (scripts/regressions/mari/preset-update-sections.regression.ts)

  • Replays the live call (one section, quoted id, apply: true) and asserts the refusal, the unchanged three-section order, no new row and no review card. Also covers top-level promptSections, a quoted id in sectionOrder and on preset.create, that a complete sectionOrder still reorders, and that a raw preset/lorebook delete prunes only its own scope's folder and that Restore brings the id back.
  • Fails on staging without the fix (preset.update refuses sections).

Local CodeRabbit (two runs, 5 findings)

  • Fixed: the quote check missed the section_order alias that normalizePromptPresetActionData also reads. Also fixed: the handbook said to reorder with "every existing id", which would pull sections the user had left out of the order back in. It now says to rearrange the sectionOrder from preset.get.
  • Declined: prune folders in planTransform too. A transform is a raw script that can write library_folders itself, so a second planned update of the same row could conflict, and #7977's startup prune heals what a transform leaves.
  • Declined: include cascade-child (apply: false) lorebook deletes. No entry in CASCADES has lorebooks or prompt_presets as its child, so that case can't happen.
  • Declined for this PR (a separate decision): reject a sectionOrder that drops ids from the current order. Leaving a section out of the order is a documented way to keep it from being sent, so refusing it changes behavior beyond this fix. Listed as a follow-up.

Not changed, follow-up: the permanent prompt in workspace-agent.service.ts still says "preset.update with data.sections replaces sectionOrder unless you send the complete order". That file is being edited by the output-limit PR, so I left it alone. The refusal now points Mari at the right action anyway. Also, preset.update with groups rebuilds groupOrder the same way. groupOrder only drives the panel listing (not the prompt), so it isn't part of this fix. A sectionOrder that leaves ids out still drops those sections by design; whether preset.update should refuse a partial order is a separate 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

Agent-run, for reference: pnpm check, node ./scripts/run-regressions.mjs --filter scripts/regressions/mari and --filter scripts/regressions/professor-mari (results in the PR conversation).

Manual verification notes

  • Manually verify in the browser: ask Professor Mari to edit one section of a multi-section preset. She should use preset.updateSection (or recover to it after the refusal), and the preset editor should still list every section in its original order afterwards.
  • Manually verify in the browser: put a preset into a library folder, ask Mari to delete the preset, keep the change, and confirm the folder no longer lists it. Then restore the review card and confirm the preset is back in the folder.

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)

Only Mari's bundled handbook (packages/server/src/assets/mari-skills/presets.md) changed; nothing under docs/.

🤖 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/8091 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `fix/mari-preset-update-sections` --- ### 📝 Commits (2) - [`32d290d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/32d290d3155d29010cbb9425095d42b271dcfbb7) fix(mari): refuse sections in preset.update so the order survives - [`fc26ae1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fc26ae1de301842c160257406bcac72b4b4911c5) fix(mari): check the section_order alias for quoted ids ### 📊 Changes **3 files changed** (+239 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/assets/mari-skills/presets.md` (+1 -1) 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+60 -0) ➕ `scripts/regressions/mari/preset-update-sections.regression.ts` (+178 -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 No issue yet: a user hit this live with Professor Mari. An issue should be opened and linked before merge. ## Why this change - **Data loss in a user's preset.** Professor Mari edited one section of a preset with `preset.update` and `data.sections: [<that section>]`. `normalizePromptPresetChildInserts` rebuilds `sectionOrder` from whatever sections are sent, so the preset was left with a one-section order. Every other section dropped out of the prompt while its row survived, so the editor still listed them and nothing looked wrong until the replies changed. - The same call sent the id as `"\"YZuq…\""`, a JSON-encoded id with literal quotes inside. Ids like that never match a real section, so the path wrote a new row instead of editing the existing one. - Mari's raw delete of a preset (or a lorebook) left the deleted id in `library_folders.itemIds`. #7977 added this cleanup to the HTTP routes and a startup prune; Mari's delete path didn't do it. ## What changed **`preset.update` refuses sections** (`mari-db.service.ts`) - `sections` / `promptSections` (top-level or inside `data`/`patch`) are refused before anything is planned. The refusal follows `tool-error.ts`: what was refused and what arrived, that nothing was changed, and the exact `preset.updateSection` / `preset.addSection` calls to make instead. A complete `sectionOrder` still reorders. - `preset.create` keeps taking `sections`: there's no existing order to lose when the preset is new. **Quoted section ids are refused** - `preset.create` and `preset.update` refuse a section id (in `sections` or `sectionOrder`) that contains `"` or `'`, saying nothing was changed and to send the id exactly as `preset.sections` returns it. **Library folders are pruned on Mari's deletes** - `planDelete` adds an `update` of each `library_folders` row that lists a deleted preset (scope `presets`) or lorebook (scope `lorebooks`). It's part of the same plan, so the review card shows it and Restore puts the id back. I used plan changes instead of #7977's `removeItemReferences`, because a direct write would happen outside Mari's journal and survive a Restore. - The task brief said Mari's lorebook delete already pruned folders. It didn't: nothing in `mari-db.service.ts` touched `library_folders.itemIds`. The fix covers both scopes, since it's the same few lines. **Handbook** (`mari-skills/presets.md`) - The paragraph that told Mari to send sections through `preset.update` (with the complete `sectionOrder`) now says `preset.update` takes none and names `addSection` / `updateSection` / `deleteSection`. **Regression** (`scripts/regressions/mari/preset-update-sections.regression.ts`) - Replays the live call (one section, quoted id, `apply: true`) and asserts the refusal, the unchanged three-section order, no new row and no review card. Also covers top-level `promptSections`, a quoted id in `sectionOrder` and on `preset.create`, that a complete `sectionOrder` still reorders, and that a raw preset/lorebook delete prunes only its own scope's folder and that Restore brings the id back. - Fails on `staging` without the fix (`preset.update refuses sections`). **Local CodeRabbit** (two runs, 5 findings) - Fixed: the quote check missed the `section_order` alias that `normalizePromptPresetActionData` also reads. Also fixed: the handbook said to reorder with "every existing id", which would pull sections the user had left out of the order back in. It now says to rearrange the `sectionOrder` from `preset.get`. - Declined: prune folders in `planTransform` too. A transform is a raw script that can write `library_folders` itself, so a second planned update of the same row could conflict, and #7977's startup prune heals what a transform leaves. - Declined: include cascade-child (`apply: false`) lorebook deletes. No entry in `CASCADES` has `lorebooks` or `prompt_presets` as its child, so that case can't happen. - Declined for this PR (a separate decision): reject a `sectionOrder` that drops ids from the current order. Leaving a section out of the order is a documented way to keep it from being sent, so refusing it changes behavior beyond this fix. Listed as a follow-up. **Not changed, follow-up:** the permanent prompt in `workspace-agent.service.ts` still says "`preset.update` with `data.sections` replaces `sectionOrder` unless you send the complete order". That file is being edited by the output-limit PR, so I left it alone. The refusal now points Mari at the right action anyway. Also, `preset.update` with `groups` rebuilds `groupOrder` the same way. `groupOrder` only drives the panel listing (not the prompt), so it isn't part of this fix. A `sectionOrder` that leaves ids out still drops those sections by design; whether `preset.update` should refuse a partial order is a separate 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` Agent-run, for reference: `pnpm check`, `node ./scripts/run-regressions.mjs --filter scripts/regressions/mari` and `--filter scripts/regressions/professor-mari` (results in the PR conversation). ### Manual verification notes - Manually verify in the browser: ask Professor Mari to edit one section of a multi-section preset. She should use `preset.updateSection` (or recover to it after the refusal), and the preset editor should still list every section in its original order afterwards. - Manually verify in the browser: put a preset into a library folder, ask Mari to delete the preset, keep the change, and confirm the folder no longer lists it. Then restore the review card and confirm the preset is back in the folder. ## 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) Only Mari's bundled handbook (`packages/server/src/assets/mari-skills/presets.md`) changed; nothing under `docs/`. 🤖 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 2026-10-24 04:10:20 +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#8094
No description provided.