Skip to content

fix(memory-core): preserve canonical cache rows during legacy migration - #107243

Merged
steipete merged 8 commits into
openclaw:mainfrom
felirami:codex/fix-memory-cache-migration
Jul 14, 2026
Merged

steipete merged 8 commits into
openclaw:mainfrom
felirami:codex/fix-memory-cache-migration

Conversation

@felirami

@felirami felirami commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an upgrade failure introduced in v2026.7.1: Gateway startup can loop when a legacy Memory Core sidecar and the canonical per-agent database contain the same embedding-cache identity with different derived payloads. The import previously treated every collision as a conflict, retained the sidecar, and repeated the failed startup migration on every restart.

Why This Change Was Made

The cache identity is (provider, model, provider_key, hash), and the canonical database is authoritative once a compatible row exists. The migration now retains that canonical row only when both rows declare the same dimensions, both embeddings are valid JSON arrays, and each array length matches its declared dimensions. It still imports non-colliding legacy rows. Any dimensional or payload-shape mismatch rolls back and preserves the sidecar for repair instead of archiving potentially recoverable state.

User Impact

Affected Gateways can complete the v2026.7.1 state migration without deleting a valid canonical cache row. Legacy sources, chunks, and non-colliding cache entries still import; compatible canonical rows win; malformed or incompatible collisions remain fail-closed.

Evidence

  • Exact reviewed head: e35ddb3ce365c07419365d5b799bbb45b65ac38e.
  • Sanitized public-network AWS run run_6ac4a00dc21c: focused Memory Core doctor suite, 35/35 passed. Coverage includes preservation/import/idempotency, different dimensions, same wrong length relative to dimensions, one-sided wrong length, malformed canonical/legacy JSON, and missing dimensions.
  • Sanitized public-network AWS run run_b5f278178191: created real canonical and legacy SQLite state, started openclaw gateway run, reached /readyz, preserved canonical [9,9,9] with dims 3 and timestamp 99, imported the legacy source/chunk, archived the sidecar, then reached /readyz again on a second start.
  • GitHub Actions run 29349881414: exact-head CI gate passed, including build, lint, production/test types, dependency and architecture guards, and both QA smoke profiles.
  • Fresh exact-head autoreview: clean, confidence 0.96.
  • A standalone raw-head changed gate reached unrelated Plugin SDK baseline drift from newer main; this PR changes no SDK files, and the current merge-ref CI gate passed.

Fixes #107133

@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 14, 2026
@felirami
felirami marked this pull request as ready for review July 14, 2026 07:14

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 343e945a8e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 14, 2026
@felirami
felirami force-pushed the codex/fix-memory-cache-migration branch from ddd4c8b to d851aa3 Compare July 14, 2026 07:28
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 14, 2026
@clawsweeper

clawsweeper Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed July 14, 2026, 8:29 AM ET / 12:29 UTC.

Summary
The PR changes Memory Core legacy embedding-cache migration to retain compatible canonical duplicate-key rows while importing other legacy rows, with rollback coverage for unsafe collisions.

PR surface: Source 0, Tests +135. Total +135 across 2 files.

Reproducibility: yes. The linked issue and PR proof establish a v2026.7.1 fixture with duplicate embedding-cache identities that repeatedly blocks Gateway startup, plus the intended successful migration path.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: persistent cache schema: extensions/memory-core/doctor-contract-api.test.ts, unknown-data-model-change: extensions/memory-core/doctor-contract-api.test.ts, vector/embedding metadata: extensions/memory-core/doctor-contract-api.test.ts, vector/embedding metadata: extensions/memory-core/doctor-contract-api.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #107133
Summary: This PR is the active candidate fix for the canonical duplicate embedding-cache migration startup-loop issue; the closed alternative PR covered the same bug with a weaker key-only policy.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Require each embedding array length to equal its declared dims and add the equal-length malformed-row regression.
  • Refresh exact-head live output for both successful startup convergence and preserved-sidecar rollback after the predicate change.

Risk before merge

  • [P1] Merging this predicate can archive the legacy retry source when both duplicate rows have the same wrong vector length relative to dims, leaving the malformed canonical cache row authoritative.
  • [P1] Because this runs during automatic startup migration, the missed invariant can move failures from a visible fail-closed warning into later memory-index or runtime behavior.

Maintainer options:

  1. Enforce internal dimension consistency (recommended)
    Before merge, require each duplicate embedding array length to equal its declared dimensions and prove the sidecar remains unarchived when both rows are equally malformed.
  2. Keep the fail-closed behavior
    Pause this PR if the collision policy cannot distinguish safe derived-cache replacement from internally inconsistent persisted rows.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Validate each canonical and legacy embedding array length against its own declared dims, add an equal-length-but-wrong-dims regression, and refresh focused migration plus Gateway-startup proof.

Next step before merge

  • [P2] A narrow mechanical repair remains on the current PR: strengthen one SQL predicate, add one regression, and refresh the existing upgrade proof without making a product-policy choice.

Security
Cleared: The two-file SQLite migration and test diff adds no dependency, workflow, secret, permission, artifact-download, or other concrete security or supply-chain concern.

Review findings

  • [P2] Validate each embedding length against its declared dims — extensions/memory-core/doctor-contract-api.ts:515
Review details

Best possible solution:

Require both canonical and legacy embeddings to be valid arrays whose lengths each equal their shared declared dims, add the equal-but-wrong-length regression, and refresh exact-head upgrade proof for successful and rejected collisions.

