[GH-ISSUE #1891] [Issue]: storage_create can overwrite an existing record when the caller supplies a duplicate id #915

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

Originally created by @Xelvanis on GitHub (Jun 2, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1891

Originally assigned to: @Promansis on GitHub.

Summary

storage_create can replace an existing row when the caller supplies an id that already exists in the target collection. FileStorage::create removes any row with the same id and then pushes the new record.

Expected behavior

Create semantics should reject duplicate IDs. Intentional replacement should go through an explicit update or upsert path.

Actual behavior

A duplicate caller-provided id is treated like an implicit upsert for most collections.

Steps to reproduce

  1. Use storage_create or FileStorage::create to create a record with id: "duplicate-test" in a collection.
  2. Call the same create path again with the same id and different content.
  3. Read the record back.

Expected: duplicate create fails.
Actual from code inspection: the old row is removed and the new row is written.

Impact area

  • App shell, navigation, startup, or providers
  • Catalog resources
  • Chat mode
  • Roleplay mode
  • Game mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Professor Mari or shell tools
  • React-free engine behavior, contracts, agents, or capability ports
  • Shared API wrapper or remote runtime routing
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime
  • Docs, contributor workflow, or templates

Environment

  • Branch or commit: current refactor checkout, e546fdf2
  • Run mode: Tauri desktop or remote runtime storage command
  • OS + version: not captured
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not captured
  • Remote Runtime URL configured? relevant when called through /api/invoke
  • Provider, model, or integration, if relevant: not relevant

Logs, screenshots, or video

Static evidence:

  • src-tauri/crates/storage/src/lib.rs: FileStorage::create assigns the incoming or generated id, then calls rows.retain(...) to remove any existing row with that id before writing the collection.
  • Legacy file-native storage rejected duplicate primary keys unless the caller explicitly used onConflictDoUpdate.

Regression notes

Legacy file-native insert semantics rejected duplicate primary keys unless an explicit conflict-update path was used. Refactor currently makes replacement implicit in the generic create path.

Additional context

Suggested fix: make FileStorage::create reject an existing non-empty caller-provided id; keep upsert_with_id or update paths for intentional replacement. Add a focused Rust test proving duplicate create does not mutate the existing row.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Xelvanis on GitHub (Jun 2, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1891 Originally assigned to: @Promansis on GitHub. ## Summary `storage_create` can replace an existing row when the caller supplies an `id` that already exists in the target collection. `FileStorage::create` removes any row with the same `id` and then pushes the new record. ## Expected behavior Create semantics should reject duplicate IDs. Intentional replacement should go through an explicit update or upsert path. ## Actual behavior A duplicate caller-provided `id` is treated like an implicit upsert for most collections. ## Steps to reproduce 1. Use `storage_create` or `FileStorage::create` to create a record with `id: "duplicate-test"` in a collection. 2. Call the same create path again with the same `id` and different content. 3. Read the record back. Expected: duplicate create fails. Actual from code inspection: the old row is removed and the new row is written. ## Impact area - [ ] App shell, navigation, startup, or providers - [x] Catalog resources - [x] Chat mode - [x] Roleplay mode - [x] Game mode - [ ] Shared mode UI - [ ] Runtime systems: generation, world-state, visuals, tracker, or haptics - [ ] Professor Mari or shell tools - [ ] React-free engine behavior, contracts, agents, or capability ports - [x] Shared API wrapper or remote runtime routing - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Environment - Branch or commit: current refactor checkout, `e546fdf2` - Run mode: Tauri desktop or remote runtime storage command - OS + version: not captured - Node + pnpm versions: not relevant - Rust version, if relevant: not captured - Remote Runtime URL configured? relevant when called through `/api/invoke` - Provider, model, or integration, if relevant: not relevant ## Logs, screenshots, or video Static evidence: - `src-tauri/crates/storage/src/lib.rs`: `FileStorage::create` assigns the incoming or generated `id`, then calls `rows.retain(...)` to remove any existing row with that `id` before writing the collection. - Legacy file-native storage rejected duplicate primary keys unless the caller explicitly used `onConflictDoUpdate`. ## Regression notes Legacy file-native insert semantics rejected duplicate primary keys unless an explicit conflict-update path was used. Refactor currently makes replacement implicit in the generic create path. ## Additional context Suggested fix: make `FileStorage::create` reject an existing non-empty caller-provided `id`; keep `upsert_with_id` or update paths for intentional replacement. Add a focused Rust test proving duplicate create does not mutate the existing row. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:23:25 +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#915
No description provided.