[PR #1526] [MERGED] fix(long-term-memory): rebuild the recall index in one background job after draft apply and extraction (1.4.67) #1529

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Agents/pull/1526
Author: @Promansis
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @Promansis

Base: staging ← Head: fix(long-term-memory)/debounced-rebuild


📝 Commits (2)

  • bd1633f fix(long-term-memory): rebuild the recall index in one background job after draft apply and extraction (#1523)
  • 6f3473c chore(long-term-memory): release 1.4.67 (#1523)

📊 Changes

25 files changed (+1050 additions, -257 deletions)

View changed files

📝 .github/workflows/ltm-browser.yml (+1 -1)
➕ artifacts/long-term-memory-1.4.67.zip (+0 -0)
📝 catalog/catalog.json (+6 -6)
📝 catalog/notes.json (+6 -6)
📝 catalog/v2/catalog.json (+6 -6)
📝 catalog/v2/notes.json (+6 -6)
📝 catalog/v3/catalog.json (+6 -6)
📝 catalog/v3/notes.json (+6 -6)
📝 packages/long-term-memory/CHANGELOG.md (+4 -0)
📝 packages/long-term-memory/docs/ARCHITECTURE.md (+17 -1)
📝 packages/long-term-memory/manifest.json (+3 -3)
📝 packages/long-term-memory/server.mjs (+40 -40)
📝 packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/review/ReviewQueue.tsx (+1 -1)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/drafts/reconciliation.ts (+8 -26)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/extraction/source-processing.ts (+3 -11)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/maintenance/maintenance.ts (+8 -1)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/persistence/vault-lock.ts (+11 -0)
➕ packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/recall/rebuild-job.ts (+148 -0)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/recall/rebuild.ts (+195 -94)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/recall/retrieval.ts (+4 -2)

...and 5 more files

📄 Description

Pull request

Linked issue

Closes #1523. This PR does the background index rebuild. Moving the debug log onto its own lock, the issue's on-hold second part, needs a new design decision and will get its own issue.

Why this change

  • Every applied Review suggestion and every extraction that applies memories rebuilt the recall index while holding the vault lock, embedding included. "Apply all" over 10 suggestions ran 10 rebuilds (4 s on a 197-note vault with local MiniLM), and every other save and debug line waited behind them.
  • After the embedding source changed, the first recall re-embedded the whole vault before answering (4 s at 197 notes, growing with vault size), with the lock held.

What changed

  • long-term-memory: draft apply and source extraction schedule one background rebuild per vault: 1 s after the last change, at most 10 s after the first. The rebuild holds the vault lock only to read the notes and to publish. It publishes only when nothing changed while it embedded; otherwise it runs again and reuses the vectors it already has.
  • Recall, the Engine's index refresh and the integrity check run a pending rebuild first, so they still see every applied change. They wait for one run; a change it missed leaves the index dirty, and the read rebuilds it inline as before.
  • After an embedding-source change, recall answers from the keyword lanes at once and re-embeds in the background. That re-embed stops when a change or a rebuild under the lock overtakes it, instead of trying again with the old source. The Engine's refresh still re-embeds before answering.
  • Waiting for the rebuild while holding the vault lock throws instead of deadlocking, and a rebuild scheduled inside a vault write waits for that write to finish. Deactivation stops a pending or running rebuild, and none starts again until the package is activated.
  • Editor, settings, scope-link, repair, explicit and restore rebuilds stay synchronous.
  • Regression: new tests/long-term-memory-rebuild-job.regression.ts, wired into ltm-browser.yml. The runtime and extraction-graph suites now drive the scheduled rebuild with fake timers.
  • Release: long-term-memory 1.4.67 on staging 77acb942b, with the CHANGELOG entry, version, manifest, rebuilt server.mjs, artifact and catalog entries. client.js is unchanged (the client change is a type only).

Package and security impact

  • Affected package IDs: long-term-memory
  • Engine compatibility impact: none
  • New or changed permissions/entrypoints: none
  • Restart, storage, update, or uninstall impact: none on disk formats. A pending rebuild is dropped and a running one aborted at deactivation; the index stays marked dirty, so the next recall rebuilds it.
  • Concurrency: executable server code now writes recall.json from a background job. Lock order and the publish check are in the validation notes.
  • Draft apply returns indexRebuild: { status: "pending" }, so Review no longer shows "the index rebuild failed" for a suggestion. A background failure shows in the index status and the server log.

Validation

  • node scripts/validate-catalog.mjs passes locally
  • git diff --check passes locally
  • Rebuilt every affected manifest, payload, artifact, and catalog entry
  • Installed or updated the affected package through Marinara Engine
  • Checked supported modes, restart behavior, and uninstall cleanup
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • tests/long-term-memory-rebuild-job.regression.ts fails on staging (ten draft applies in one quiet period must rebuild the index once, 10 calls instead of 1) and passes with the fix. Seven deliberate breaks each make it fail: job inside the caller's lock, no cap, no follow-up, no revision check, no deadlock guard, failure rejecting the job, no vector reuse. Five more, from review, each fail their own check: a reader waiting for every re-run, an upgrade retrying with its old source, a locked rebuild not aborting an upgrade, a failed state without a build, a schedule after deactivation.
  • long-term-memory-runtime, -extraction-graph and -routes regressions pass. Typecheck, lint, the package build and every Long-Term Memory regression suite pass on the release head.
  • Burst of 10 applies on a 197-note vault copy: 4,033 ms with 10 rebuilds before, 428 ms with 1 rebuild after. First recall after an embedding-source change: 4,138 ms before, 5 ms after (background upgrade done about 3 s later).

Documentation impact

  • No documentation changes needed
  • Updated this README catalog and package guidance
  • Updated linked Marinara Engine documentation

packages/long-term-memory/docs/ARCHITECTURE.md describes the background rebuild and the embedding-source behaviour.

UI evidence (if applicable)

  • n/a (server; one client type widened)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Agents/pull/1526 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `staging` ← **Head:** `fix(long-term-memory)/debounced-rebuild` --- ### 📝 Commits (2) - [`bd1633f`](https://github.com/Pasta-Devs/Marinara-Agents/commit/bd1633f578c12520e111f56562a68ff5f99ab103) fix(long-term-memory): rebuild the recall index in one background job after draft apply and extraction (#1523) - [`6f3473c`](https://github.com/Pasta-Devs/Marinara-Agents/commit/6f3473c3009f595f100992603dc6b6a8ca19a796) chore(long-term-memory): release 1.4.67 (#1523) ### 📊 Changes **25 files changed** (+1050 additions, -257 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/ltm-browser.yml` (+1 -1) ➕ `artifacts/long-term-memory-1.4.67.zip` (+0 -0) 📝 `catalog/catalog.json` (+6 -6) 📝 `catalog/notes.json` (+6 -6) 📝 `catalog/v2/catalog.json` (+6 -6) 📝 `catalog/v2/notes.json` (+6 -6) 📝 `catalog/v3/catalog.json` (+6 -6) 📝 `catalog/v3/notes.json` (+6 -6) 📝 `packages/long-term-memory/CHANGELOG.md` (+4 -0) 📝 `packages/long-term-memory/docs/ARCHITECTURE.md` (+17 -1) 📝 `packages/long-term-memory/manifest.json` (+3 -3) 📝 `packages/long-term-memory/server.mjs` (+40 -40) 📝 `packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/review/ReviewQueue.tsx` (+1 -1) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/drafts/reconciliation.ts` (+8 -26) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/extraction/source-processing.ts` (+3 -11) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/maintenance/maintenance.ts` (+8 -1) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/persistence/vault-lock.ts` (+11 -0) ➕ `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/recall/rebuild-job.ts` (+148 -0) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/recall/rebuild.ts` (+195 -94) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/recall/retrieval.ts` (+4 -2) _...and 5 more files_ </details> ### 📄 Description # Pull request ## Linked issue Closes #1523. This PR does the background index rebuild. Moving the debug log onto its own lock, the issue's on-hold second part, needs a new design decision and will get its own issue. ## Why this change - Every applied Review suggestion and every extraction that applies memories rebuilt the recall index while holding the vault lock, embedding included. "Apply all" over 10 suggestions ran 10 rebuilds (4 s on a 197-note vault with local MiniLM), and every other save and debug line waited behind them. - After the embedding source changed, the first recall re-embedded the whole vault before answering (4 s at 197 notes, growing with vault size), with the lock held. ## What changed - `long-term-memory`: draft apply and source extraction schedule one background rebuild per vault: 1 s after the last change, at most 10 s after the first. The rebuild holds the vault lock only to read the notes and to publish. It publishes only when nothing changed while it embedded; otherwise it runs again and reuses the vectors it already has. - Recall, the Engine's index refresh and the integrity check run a pending rebuild first, so they still see every applied change. They wait for one run; a change it missed leaves the index dirty, and the read rebuilds it inline as before. - After an embedding-source change, recall answers from the keyword lanes at once and re-embeds in the background. That re-embed stops when a change or a rebuild under the lock overtakes it, instead of trying again with the old source. The Engine's refresh still re-embeds before answering. - Waiting for the rebuild while holding the vault lock throws instead of deadlocking, and a rebuild scheduled inside a vault write waits for that write to finish. Deactivation stops a pending or running rebuild, and none starts again until the package is activated. - Editor, settings, scope-link, repair, explicit and restore rebuilds stay synchronous. - Regression: new `tests/long-term-memory-rebuild-job.regression.ts`, wired into `ltm-browser.yml`. The runtime and extraction-graph suites now drive the scheduled rebuild with fake timers. - **Release:** `long-term-memory` 1.4.67 on staging 77acb942b, with the CHANGELOG entry, version, manifest, rebuilt `server.mjs`, artifact and catalog entries. `client.js` is unchanged (the client change is a type only). ## Package and security impact - Affected package IDs: `long-term-memory` - Engine compatibility impact: none - New or changed permissions/entrypoints: none - Restart, storage, update, or uninstall impact: none on disk formats. A pending rebuild is dropped and a running one aborted at deactivation; the index stays marked dirty, so the next recall rebuilds it. - Concurrency: executable server code now writes `recall.json` from a background job. Lock order and the publish check are in the validation notes. - Draft apply returns `indexRebuild: { status: "pending" }`, so Review no longer shows "the index rebuild failed" for a suggestion. A background failure shows in the index status and the server log. ## Validation - [ ] `node scripts/validate-catalog.mjs` passes locally - [ ] `git diff --check` passes locally - [ ] Rebuilt every affected manifest, payload, artifact, and catalog entry - [ ] Installed or updated the affected package through Marinara Engine - [ ] Checked supported modes, restart behavior, and uninstall cleanup - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - `tests/long-term-memory-rebuild-job.regression.ts` fails on `staging` (`ten draft applies in one quiet period must rebuild the index once`, 10 calls instead of 1) and passes with the fix. Seven deliberate breaks each make it fail: job inside the caller's lock, no cap, no follow-up, no revision check, no deadlock guard, failure rejecting the job, no vector reuse. Five more, from review, each fail their own check: a reader waiting for every re-run, an upgrade retrying with its old source, a locked rebuild not aborting an upgrade, a failed state without a build, a schedule after deactivation. - `long-term-memory-runtime`, `-extraction-graph` and `-routes` regressions pass. Typecheck, lint, the package build and every Long-Term Memory regression suite pass on the release head. - Burst of 10 applies on a 197-note vault copy: 4,033 ms with 10 rebuilds before, 428 ms with 1 rebuild after. First recall after an embedding-source change: 4,138 ms before, 5 ms after (background upgrade done about 3 s later). ## Documentation impact - [ ] No documentation changes needed - [ ] Updated this README catalog and package guidance - [ ] Updated linked Marinara Engine documentation `packages/long-term-memory/docs/ARCHITECTURE.md` describes the background rebuild and the embedding-source behaviour. ## UI evidence (if applicable) - n/a (server; one client type widened) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:03:09 +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#1529
No description provided.