mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #5613] Deleting any gallery image makes the chat_images table permanently resident #3108
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#3108
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 @kolacheee on GitHub (Aug 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5613
Originally assigned to: @kolacheee on GitHub.
What happens
galleryFileHasReferences(packages/server/src/services/image/gallery-file-lifecycle.ts:88-93) asks "does any chat still reference this physical file?" witheq(chatImages.filePath, filePath). BecausefilePathis neither the shard column nor the primary key, the lazy store cannot scope the query, so the first call permanently convertschat_imagesto fully resident (Lazy table chat_images is now fully residentin the log).It is called from every image-deletion path in the app — chat gallery, character/persona images, global gallery, cascade deletion (
chats.storage.ts:884/:892/:931/:944,characters.routes.ts×6,global-gallery.routes.ts:270,chat-gallery-cascade-deletion.ts:195,mari-images.service.ts:1364). So on any install where the user has ever deleted an image, thechat_imagestable ignores the memory cap for the rest of the process.Why a simple scoping fix doesn't work
Unlike the #5611 sites, this one is cross-chat by design: shared files must only be unlinked when the last referencing chat lets go. Adding a chatId conjunct would make the check wrong and delete files other chats still use.
Possible directions
filePath → reference count(orfilePath → owner set) index, updated on chat_images insert/remove, so the liveness check never needs a table scan.Found during the residual-lease audit for #5611 / #5592.
@kolacheee commented on GitHub (Aug 29, 2026):
Taking this one (kolacheee, agent-assisted) — going with the shard-peek direction now that #5616 established the pattern: answer the cross-chat reference question from resident memory plus direct shard-file reads, loading a unit only when a shard can't be trusted. PR incoming.