Do we have a high-confidence way to reproduce the issue?

Yes. The linked issue and PR proof establish a v2026.7.1 fixture with duplicate embedding-cache identities that repeatedly blocks Gateway startup, plus the intended successful migration path.

Is this the best way to solve the issue?

No, not yet. Canonical-wins for derived cache payloads is the narrow owner-boundary fix, but the predicate must validate each row’s internal dimension consistency rather than only comparing the rows to each other.

Full review comments:

  • [P2] Validate each embedding length against its declared dims — extensions/memory-core/doctor-contract-api.ts:515
    The predicate only checks that the two JSON arrays have equal lengths. If both rows store four elements while both declare dims = 3, this passes, the sidecar is archived, and the malformed canonical vector remains authoritative. Require each array length to equal its declared dims and add that regression; this is the still-unfixed finding from the prior review of the same head.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against b4128978cdbd.

Label changes

Label justifications:

  • P0: The linked v2026.7.1 upgrade bug produces a repeatable Gateway startup loop with no normal in-product recovery path.
  • merge-risk: 🚨 compatibility: The PR changes a shipped upgrade migration from exact conflict rejection to conditional canonical-wins acceptance and can retire the legacy retry source.
  • merge-risk: 🚨 availability: An incomplete acceptance predicate can replace a startup-time warning with later wrong-dimension memory-index failures or continued Gateway unavailability.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body supplies live before-and-after output showing the released startup failure, successful compatible migration, idempotent second run, and Gateway readiness; it does not cover the remaining equal-but-internally-invalid collision.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies live before-and-after output showing the released startup failure, successful compatible migration, idempotent second run, and Gateway readiness; it does not cover the remaining equal-but-internally-invalid collision.
Evidence reviewed

PR surface:

Source 0, Tests +135. Total +135 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 135 0 +135
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 137 2 +135

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs extensions/memory-core/doctor-contract-api.test.ts.
  • [P1] node scripts/check-changed.mjs -- extensions/memory-core/doctor-contract-api.ts extensions/memory-core/doctor-contract-api.test.ts.
  • [P1] Run a sanitized real v2026.7.1 state fixture proving valid compatible collisions archive the sidecar and reach Gateway ready, while equal-length arrays inconsistent with dims roll back and preserve the sidecar.

What I checked:

Likely related people:

  • steipete: Authored the recent cross-surface state-migration convergence and plugin-state/doctor seam work touching this contract. (role: recent migration convergence contributor; confidence: high; commits: 4da0eb19c570, eafe2a8; files: extensions/memory-core/doctor-contract-api.ts)
  • sallyom: Authored recent recoverable legacy-state convergence work on this migration contract. (role: recent area contributor; confidence: medium; commits: cdb58ca; files: extensions/memory-core/doctor-contract-api.ts)
  • mushuiyu886: Co-authored the earlier Memory Core store relocation and migration implementation from which this sidecar path developed. (role: original migration contributor; confidence: medium; commits: 414c250; files: extensions/memory-core/doctor-contract-api.ts)
  • vincentkoc: Co-authored the earlier Memory Core store relocation and migration implementation and is relevant to the intended upgrade contract. (role: original migration contributor; confidence: medium; commits: 414c250; files: extensions/memory-core/doctor-contract-api.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (1 earlier review cycle)
  • reviewed 2026-07-14T12:06:26.959Z sha 89a5bda :: needs changes before merge. :: [P2] Validate each embedding length against its declared dims

@steipete

Copy link
Copy Markdown
Contributor

Land-ready at e35ddb3ce365c07419365d5b799bbb45b65ac38e.

Maintainer work completed:

  • tightened cache-collision compatibility to validate declared dimensions, JSON array shape, and actual embedding lengths before archival;
  • added regression coverage for malformed and dimensionally inconsistent canonical and legacy rows;
  • reviewed the startup migration caller/callee path, runtime cache loader, and sibling in-place schema migration; this external sidecar import is the correct owner boundary;
  • fresh exact-head autoreview: clean, confidence 0.96.

Proof:

  • AWS run_6ac4a00dc21c: focused Memory Core doctor suite, 35/35 passed;
  • AWS run_b5f278178191: real Gateway startup imported legacy source/chunk, preserved the compatible canonical cache row, archived the sidecar, reached /readyz, and repeated cleanly on a second start;
  • GitHub Actions 29349881414: exact-head CI gate passed, including build, lint, production/test types, dependency/architecture guards, and QA smoke.

Known gap: the standalone raw-head changed gate saw unrelated Plugin SDK API baseline drift because that checkout predates current main; this PR does not touch the SDK, and current merge-ref CI is green.

@steipete
steipete merged commit c1191cd into openclaw:main Jul 14, 2026
88 of 89 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 15, 2026
…on (openclaw#107243)

* fix(memory-core): preserve canonical cache rows on migration

* fix(memory-core): guard cache migration dimensions

* fix(memory-core): validate cache embedding lengths

* fix(memory-core): validate cache migration dimensions

* refactor(memory-core): keep cache guard compact

---------

Co-authored-by: felirami <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…on (openclaw#107243)

* fix(memory-core): preserve canonical cache rows on migration

* fix(memory-core): guard cache migration dimensions

* fix(memory-core): validate cache embedding lengths

* fix(memory-core): validate cache migration dimensions

* refactor(memory-core): keep cache guard compact

---------

Co-authored-by: felirami <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

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

2 participants