mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #5611] Remaining unscoped queries silently make lazy tables fully resident (defeats the chat memory cap) #3106
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#3106
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/5611
Originally assigned to: @kolacheee on GitHub.
What happens
Since #5597/#5603, chat-scoped tables load per chat and evict past the memory cap — but a query the store cannot scope to specific chats triggers the safety fallback: the whole table becomes permanently resident for the process (the log says
Lazy table <name> is now fully resident). A follow-up audit found the remaining queries that hit this, and the biggest one fires on essentially every Game-mode turn — meaning on game-heavy installs the memory cap forgame_state_snapshotssilently stops working the moment a tracker updates.The sites (all verified on current staging; every one has the owning chatId already in scope or one call away)
Hot — fire per turn:
game-state.storage.ts:276getByMessage(messageId, swipeIndex)— no chatId conjunct; ~16 callers across the generation loop, andupdateByMessage(which takes chatId as a parameter) funnels through it twice. The correctly scoped siblinggetByChatAndMessagealready exists at:287.game-state.storage.ts:340create()'s dedupe delete — missing the chatId conjunct its sibling ingame-engine-state.storage.ts:243already has.game-state.storage.ts:304getCommittedForMessages— batch read per generation; both callers hold the chatId.generate.routes.ts(:9175/:9216/:9274/:9334) andretry-agents-route.ts(:2933/:3062/:3123/:3161) — currently masked becausegetByMessageleases first; they must be scoped together with it or the lease just relocates.Routine interactions:
chats.storage.tsdeleteSwipe(:2177-2234) — nine unscoped statements acrossgame_state_snapshots/spatial_context_snapshots/game_engine_state;msg.chatIdis fetched at the top of the function and already used at:2245.checkpoint.service.ts:148and:158— the captured-snapshot reads on every checkpoint create;input.chatIdis validated against the result on the very next line, so the conjunct also enforces the existing cross-chat check.gallery.storage.ts:35listByFilePath— the sole caller builds the path as${chatId}/${filename}, so the owner is literally embedded in the argument.gallery.storage.ts:39/:60,game-scene-videos.storage.ts:28/:33— id-only reads/removes whose warm callers hold the chatId.Cold, id-only endpoints (need an optional param to carry the owner): gallery
DELETE /:id, checkpointDELETE /:id, workspaceDELETE /context/:id, agentsPATCH /runs/:runId,game-state.storage.ts:164getById,capability-persistence.service.ts:273spatialgetById,chats.routes.ts:2398, and the defensivepruneToNewestAnchorslist-delete.Try it yourself (Termux or any install with
MARINARA_MAX_RESIDENT_CHATSset)Play one Game-mode turn with any tracker enabled, then check the log:
[file-storage] Lazy table game_state_snapshots is now fully resident (unbounded access). From that point the table never evicts again for the process.The fix
The same mechanical treatment ~20 write sites received in #5603: AND the owning chatId into each condition (the store's scope resolver ignores conjuncts it can't resolve, so this is behavior-preserving — it only tells the store which chat's rows to load). For the id-only endpoints, accept an optional chatId the client can start passing later; until then those few cold endpoints keep the lease, which this issue documents.
Deliberately out of scope (tracked separately):
galleryFileHasReferences(cross-chat by design — needs a refcount/index, not a conjunct) and the boot-time gallery-recovery walk (its queries are perfectly scoped; the problem is that it visits every chat).Part of the #5592 close-out.
@kolacheee commented on GitHub (Aug 29, 2026):
Taking this one (kolacheee, agent-assisted) — PR incoming with the conjunct-threading batch; #5612/#5613 stay open for the two design-shaped cases.