mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #2538] [MERGED] fix(import): clamp Marinara lorebook entry role to the system/user/assistant union #5642
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#5642
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?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2538
Author: @Romuromylus
Created: 6/9/2026
Status: ✅ Merged
Merged: 6/9/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/lorebook-import-role-allowlist📝 Commits (2)
4c33dd3fix(import): clamp Marinara lorebook entry role to the system/user/assistant union7c26135Merge branch 'staging' into fix/lorebook-import-role-allowlist📊 Changes
3 files changed (+23 additions, -12 deletions)
View changed files
➕
packages/server/src/services/import/lorebook-role.ts(+19 -0)📝
packages/server/src/services/import/marinara.importer.ts(+2 -1)📝
packages/server/src/services/import/st-lorebook.importer.ts(+2 -11)📄 Description
Linked issue
Closes #2530
Why this change
The Marinara native importer wrote the lorebook entry role verbatim:
The bulk-import path (
bulkCreateEntries→createEntry) insertsrolewith no zod parse, so an arbitrary string from a hand-crafted.marinara.jsonpersisted as the entry role and later propagated into a providerPromptMessagerole. The ST lorebook importer already normalizes the identical field viaresolveRole, and the manual entry-create routes runcreateLorebookEntrySchema.parse()(which clamps toz.enum(["system","user","assistant"])). The Marinara bulk path was the one site that skipped the clamp.What changed
resolveRoleinto a sharedresolveLorebookEntryRolehelper (services/import/lorebook-role.ts), with the parameter widened tounknownso the Marinara importer (wheree.roleisunknown) can call it without a cast. The body already narrows safely, so this is behavior-preserving for the ST path.marinara.importer.tswithresolveLorebookEntryRole(e.role).Legitimate roles (
"system"/"user"/"assistant"and ST numeric0/1/2) round-trip identically; only out-of-enum garbage now falls back to"system".Out of scope (noted for transparency):
marinara.importer.tshas a secondrole: (s.role as any) ?? "system"at the preset-section import path (createSection). That is a different entity with its own storage/validation path, not a lorebook entry role, so it's left untouched here.Not a regression:
mainhas the byte-identical unclamped assignment; long-standing shared-code bug.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
pnpm checkpasses locally (confirms no danglingresolveRolereference after the extraction). Added a local-only node:test (lorebook-role.test.ts, gitignored): clamps out-of-enum/missing roles to"system"(the fix), preserves legitimate string roles, and maps ST numeric0/1/2(parity with the oldresolveRole). Local run: 3/3 pass.Still to verify manually against the deploy:
.marinara.jsonlorebook so one entry has"role": "hacker-role", import it, and confirm the entry reads"system"(clamped) while a sibling entry whose role was legitimately"assistant"still reads"assistant".Docs and release impact
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.