[PR #4825] [MERGED] fix(mari-db): route Professor Mari creates through Keep/Restore review (#4813, Thread B part 1) #6508

Closed
opened 2026-10-23 04:11:05 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4825
Author: @kolacheee
Created: 8/9/2026
Status: ✅ Merged
Merged: 8/9/2026
Merged by: @kolacheee

Base: staging ← Head: fix/4813-mari-safe-creates


📝 Commits (2)

  • b960878 fix(mari-db): route Professor Mari creates through Keep/Restore review (#4813)
  • 6c3ce3b Merge branch 'staging' into fix/4813-mari-safe-creates

📊 Changes

4 files changed (+181 additions, -37 deletions)

View changed files

📝 packages/client/src/components/chat/HomeProfessorMariChat.tsx (+40 -0)
📝 packages/client/src/localization/locales/en.json (+4 -0)
📝 packages/server/src/services/mari-db/mari-db.service.ts (+9 -37)
📝 scripts/regressions/open-issues.regression.ts (+128 -0)

📄 Description

Linked issue

Refs #4813 (the approval-architecture half — "Thread B", part 1 of 2).

Why this change

The prompt guardrail already merged (#4816) makes Professor Mari less eager to modify things she was only asked to inspect. But #4813 has a second, more serious half: even when a change is genuinely unwanted, the approval flow could not stop it.

Every workspace-Mari *.create action — character, persona, lorebook, lorebook entry, theme, personal-extension draft, agent, and preset — was issued with requiresApproval: false. That routed it down a branch that writes to disk immediately with no review card and no in-chat undo. So a creation Mari made on her own (the exact complaint in #4813) landed silently, and the only recovery was restoring from a backup. Edits and deletes, by contrast, already produced a Keep/Restore review card.

There was also a latent data-loss vector: planInsert recorded beforeRaw: null unconditionally, so a create whose id collided with an existing row would overwrite that row, and a later Restore would then delete the original too.

What changed

Server (packages/server/src/services/mari-db/mari-db.service.ts):

  • Creates now flow through the same Keep/Restore review as edits and deletes. Removed requiresApproval: false from all 8 *.create sites, so executeMutation takes the review branch (createAppliedReview) and returns a pending approval. The change is still applied immediately (apply-with-undo), but it is now undoable in chat: Restore deletes exactly the rows the create added, and restorePlan already reverses inserts in FK-safe order (children before parents), so a multi-row create like a lorebook plus its entries restores cleanly. This also brings non-activating theme.create into review (activating themes already reviewed).
  • planInsert clobber guard. A create whose primary-key row already exists is now refused with a clear error instead of overwriting it. An insert records beforeRaw: null, so a colliding overwrite followed by Restore would have deleted the original too. (theme-create runs through planThemeCreate, which already blocks a colliding id with a validation error.)
  • Removed the now-dead requiresApproval escape hatch. With every create routed through review, nothing set requiresApproval: false anymore, leaving executeMutation's approval-free apply branch unreachable. Removed the branch and the ParsedMutationRequest.requiresApproval field so there is no dormant way to apply a managed mutation without a review card.

Client (packages/client/src/components/chat/HomeProfessorMariChat.tsx, localization/locales/en.json):

  • The Keep/Restore card gains a create-specific block (mirroring the existing delete block) that explains Restore removes what Mari just created. New UI copy added to the English locale via the standard migration; community locales fall back to English.

Tests (scripts/regressions/open-issues.regression.ts):

  • Asserts a create routes to a pending review and is readable while pending; Restore deletes a single-row create and a multi-row (lorebook + entry) create; Keep persists it; the clobber guard refuses a colliding id and leaves the pre-existing row intact; and a non-activating theme.create still reviews.

This is part 1 of the Thread-B fix. Part 2 (a follow-up PR) makes the Keep/Restore undo itself durable — today the pending review lives only in memory and is dropped after ten minutes or on restart.

Known limitation (deferred)

The clobber guard covers the parent row of a create. Related child inserts (a preset's sections and choice blocks, built by planRelatedInserts) are not yet guarded, so a preset.create that reuses an existing section/choice-block id could still overwrite it. Lorebook entries are unaffected because they always allocate fresh ids. This is a narrow, preset-specific gap and is being folded into the preset-focused fix for #4812 rather than widened here.

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

Manual verification notes

  • pnpm check (TypeScript + ESLint + localization + build) passes.
  • pnpm regression:issues open-issues lane passes, including the new create-review assertions above.
  • Manually verify in browser: in the Home Professor Mari chat, have Mari create something (a character, a lorebook, a theme). Confirm a Keep/Restore card now appears with the "Mari created new items" block, that Restore removes the created item (and, for a lorebook, its entries), and that Keep leaves it in place. Confirm in light + dark mode.
  • Note: capability-package-lifecycle.regression.ts currently fails on staging for an unrelated reason (it expects capability minor 8 but the tree is at minor 9); it is not touched by this PR.

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)

No docs/ changes and no version bump. New user-facing UI copy is added to the canonical English locale; community locales fall back to English per the project convention.

Summary by CodeRabbit

  • New Features

    • Database approval cards now identify newly created records by name or title.
    • Added previews of up to three created items, with indicators for additional or potentially omitted items.
    • Clarified how Keep and Restore affect newly created records.
  • Bug Fixes

    • All newly created records now enter the review flow consistently.
    • Prevented duplicate creations from overwriting existing records.
    • Restoring newly created records removes them correctly and clears the associated review.

🔄 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/4825 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/9/2026 **Status:** ✅ Merged **Merged:** 8/9/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/4813-mari-safe-creates` --- ### 📝 Commits (2) - [`b960878`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b960878422f62814c5a01526d0e60e8d73c638f4) fix(mari-db): route Professor Mari creates through Keep/Restore review (#4813) - [`6c3ce3b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6c3ce3b9ba0a1ab80320b8267cadfb7957d3d39d) Merge branch 'staging' into fix/4813-mari-safe-creates ### 📊 Changes **4 files changed** (+181 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/HomeProfessorMariChat.tsx` (+40 -0) 📝 `packages/client/src/localization/locales/en.json` (+4 -0) 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+9 -37) 📝 `scripts/regressions/open-issues.regression.ts` (+128 -0) </details> ### 📄 Description ## Linked issue Refs #4813 (the approval-architecture half — "Thread B", part 1 of 2). ## Why this change The prompt guardrail already merged (#4816) makes Professor Mari less eager to modify things she was only asked to inspect. But #4813 has a second, more serious half: even when a change is genuinely unwanted, the approval flow could not stop it. Every workspace-Mari `*.create` action — character, persona, lorebook, lorebook entry, theme, personal-extension draft, agent, and preset — was issued with `requiresApproval: false`. That routed it down a branch that **writes to disk immediately with no review card and no in-chat undo**. So a creation Mari made on her own (the exact complaint in #4813) landed silently, and the only recovery was restoring from a backup. Edits and deletes, by contrast, already produced a Keep/Restore review card. There was also a latent data-loss vector: `planInsert` recorded `beforeRaw: null` unconditionally, so a create whose id collided with an existing row would **overwrite** that row, and a later Restore would then delete the original too. ## What changed Server (`packages/server/src/services/mari-db/mari-db.service.ts`): - **Creates now flow through the same Keep/Restore review as edits and deletes.** Removed `requiresApproval: false` from all 8 `*.create` sites, so `executeMutation` takes the review branch (`createAppliedReview`) and returns a `pending` approval. The change is still applied immediately (apply-with-undo), but it is now undoable in chat: Restore deletes exactly the rows the create added, and `restorePlan` already reverses inserts in FK-safe order (children before parents), so a multi-row create like a lorebook plus its entries restores cleanly. This also brings non-activating `theme.create` into review (activating themes already reviewed). - **`planInsert` clobber guard.** A create whose primary-key row already exists is now refused with a clear error instead of overwriting it. An insert records `beforeRaw: null`, so a colliding overwrite followed by Restore would have deleted the original too. (`theme-create` runs through `planThemeCreate`, which already blocks a colliding id with a validation error.) - **Removed the now-dead `requiresApproval` escape hatch.** With every create routed through review, nothing set `requiresApproval: false` anymore, leaving `executeMutation`'s approval-free apply branch unreachable. Removed the branch and the `ParsedMutationRequest.requiresApproval` field so there is no dormant way to apply a managed mutation without a review card. Client (`packages/client/src/components/chat/HomeProfessorMariChat.tsx`, `localization/locales/en.json`): - The Keep/Restore card gains a create-specific block (mirroring the existing delete block) that explains Restore removes what Mari just created. New UI copy added to the English locale via the standard migration; community locales fall back to English. Tests (`scripts/regressions/open-issues.regression.ts`): - Asserts a create routes to a `pending` review and is readable while pending; Restore deletes a single-row create and a multi-row (lorebook + entry) create; Keep persists it; the clobber guard refuses a colliding id and leaves the pre-existing row intact; and a non-activating `theme.create` still reviews. This is part 1 of the Thread-B fix. Part 2 (a follow-up PR) makes the Keep/Restore undo itself durable — today the pending review lives only in memory and is dropped after ten minutes or on restart. ### Known limitation (deferred) The clobber guard covers the parent row of a create. Related **child** inserts (a preset's sections and choice blocks, built by `planRelatedInserts`) are not yet guarded, so a `preset.create` that reuses an existing section/choice-block id could still overwrite it. Lorebook entries are unaffected because they always allocate fresh ids. This is a narrow, preset-specific gap and is being folded into the preset-focused fix for #4812 rather than widened here. ## Validation - [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` ### Manual verification notes - `pnpm check` (TypeScript + ESLint + localization + build) passes. - `pnpm regression:issues` open-issues lane passes, including the new create-review assertions above. - **Manually verify in browser:** in the Home Professor Mari chat, have Mari create something (a character, a lorebook, a theme). Confirm a **Keep/Restore card** now appears with the "Mari created new items" block, that **Restore removes** the created item (and, for a lorebook, its entries), and that **Keep** leaves it in place. Confirm in light + dark mode. - Note: `capability-package-lifecycle.regression.ts` currently fails on `staging` for an unrelated reason (it expects capability minor 8 but the tree is at minor 9); it is not touched by this PR. ## Docs and release impact - [x] 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) No `docs/` changes and no version bump. New user-facing UI copy is added to the canonical English locale; community locales fall back to English per the project convention. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Database approval cards now identify newly created records by name or title. * Added previews of up to three created items, with indicators for additional or potentially omitted items. * Clarified how Keep and Restore affect newly created records. * **Bug Fixes** * All newly created records now enter the review flow consistently. * Prevented duplicate creations from overwriting existing records. * Restoring newly created records removes them correctly and clears the associated review. <!-- 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-23 04:11:05 +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#6508
No description provided.