[GH-ISSUE #1178] [Issue]: Long-Term Memory: recheck index freshness under the vault lock and honor recall cancellation #601

Closed
opened 2026-10-20 17:28:57 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

Long-Term Memory makes recall-index freshness and quarantine decisions outside the vault lock, so concurrent stale callers can rebuild the same index twice and can quarantine a newly published index. Recall cancellation also fails to reach rebuild embedding work: a timed-out recall keeps rebuilding and holding the vault lock.

Affected package

long-term-memory (Long-Term Memory), package-owned server runtime. Findings A7 and the cancellation/lifecycle portion of A17.

Expected behavior

  • Read/validate the index, decide freshness, quarantine invalid artifacts, and rebuild within one serialized vault lifecycle. A queued caller must recheck the latest index before rebuilding.
  • Two concurrent stale callers with unchanged vault/configuration inputs should produce one rebuild; the second should use the newly validated index.
  • Propagate the recall AbortSignal through stale-index rebuilding, semantic upgrades, and embedding batches. Check cancellation before publishing results.
  • Cancelled work must not publish an index, mark indexing complete, quarantine an otherwise valid index because of cancellation, or suppress a later semantic-upgrade retry.
  • Preserve synchronous freshness validation: stale/deleted memory text must never be served as a fallback. Ordinary embedding unavailability must still permit lexical recall.

Actual behavior

  • loadOrRebuildLongTermMemoryIndexes reads and checks freshness before rebuildLongTermMemoryIndexes enters withLtmVaultLock; there is no in-lock freshness recheck for the queued caller.
  • A deterministic two-caller fixture produced two embedding/rebuild calls, each covering the same three chunks.
  • retrieveLongTermMemory receives a signal but does not pass it to the index loader. Its rebuild and semantic-upgrade paths consequently receive no recall cancellation signal.
  • In a disposable runtime fixture, the Engine timeout aborted the caller after 80 ms, but the rebuild adapter received no signal. A vault reader remained blocked until the fixture released embedding work; the rebuild then published after the timeout.

Steps to reproduce

  1. Activate the package runtime against a disposable vault and a synthetic embedding adapter. Build the initial index, then create another note so the index is stale.
  2. Start two loadOrRebuildLongTermMemoryIndexes calls. Use a deterministic fixture barrier so both observe the old index/current notes before either rebuilds. Observe two rebuild embedding calls instead of one.
  3. In a separate stale-index recall, hold a synthetic embedding batch open and call the runtime through withLongTermMemoryRuntimeTimeout(80, ...), forwarding its signal to runtime.recall. Queue storage.listNotes, let the timeout fire, then release the embedding batch. Observe the missing rebuild signal, blocked reader, and post-timeout publication.

Environment

  • Marinara Engine version: 2.4.6, source checkout 227e3e12c87a55c40074413f1f32e57d732217da.
  • Package version: 1.3.34; Agents checkout d5bd5c2a8b17503df2b4145869f5d5dade684217. The package-owned server/shared trees also match upstream staging at 2336c3ca59f743f6c03afe9c574c0cdaab8ddc9f.
  • Install type: source-module/runtime fixture; not an installed ZIP-package test.
  • OS + version: Linux; exact distribution/version not captured.
  • Browser or app shell: not applicable; Node v24.15.0, installed tsx 4.23.13.

Logs, screenshots, or video

Observed output from the disposable synthetic-data fixture:

{"case":"concurrent-stale-loaders","initialReads":2,"rebuildEmbeddingCalls":2,"textsPerCall":[3,3]}
{"case":"recall-timeout-rebuild","callerSignalAborted":true,"rebuildReceivedSignal":false,"vaultWaiterBlockedAfterTimeout":true,"rebuildFinishedAfterTimeout":true}

Current-behavior characterization exited 0. Desired-invariant runs exited 1 with:

Concurrent stale loaders must recheck freshness under the lock and rebuild once
2 !== 1

Recall cancellation must reach rebuild embedding work
actual: undefined; expected: caller AbortSignal

No private chat data, real providers, or models were used.

Additional context

Scope and ownership

  • Implement against Agents staging; this issue does not require Engine source changes. Engine already forwards an abort signal to the registered LTM runtime.
  • Primary owners: packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/{rebuild,retrieval,embedding-adapter,vault-lock}.ts.
  • Trace all index-loader/rebuild callers, including semantic upgrades and bounded reconciliation/extraction consumers; fix the shared lifecycle rather than only generation.
  • Preserve atomic index publication, existing corruption validation, full-vault error handling, zero-match behavior, and ordinary provider-failure fallback.
  • Do not add fingerprint caching, vector reuse, asynchronous/stale-index serving, sidecar identity changes, or eager configuration-save rebuilds here. Those are separate workstreams. This issue does not claim to eliminate all A17 rebuild latency.

Validation plan

  • Add the smallest persistent regression proving concurrent stale callers rebuild once, using scheduling that still works after moving freshness checks inside the lock.
  • Cover cancellation while queued for the vault lock, during a stale rebuild, and during a semantic upgrade; cancelled results must not publish or prevent a later retry.
  • Cover an adapter that honors abort and one whose delayed result arrives after abort. Vault waiters must proceed when cancelled work settles, without publishing the delayed result.
  • Preserve malformed-index/note handling and lexical fallback for ordinary embedding failures; run affected runtime, index, reconciliation, and route regressions.
  • Run repository-required validation and rebuild/validate the package and generated catalog outputs from source before publication.

Proof above is characterization, not repaired behavior or release validation. Installed dependencies differ from the repository's pins; install locked dependencies in the implementation workspace before claiming repository gates. No implementation, real-provider, installed-package, or browser validation has been performed for this issue.

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 1, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1178 Originally assigned to: @Promansis on GitHub. ## Summary Long-Term Memory makes recall-index freshness and quarantine decisions outside the vault lock, so concurrent stale callers can rebuild the same index twice and can quarantine a newly published index. Recall cancellation also fails to reach rebuild embedding work: a timed-out recall keeps rebuilding and holding the vault lock. ## Affected package `long-term-memory` (Long-Term Memory), package-owned server runtime. Findings A7 and the cancellation/lifecycle portion of A17. ## Expected behavior - Read/validate the index, decide freshness, quarantine invalid artifacts, and rebuild within one serialized vault lifecycle. A queued caller must recheck the latest index before rebuilding. - Two concurrent stale callers with unchanged vault/configuration inputs should produce one rebuild; the second should use the newly validated index. - Propagate the recall `AbortSignal` through stale-index rebuilding, semantic upgrades, and embedding batches. Check cancellation before publishing results. - Cancelled work must not publish an index, mark indexing complete, quarantine an otherwise valid index because of cancellation, or suppress a later semantic-upgrade retry. - Preserve synchronous freshness validation: stale/deleted memory text must never be served as a fallback. Ordinary embedding unavailability must still permit lexical recall. ## Actual behavior - `loadOrRebuildLongTermMemoryIndexes` reads and checks freshness before `rebuildLongTermMemoryIndexes` enters `withLtmVaultLock`; there is no in-lock freshness recheck for the queued caller. - A deterministic two-caller fixture produced **two embedding/rebuild calls**, each covering the same three chunks. - `retrieveLongTermMemory` receives a signal but does not pass it to the index loader. Its rebuild and semantic-upgrade paths consequently receive no recall cancellation signal. - In a disposable runtime fixture, the Engine timeout aborted the caller after 80 ms, but the rebuild adapter received no signal. A vault reader remained blocked until the fixture released embedding work; the rebuild then published after the timeout. ## Steps to reproduce 1. Activate the package runtime against a disposable vault and a synthetic embedding adapter. Build the initial index, then create another note so the index is stale. 2. Start two `loadOrRebuildLongTermMemoryIndexes` calls. Use a deterministic fixture barrier so both observe the old index/current notes before either rebuilds. Observe two rebuild embedding calls instead of one. 3. In a separate stale-index recall, hold a synthetic embedding batch open and call the runtime through `withLongTermMemoryRuntimeTimeout(80, ...)`, forwarding its signal to `runtime.recall`. Queue `storage.listNotes`, let the timeout fire, then release the embedding batch. Observe the missing rebuild signal, blocked reader, and post-timeout publication. ## Environment - Marinara Engine version: `2.4.6`, source checkout `227e3e12c87a55c40074413f1f32e57d732217da`. - Package version: `1.3.34`; Agents checkout `d5bd5c2a8b17503df2b4145869f5d5dade684217`. The package-owned server/shared trees also match upstream `staging` at `2336c3ca59f743f6c03afe9c574c0cdaab8ddc9f`. - Install type: source-module/runtime fixture; not an installed ZIP-package test. - OS + version: Linux; exact distribution/version not captured. - Browser or app shell: not applicable; Node `v24.15.0`, installed `tsx` `4.23.13`. ## Logs, screenshots, or video Observed output from the disposable synthetic-data fixture: ```json {"case":"concurrent-stale-loaders","initialReads":2,"rebuildEmbeddingCalls":2,"textsPerCall":[3,3]} {"case":"recall-timeout-rebuild","callerSignalAborted":true,"rebuildReceivedSignal":false,"vaultWaiterBlockedAfterTimeout":true,"rebuildFinishedAfterTimeout":true} ``` Current-behavior characterization exited 0. Desired-invariant runs exited 1 with: ```text Concurrent stale loaders must recheck freshness under the lock and rebuild once 2 !== 1 Recall cancellation must reach rebuild embedding work actual: undefined; expected: caller AbortSignal ``` No private chat data, real providers, or models were used. ## Additional context ### Scope and ownership - Implement against Agents `staging`; this issue does not require Engine source changes. Engine already forwards an abort signal to the registered LTM runtime. - Primary owners: `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/{rebuild,retrieval,embedding-adapter,vault-lock}.ts`. - Trace all index-loader/rebuild callers, including semantic upgrades and bounded reconciliation/extraction consumers; fix the shared lifecycle rather than only generation. - Preserve atomic index publication, existing corruption validation, full-vault error handling, zero-match behavior, and ordinary provider-failure fallback. - Do not add fingerprint caching, vector reuse, asynchronous/stale-index serving, sidecar identity changes, or eager configuration-save rebuilds here. Those are separate workstreams. This issue does not claim to eliminate all A17 rebuild latency. ### Validation plan - [ ] Add the smallest persistent regression proving concurrent stale callers rebuild once, using scheduling that still works after moving freshness checks inside the lock. - [ ] Cover cancellation while queued for the vault lock, during a stale rebuild, and during a semantic upgrade; cancelled results must not publish or prevent a later retry. - [ ] Cover an adapter that honors abort and one whose delayed result arrives after abort. Vault waiters must proceed when cancelled work settles, without publishing the delayed result. - [ ] Preserve malformed-index/note handling and lexical fallback for ordinary embedding failures; run affected runtime, index, reconciliation, and route regressions. - [ ] Run repository-required validation and rebuild/validate the package and generated catalog outputs from source before publication. Proof above is characterization, not repaired behavior or release validation. Installed dependencies differ from the repository's pins; install locked dependencies in the implementation workspace before claiming repository gates. No implementation, real-provider, installed-package, or browser validation has been performed for this issue. ## 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-20 17:28:57 +07:00
  • closed this issue
  • added the
    bug
    label
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#601
No description provided.