LearnNewsExamplesServices
Frontmatter
id13634
titleMemory Core defrag repair path: full-enumeration + re-embed + promote
stateClosed
labels
enhancementaiarchitecture
assigneesneo-opus-ada
createdAtJun 20, 2026, 4:55 PM
updatedAtJun 20, 2026, 6:11 PM
githubUrlhttps://github.com/neomjs/neo/issues/13634
authorneo-opus-ada
commentsCount0
parentIssue13496
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJun 20, 2026, 6:11 PM

Memory Core defrag repair path: full-enumeration + re-embed + promote

Closed v13.1.0/archive-v13-1-0-chunk-4 enhancementaiarchitecture
neo-opus-ada
neo-opus-ada commented on Jun 20, 2026, 4:55 PM

Context

Delivers AC4 of #13496 ("a safe repair/rebuild path is selected and validated on a copy or shadow collection before live mutation"). MC defrag previously failed closed (assertDefragTargetSupported throws DEFRAG_MEMORY_CORE_UNSAFE) because the KB extract path (collection.get({include:['embeddings']})) throws "Error finding id" for the missing-vector rows the stored-embedding export bug leaves behind. Shipped on branch agent/13496-ac2-defrag-wiring (PR #13635).

Live latest-open sweep: checked the latest 20 open issues at 2026-06-20; no equivalent repair-path leaf found.

Release classification: boardless — Agent OS / Memory Core stability, not v13-release-blocking.

The Problem

MC cannot delete/recreate-defrag (it is an irreplaceable store) and cannot use the KB extract (it throws for missing-vector rows). It needs a repair that recovers the missing vectors and promotes the result safely, without ever silently dropping data.

The Architectural Reality

  • ai/scripts/maintenance/defragChromaDB.mjs — the defrag orchestrator (the fail-closed gate + the shadow-promotion + the durable state-marker lifecycle).
  • ai/scripts/maintenance/checkChromaIntegrity.mjsauditChromaVectorCoverage + enumerateMetadataVectorDrift (the full, uncapped metadata-id vs vector-index-id enumeration via includeFullIds).
  • ai/scripts/maintenance/repairMemoryCoreStoredEmbeddings.mjsextractMemoryCoreCollectionData (extract intact rows with stored vectors + re-embed the missing-vector rows from their documents).
  • rewriteCollectionViaShadowPromotion — the existing shadow/parking promotion (writes durable per-phase state markers).

The Fix (shipped)

repairMemoryCoreCollectionsViaFullEnumeration: per MC collection, auditChromaVectorCoverage({includeFullIds:true}) → full {allIds, missingVectorIds}extractMemoryCoreCollectionData (intact + re-embed missing) → rewriteCollectionViaShadowPromotion. Behind the explicit --allow-memory-core opt-in; the default still fails closed. The memory-core config adapt surfaces embeddingProvider for the re-embedder (TextEmbeddingService.embedTexts, lazy-imported only on the MC path).

Two-level fail-loud + state-marker lifecycle:

  • Collection: any unrecoverable row (document-less / metadata-absent) aborts that collection's promotion with counts — never a silent partial.
  • Operator CLI: any aborted collection exits non-zero (anyRepairAbortedprocess.exit(1)) — a partial repair never reports success (mirrors the KB extractionErrors/hasRestoreErrors discipline).
  • State marker: a clean repair clears the durable marker; an aborted repair rewrites an explicit memory-core-repair-aborted marker so assertNoIncompleteDefragState blocks rerun with an accurate diagnostic instead of poisoning the next run as DEFRAG_INCOMPLETE_STATE.

Contract Ledger Matrix

Target Surface Source of Authority Proposed Behavior Fallback Evidence
defragChromaDB --allow-memory-core (CLI flag) this leaf opt-in to the MC repair-defrag path absent → fails closed (DEFRAG_MEMORY_CORE_UNSAFE) gate unit tests
repairMemoryCoreCollectionsViaFullEnumeration (export) this leaf the MC repair orchestration + state-marker lifecycle n/a (new export) 10/10 unit tests
assertDefragTargetSupported({allowMemoryCore}) this leaf gate-param admits MC only on opt-in default false (fail closed) gate unit tests
anyRepairAborted(results) (export) this leaf operator-boundary fail-loud predicate (CLI exits non-zero) n/a (new export) predicate unit tests
MC defrag state marker defragChromaDB.mjs (existing invariant) clear on clean success; rewrite explicit aborted marker on partial leave → next run blocks as DEFRAG_INCOMPLETE_STATE marker-lifecycle unit tests
TARGETS['memory-core'].adapt.embeddingProvider ai/mcp/server/memory-core/config.mjs surfaces the re-embed provider n/a live run

Decision Record impact

none — aligns with the existing shadow-promotion defrag architecture; adds an opt-in MC repair path + preserves the existing state-marker invariant on it, no ADR change.

Acceptance Criteria

  • Full-enumeration repair orchestration (audit-full → extract+re-embed → shadow-promote), fail-loud on unrecoverable.
  • Behind the explicit --allow-memory-core opt-in; default fails closed.
  • Operator-CLI fail-loud: an aborted/partial repair exits non-zero (never reports success).
  • State-marker lifecycle preserved on the MC path: clean success clears the marker; partial rewrites an explicit aborted marker (no rerun-poisoning).
  • Unit tests: 10/10 (4 orchestration + 3 gate + 3 predicate).
  • Live validation on the real MC store — operator/env-gated (sandbox cannot reach Chroma; IPv6-loopback only). [L3-deferred — operator handoff needed]

Sub of #13496 (delivers AC4). #13496 stays open for AC5 (runbook) + AC6 (bounded healthchecks) + the live validation.