[GH-ISSUE #1087] [Issue]: Reconciliation uses a stale preparation index and misses concurrent or same-batch commits #554

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

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

Originally assigned to: @Promansis on GitHub.

Summary

The bounded post-extraction reconciliation added for #1085 matches candidates against the recall index captured before the provider call, so any note committed after preparation is invisible to it. A concurrent import, or a sibling source in the same import batch, can therefore create a duplicate note under a second id — the defect class #1085 adds reconciliation to prevent. This is the residual "F4" finding from the #1085 repair review.

Affected package

  • Package: long-term-memory (Long-Term Memory, server)
  • Package version: 1.3.21 (manifest engine.min 2.4.1)
  • Not yet merged: the reconciliation pass exists only on the #1085 branch. staging/main have no reconciliation pass, so this is a pre-merge follow-up rather than a shipped regression.

Expected behavior

Reconciliation must not silently create a note when a compatible note already exists at commit time — including notes committed after preparation by a concurrent import or by another source in the same batch.

Actual behavior

  • source-extraction.ts captures recallIndex (loadOrRebuildLongTermMemoryIndexes) before the provider call and passes it to reconcileEvidenceUnitCandidates.
  • retrieveLongTermMemory does not re-load or re-scan when an index is supplied.
  • Reconciliation therefore cannot observe later commits: the missed identity/content match yields plausible.length === 0 -> no remap -> a create_note under a new id.
  • processLongTermMemorySourceBatch prepares all items concurrently and commits only after every preparation finishes, so each item in a batch reconciles against the pre-batch index deterministically (no timing race required). Direct game-mode shares this via its preparation-time listNotes snapshot.
  • Two concurrent imports race the same way: preparation is outside the vault lock, which only serializes finalization.

Steps to reproduce

Mechanism reproduction (executed, exit 0):

  1. Create a vault with world note world_cobalt_archive; rebuild indexes.
  2. Capture loadOrRebuildLongTermMemoryIndexes(root).
  3. Commit a second same-title note world_cobalt_archive_twin under a different id.
  4. Retrieve with the captured index: only world_cobalt_archive is returned.
  5. Retrieve without index (fresh load): world_cobalt_archive_twin is returned.
MARINARA_AGENTS_ROOT=<worktree> MARINARA_ENGINE_ROOT=/home/damo/dev/Marinara-Engine \
  pnpm --dir "$MARINARA_ENGINE_ROOT" --filter @marinara-engine/server exec tsx /tmp/opencode/f4-stale-index.mts

An import-level end-to-end reproduction of the batch case has not been written yet; batch reachability is established by the reproduced mechanism plus the prepare-all/commit-all control flow in processLongTermMemorySourceBatch.

Environment

  • Marinara Engine revision: 41d5d12cdba43efddd8d94d45657bef0fb8b07d7
  • Package version: 1.3.21
  • Install type: source
  • OS: Linux
  • Runtime: Node v24.15.0 (Engine tsx runner)

Logs, screenshots, or video

prepared-index candidate ids: world_cobalt_archive
fresh-index candidate ids:    world_cobalt_archive_twin
F4 mechanism confirmed: captured recallIndex is stale, fresh load is not

Additional context

Related: #1085.

Blocking constraint for a fix: loading the index calls listNotes(), and tests/long-term-memory-extraction-reliability.regression.ts:483-487,533-535 require exactly one preparation snapshot plus one deferred rebuild scan, and forbid a vault re-scan after the provider responds. A reload-before-reconciliation was attempted during the #1085 repair and reverted because it broke that contract.

Impact: a duplicate note/draft under a second id; applyLowRisk can auto-apply it without review. Not data loss. Subsequent extractions self-heal because the index is rebuilt after commit, and the existing maintenance.ts duplicate scan plus fork repair can merge duplicates after the fact.

Options to decide:

  • A — freshness gate: compare index-state revision (or note-summary lastMutationId) captured after the index load against the value before reconciliation; on change, add a diagnostic and set reviewRequired. Cheap and contract-safe, detects the concurrent-import race, but cannot detect the batch case and gates rather than resolves.
  • B — reconcile at commit: retain units on the prepared result, then under the vault lock load a fresh index, reconcile, re-resolve scope, recompile and finalize. Closes the deterministic batch case, but needs an explicit amendment to the preparation-snapshot contract because it re-scans.
  • C — per-item prepare/commit/rebuild: restores freshness by construction but serializes provider calls and loses import concurrency.

B is the only option that closes the deterministic batch case; the contract decision should be made first.

Scope: read-only investigation of the #1085 residual; no source changes in this issue yet.

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 (Sep 26, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1087 Originally assigned to: @Promansis on GitHub. ## Summary The bounded post-extraction reconciliation added for #1085 matches candidates against the recall index captured *before* the provider call, so any note committed after preparation is invisible to it. A concurrent import, or a sibling source in the same import batch, can therefore create a duplicate note under a second id — the defect class #1085 adds reconciliation to prevent. This is the residual "F4" finding from the #1085 repair review. ## Affected package - Package: `long-term-memory` (Long-Term Memory, server) - Package version: 1.3.21 (manifest `engine.min` 2.4.1) - Not yet merged: the reconciliation pass exists only on the #1085 branch. `staging`/`main` have no reconciliation pass, so this is a pre-merge follow-up rather than a shipped regression. ## Expected behavior Reconciliation must not silently create a note when a compatible note already exists at commit time — including notes committed after preparation by a concurrent import or by another source in the same batch. ## Actual behavior - `source-extraction.ts` captures `recallIndex` (`loadOrRebuildLongTermMemoryIndexes`) before the provider call and passes it to `reconcileEvidenceUnitCandidates`. - `retrieveLongTermMemory` does not re-load or re-scan when an `index` is supplied. - Reconciliation therefore cannot observe later commits: the missed identity/content match yields `plausible.length === 0` -> no remap -> a `create_note` under a new id. - `processLongTermMemorySourceBatch` prepares all items concurrently and commits only after every preparation finishes, so each item in a batch reconciles against the pre-batch index deterministically (no timing race required). Direct game-mode shares this via its preparation-time `listNotes` snapshot. - Two concurrent imports race the same way: preparation is outside the vault lock, which only serializes finalization. ## Steps to reproduce Mechanism reproduction (executed, exit 0): 1. Create a vault with world note `world_cobalt_archive`; rebuild indexes. 2. Capture `loadOrRebuildLongTermMemoryIndexes(root)`. 3. Commit a second same-title note `world_cobalt_archive_twin` under a different id. 4. Retrieve with the captured `index`: only `world_cobalt_archive` is returned. 5. Retrieve without `index` (fresh load): `world_cobalt_archive_twin` is returned. ``` MARINARA_AGENTS_ROOT=<worktree> MARINARA_ENGINE_ROOT=/home/damo/dev/Marinara-Engine \ pnpm --dir "$MARINARA_ENGINE_ROOT" --filter @marinara-engine/server exec tsx /tmp/opencode/f4-stale-index.mts ``` An import-level end-to-end reproduction of the batch case has not been written yet; batch reachability is established by the reproduced mechanism plus the prepare-all/commit-all control flow in `processLongTermMemorySourceBatch`. ## Environment - Marinara Engine revision: `41d5d12cdba43efddd8d94d45657bef0fb8b07d7` - Package version: 1.3.21 - Install type: source - OS: Linux - Runtime: Node v24.15.0 (Engine `tsx` runner) ## Logs, screenshots, or video ``` prepared-index candidate ids: world_cobalt_archive fresh-index candidate ids: world_cobalt_archive_twin F4 mechanism confirmed: captured recallIndex is stale, fresh load is not ``` ## Additional context Related: #1085. Blocking constraint for a fix: loading the index calls `listNotes()`, and `tests/long-term-memory-extraction-reliability.regression.ts:483-487,533-535` require exactly one preparation snapshot plus one deferred rebuild scan, and forbid a vault re-scan after the provider responds. A reload-before-reconciliation was attempted during the #1085 repair and reverted because it broke that contract. Impact: a duplicate note/draft under a second id; `applyLowRisk` can auto-apply it without review. Not data loss. Subsequent extractions self-heal because the index is rebuilt after commit, and the existing `maintenance.ts` duplicate scan plus fork repair can merge duplicates after the fact. Options to decide: - A — freshness gate: compare index-state revision (or note-summary `lastMutationId`) captured after the index load against the value before reconciliation; on change, add a diagnostic and set `reviewRequired`. Cheap and contract-safe, detects the concurrent-import race, but cannot detect the batch case and gates rather than resolves. - B — reconcile at commit: retain units on the prepared result, then under the vault lock load a fresh index, reconcile, re-resolve scope, recompile and finalize. Closes the deterministic batch case, but needs an explicit amendment to the preparation-snapshot contract because it re-scans. - C — per-item prepare/commit/rebuild: restores freshness by construction but serializes provider calls and loses import concurrency. B is the only option that closes the deterministic batch case; the contract decision should be made first. Scope: read-only investigation of the #1085 residual; no source changes in this issue yet. ## 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:33 +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#554
No description provided.