[PR #6746] [MERGED] fix(memory): batch long-chat rebuilds without losing the previous index #7310

Closed
opened 2026-10-23 04:18:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6746
Author: @SirAdoni
Created: 9/27/2026
Status: ✅ Merged
Merged: 9/27/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/issue-6708


📝 Commits (4)

  • abc6fac fix(memory): batch long-chat rebuilds and preserve prior indexes (#6708)
  • 83af134 Merge remote-tracking branch 'origin/staging' into codex/merge-6746
  • 9742b28 fix(memory): warn once when the embedder is unavailable
  • a51f8e5 test(memory): distinguish vectors in the batch ordering proof

📊 Changes

3 files changed (+426 additions, -40 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 packages/server/src/services/memory-recall.ts (+135 -39)
📝 scripts/regressions/memory-recall-revectorize.regression.ts (+289 -1)

📄 Description

Linked issue

Closes #6708

Why this change

Memory rebuilding currently sends the entire chat's chunks in one embedding request. Long chats can exceed a provider's aggregate request limit even when each chunk fits individually. The existing rebuild also deletes the native index before obtaining replacement vectors, so a failed request can leave the chat without its previous index.

What changed

  • Batch the existing embedding helper sequentially at 64 texts or 100,000 JavaScript string code units, preserving input/vector order. This is a conservative character budget, not a tokenizer-derived guarantee for every provider. An oversized individual input stays intact; existing memory chunk splitting remains in place.
  • Validate returned counts, finite nonempty vectors, and consistent dimensions across batches. Reject cancellation before and after each awaited batch, including a provider that returns a final response after cancellation.
  • Build and validate replacement rows before changing the native index, then replace it transactionally. Failed embeddings, cancellation, and insertion failures preserve the previous native index. Imported memory rows are excluded from native replacement.
  • Retain the existing per-chat mutation serialization and embedding-space checks. Failed explicit rebuilds now report failure instead of appearing successful with an empty replacement.
  • Add regression coverage and an Unreleased changelog entry. No new dependency, schema migration, UI, or provider-specific implementation.

Resumable partial progress, configurable batch limits, and provider-error-driven adaptive sizing are not implemented. A failed rebuild keeps the old index; retry starts the embedding work again.

Validation

Maintainer integration validation on 9742b28f5c95dd008a08c05dee95136cf3a90b02 (merged with staging 4be7698e7):

  • pnpm check passed in one complete run.
  • node scripts/run-regressions.mjs --filter memory-recall: 2/2 files passed, including batching, order, failed/canceled rebuild preservation, transaction rollback, imported rows, and unavailable-embedder warning coverage.
  • Local CodeRabbit reviewed all three changed files; zero findings.
  • Resolved the changelog conflict and fixed the review finding so an unavailable embedder warns once; malformed non-null results still report a count mismatch.
  • GitHub checks and CodeRabbit on this head are merge gates; their status is recorded by GitHub.

Human verification checklist:

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Manually rebuild a long chat using the intended embedding provider and confirm multiple bounded requests complete. Verify retrieval afterward. Cancel or interrupt a rebuild and confirm the previous native index remains usable; then retry. No human or real-provider verification is claimed by the automated results above.

Docs and release impact

Unreleased changelog updated. No version bump or changes under docs/.

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs updated or follow-up issue opened, if applicable
  • Version/release files updated, if applicable

UI evidence (if applicable)

No UI changes.

Summary by CodeRabbit

  • Bug Fixes
    • Existing long-chat memory remains available if a rebuild fails or is canceled.
    • Incomplete, invalid, or inconsistent embedding results no longer replace stored memory.
    • Memory rebuilds split large sets of messages into batches of up to 64 texts and 100,000 characters, while preserving result order.
    • Canceled embedding requests and failed replacement writes leave the previous memory index intact.
    • Rebuilding an empty native index skips embedding and retains imported memory.

🔄 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-Engine/pull/6746 **Author:** [@SirAdoni](https://github.com/SirAdoni) **Created:** 9/27/2026 **Status:** ✅ Merged **Merged:** 9/27/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/issue-6708` --- ### 📝 Commits (4) - [`abc6fac`](https://github.com/Pasta-Devs/Marinara-Engine/commit/abc6faccd73194af46cad8aa86f7291339834654) fix(memory): batch long-chat rebuilds and preserve prior indexes (#6708) - [`83af134`](https://github.com/Pasta-Devs/Marinara-Engine/commit/83af134be92e8f808c0585c60904de57e84fa7ed) Merge remote-tracking branch 'origin/staging' into codex/merge-6746 - [`9742b28`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9742b28f5c95dd008a08c05dee95136cf3a90b02) fix(memory): warn once when the embedder is unavailable - [`a51f8e5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a51f8e5b9a8f904a522d6a9c2a3f5f9e615a052b) test(memory): distinguish vectors in the batch ordering proof ### 📊 Changes **3 files changed** (+426 additions, -40 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `packages/server/src/services/memory-recall.ts` (+135 -39) 📝 `scripts/regressions/memory-recall-revectorize.regression.ts` (+289 -1) </details> ### 📄 Description ## Linked issue Closes #6708 ## Why this change Memory rebuilding currently sends the entire chat's chunks in one embedding request. Long chats can exceed a provider's aggregate request limit even when each chunk fits individually. The existing rebuild also deletes the native index before obtaining replacement vectors, so a failed request can leave the chat without its previous index. ## What changed - Batch the existing embedding helper sequentially at 64 texts or 100,000 JavaScript string code units, preserving input/vector order. This is a conservative character budget, not a tokenizer-derived guarantee for every provider. An oversized individual input stays intact; existing memory chunk splitting remains in place. - Validate returned counts, finite nonempty vectors, and consistent dimensions across batches. Reject cancellation before and after each awaited batch, including a provider that returns a final response after cancellation. - Build and validate replacement rows before changing the native index, then replace it transactionally. Failed embeddings, cancellation, and insertion failures preserve the previous native index. Imported memory rows are excluded from native replacement. - Retain the existing per-chat mutation serialization and embedding-space checks. Failed explicit rebuilds now report failure instead of appearing successful with an empty replacement. - Add regression coverage and an Unreleased changelog entry. No new dependency, schema migration, UI, or provider-specific implementation. Resumable partial progress, configurable batch limits, and provider-error-driven adaptive sizing are not implemented. A failed rebuild keeps the old index; retry starts the embedding work again. ## Validation Maintainer integration validation on `9742b28f5c95dd008a08c05dee95136cf3a90b02` (merged with staging `4be7698e7`): - `pnpm check` passed in one complete run. - `node scripts/run-regressions.mjs --filter memory-recall`: 2/2 files passed, including batching, order, failed/canceled rebuild preservation, transaction rollback, imported rows, and unavailable-embedder warning coverage. - Local CodeRabbit reviewed all three changed files; zero findings. - Resolved the changelog conflict and fixed the review finding so an unavailable embedder warns once; malformed non-null results still report a count mismatch. - GitHub checks and CodeRabbit on this head are merge gates; their status is recorded by GitHub. Human verification checklist: - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Manually rebuild a long chat using the intended embedding provider and confirm multiple bounded requests complete. Verify retrieval afterward. Cancel or interrupt a rebuild and confirm the previous native index remains usable; then retry. No human or real-provider verification is claimed by the automated results above. ## Docs and release impact Unreleased changelog updated. No version bump or changes under `docs/`. - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs updated or follow-up issue opened, if applicable - [ ] Version/release files updated, if applicable ## UI evidence (if applicable) No UI changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Existing long-chat memory remains available if a rebuild fails or is canceled. * Incomplete, invalid, or inconsistent embedding results no longer replace stored memory. * Memory rebuilds split large sets of messages into batches of up to 64 texts and 100,000 characters, while preserving result order. * Canceled embedding requests and failed replacement writes leave the previous memory index intact. * Rebuilding an empty native index skips embedding and retains imported memory. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:18:30 +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-Engine#7310
No description provided.