[PR #4828] [MERGED] feat(mari-db): make Professor Mari's Keep/Restore undo durable (#4813, Thread B part 2) #6509

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/4828
Author: @kolacheee
Created: 8/9/2026
Status: ✅ Merged
Merged: 8/9/2026
Merged by: @kolacheee

Base: staging ← Head: fix/4813-mari-durable-review


📝 Commits (1)

  • 4f48564 feat(mari-db): make Professor Mari's Keep/Restore undo durable (#4813)

📊 Changes

3 files changed (+466 additions, -16 deletions)

View changed files

📝 package.json (+2 -1)
📝 packages/server/src/services/mari-db/mari-db.service.ts (+155 -15)
➕ scripts/regressions/mari-db-review-durability.regression.ts (+309 -0)

📄 Description

Part 2 of 2 of the #4813 Thread-B fix. Part 1 (#4825, "make Mari's creates safe") is merged; this branch is rebased onto staging, so the diff below is just the durability change.

Linked issue

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

Why this change

Part 1 (#4825) routes Professor Mari's creates through the same Keep/Restore review as edits and deletes, so an unwanted create is undoable in chat. But the undo itself was never durable: the pending review lived only in an in-memory Map with a 10-minute self-evicting timer. So an applied change quietly became permanent after ten minutes, or the moment the process restarted — exactly the "I couldn't undo it" failure mode behind #4813. A backup was still the only recovery.

What changed

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

  • Persist each pending review to a sidecar at journal/pending/<id>.json when it is created, and rehydrate the set lazily on first access, so a fresh process recovers every outstanding Keep/Restore card. Keep and Restore delete the sidecar when they resolve.
  • Removed the 10-minute self-evicting timer. Reviews no longer vanish on their own. Instead they are pruned by a retention deadline (14 days) when the set is loaded, and the set is capped at PENDING_REVIEW_LIMIT (mirrors HISTORY_LIMIT = 50) so it can't grow without bound. The oldest review past the cap loses its undo — its change stays applied — and that is logged rather than silent. Eviction uses the Map's insertion order, so the review that was just created is never the one dropped.
  • Sidecar writes and prunes degrade gracefully: a failed write logs a warning and the change still applies (only cross-restart durability is lost); an unreadable or foreign sidecar is discarded on load. Rehydration runs on the synchronous approvals path, so it is written to never throw — one locked or corrupt file (Windows file locks / AV) can't 500 the endpoint or wipe the loaded set, and the successfully-loaded reviews are kept even if a later prune fails.

Behavioral note (intended, worth a glance)

Because reviews are now durable, a pending Keep/Restore card — and the "Professor Mari needs your approval" notification the client fires for an unseen approval — reappears after a restart for any change still within the retention window. That is the feature working: the undo survives the restart. Two consequences worth a conscious call:

  • On a restart with several outstanding reviews, several cards (and their notifications) re-materialize at once. If that proves noisy, suppressing the notification for reviews already present at load is a small client-side follow-up (not included here).
  • clearHistory() clears the history log only; it deliberately does not discard live pending undos, since those are unresolved state a user did not ask to drop.

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.
  • New regression pnpm regression:mari-review-durability passes: it drives the real MariDbService against a file-native store and asserts a create's review persists to a sidecar, a fresh service instance (a simulated restart) rehydrates it, Restore and Keep still work after the restart and remove the sidecar, an expired sidecar is pruned on load, and the persisted set is capped. Also wired into the regression:issues lane.
  • pnpm regression:issues open-issues lane (part 1's create-review assertions) still passes with these changes.
  • Manually verify in browser: have Mari apply a change, confirm the Keep/Restore card appears, restart the server, and confirm the card is still present and Restore still reverts the change.
  • Note: capability-package-lifecycle.regression.ts fails on staging for an unrelated, pre-existing reason (tracked in #4824); 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)

Server-internal behavior change; no docs/ changes and no version bump. The on-disk sidecars live under the existing journal/ directory.

Summary by CodeRabbit

  • New Features

    • Pending reviews now persist across service restarts.
    • Review records automatically expire and are limited to 50 stored items.
    • Keeping or restoring a review removes its saved pending record.
    • Applied changes remain intact when older reviews are removed.
  • Bug Fixes

    • Improved recovery of pending reviews after interruptions, including update reviews.
    • Invalid or expired saved review records are automatically discarded.
  • Tests

    • Added regression coverage for persistence, expiration, capacity limits, and review recovery.

🔄 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/4828 **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-durable-review` --- ### 📝 Commits (1) - [`4f48564`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4f4856489470566b4e96b2328a5d155bbef9adbe) feat(mari-db): make Professor Mari's Keep/Restore undo durable (#4813) ### 📊 Changes **3 files changed** (+466 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `package.json` (+2 -1) 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+155 -15) ➕ `scripts/regressions/mari-db-review-durability.regression.ts` (+309 -0) </details> ### 📄 Description > **Part 2 of 2 of the #4813 Thread-B fix.** Part 1 (#4825, "make Mari's creates safe") is merged; this branch is rebased onto `staging`, so the diff below is just the durability change. ## Linked issue Refs #4813 (the approval-architecture half — "Thread B", part 2 of 2). ## Why this change Part 1 (#4825) routes Professor Mari's creates through the same Keep/Restore review as edits and deletes, so an unwanted create is undoable in chat. But the undo itself was never durable: the pending review lived only in an in-memory Map with a **10-minute self-evicting timer**. So an applied change quietly became permanent after ten minutes, or the moment the process restarted — exactly the "I couldn't undo it" failure mode behind #4813. A backup was still the only recovery. ## What changed Server-only (`packages/server/src/services/mari-db/mari-db.service.ts`): - **Persist each pending review to a sidecar** at `journal/pending/<id>.json` when it is created, and **rehydrate the set lazily** on first access, so a fresh process recovers every outstanding Keep/Restore card. Keep and Restore delete the sidecar when they resolve. - **Removed the 10-minute self-evicting timer.** Reviews no longer vanish on their own. Instead they are pruned by a **retention deadline** (14 days) when the set is loaded, and the set is **capped** at `PENDING_REVIEW_LIMIT` (mirrors `HISTORY_LIMIT` = 50) so it can't grow without bound. The oldest review past the cap loses its undo — its change stays applied — and that is logged rather than silent. Eviction uses the Map's insertion order, so the review that was just created is never the one dropped. - Sidecar writes and prunes degrade gracefully: a failed write logs a warning and the change still applies (only cross-restart durability is lost); an unreadable or foreign sidecar is discarded on load. Rehydration runs on the synchronous approvals path, so it is written to **never throw** — one locked or corrupt file (Windows file locks / AV) can't 500 the endpoint or wipe the loaded set, and the successfully-loaded reviews are kept even if a later prune fails. ### Behavioral note (intended, worth a glance) Because reviews are now durable, a pending Keep/Restore card — and the "Professor Mari needs your approval" notification the client fires for an unseen approval — **reappears after a restart** for any change still within the retention window. That is the feature working: the undo survives the restart. Two consequences worth a conscious call: - On a restart with several outstanding reviews, several cards (and their notifications) re-materialize at once. If that proves noisy, suppressing the notification for reviews already present at load is a small client-side follow-up (not included here). - `clearHistory()` clears the history log only; it deliberately does **not** discard live pending undos, since those are unresolved state a user did not ask to drop. ## 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. - New regression `pnpm regression:mari-review-durability` passes: it drives the real `MariDbService` against a file-native store and asserts a create's review persists to a sidecar, a fresh service instance (a simulated restart) rehydrates it, Restore and Keep still work after the restart and remove the sidecar, an expired sidecar is pruned on load, and the persisted set is capped. Also wired into the `regression:issues` lane. - `pnpm regression:issues` open-issues lane (part 1's create-review assertions) still passes with these changes. - **Manually verify in browser:** have Mari apply a change, confirm the Keep/Restore card appears, **restart the server**, and confirm the card is still present and Restore still reverts the change. - Note: `capability-package-lifecycle.regression.ts` fails on `staging` for an unrelated, pre-existing reason (tracked in #4824); 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) Server-internal behavior change; no `docs/` changes and no version bump. The on-disk sidecars live under the existing `journal/` directory. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Pending reviews now persist across service restarts. * Review records automatically expire and are limited to 50 stored items. * Keeping or restoring a review removes its saved pending record. * Applied changes remain intact when older reviews are removed. * **Bug Fixes** * Improved recovery of pending reviews after interruptions, including update reviews. * Invalid or expired saved review records are automatically discarded. * **Tests** * Added regression coverage for persistence, expiration, capacity limits, and review recovery. <!-- 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#6509
No description provided.