mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5614] [MERGED] fix(storage): scope residual lazy-table queries to their owning chat #6848
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#6848
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/5614
Author: @kolacheee
Created: 8/29/2026
Status: ✅ Merged
Merged: 8/29/2026
Merged by: @kolacheee
Base:
staging← Head:fix/5611-residual-lease-scoping📝 Commits (4)
c0ad3defix(storage): scope residual lazy-table queries to their owning chat679609bfix(storage): guard repeated chatId query params and update the scene-video delete pin5493199style: format the updated scene-video delete pind9747f3test: anchor the scene-video delete pin to its one handler📊 Changes
22 files changed (+312 additions, -118 deletions)
View changed files
📝
packages/server/src/routes/agents.routes.ts(+4 -1)📝
packages/server/src/routes/characters.routes.ts(+2 -1)📝
packages/server/src/routes/chats.routes.ts(+5 -5)📝
packages/server/src/routes/gallery.routes.ts(+7 -5)📝
packages/server/src/routes/game.routes.ts(+10 -6)📝
packages/server/src/routes/generate.routes.ts(+39 -20)📝
packages/server/src/routes/generate/retry-agents-route.ts(+7 -6)📝
packages/server/src/routes/professor-mari-workspace.routes.ts(+7 -2)📝
packages/server/src/services/capability-packages/capability-persistence.service.ts(+5 -2)📝
packages/server/src/services/game/checkpoint.service.ts(+17 -6)📝
packages/server/src/services/mari-db/mari-images.service.ts(+2 -2)📝
packages/server/src/services/storage/agents.storage.ts(+4 -3)📝
packages/server/src/services/storage/chats.storage.ts(+45 -9)📝
packages/server/src/services/storage/gallery.storage.ts(+16 -5)📝
packages/server/src/services/storage/game-engine-state.storage.ts(+13 -6)📝
packages/server/src/services/storage/game-scene-videos.storage.ts(+12 -6)📝
packages/server/src/services/storage/game-state.storage.ts(+25 -19)📝
packages/server/src/services/storage/mari-workspace-context.storage.ts(+7 -4)📝
packages/server/src/services/storage/spatial-context.storage.ts(+2 -1)📝
packages/shared/src/types/capability-runtime.ts(+2 -1)...and 2 more files
📄 Description
Closes #5611. Part of the #5592 close-out (follows #5597/#5603/#5607–#5610).
Why
Any query the lazy store cannot scope to specific chats trips the safety fallback: the whole table becomes permanently fully resident for the process (
Lazy table <name> is now fully residentin the log). A post-merge audit found the residual sites — and the worst one (getByMessage, funneling ~16 callers includingupdateByMessage, which already takes the chatId) fires on essentially every Game-mode turn, so on game-heavy installs thegame_state_snapshotsmemory cap silently stopped working the moment a tracker updated.What changed
getByMessageis deleted; all callers use the already-scopedgetByChatAndMessage(compiler-enforced migration).create()'s dedupe delete andgetCommittedForMessagesgain the chatId conjunct, and the eight bare-PK tracker writes ingenerate.routes.ts/retry-agents-route.tsare scoped with them — they were only masked becausegetByMessageleased first, so fixing one without the other just relocates the lease.deleteSwipe: all nine cascade statements acrossgame_state_snapshots/spatial_context_snapshots/game_engine_statenow carrymsg.chatId(already fetched at the top of the function).getById/deleteByIdaccept an optional chatId, threaded from the load route.listByChatAndFilePathfor the image-serving route (the filePath argument literally embeds the chatId);getById/removeaccept optional chatId, threaded at every warm caller.DELETE /:id, checkpointDELETE /:id, workspaceDELETE /context/:id, agentsPATCH /runs/:runId): accept an optional chatId (query/body) so the client can start passing it; until it does, these few cold endpoints keep the lease, as documented in #5611.getFullyResidentLazyTables()on the store controller, mirroringgetResidentChatUnits()— empty is the healthy state.galleryFileHasReferences(#5613) and the boot gallery walk (#5612) are tracked separately.The chatId conjunct is behavior-preserving for reads and writes alike: the store's scope resolver uses it only to decide which chat's shards to load, and every scoped condition still matches exactly the rows it matched before (each site's rows always belonged to the chat being threaded — most sites validated exactly that one line later).
Regression
New block in
lazy-chat-units.regression.ts: drives the realcreateGameStateStoragelayer cold (scoped lookup,updateByMessageclone throughcreate()'s dedupe, batch committed fetch) and asserts no table lease forms and the other chat's unit never loads — then runs the pre-fix condition shape and asserts the lease tripwire still fires. Verified red against the pre-fix storage layer (restoredgame-state.storage.tsfrom staging → suite fails; restored the fix → passes).Validation done
tsc --noEmitall packages ✅ (shared rebuilt first)lintscripts ✅--check --end-of-line auto) on all 22 changed files ✅ (repo-widepnpm checkprettier step fails on this Windows box for all files — #5598, pre-existing)lazy-chat-units(lazy + eager-skip) ✅,message-sharding(lazy + eager) ✅,autonomous-check-storage✅Manual verification
MARINARA_MAX_RESIDENT_CHATSset and confirm the log no longer printsLazy table game_state_snapshots is now fully residentClient follow-up (not in this PR)
The four id-only endpoints now accept an optional
chatId; the client always has the chat open at those call sites and can start passing it to close the last cold leases. Happy to do that as a follow-up.Summary by CodeRabbit
Bug Fixes
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.