Skip to content

fix(memory-core): preserve canonical embedding cache on migration - #107276

Closed
arcabotai wants to merge 1 commit into
openclaw:mainfrom
arcabotai:fix/sqlite-migration-embedding-cache
Closed

arcabotai wants to merge 1 commit into
openclaw:mainfrom
arcabotai:fix/sqlite-migration-embedding-cache

Conversation

@arcabotai

Copy link
Copy Markdown
Contributor

What Problem This Solves

Closes #107133.

Upgrading to 2026.7.1 can leave the Gateway unable to start when a legacy Memory Core sidecar and the canonical per-agent database contain the same embedding-cache key with different derived values or timestamps. The migration uses INSERT OR IGNORE, then incorrectly requires the ignored legacy row to match every canonical value, so Doctor reports a persistent migration warning and startup refuses readiness.

Related: #107220. That issue also covers meta and chunks conflicts; this change intentionally addresses only the derived embedding-cache case, where the existing cache key defines the identity and the canonical database is already authoritative.

Why This Change Was Made

Embedding-cache rows are derived data keyed by (provider, model, provider_key, hash). The migration now verifies that every legacy cache key exists after the import instead of requiring non-key cache values to be byte-identical. Existing canonical values win for duplicate keys, while non-conflicting legacy cache rows and unrelated legacy files/chunks still import inside the existing savepoint.

The strict conflict checks for source rows, chunks, FTS/vector rows, and metadata are unchanged.

User Impact

Affected upgrades can converge through the normal migration path without deleting SQLite files or manually moving the legacy sidecar. The canonical embedding cache is preserved, unrelated legacy memory rows are imported, the sidecar is archived only after the transaction succeeds, and rerunning the migration is a no-op.

Evidence

  • Published [email protected] (2d2ddc43d0dcf71f31283d780f9fe9ff4cc04fe4, npm integrity sha512-ge/Xss99CHAjPL/ikmH/UFoiOrjcxDB4sW3y9mhyCD+dYW3wzV7TKbAVdkrXFgAG2d2BjpJofP97zUZ+umxo8g==) reproduced the warning with a seeded same-key/different-value cache conflict. Doctor exited 0 but left the legacy database in place and imported no legacy sources/chunks.
  • Exact current-main RED at 21382b3755fafd7253339b2f3146b8667c5a7bde: the focused regression failed with legacy memory embedding_cache rows conflict with canonical memory index rows.
  • Focused GREEN: extensions/memory-core/doctor-contract-api.test.ts passed all 29 tests.
  • Owner-suite GREEN: 103 test files, 1,423 tests passed.
  • pnpm check:changed passed formatting, extension/test typechecks, lint, database-first guards, and import-cycle checks.
  • Seeded candidate audit preserved the canonical cache row, imported the legacy source/chunk, archived the legacy database, returned ok from both PRAGMA quick_check and PRAGMA integrity_check on canonical and archived databases, and produced byte-identical verification output on a second Doctor run.
  • Final base 4ed76a7ddb89604c35769e88d9d61c32e1a41d05 did not change either owner/test file from the fully tested base; their blob contents are byte-identical. The rebased candidate is 3072762c82526c0fce27804c6b3839f0002db49a; its 29 focused tests and local check:changed gate passed on Node 24.15.0 / SQLite 3.51.3.

AI-assisted change. I reviewed the implementation, migration boundary, tests, and evidence.

@arcabotai

Copy link
Copy Markdown
Contributor Author

Closing in favor of #107243, which addresses the same #107133 migration failure with stricter dimension and embedding-length compatibility guards plus exact runtime Gateway proof. This PR’s broader canonical-key-only approach is superseded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Memory Core embedding_cache conflict permanently blocks Gateway startup on 2026.7.1

1 participant