[GH-ISSUE #1504] [Issue]: Long-Term Memory: a multi-source extraction re-reads the whole vault for every source while recall waits on the lock #1495

Closed
opened 2026-10-22 04:02:41 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Oct 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1504

Originally assigned to: @Promansis on GitHub.

Summary

When several sources are extracted in one batch, each source's commit lists and parses every note in the vault again and matches each candidate group against all of them. This happens while the batch holds the vault lock, and recall for a chat reply needs that same lock (S/recall/retrieval.ts:84).

On a synthetic vault of 8,000 notes, a 10-source batch holds the lock for about 24 s today, or 2,400 ms per source. Most of that time is spent re-reading the vault. A source's own fingerprint write discards the parsed vault snapshot, so the next source parses every file again.

The fix lists the vault once per batch and re-reads only the notes that later writes touch. It also filters and tokenizes the candidate set once per reconciliation instead of once per group and unit. With the fix the same batch holds the lock for 1.3 s (18.5× less), and every outcome stays identical.

Affected package

Re-checked 2026-10-21 at upstream/staging edb9c4928 (long-term-memory 1.4.57, built on the Engine's host, capability API 1.341): the fix applies unchanged there; line numbers are at the commit named below.

long-term-memory 1.4.54 (upstream/staging b1873710f). PR #1473 (head c4b1c0192) shifts lines in source-processing.ts and changes one line in candidate-reconciliation.ts without moving any line. Where the two differ, references read staging / #1473. #1473 merged on 2026-10-19 (staging 8b72729f1, LTM 1.4.55), so the second number is the current line.

S = packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory

Expected behavior

  • A batch reads the vault once for commit-time reconciliation, not once per source. The list still matches a fresh listNotes() for every source, including writes that land between two commits.
  • Reconciling one source costs about one pass over the compatible notes. Today it costs one pass per candidate group, with every section re-tokenized for every unit.
  • Match results stay the same: same rules, threshold and candidate order.

Actual behavior

  • processLongTermMemorySourceBatch holds one vault lock across the ordered commit loop (S/extraction/source-processing.ts:528 / :531). Each item's commit calls recompilePreparedWithFreshCandidates, which runs storage.listNotes() (:289 / :290).
  • Every vault mutation drops the parsed snapshot (S/persistence/mutation-transaction.ts:91), and each item writes its source fingerprint (source-processing.ts:356-363 / :357-364). From the second item on, listNotes() therefore reads and parses every vault file, then clones and sorts them all. The audit's probe D did not include this cost.
  • reconcileEvidenceUnitCandidates (S/extraction/candidate-reconciliation.ts:70) does the following on the complete-set path (:123-129), once per candidate group:
    • filters every candidate note for type, scope (canUpdateLtmScopedTarget), mode and status;
    • recomputes each unit's identity keys for every note (identityMatchesGroup, :273);
    • re-tokenizes every section of every note for every unit (contentMatchesGroup, :287).

Measurement

The fixture is private: synthetic vaults built from the real vault's non-source notes, with about 35% of the words changed and 60% of the notes in the batch's scope. It also includes a copy of the real vault (197 notes). Only aggregate numbers are shared here.

Each batch has 10 sources of 20 units each and mixes identity, content, ambiguous and sibling matches with creates. A fake provider returns fixed units, and each source is committed one after another (concurrency 1). Each figure is the median of 3 runs on a RAM disk.

"Lock" is the time the batch holds the vault lock, per source. "Today" and "fixed" are the same bench source with timing hooks; only "fixed" has the change. Listing and reconcile are in milliseconds per source. Other jobs were using the host (load 6–15 on 12 cores), so absolute times are 25–45% higher than in a quieter run of an earlier version of the patch. The ratios held.

Vault Mode Lock today Listing Reconcile Lock fixed Listing Reconcile Factor
Real copy (197) review 126 ms 45 18 71 ms 0.6 4 1.8×
Real copy (197) auto-apply 245 ms 61 19 169 ms 4.7 4 1.5×
2,000 review 596 ms 454 95 86 ms 3.5 24 6.9×
2,000 auto-apply 808 ms 537 106 195 ms 8.9 25 4.1×
8,000 review 2,415 ms 1,993 350 131 ms 8.9 74 18.5×
8,000 auto-apply 2,205 ms 1,711 339 234 ms 18.6 88 9.4×
20,000 review 4,733 ms 3,971 716 240 ms 26.6 169 19.7×
20,000 auto-apply 4,416 ms 3,639 667 304 ms 31.3 163 14.5×
  • Finalize (25–58 ms), the source fingerprint write (4–8 ms) and auto-apply (66–104 ms) take the same time today and with the fix. Listing and reconcile are the only parts that change.
  • In review mode, a 10-source batch on 8,000 notes holds the lock for 24 s today and 1.3 s with the fix. At 20,000 notes it is 47 s today and 2.4 s with the fix.
  • Reconcile alone, warm, per source: 6.1 → 1.9 ms on the real copy, 74 → 18 ms at 2,000 notes, 337 → 99 ms at 8,000 and 652 → 179 ms at 20,000.
  • After the fix, what remains of the reconcile time is one Jaccard pass over every compatible note of the same type, per group. It grows linearly with the vault.

Steps to reproduce

  1. Use a vault with a few thousand notes in one chat's scope.
  2. Import or re-extract several sources from that chat in one batch, with any provider.
  3. Time the commit loop, or try a recall in that chat while the batch commits. Recall waits for the batch lock, and the wait grows with vault size multiplied by the number of sources.

Minimal fix

One PR, patch bump. The finished patch is private (source plus regressions, on 8b72729f1). The first reference patch (171 changed lines) is superseded.

  • S/persistence/vault-snapshot.ts:43-46 (same at #1473):
    • invalidateLtmVaultSnapshot(root, paths?) also calls write watchers with the paths a mutation wrote. Callers that give no paths pass undefined: repair, recovery and cleanup().
    • New watchLtmVaultWrites(root, onWrite) registers a watcher and returns its stop function.
    • About 17 lines.
  • S/persistence/mutation-transaction.ts:90-92 (same): commitLtmMutation invalidates after create() and passes prepared.files.map((file) => file.path). create() has already validated these as root-relative paths. It is synchronous, so no read can run between it and the invalidation.
  • S/extraction/source-processing.ts:
    • Add a batchCommittedNotes(storage) helper above commitPreparedLongTermMemorySource (:306 / :307):
      • It lists the vault once and watches writes after that.
      • Before the next listing it re-reads only the vault paths that writes reported (getNotesByIds). It deletes notes that are gone and re-sorts by id when a note was added, matching listNotes() order.
      • A write without paths, or a failed re-read, makes the next listing a full listNotes().
    • recompilePreparedWithFreshCandidates (:277 / :278) takes committedNotes? and lists through it at :289 / :290.
    • commitPreparedLongTermMemorySource takes committedNotes? in its options (:308 / :309) and passes it at :316 / :317.
    • processLongTermMemorySourceBatch creates the helper before the lock (:528 / :531) and passes it to each commit (:538-542 / :541-545). It stops the helper with .finally(committedNotes.stop) on the lock call (:567 / :571).
    • The single-source processLongTermMemorySource (:380-385 / :381-386) is unchanged; it already lists once.
  • S/extraction/candidate-reconciliation.ts (same lines at both):
    • Before the group loop (:102): when candidateNotes is given, filter it once with isReconcilableNote and bucket the result by type. isReconcilableNote is today's isCompatibleCandidateNote without the type check: source-like and scene notes, archived/resolved, scope, mode.
    • Complete-set branch (:123-129): take the bucket for the type, then drop the derived id and ids the unit cannot remap to, as today.
    • Matching (:168-171):
      • Build the group's identity keys once as a Set and compare them with each note's normalized title, cached once per call.
      • contentMatches computes each unit's normalized text and tokens once per group, and each note's section text and tokens at most once per call.
      • identityMatchesGroup (:273) and contentMatchesGroup (:287) go away.
    • isCompatibleCandidateNote (:248) becomes note.type === noteType && isReconcilableNote(...), so the bounded preparation path (:163) is unchanged.
  • CHANGELOG under ## Unreleased: one bullet, below.

Why a write watcher, not "re-read what apply wrote": a first version re-read only the notes that the batch's own auto-apply wrote. It passed the probe below but failed tests/long-term-memory-extraction-reliability.regression.ts:1046 (#1087 terminal-overlay case). That test archives a target between two commits through a write the batch did not make. The list must stay equal to a fresh listing whoever writes, so it follows the vault's own write reports.

Validation of this patch (on a patched copy of the bench tree, with a private harness, pass rule fixed before the first run):

Check Result
P1: per-item results (status, outcome, accounting, diagnostics, draft mutations, applied/skipped) and the final vault are identical, today vs fixed, for every vault and both apply modes identical (4 vaults × 2 modes; today's runs are also identical run to run)
P1: reconcile alone, complete set, deep-equal per source (10 sources × 4 vaults) identical
P2: lock time per source at 8,000 notes falls at least 5× in both modes 18.5× review, 9.4× auto-apply
PL-1 replay (24 real known pairs × 2 models × 2 runs, cached responses) 96/96 rows identical to the baseline. S1 24/24; commit matched 69 → 69; code-side plausible 0/36 → 0/36; world matched 3 → 3
listNotes() calls after the first finalize, 3-source batch, review / auto-apply 2 / 3 → 0 / 1 (the 1 is the post-batch index rebuild)
Cached notes deep-frozen during six batch-heavy suites no write to a cached note (no swallowed TypeError)
LTM engine lanes on the patched copy (the 21 in the local LTM runner plus candidate-reconciliation and reconciliation-recall) 21 pass; browser and installation need the rebuilt archive and were not run
#1473's strict typecheck (scripts/typecheck-packages.mjs long-term-memory with an Engine) on #1473 + patch clean (81 server/shared, 44 client files)
ESLint and Prettier on the four files clean

The PL-1 run covers single-source commits, so it checks only the reconciliation half. The batch half is covered by the probe and the extraction-reliability suite.

Not included

  • F10 (redundant compiler passes). Its items are in source-extraction.ts, evidence-unit-extraction.ts, structured-summary-normalizer.ts and evidence-unit-validation.ts, which this fix does not touch. They are not hot either: at 8,000 notes, the second compile without reconciliation takes about 12 ms per source.
  • An inverted token index for content matching. Add one only if a vault far beyond 20,000 notes needs it.
  • Updating the parsed snapshot in place on every write instead of dropping it. That would help every read-after-write, but it changes shared persistence behavior for all callers.
  • The preparation path, which is already bounded.

CHANGELOG

  • Saving several imported or re-extracted sources into a large memory vault is faster, and recall and other memory actions wait less while it happens. Each source used to re-read and re-check every memory in the vault while it saved; now a batch reads the vault once and re-reads only the memories that changed. The same memories are matched as before.

Regression proof

Written first and proven on 8b72729f1:

  1. tests/long-term-memory-candidate-reconciliation.regression.ts: a table for the candidateNotes path. No test calls it directly today. It passes on staging and after the fix. A second case, which fails on staging, bounds reads per call: 3 groups × 4 candidate notes read each note's scope 12 times today and 4 times with the fix. The table pins:
    • identity by title, by subjectId and by subjectNames;
    • exact normalized content;
    • Jaccard at 0.85 and just below it;
    • a note with an empty title or no sections;
    • archived, resolved, source-like, scene, global, other-scope, wider-scope, other-mode and other-type notes skipped;
    • a note in a narrower scope than the source reused;
    • the derived id skipped;
    • nine plausible notes left ambiguous, the diagnostic keeping the first eight in candidate order.
  2. tests/long-term-memory-extraction-reliability.regression.ts: after the #1087 terminal-overlay case, a three-source model batch in review mode counts LongTermMemoryStorage.prototype.listNotes calls after the first LongTermMemoryDraftStore.prototype.createDraft: 2 today, 0 with the fix. The first batch's draft hook also creates a matching note under another id and deletes another, and the later items must reuse the new note and not target the deleted one. A second three-source batch drops the snapshot without paths after the first draft: 2 today, 1 with the fix (one full relist). A two-source batch drops it while the second item re-reads: 1 relist. The listings returned to the batch are deep-frozen. The #1087 cases (:568-1220), and the terminal-overlay case at :935-1060 in particular, remain the freshness guards.
  3. tests/long-term-memory-storage.regression.ts: next to the snapshot count (:3210-3222), check that watchLtmVaultWrites reports the note's root-relative path for create, update and delete. It reports undefined for cleanup(), nothing after stop, and a repeated stop leaves a later watcher on the same root registered.
  4. Not added: a 2,000-note case in tests/long-term-memory-reconciliation-recall.regression.ts. The listNotes count in 2 is the bound, and a 2,000-note fixture adds CI time without a new assertion.

All three suites run in ltm-browser.yml ("Run Long-Term Memory regressions").

Environment

  • Marinara Engine version: 2.5.0 (staging 2039583ca, local checkout used read-only for tests)
  • Package version: long-term-memory 1.4.54 (upstream/staging b1873710f)
  • Install type: source (measurement on a private fixture)
  • OS + version: Linux, Node 24.15.0
  • Browser or app shell: n/a (server)

Logs, screenshots, or video

None. Timings come from a private harness on a 12-core host that other jobs were also using.

Additional context

Tracker item EX-I4 (extraction stages audit F3, high at scale). F10 was to be folded in only where this fix touches the same code, and it does not (see Not included). The audit's probe D measured reconcile alone (41 / 354 / 1,405 ms at 200 / 2,000 / 8,000 notes, with 75% compatible notes). The table above uses about 10% compatible notes and adds the per-source vault read.

Scope: the fix may change persistence/vault-snapshot.ts and persistence/mutation-transaction.ts so the vault reports every write it makes. The alternative was weakening tests/long-term-memory-extraction-reliability.regression.ts:1046. Because this changes executable server code on the vault write path, the PR carries explicit validation notes for it.
The patch rebased onto upstream/staging 8b72729f1 (after #1473) passes typecheck with the strict gate, npm run check, the package rebuild and all 32 LTM suites there.

Related: #1473, #1087.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 20, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1504 Originally assigned to: @Promansis on GitHub. ## Summary When several sources are extracted in one batch, each source's commit lists and parses every note in the vault again and matches each candidate group against all of them. This happens while the batch holds the vault lock, and recall for a chat reply needs that same lock (`S/recall/retrieval.ts:84`). On a synthetic vault of 8,000 notes, a 10-source batch holds the lock for about 24 s today, or 2,400 ms per source. Most of that time is spent re-reading the vault. A source's own fingerprint write discards the parsed vault snapshot, so the next source parses every file again. The fix lists the vault once per batch and re-reads only the notes that later writes touch. It also filters and tokenizes the candidate set once per reconciliation instead of once per group and unit. With the fix the same batch holds the lock for 1.3 s (18.5× less), and every outcome stays identical. ## Affected package Re-checked 2026-10-21 at `upstream/staging` edb9c4928 (long-term-memory 1.4.57, built on the Engine's host, capability API 1.341): the fix applies unchanged there; line numbers are at the commit named below. `long-term-memory` 1.4.54 (`upstream/staging` b1873710f). PR #1473 (head c4b1c0192) shifts lines in `source-processing.ts` and changes one line in `candidate-reconciliation.ts` without moving any line. Where the two differ, references read `staging / #1473`. #1473 merged on 2026-10-19 (staging 8b72729f1, LTM 1.4.55), so the second number is the current line. `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` ## Expected behavior - A batch reads the vault once for commit-time reconciliation, not once per source. The list still matches a fresh `listNotes()` for every source, including writes that land between two commits. - Reconciling one source costs about one pass over the compatible notes. Today it costs one pass per candidate group, with every section re-tokenized for every unit. - Match results stay the same: same rules, threshold and candidate order. ## Actual behavior - `processLongTermMemorySourceBatch` holds one vault lock across the ordered commit loop (`S/extraction/source-processing.ts:528 / :531`). Each item's commit calls `recompilePreparedWithFreshCandidates`, which runs `storage.listNotes()` (`:289 / :290`). - Every vault mutation drops the parsed snapshot (`S/persistence/mutation-transaction.ts:91`), and each item writes its source fingerprint (`source-processing.ts:356-363 / :357-364`). From the second item on, `listNotes()` therefore reads and parses every vault file, then clones and sorts them all. The audit's probe D did not include this cost. - `reconcileEvidenceUnitCandidates` (`S/extraction/candidate-reconciliation.ts:70`) does the following on the complete-set path (`:123-129`), once per candidate group: - filters every candidate note for type, scope (`canUpdateLtmScopedTarget`), mode and status; - recomputes each unit's identity keys for every note (`identityMatchesGroup`, `:273`); - re-tokenizes every section of every note for every unit (`contentMatchesGroup`, `:287`). ### Measurement The fixture is private: synthetic vaults built from the real vault's non-source notes, with about 35% of the words changed and 60% of the notes in the batch's scope. It also includes a copy of the real vault (197 notes). Only aggregate numbers are shared here. Each batch has 10 sources of 20 units each and mixes identity, content, ambiguous and sibling matches with creates. A fake provider returns fixed units, and each source is committed one after another (concurrency 1). Each figure is the median of 3 runs on a RAM disk. "Lock" is the time the batch holds the vault lock, per source. "Today" and "fixed" are the same bench source with timing hooks; only "fixed" has the change. Listing and reconcile are in milliseconds per source. Other jobs were using the host (load 6–15 on 12 cores), so absolute times are 25–45% higher than in a quieter run of an earlier version of the patch. The ratios held. | Vault | Mode | Lock today | Listing | Reconcile | Lock fixed | Listing | Reconcile | Factor | |---|---|---:|---:|---:|---:|---:|---:|---:| | Real copy (197) | review | 126 ms | 45 | 18 | 71 ms | 0.6 | 4 | 1.8× | | Real copy (197) | auto-apply | 245 ms | 61 | 19 | 169 ms | 4.7 | 4 | 1.5× | | 2,000 | review | 596 ms | 454 | 95 | 86 ms | 3.5 | 24 | 6.9× | | 2,000 | auto-apply | 808 ms | 537 | 106 | 195 ms | 8.9 | 25 | 4.1× | | 8,000 | review | 2,415 ms | 1,993 | 350 | 131 ms | 8.9 | 74 | **18.5×** | | 8,000 | auto-apply | 2,205 ms | 1,711 | 339 | 234 ms | 18.6 | 88 | **9.4×** | | 20,000 | review | 4,733 ms | 3,971 | 716 | 240 ms | 26.6 | 169 | 19.7× | | 20,000 | auto-apply | 4,416 ms | 3,639 | 667 | 304 ms | 31.3 | 163 | 14.5× | - Finalize (25–58 ms), the source fingerprint write (4–8 ms) and auto-apply (66–104 ms) take the same time today and with the fix. Listing and reconcile are the only parts that change. - In review mode, a 10-source batch on 8,000 notes holds the lock for 24 s today and 1.3 s with the fix. At 20,000 notes it is 47 s today and 2.4 s with the fix. - Reconcile alone, warm, per source: 6.1 → 1.9 ms on the real copy, 74 → 18 ms at 2,000 notes, 337 → 99 ms at 8,000 and 652 → 179 ms at 20,000. - After the fix, what remains of the reconcile time is one Jaccard pass over every compatible note of the same type, per group. It grows linearly with the vault. ## Steps to reproduce 1. Use a vault with a few thousand notes in one chat's scope. 2. Import or re-extract several sources from that chat in one batch, with any provider. 3. Time the commit loop, or try a recall in that chat while the batch commits. Recall waits for the batch lock, and the wait grows with vault size multiplied by the number of sources. ## Minimal fix One PR, patch bump. The finished patch is private (source plus regressions, on 8b72729f1). The first reference patch (171 changed lines) is superseded. - **`S/persistence/vault-snapshot.ts:43-46`** (same at #1473): - `invalidateLtmVaultSnapshot(root, paths?)` also calls write watchers with the paths a mutation wrote. Callers that give no paths pass `undefined`: repair, recovery and `cleanup()`. - New `watchLtmVaultWrites(root, onWrite)` registers a watcher and returns its stop function. - About 17 lines. - **`S/persistence/mutation-transaction.ts:90-92`** (same): `commitLtmMutation` invalidates after `create()` and passes `prepared.files.map((file) => file.path)`. `create()` has already validated these as root-relative paths. It is synchronous, so no read can run between it and the invalidation. - **`S/extraction/source-processing.ts`**: - Add a `batchCommittedNotes(storage)` helper above `commitPreparedLongTermMemorySource` (`:306 / :307`): - It lists the vault once and watches writes after that. - Before the next listing it re-reads only the vault paths that writes reported (`getNotesByIds`). It deletes notes that are gone and re-sorts by id when a note was added, matching `listNotes()` order. - A write without paths, or a failed re-read, makes the next listing a full `listNotes()`. - `recompilePreparedWithFreshCandidates` (`:277 / :278`) takes `committedNotes?` and lists through it at `:289 / :290`. - `commitPreparedLongTermMemorySource` takes `committedNotes?` in its options (`:308 / :309`) and passes it at `:316 / :317`. - `processLongTermMemorySourceBatch` creates the helper before the lock (`:528 / :531`) and passes it to each commit (`:538-542 / :541-545`). It stops the helper with `.finally(committedNotes.stop)` on the lock call (`:567 / :571`). - The single-source `processLongTermMemorySource` (`:380-385 / :381-386`) is unchanged; it already lists once. - **`S/extraction/candidate-reconciliation.ts`** (same lines at both): - Before the group loop (`:102`): when `candidateNotes` is given, filter it once with `isReconcilableNote` and bucket the result by type. `isReconcilableNote` is today's `isCompatibleCandidateNote` without the type check: source-like and scene notes, archived/resolved, scope, mode. - Complete-set branch (`:123-129`): take the bucket for the type, then drop the derived id and ids the unit cannot remap to, as today. - Matching (`:168-171`): - Build the group's identity keys once as a `Set` and compare them with each note's normalized title, cached once per call. - `contentMatches` computes each unit's normalized text and tokens once per group, and each note's section text and tokens at most once per call. - `identityMatchesGroup` (`:273`) and `contentMatchesGroup` (`:287`) go away. - `isCompatibleCandidateNote` (`:248`) becomes `note.type === noteType && isReconcilableNote(...)`, so the bounded preparation path (`:163`) is unchanged. - **CHANGELOG under `## Unreleased`**: one bullet, below. **Why a write watcher, not "re-read what apply wrote":** a first version re-read only the notes that the batch's own auto-apply wrote. It passed the probe below but failed `tests/long-term-memory-extraction-reliability.regression.ts:1046` (#1087 terminal-overlay case). That test archives a target between two commits through a write the batch did not make. The list must stay equal to a fresh listing whoever writes, so it follows the vault's own write reports. **Validation of this patch** (on a patched copy of the bench tree, with a private harness, pass rule fixed before the first run): | Check | Result | |---|---| | P1: per-item results (status, outcome, accounting, diagnostics, draft mutations, applied/skipped) and the final vault are identical, today vs fixed, for every vault and both apply modes | identical (4 vaults × 2 modes; today's runs are also identical run to run) | | P1: reconcile alone, complete set, deep-equal per source (10 sources × 4 vaults) | identical | | P2: lock time per source at 8,000 notes falls at least 5× in both modes | 18.5× review, 9.4× auto-apply | | PL-1 replay (24 real known pairs × 2 models × 2 runs, cached responses) | 96/96 rows identical to the baseline. S1 24/24; commit matched 69 → 69; code-side plausible 0/36 → 0/36; world matched 3 → 3 | | `listNotes()` calls after the first finalize, 3-source batch, review / auto-apply | 2 / 3 → 0 / 1 (the 1 is the post-batch index rebuild) | | Cached notes deep-frozen during six batch-heavy suites | no write to a cached note (no swallowed `TypeError`) | | LTM engine lanes on the patched copy (the 21 in the local LTM runner plus `candidate-reconciliation` and `reconciliation-recall`) | 21 pass; `browser` and `installation` need the rebuilt archive and were not run | | #1473's strict typecheck (`scripts/typecheck-packages.mjs long-term-memory` with an Engine) on #1473 + patch | clean (81 server/shared, 44 client files) | | ESLint and Prettier on the four files | clean | The PL-1 run covers single-source commits, so it checks only the reconciliation half. The batch half is covered by the probe and the extraction-reliability suite. **Not included** - F10 (redundant compiler passes). Its items are in `source-extraction.ts`, `evidence-unit-extraction.ts`, `structured-summary-normalizer.ts` and `evidence-unit-validation.ts`, which this fix does not touch. They are not hot either: at 8,000 notes, the second compile without reconciliation takes about 12 ms per source. - An inverted token index for content matching. Add one only if a vault far beyond 20,000 notes needs it. - Updating the parsed snapshot in place on every write instead of dropping it. That would help every read-after-write, but it changes shared persistence behavior for all callers. - The preparation path, which is already bounded. ### CHANGELOG - Saving several imported or re-extracted sources into a large memory vault is faster, and recall and other memory actions wait less while it happens. Each source used to re-read and re-check every memory in the vault while it saved; now a batch reads the vault once and re-reads only the memories that changed. The same memories are matched as before. ## Regression proof Written first and proven on 8b72729f1: 1. **`tests/long-term-memory-candidate-reconciliation.regression.ts`**: a table for the `candidateNotes` path. No test calls it directly today. It passes on staging and after the fix. A second case, which fails on staging, bounds reads per call: 3 groups × 4 candidate notes read each note's `scope` 12 times today and 4 times with the fix. The table pins: - identity by title, by `subjectId` and by `subjectNames`; - exact normalized content; - Jaccard at 0.85 and just below it; - a note with an empty title or no sections; - archived, resolved, source-like, scene, global, other-scope, wider-scope, other-mode and other-type notes skipped; - a note in a narrower scope than the source reused; - the derived id skipped; - nine plausible notes left ambiguous, the diagnostic keeping the first eight in candidate order. 2. **`tests/long-term-memory-extraction-reliability.regression.ts`**: after the #1087 terminal-overlay case, a three-source model batch in review mode counts `LongTermMemoryStorage.prototype.listNotes` calls after the first `LongTermMemoryDraftStore.prototype.createDraft`: 2 today, 0 with the fix. The first batch's draft hook also creates a matching note under another id and deletes another, and the later items must reuse the new note and not target the deleted one. A second three-source batch drops the snapshot without paths after the first draft: 2 today, 1 with the fix (one full relist). A two-source batch drops it while the second item re-reads: 1 relist. The listings returned to the batch are deep-frozen. The #1087 cases (`:568-1220`), and the terminal-overlay case at `:935-1060` in particular, remain the freshness guards. 3. **`tests/long-term-memory-storage.regression.ts`**: next to the snapshot count (`:3210-3222`), check that `watchLtmVaultWrites` reports the note's root-relative path for create, update and delete. It reports `undefined` for `cleanup()`, nothing after stop, and a repeated stop leaves a later watcher on the same root registered. 4. Not added: a 2,000-note case in `tests/long-term-memory-reconciliation-recall.regression.ts`. The `listNotes` count in 2 is the bound, and a 2,000-note fixture adds CI time without a new assertion. All three suites run in `ltm-browser.yml` ("Run Long-Term Memory regressions"). ## Environment - Marinara Engine version: 2.5.0 (`staging` 2039583ca, local checkout used read-only for tests) - Package version: long-term-memory 1.4.54 (`upstream/staging` b1873710f) - Install type: source (measurement on a private fixture) - OS + version: Linux, Node 24.15.0 - Browser or app shell: n/a (server) ## Logs, screenshots, or video None. Timings come from a private harness on a 12-core host that other jobs were also using. ## Additional context Tracker item EX-I4 (extraction stages audit F3, high at scale). F10 was to be folded in only where this fix touches the same code, and it does not (see Not included). The audit's probe D measured reconcile alone (41 / 354 / 1,405 ms at 200 / 2,000 / 8,000 notes, with 75% compatible notes). The table above uses about 10% compatible notes and adds the per-source vault read. Scope: the fix may change `persistence/vault-snapshot.ts` and `persistence/mutation-transaction.ts` so the vault reports every write it makes. The alternative was weakening `tests/long-term-memory-extraction-reliability.regression.ts:1046`. Because this changes executable server code on the vault write path, the PR carries explicit validation notes for it. The patch rebased onto `upstream/staging` 8b72729f1 (after #1473) passes typecheck with the strict gate, `npm run check`, the package rebuild and all 32 LTM suites there. Related: #1473, #1087. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-22 04:02:41 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Agents#1495
No description provided.