[PR #2115] [MERGED] Fix storage deletion & cleanup correctness #5443

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2115
Author: @kolacheee
Created: 6/4/2026
Status: ✅ Merged
Merged: 6/4/2026
Merged by: @Xelvanis

Base: refactor ← Head: fix/storage-deletion-correctness


📝 Commits (3)

  • 63acd16 Ignore local .pnpm-store/ and per-user .claude settings
  • b7a1e03 Fix storage deletion & cleanup correctness (#2114)
  • 58c2e8d Revert stale swipe-cleanup change; add avatarPath regression test

📊 Changes

3 files changed (+151 additions, -6 deletions)

View changed files

📝 .gitignore (+4 -0)
📝 src-tauri/src/commands/storage/avatars.rs (+76 -4)
📝 src-tauri/src/commands/storage/chats.rs (+71 -2)

📄 Description

Linked issue

Closes #2114

Why this change

  • Bunny Review surfaced four storage-layer correctness findings (1 HIGH, 3 MEDIUM) while scanning #1812. Two are verified and fixed here — the HIGH (bulk_delete_messages could delete messages belonging to a different chat) and one MEDIUM (persona-avatar reference detection missed avatarPath). The other two were investigated and found not to hold for the actual code paths, and are left unchanged with the reasoning recorded below.

What changed

  • (HIGH) chats.rs bulk_delete_messages — the pre-scan only confirmed each id exists, never that it belongs to chat_id, so a caller passing message ids from another chat would destroy them (and their swipe sidecars). Now filtered by chatId == chat_id (mirrors the existing gallery-cleanup pattern). Regression test added.
  • (MEDIUM) avatars.rs — the "is this persona avatar still referenced by a message snapshot?" scan only inspected snapshot.avatarUrl. A snapshot referencing the avatar via avatarPath (or avatar) looked unused, risking its file being cleaned up. Now checks avatarUrl / avatarPath / avatar. Regression test added.

Findings investigated and left unchanged (stale — code already correct):

  • (MEDIUM) message-swipe cleanup on delete — the finding read the message cleanup contract (DeleteMessageTrackerSnapshots only) and concluded deleting a message orphans its message-swipes sidecar rows. It does not. delete_entity routes every message deletion through message_swipes::delete_message_rows_with_swipes, which atomically removes the message row and its swipe sidecars in one transaction — asserted by the existing test delete_message_rows_with_swipes_replaces_parent_and_sidecar_together. apply_delete_cleanup runs after that atomic delete, and there is no code path that deletes a message row while skipping the helper (apply_delete_cleanup has a single caller). A DeleteMessageSwipes cleanup would therefore be a redundant no-op — it calls delete_for_messages, which uses the identical sidecar_message_id matching and can only ever find 0 remaining rows. Left unchanged.
  • (MEDIUM) projection activeSwipeIndex — the finding suggested the projection should add activeSwipeIndex for content/characterId. activeSwipeIndex is a deliberate internal sidecar field excluded from content-only projections — asserted by message_projection_materialization_includes_internal_sort_fields — and active-swipe content materializes through the extra/swipes path. Adding it breaks that tested contract, so the finding does not hold for this design.

Refactor impact

Primary owner: Rust storage / capability layer (src-tauri/src/commands/storage)

Impact areas reviewed:

  • chats.rs (bulk message delete) and avatars.rs (persona-snapshot avatar reference scan). No frontend changes.

Boundary notes:

  • Confined to the Tauri storage command layer. No engine, shared-API, remote-runtime, or frontend boundary crossed. Both fixes reuse existing patterns (the gallery-cleanup chatId filter; the persona-snapshot URL-field scan) rather than adding a parallel path.

Pressure points touched:

  • src-tauri storage commands only. No storage-collection contract (contracts.rs) or delete-cleanup dispatch (commands/entities.rs) change, and no src-tauri/src/lib.rs command-registration change.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • cargo test --manifest-path src-tauri/Cargo.toml --lib → 451 passed, 0 failed (includes both new regression tests — bulk-delete cross-chat and the persona-avatar avatarPath scan — plus the full existing storage suite, e.g. the swipe-projection materialization tests and the atomic message+sidecar delete test).

Feature Discoverability

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • N/A — internal storage-layer correctness fix; no new user-discoverable surface.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

Proof

Core claim:

  • Bulk message delete can no longer destroy another chat's messages, and persona-avatar reference detection no longer misses avatarPath/avatar-referenced avatars — each backed by a dedicated regression test, with the existing active-swipe projection and atomic message+sidecar delete contracts preserved unchanged.

Verification run:

  • cargo test --manifest-path src-tauri/Cargo.toml --lib → 451 passed / 0 failed.

Evidence:

  • New regression test bulk_delete_messages_ignores_ids_from_another_chat: with one message in chat-1 and one in chat-2, bulk_delete_messages(chat-1, [both ids]) reports deleted == 1, removes the chat-1 message, and leaves the chat-2 message intact.
  • New regression test persona_avatar_update_preserves_snapshot_referenced_by_avatar_path: a message snapshot references the persona avatar only via avatarPath (no avatarUrl, no matching avatarFilePath), so preservation must come from the broadened URL-field scan rather than the file-path fallback; after re-uploading the persona avatar, the originally-referenced managed file still exists.
  • The full storage suite — including the swipe-projection materialization tests and delete_message_rows_with_swipes_replaces_parent_and_sidecar_together — stays green, confirming the two fixes and both dismissed findings don't regress existing behavior.

Risk coverage:

  • Positive rows: a chat deletes its own message; an avatarPath-referenced avatar is counted as referenced and its file preserved.
  • Negative controls: a chat cannot delete another chat's message via bulk delete; a filename-only snapshot match does not preserve an unrelated avatar file (existing test).
  • Both shipped fixes now carry dedicated regression tests; no part of this PR leans on reasoning-only coverage.

Manual verification requested:

  • None beyond the automated suite; this is a backend correctness change with no UI surface.

UI evidence (if applicable)

N/A — backend storage-layer fix with no visible UI change.


🔄 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/2115 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 6/4/2026 **Status:** ✅ Merged **Merged:** 6/4/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `fix/storage-deletion-correctness` --- ### 📝 Commits (3) - [`63acd16`](https://github.com/Pasta-Devs/Marinara-Engine/commit/63acd1653b3f498aa59b56d6155d5d3678748b0e) Ignore local .pnpm-store/ and per-user .claude settings - [`b7a1e03`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b7a1e03c7b1866430f32fce7c76421b201acb74e) Fix storage deletion & cleanup correctness (#2114) - [`58c2e8d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/58c2e8d71c96bde91fd20a7b29f49a58a94f5e7c) Revert stale swipe-cleanup change; add avatarPath regression test ### 📊 Changes **3 files changed** (+151 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+4 -0) 📝 `src-tauri/src/commands/storage/avatars.rs` (+76 -4) 📝 `src-tauri/src/commands/storage/chats.rs` (+71 -2) </details> ### 📄 Description ## Linked issue Closes #2114 ## Why this change - Bunny Review surfaced four storage-layer correctness findings (1 HIGH, 3 MEDIUM) while scanning #1812. Two are verified and fixed here — the HIGH (`bulk_delete_messages` could delete messages belonging to a *different* chat) and one MEDIUM (persona-avatar reference detection missed `avatarPath`). The other two were investigated and found not to hold for the actual code paths, and are left unchanged with the reasoning recorded below. ## What changed - **(HIGH) `chats.rs` `bulk_delete_messages`** — the pre-scan only confirmed each id *exists*, never that it belongs to `chat_id`, so a caller passing message ids from another chat would destroy them (and their swipe sidecars). Now filtered by `chatId == chat_id` (mirrors the existing gallery-cleanup pattern). Regression test added. - **(MEDIUM) `avatars.rs`** — the "is this persona avatar still referenced by a message snapshot?" scan only inspected `snapshot.avatarUrl`. A snapshot referencing the avatar via `avatarPath` (or `avatar`) looked unused, risking its file being cleaned up. Now checks `avatarUrl` / `avatarPath` / `avatar`. Regression test added. **Findings investigated and left unchanged (stale — code already correct):** - **(MEDIUM) message-swipe cleanup on delete** — the finding read the message cleanup contract (`DeleteMessageTrackerSnapshots` only) and concluded deleting a message orphans its `message-swipes` sidecar rows. It does not. `delete_entity` routes every message deletion through `message_swipes::delete_message_rows_with_swipes`, which atomically removes the message row **and** its swipe sidecars in one transaction — asserted by the existing test `delete_message_rows_with_swipes_replaces_parent_and_sidecar_together`. `apply_delete_cleanup` runs *after* that atomic delete, and there is no code path that deletes a message row while skipping the helper (`apply_delete_cleanup` has a single caller). A `DeleteMessageSwipes` cleanup would therefore be a redundant no-op — it calls `delete_for_messages`, which uses the identical `sidecar_message_id` matching and can only ever find 0 remaining rows. Left unchanged. - **(MEDIUM) projection `activeSwipeIndex`** — the finding suggested the projection should add `activeSwipeIndex` for `content`/`characterId`. `activeSwipeIndex` is a deliberate internal sidecar field excluded from `content`-only projections — asserted by `message_projection_materialization_includes_internal_sort_fields` — and active-swipe content materializes through the `extra`/`swipes` path. Adding it breaks that tested contract, so the finding does not hold for this design. ## Refactor impact Primary owner: Rust storage / capability layer (`src-tauri/src/commands/storage`) Impact areas reviewed: - `chats.rs` (bulk message delete) and `avatars.rs` (persona-snapshot avatar reference scan). No frontend changes. Boundary notes: - Confined to the Tauri storage command layer. No engine, shared-API, remote-runtime, or frontend boundary crossed. Both fixes reuse existing patterns (the gallery-cleanup `chatId` filter; the persona-snapshot URL-field scan) rather than adding a parallel path. Pressure points touched: - `src-tauri` storage commands only. No storage-collection contract (`contracts.rs`) or delete-cleanup dispatch (`commands/entities.rs`) change, and no `src-tauri/src/lib.rs` command-registration change. ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] Full `pnpm check` passes before PR push/handoff - [x] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `cargo test --manifest-path src-tauri/Cargo.toml --lib` → **451 passed, 0 failed** (includes both new regression tests — bulk-delete cross-chat and the persona-avatar `avatarPath` scan — plus the full existing storage suite, e.g. the swipe-projection materialization tests and the atomic message+sidecar delete test). ## Feature Discoverability - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [ ] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - N/A — internal storage-layer correctness fix; no new user-discoverable surface. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims ## Proof Core claim: - Bulk message delete can no longer destroy another chat's messages, and persona-avatar reference detection no longer misses `avatarPath`/`avatar`-referenced avatars — each backed by a dedicated regression test, with the existing active-swipe projection and atomic message+sidecar delete contracts preserved unchanged. Verification run: - `cargo test --manifest-path src-tauri/Cargo.toml --lib` → 451 passed / 0 failed. Evidence: - New regression test `bulk_delete_messages_ignores_ids_from_another_chat`: with one message in `chat-1` and one in `chat-2`, `bulk_delete_messages(chat-1, [both ids])` reports `deleted == 1`, removes the `chat-1` message, and leaves the `chat-2` message intact. - New regression test `persona_avatar_update_preserves_snapshot_referenced_by_avatar_path`: a message snapshot references the persona avatar only via `avatarPath` (no `avatarUrl`, no matching `avatarFilePath`), so preservation must come from the broadened URL-field scan rather than the file-path fallback; after re-uploading the persona avatar, the originally-referenced managed file still exists. - The full storage suite — including the swipe-projection materialization tests and `delete_message_rows_with_swipes_replaces_parent_and_sidecar_together` — stays green, confirming the two fixes and both dismissed findings don't regress existing behavior. Risk coverage: - Positive rows: a chat deletes its own message; an `avatarPath`-referenced avatar is counted as referenced and its file preserved. - Negative controls: a chat cannot delete another chat's message via bulk delete; a filename-only snapshot match does not preserve an unrelated avatar file (existing test). - Both shipped fixes now carry dedicated regression tests; no part of this PR leans on reasoning-only coverage. Manual verification requested: - None beyond the automated suite; this is a backend correctness change with no UI surface. ## UI evidence (if applicable) N/A — backend storage-layer fix with no visible UI change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:16:22 +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#5443
No description provided.