mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #6289] [MERGED] fix(lorebook): cascade agent lore when the message it came from is deleted #7125
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#7125
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/6289
Author: @Ejmathewp
Created: 9/17/2026
Status: ✅ Merged
Merged: 9/17/2026
Merged by: @undefined
Base:
staging← Head:fix/lorebook-deleted-message-cascade📝 Commits (10+)
69f4746fix(lorebook): cascade agent lore when the message it came from is deletedfd96ed6Merge branch 'staging' into fix/lorebook-deleted-message-cascade2dde0f6fix(lorebook): cascade agent lore when the message it came from is deletedcc93a12fix(lorebook): address CodeRabbit review findings on the cascade2909ffffix(lorebook): bind tool writes to saved responses and preserve undo1a34a65Merge contributor provenance review fixes without losing staging changes970f2a2Merge lorebook provenance and package tools for integration review858d2edfix(lorebook): retain turn snapshots before a source message exists1c18d01Merge branch 'review/pr-6290' into review/pr-628961ff062fix(lorebook): release transactions before queued metadata cleanup📊 Changes
22 files changed (+1533 additions, -49 deletions)
View changed files
📝
CHANGELOG.md(+6 -0)📝
packages/server/src/db/file-backed-store.ts(+8 -1)📝
packages/server/src/db/schema/lorebooks.ts(+12 -0)📝
packages/server/src/routes/backup.routes.ts(+7 -1)📝
packages/server/src/routes/chats.routes.ts(+16 -0)📝
packages/server/src/routes/generate.routes.ts(+43 -4)📝
packages/server/src/routes/generate/agent-write-approval.ts(+19 -1)📝
packages/server/src/routes/generate/lorebook-keeper-utils.ts(+30 -0)📝
packages/server/src/routes/generate/retry-agents-route.ts(+44 -1)📝
packages/server/src/routes/lorebooks.routes.ts(+16 -3)📝
packages/server/src/services/generation/tool-resolution-runtime.ts(+73 -3)📝
packages/server/src/services/lorebook/index.ts(+40 -0)📝
packages/server/src/services/mari-db/mari-db.service.ts(+8 -0)📝
packages/server/src/services/storage/chats.storage.ts(+139 -29)➕
packages/server/src/services/storage/lorebook-provenance.ts(+39 -0)📝
packages/server/src/services/storage/lorebooks.storage.ts(+90 -4)📝
packages/shared/src/types/lorebook.ts(+26 -0)📝
scripts/regressions/file-backed-shutdown.regression.ts(+45 -1)➕
scripts/regressions/lorebook-entry-message-provenance.regression.ts(+849 -0)📝
scripts/regressions/profile-import-data-security.regression.ts(+20 -0)...and 2 more files
📄 Description
Linked issue
Closes #6298: the final CI run exposed an admitted storage flush racing with shutdown.
Closes #6288. Original contribution by @Ejmathewp; maintainer follow-up by @SpicyMarinara with Codex.
Why this change
Deleting or regenerating a message left agent-written lore in later prompts, including facts written into older entries. Track the source messages and swipes so deleting a turn removes its new lore or restores the previous content, and discarded swipes stop contributing lore.
What changed
Let flushes admitted before shutdown join the existing close drain, while retaining rejection of new writes after close. The shutdown drain preserves admitted write errors even when its retry succeeds.
Track source messages in keeper writes, approvals, retries and tool calls. Tool writes made before the assistant is saved are bound to the saved reply without overwriting later human edits.
Restore the previous content and author on deletion, clear stale vectors, and retain the original snapshot across repeated writes from the same turn. Scope bulk cascades to messages actually deleted.
Human edits and folder clones remain manual. Legacy profile imports clear foreign message references. Existing entries without provenance are preserved; their historical sources cannot be reconstructed reliably.
Expose source references and the existing entries endpoint's source-message filter. There is no new client purge UI in this PR.
Merged into
stagingthrough #6295 at594e9b631, preserving the exact #6289 commits and contributor history. Both PRs passed their required checks and completed GitHub CodeRabbit reviews before merge; the outside contribution had current owner approval. Package tools from #6290 were merged first.Validation
Final combined commit
d39ca9aadpassedpnpm checkand 290/290 Node regressions. All six lore suites pass. Local CodeRabbit reviewed the latest nine-file behavioral follow-up with zero findings; version and launcher format-guard checks pass.The real-store proof covers tool writes before reply persistence, repeated keeper writes across routed batches, human corrections, approval/retry provenance, inactive swipes, wrong-chat deletion, folder clones and stale embeddings. Additional regressions reproduce and then pass metadata queue deadlocks, partial bulk failure, atomic rollback of message/lore deletion, foreign attribution in legacy imports, repeated query keys and admitted flush failures followed by a successful close retry.
Message and lore deletion commit together per 500-message chunk; metadata cleanup runs afterward. One lore scan per nonempty chunk is an intentional ceiling documented with the future indexed lookup option. Pure test-organization and speculative indexing suggestions are deferred. Required GitHub checks and the completed GitHub CodeRabbit review remain merge gates.
Contributor checklist retained from the original submission
These are the contributor's existing checkbox states, retained unchanged. They are not new maintainer attestations. Current maintainer verification is described above; the unchecked maintainer checklist remains below.
pnpm checkpasses locallyCONTRIBUTING.mdMaintainer checklist
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Manually verify keeper generation, approval, retry, deletion and switching swipes in a live conversation. The maintainer's new proof is automated; it does not reproduce a reporter's private history or reconstruct provenance for old entries.
Docs and release impact
Behavior is described in CHANGELOG. Storage format 7 protects the new provenance columns from older builds that discard unknown fields. The app version is unchanged. Package-tool documentation belongs to the preceding #6290 and translation PR #6297.
UI evidence (if applicable)
No client UI changed by the lorebook feature.
Post-merge verification: the fresh staging Node run at
594e9b631passed all 290 regressions, including normal shutdown-test process exit (CI result). An earlier optional combined-PR job completed every shutdown assertion but its process timed out on exit; the other Linux PR run and final combined local run also passed. No assertion or timeout was weakened. The broader post-merge browser matrix is still running.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.