mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
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#6841
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/5597
Author: @kolacheee
Created: 8/28/2026
Status: ✅ Merged
Merged: 8/28/2026
Merged by: @kolacheee
Base:
staging← Head:feat/5592-phase2a-lazy-units📝 Commits (7)
e3871f0feat(storage): load chat-scoped tables lazily as per-chat unitsb52f6a0fix(storage): capture stale-file marks atomically with the flush's dirty keys7e1f649fix(storage): track every stray id per table during a shard-file merge4353228fix(storage): batch backup-recovery markers with the flush; scope inserts from normalized rows5f7c817feat(storage): boot guard — lazy unit tables must be PK-only uniqueea062f2fix(storage): table-wide message-id uniqueness via the harvest index; misfiled rows reachable through their owning unit19a7dc2docs(capability): spatial snapshot ids must be globally unique📊 Changes
8 files changed (+1514 additions, -58 deletions)
View changed files
📝
CHANGELOG.md(+5 -0)📝
packages/server/src/db/file-backed-store.ts(+876 -26)📝
packages/server/src/routes/game.routes.ts(+22 -3)📝
packages/server/src/services/storage/chats.storage.ts(+42 -21)📝
packages/server/src/services/storage/game-storyboards.storage.ts(+12 -7)📝
packages/shared/src/types/capability-runtime.ts(+7 -0)➕
scripts/regressions/lazy-chat-units.regression.ts(+540 -0)📝
scripts/regressions/message-sharding.regression.ts(+10 -1)📄 Description
Why
Part of #5592 (Phase 2, PR-A of the two-PR plan posted there). The file-native store keeps every row of every chat heap-resident, which is what pushes long multi-chat Termux profiles into the ~1 GB phone heap and exit-134 territory. Phases 0–1 (#5596) removed the biggest non-structural costs; this PR delivers the structural half: chat-scoped tables stop loading at boot and become resident one chat at a time.
What
Boot now only discovers shards for the 17 chat-scoped tables (messages, message_swipes, memory_chunks, agent_runs, agent_memory, chat_images, the game tables, workspace context, ooc/notes, call tables). For
messagesit additionally harvests the completemessageId -> chatIdindex (ids only; rows are dropped), because swipe shard resolution and query scoping depend on that map being total. The unassigned/orphan pseudo-unit still loads at boot — orphan-adoption healing needs it resident and it is tiny by design.First touch loads a whole chat unit: every lazy table's shard for that chatId, messages before swipes, through the same per-file recovery pipeline the eager loader ran (bak fallback, malformed-row quarantine, self-heal marking — now recorded at load time, when the unit's dirty keys can actually flush). Stray rows found in another unit's file pull their unit in transitively, and a canonical file's copy still beats a stray copy regardless of load order (the eager dedup rule, preserved via stray-provenance tracking).
Scoping: a WHERE-condition extractor computes which units a query can possibly match — directly from the shard column, through the message index for swipes and
messages.id, or by probing resident rows for other primary keys — with AND/OR combinators matching the evaluator exactly. Anything it cannot bound (backup export, cross-chat predicates likesourceChatId,agentConfigIdcascades) leases the whole table, so correctness never depends on the extractor being clever. Inserts/updates load their destination units before uniqueness checks; intra-unit cascades (messageId/snapshotId/callId children) ride a parent-unit hint instead of leasing.Consistency machinery: per-unit positive evidence for emptied-shard deletion (with a defensive requeue for dirty keys of unloaded units), scoped message-index rebuild on rollback (the complete harvested map must survive), transaction snapshots mirror mid-transaction unit loads so a rollback reverts the write but keeps the loaded rows, and the manifest reports the harvested messages total while omitting counts it cannot know.
Storage-layer scoping so hot paths do not lease: game-state cleanup on message delete threads the owning chatIds; the chat lastMessageAt backfill queries per chat instead of sweeping all messages; stale-storyboard recovery is per-chat at read time with a process-start cutoff floor, replacing the startup-wide sweep (a chat never read again keeps its stale rows on disk, invisible, until first read — see the storyboard commit note).
Kill switch:
MARINARA_EAGER_STORAGE=1empties the lazy tier and restores the previous eager boot end to end.Explicitly out of scope (PR-B): unit eviction. This PR changes when rows become resident, never whether loaded rows stay.
Regressions
New lane
scripts/regressions/lazy-chat-units.regression.ts: scoped query loads one unit while an untouched unit's file stays byte-identical (no boot healing), first-touch healing, swipes-load-with-unit, cold insert preserves shard siblings, unbounded select leases, chat deletion removes never-read units' files, mid-transaction unit load survives rollback, manifest counts. It self-skips underMARINARA_EAGER_STORAGE.Adapted
message-sharding.regression.tsminimally: four blocks that asserted heal-at-boot now touch the table first (heal-at-first-load); every other assertion is unchanged, and the whole suite also passes withMARINARA_EAGER_STORAGE=1(verified locally), so the eager path stays pinned.Also run locally and green: file-backed-shutdown, storage-writer-lock, slurp-storage, memory-recall-revectorize, chat-branch-lineage, agent-runtime, capability-package-lifecycle, checkpoint-retention; full node regression suite run in progress at submission time — result will be posted as a comment if anything surfaces.
Test plan
pnpm checkon a non-Windows checkout (Windows checkouts currently failformat:checkrepo-wide on CRLF — unrelated)pnpm regression(full node suite)MARINARA_EAGER_STORAGE=1: server boots and behaves identically to v2.4.4--max-old-space-size): boot memory with a large profile is visibly lower and chats load on first openReferences #5592 (PR-B, eviction, follows separately — do not auto-close).
Summary by CodeRabbit
New Features
Bug Fixes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.