[GH-ISSUE #1571] [Issue]: Generic storage writes can persist malformed lorebook-entry fields #812

Closed
opened 2026-10-21 05:21:25 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @cha1latte on GitHub (May 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1571

Originally assigned to: @Romuromylus on GitHub.

Summary

Generic storage writes can still persist malformed lorebook-entries records even though the legacy import path now normalizes string booleans and JSON-like arrays.

Expected behavior

Every subsystem that writes lorebook-entries should cross one strong record-shape contract. Boolean, array, number, metadata, timing, and scope fields should either be normalized to the native shape or rejected before they reach persistent storage, regardless of whether the row came from the editor, bulk creation, import, tool-generated entries, remote runtime, or another generic storage caller.

Actual behavior

The legacy import path was fixed for #1513, but the generic storage boundary remains loosely typed. Source audit against upstream/refactor found:

  • src/features/catalog/lorebooks/hooks/use-lorebooks.ts creates, updates, copies, moves, reorders, and bulk-creates lorebook entries through storageApi with Record<string, unknown> / unknown[] payloads.
  • src/shared/api/storage-api.ts normalizes stored JSON for chats and messages, but does not normalize lorebook-entries.
  • src/engine/contracts/schemas/lorebook.schema.ts exports createLorebookEntrySchema and updateLorebookEntrySchema, but current grep found no active call sites using those schemas at the write boundary.
  • Native import normalization in src-tauri/src/commands/storage/imports/normalization.rs handles legacy lorebook fields, but that does not protect later generic storage_create / storage_update calls.

That means a future or existing caller that bypasses the fixed legacy import path can still hand strings like "false" or JSON strings like "[\"moon\"]" across the storage boundary and rely on downstream UI/generation code to guess the intended shape.

Steps to reproduce

  1. Use a generic storage write path such as storage_create / storage_update for entity lorebook-entries.
  2. Send a malformed but plausible legacy-style payload, for example enabled: "false", constant: "true", keys: "[\"moon\"]", or secondaryKeys: "[]".
  3. Read the row through the lorebook editor, active lorebook scan, or search_lorebook tooling.
  4. Observe that the row shape depends on caller-side assumptions instead of one enforced storage/lorebook-entry contract.

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: source audit against upstream/refactor at ab8af081
  • Run mode: source audit / smoke-test follow-up
  • OS + version: Windows desktop, exact version not captured
  • Node + pnpm versions: Not specified
  • Rust version, if relevant: Not specified
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: not relevant

Logs, screenshots, or video

No screenshot. This was found during the focused system-boundary/data-contract audit after #1513 was closed.

Relevant source signals:

  • src/features/catalog/lorebooks/hooks/use-lorebooks.ts
  • src/shared/api/storage-api.ts
  • src/engine/contracts/schemas/lorebook.schema.ts
  • src-tauri/src/commands/storage/imports/normalization.rs

Regression notes

Related to #1513, but not a duplicate. #1513 covered legacy import normalization. This issue covers the remaining generic storage write boundary for lorebook-entry records.

Also related to #1566 because Knip reports the lorebook entry schemas as unused, which is a useful signal that the intended TypeScript contract may not be wired into active write paths.

Additional context

Suggested regression coverage should include at least one positive normalized row and one negative/malformed row for lorebook-entry create/update outside the legacy import path.

Template check

Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @cha1latte on GitHub (May 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1571 Originally assigned to: @Romuromylus on GitHub. ## Summary Generic storage writes can still persist malformed `lorebook-entries` records even though the legacy import path now normalizes string booleans and JSON-like arrays. ## Expected behavior Every subsystem that writes `lorebook-entries` should cross one strong record-shape contract. Boolean, array, number, metadata, timing, and scope fields should either be normalized to the native shape or rejected before they reach persistent storage, regardless of whether the row came from the editor, bulk creation, import, tool-generated entries, remote runtime, or another generic storage caller. ## Actual behavior The legacy import path was fixed for #1513, but the generic storage boundary remains loosely typed. Source audit against `upstream/refactor` found: - `src/features/catalog/lorebooks/hooks/use-lorebooks.ts` creates, updates, copies, moves, reorders, and bulk-creates lorebook entries through `storageApi` with `Record<string, unknown>` / `unknown[]` payloads. - `src/shared/api/storage-api.ts` normalizes stored JSON for chats and messages, but does not normalize `lorebook-entries`. - `src/engine/contracts/schemas/lorebook.schema.ts` exports `createLorebookEntrySchema` and `updateLorebookEntrySchema`, but current grep found no active call sites using those schemas at the write boundary. - Native import normalization in `src-tauri/src/commands/storage/imports/normalization.rs` handles legacy lorebook fields, but that does not protect later generic `storage_create` / `storage_update` calls. That means a future or existing caller that bypasses the fixed legacy import path can still hand strings like `"false"` or JSON strings like `"[\"moon\"]"` across the storage boundary and rely on downstream UI/generation code to guess the intended shape. ## Steps to reproduce 1. Use a generic storage write path such as `storage_create` / `storage_update` for entity `lorebook-entries`. 2. Send a malformed but plausible legacy-style payload, for example `enabled: "false"`, `constant: "true"`, `keys: "[\"moon\"]"`, or `secondaryKeys: "[]"`. 3. Read the row through the lorebook editor, active lorebook scan, or `search_lorebook` tooling. 4. Observe that the row shape depends on caller-side assumptions instead of one enforced storage/lorebook-entry contract. ## Impact area - [ ] App shell, navigation, startup, or providers - [x] Catalog resources - [ ] Chat mode - [ ] Roleplay mode - [ ] Game mode - [ ] Shared mode UI - [x] Runtime systems: generation, world-state, visuals, tracker, or haptics - [ ] Professor Mari or shell tools - [x] 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: source audit against `upstream/refactor` at `ab8af081` - Run mode: source audit / smoke-test follow-up - OS + version: Windows desktop, exact version not captured - Node + pnpm versions: Not specified - Rust version, if relevant: Not specified - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: not relevant ## Logs, screenshots, or video No screenshot. This was found during the focused system-boundary/data-contract audit after #1513 was closed. Relevant source signals: - `src/features/catalog/lorebooks/hooks/use-lorebooks.ts` - `src/shared/api/storage-api.ts` - `src/engine/contracts/schemas/lorebook.schema.ts` - `src-tauri/src/commands/storage/imports/normalization.rs` ## Regression notes Related to #1513, but not a duplicate. #1513 covered legacy import normalization. This issue covers the remaining generic storage write boundary for lorebook-entry records. Also related to #1566 because Knip reports the lorebook entry schemas as unused, which is a useful signal that the intended TypeScript contract may not be wired into active write paths. ## Additional context Suggested regression coverage should include at least one positive normalized row and one negative/malformed row for lorebook-entry create/update outside the legacy import path. ## Template check Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:21:25 +07:00
Author
Owner

@Romuromylus commented on GitHub (May 30, 2026):

Fixed by #1637, merged into refactor.

<!-- gh-comment-id:4582246889 --> @Romuromylus commented on GitHub (May 30, 2026): Fixed by #1637, merged into `refactor`.
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#812
No description provided.