[GH-ISSUE #3486] [Issue]: mari-db service drifted from the real schema: stale cascade graph and wrong JSON column map #1885

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

Originally created by @kolacheee on GitHub (Jul 11, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3486

Originally assigned to: @kolacheee on GitHub.

Summary

services/mari-db (the Mari CLI's database layer) keeps private copies of schema knowledge that have drifted from the authoritative definitions.

Why this is a problem: duplicated schema knowledge rots. The stale copies are load-bearing: one drives cascade deletes and the dangling-reference validator, the other drives JSON encode/decode.
What it negatively affects: mari db delete --cascade silently orphans conversation-call and game-engine rows; the validator cannot flag them (it uses the same stale graph); Mari reads and writes malformed JSON for the game snapshot/checkpoint tables. It also misleads agents into "fixing" whichever copy they find first.

Expected behavior

One authoritative cascade graph and one authoritative JSON-column map, both matching the real schema.

Actual behavior

  • packages/server/src/services/mari-db/mari-db.service.ts:261 — local CASCADES is a stale duplicate of the authoritative graph in db/file-backed-store.ts:217. Missing edges: chats → conversation_call_sessions, chats → conversation_call_messages, chats → game_engine_state, and conversation_call_sessions → conversation_call_messages. Both mari db delete --cascade and the dangling-reference validator consume the stale copy.
  • packages/server/src/services/mari-db/mari-db.service.ts:327 — JSON_COLUMNS lists phantom fields for game_state_snapshots (7) and game_checkpoints (2) while omitting the real JSON columns (recentEvents, personaStats, manualOverrides, fieldLocks; game_checkpoints has snapshotId and no metadata). Result: get/list return raw JSON strings for the real columns, and insert/patch skip JSON.stringify for them.

Steps to reproduce

  1. Diff mari-db.service.ts:261 CASCADES against file-backed-store.ts:217.
  2. Run mari db delete --cascade on a chat that has conversation-call sessions: the call rows survive as orphans, and the validator reports nothing.

Environment

  • Marinara Engine version: 2.2.0 (staging @ 45b650de9)
  • Install type: source
  • OS + version: N/A — verified by reading the code
  • Browser or app shell: N/A

Logs, screenshots, or video

N/A — file/line references above point at the exact code.

Additional context

Suggested direction: import the authoritative cascade graph and derive the JSON column map from the schema instead of duplicating either. A third mari-db finding (lorebook folderId dropped by add-entry/update-entry) is filed with the lorebook-folders issue since it belongs to that data-loss cluster. Found by a repo-wide read-only sweep; adversarially re-verified before filing. No fix started. Part of a coordinated set of sweep catalogue issues filed together.

Template check

Please uncheck (untick) 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 @kolacheee on GitHub (Jul 11, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3486 Originally assigned to: @kolacheee on GitHub. ## Summary `services/mari-db` (the Mari CLI's database layer) keeps private copies of schema knowledge that have drifted from the authoritative definitions. **Why this is a problem:** duplicated schema knowledge rots. The stale copies are load-bearing: one drives cascade deletes and the dangling-reference validator, the other drives JSON encode/decode. **What it negatively affects:** `mari db delete --cascade` silently orphans conversation-call and game-engine rows; the validator cannot flag them (it uses the same stale graph); Mari reads and writes malformed JSON for the game snapshot/checkpoint tables. It also misleads agents into "fixing" whichever copy they find first. ## Expected behavior One authoritative cascade graph and one authoritative JSON-column map, both matching the real schema. ## Actual behavior - [ ] `packages/server/src/services/mari-db/mari-db.service.ts:261` — local `CASCADES` is a stale duplicate of the authoritative graph in `db/file-backed-store.ts:217`. Missing edges: `chats → conversation_call_sessions`, `chats → conversation_call_messages`, `chats → game_engine_state`, and `conversation_call_sessions → conversation_call_messages`. Both `mari db delete --cascade` and the dangling-reference validator consume the stale copy. - [ ] `packages/server/src/services/mari-db/mari-db.service.ts:327` — `JSON_COLUMNS` lists phantom fields for `game_state_snapshots` (7) and `game_checkpoints` (2) while omitting the real JSON columns (`recentEvents`, `personaStats`, `manualOverrides`, `fieldLocks`; `game_checkpoints` has `snapshotId` and no `metadata`). Result: get/list return raw JSON strings for the real columns, and insert/patch skip `JSON.stringify` for them. ## Steps to reproduce 1. Diff `mari-db.service.ts:261` `CASCADES` against `file-backed-store.ts:217`. 2. Run `mari db delete --cascade` on a chat that has conversation-call sessions: the call rows survive as orphans, and the validator reports nothing. ## Environment - Marinara Engine version: 2.2.0 (staging @ 45b650de9) - Install type: source - OS + version: N/A — verified by reading the code - Browser or app shell: N/A ## Logs, screenshots, or video N/A — file/line references above point at the exact code. ## Additional context Suggested direction: import the authoritative cascade graph and derive the JSON column map from the schema instead of duplicating either. A third mari-db finding (lorebook `folderId` dropped by `add-entry`/`update-entry`) is filed with the lorebook-folders issue since it belongs to that data-loss cluster. Found by a repo-wide read-only sweep; adversarially re-verified before filing. No fix started. Part of a coordinated set of sweep catalogue issues filed together. ## Template check Please **uncheck (untick)** 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:43:31 +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#1885
No description provided.