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#6840
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/5596
Author: @kolacheee
Created: 8/28/2026
Status: ✅ Merged
Merged: 8/28/2026
Merged by: @kolacheee
Base:
staging← Head:fix/5592-store-memory-phase0-1📝 Commits (2)
709a535perf(db): store memory groundwork for #5592 - Phase 0 + Phase 177a9a78docs(db): state the swipe-scan win precisely📊 Changes
8 files changed (+465 additions, -39 deletions)
View changed files
📝
CHANGELOG.md(+3 -0)📝
packages/server/src/db/file-backed-store.ts(+171 -12)📝
packages/server/src/db/file-schema.ts(+12 -0)📝
packages/server/src/db/schema/chats.ts(+2 -2)📝
packages/server/src/routes/chats.routes.ts(+4 -1)📝
packages/server/src/services/memory-recall.ts(+9 -7)📝
packages/server/src/services/storage/chats.storage.ts(+16 -16)📝
scripts/regressions/message-sharding.regression.ts(+248 -1)📄 Description
Linked issue
Part of #5592 (Phase 0 + Phase 1 of the plan in the issue's audit comment — Phase 2, partial residency, deliberately stays parked, so this PR does not close the issue).
Why this change
Termux servers keep dying with
FATAL ERROR: Reached heap limit(#4730, #4936, #5585) because the file-native store holds every row of every table on the V8 heap and several hot paths add O(whole-table) allocation on top. A pre-implementation audit (132 consumer classifications, 51 hazards — recorded on #5592) showed the eventual fix, partial residency, has hard prerequisites. This PR ships those prerequisites plus the single biggest memory win, each independently valuable today and none changing behavior or the on-disk format.What changed
Phase 0 — store groundwork (no behavior change):
inArray/notInArrayused to re-materialize the values array and runArray.includesfor every scanned row — O(rows × values), the measured cause of the #3402 post-generation stall. They now build aSetonce per condition object (WeakMap-cached;Set.hasandincludesshare SameValueZero semantics; column/array-valued entries keep the old path — no call site in the repo uses those today).countSwipesByMessageIdandlistSwipesByMessageIdsdropped their WHERE deliberately in #3402 because of (1); with (1) fixed at the root, the scoped form is exactly as fast as the full scan and stops reading — and in the list case cloning — every other chat's swipes on the hottest read path in the app. No caller changes; both callers already pass the right ids.count()and no-join selects share one iteration. Previously every select materialized two objects for every row of the table before the WHERE ran (andcount()did the same per call). The shared scan reuses a singleRowContext— safe because the evaluator never retains it — and allocates contexts only for matching rows.count()keeps exact integer semantics (the paginated-cursor!== 1check andupperRowidarithmetic depend on it).messagesfirst explicitly (themessageId→chatIdswipe-shard index depended on array declaration order enforced only by a comment), and the flush's "dirty key with no rows ⇒ shard emptied ⇒ delete its file" inference is now gated on positive evidence (fullyResidentTables— always true today, inert; exactly the gate Phase 2 needs so an evicted shard can never be mistaken for an emptied one and unlinked).Phase 1 — Memory Recall embeddings off the V8 heap:
memory_chunks.embedding(a JSON float-array string per 5-message chunk, ~8 KB each, resident forever) is plausibly the largest single heap block for a long roleplay profile with recall enabled — the #5585 reporter's diagnostics showed 1.1 GiB steady-state against a 1.6 GiB cap. The store now packs these toFloat64Arrayat its boundary: ~6 KB of ArrayBuffer outside the V8 heap, which is what the Android 134-aborts actually measure. Recall scoring receives the packed vector directly through its projected select and skips the per-chunkJSON.parse(the recon measured 229 ms → 13 ms for a 20k-chunk scoring pass, and removes ~60 MB of transient parse allocation per recall — the same burst shape as the crash trace).Compatibility is by construction, not enumeration:
[1.0, 1E-3]stays a string verbatim), and every write site restores the text. NoSTORAGE_VERSIONbump, no migration; the launcher format-guard regression still passes.parseStoredEmbedding,cosineSimilarity,parseMemoryEmbedding) via the newvectorTextcolumn type.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Automated, from this branch:
pnpm lintandpnpm buildpass.message-sharding(extended with 4 new blocks / ~20 assertions: chat-scoped swipe counts and listings,inArray/notInArraySet semantics, emptied-shard unlink surviving a failed flush and completing on retry, byte-identical embedding round-trips, string-vs-packed select shapes,isNotNullover packed values, non-canonical text preserved verbatim),memory-recall-revectorize,file-backed-shutdown,storage-writer-lock,slurp-storage,capability-package-lifecycle,agent-runtime,launcher/format-guard.format:checkfails pre-existing on CRLF Windows checkouts).Worth a human pass:
Server memorydiagnostics line from #5515 makes this directly observable)./memories/export) — payload shapes unchanged.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)Three CHANGELOG entries under
[Unreleased] → Fixed. No user-facing docs describe the store internals; no docs-i18n impact. Explicitly: noSTORAGE_VERSION/storage-format.jsonchange — the format-guard regression pins that the pairing is intact and this PR alters no on-disk layout.Summary by CodeRabbit
Bug Fixes
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.