mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2368] [Issue]: marinara-chat-bulk import skips the entity-defaults normalization and role allowlisting every sibling import path applies #1169
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1169
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2368
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Low — validation gap.
The
marinara-chat-bulkimporter stores the imported chat record and its messages without thewith_entity_defaults/ typed-field normalization and the message-roleallowlisting that every sibling import path applies. A hand-edited / cross-version / externally-produced bulk file can therefore persist a chat whosecharacterIds/activeLorebookIds/metadata/gameStateare TEXT-encoded strings (the pre-refactor shape) and whose messages carry an arbitraryrolestring, both violating their contracts.Expected behavior
The bulk-chat importer should run the chat record through
with_entity_defaults("chats", ...)(which appliesnormalize_typed_json_fields) and normalize each messageroleto the allowlist, exactly as the lorebook/character/persona/preset and ST-JSONL import paths do.Actual behavior
Chat record — no normalization (
src-tauri/src/commands/storage/imports/marinara_chat_bulk.rs:117-118):FileStorage::create(crates/storage/src/lib.rs:293-361) only assignsid/createdAt/updatedAt; it does not runnormalize_typed_json_fields, so normalization is the caller's job and this caller omits it.CHAT_FIELDS(contracts.rs:43-52) declarescharacterIds/activeLorebookIdsas arrays andmetadata/gameStateas objects, so a record with those fields stored as"[\"abc\"]"/"{...}"strings is left contract-violating. Non-defensive consumers misbehave:ChatSettingsDrawer.tsx:610doeschat.characterIds ?? []typedstring[], then.lengthanduseCharacterSummariesByIds(chatCharIds)— a string yields a wrong count and a malformed query. (Many consumers are defensive —parseChatCharacterIds,Array.isArrayguards — which is why impact is bounded to silent-wrong rather than a hard crash.)Message role — no allowlist (
marinara_chat_bulk.rs:126-134):MESSAGE_FIELDS(contracts.rs:53) normalizes onlyswipes/images/extra, neverrole, andcreate_message/prepare_message_create_rowdoes not constrain it. The ST JSONL importer normalizesroleto an allowlist viaimported_jsonl_message_role(bulk_imports.rs:47), so the two paths diverge — a{"role":"narrator"}or junk string is persisted verbatim. DownstreamnormalizeRole(prompt-assembly.ts:2490) coerces unknown roles to"user"at generation time, so this is silent-wrong / inconsistent render-export, not injection.Steps to reproduce
.jsonwithformat: "marinara-chat-bulk"whosechatobject has"characterIds": "[\"abc\"]"(string) and whose messages include{"role":"narrator","content":"..."}.characterIdsand the non-allowlistedrole.Impact area
Environment
330f69a8Logs, screenshots, or video
Static source audit. Cited:
imports/marinara_chat_bulk.rs:117-118(chat record),:126-134(message role);crates/storage/src/lib.rs:293-361(create skips normalization); contractscontracts.rs:43-52/:53; sibling-normalizing pathsimports/marinara.rs:396-409(lorebook),:259/:328/:509(character/persona/preset),bulk_imports.rs:47(ST role allowlist); defensive consumeruse-chat-surface-data.ts:57, non-defensiveChatSettingsDrawer.tsx:610-613.Regression notes
Found via static audit; not a regression — refactor-only surface. The
marinara-chat-bulkformat, the array-typedcharacterIdscontract, and the RustFileStoragenormalizer are all refactor-only. In main,characterIdsis atext("character_ids")column that stores a JSON string by design and consumers parse it, and main has no equivalent bulk-chat importer, so there is no prior-correct main behavior the refactor inverted.Additional context
Insert
with_entity_defaults("chats", Value::Object(chat))?(or the legacy text-array/bool normalizers plus object normalization) beforestorage.createatmarinara_chat_bulk.rs:118, mirroring the lorebook path atmarinara.rs:396-409; and normalize the messageroleto the allowlist beforecreate_messagein the bulk loop, reusingbulk_imports.rsimported_jsonl_message_role. Every other import path already does both — only the bulk-chat path skips them.Template check
@Romuromylus commented on GitHub (Jun 6, 2026):
Fixed by #2418, merged into
refactor.