Repository navigation
fix(memory): memory index fails to open when same-file legacy tables diverge - #109865
serhiileniv wants to merge 3 commits into
Conversation
|
Codex review: needs changes before merge. Reviewed July 17, 2026, 6:04 AM ET / 10:04 UTC. Summary PR surface: Source -7, Tests +67. Total +60 across 2 files. Reproducibility: yes. The PR provides a real on-disk SQLite before/after reproduction of the released repeated-open failure, and its focused regression reportedly fails on unpatched main with the reported conflict error. Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Copy recommended automerge instructionNext step before merge
Security Review findings
Review detailsBest possible solution: When any same-file identity has divergent values, keep the canonical index as one coherent unit by rolling back or avoiding all legacy inserts, then drop the superseded legacy tables; retain structural-failure rollback and add a conflicting-file plus distinct-stale-chunk regression. Do we have a high-confidence way to reproduce the issue? Yes. The PR provides a real on-disk SQLite before/after reproduction of the released repeated-open failure, and its focused regression reportedly fails on unpatched main with the reported conflict error. Is this the best way to solve the issue? No. Canonical-wins is the right policy, but applying it row by row can create an internally mixed index; the safer sibling-consistent fix preserves the canonical index atomically whenever a derived-row conflict occurs. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 44f20956e330. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source -7, Tests +67. Total +60 across 2 files. View PR surface stats
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
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
Review history (1 earlier review cycle)
|
83ea76d to
c6b7c5d
Compare
c6b7c5d to
ed4f90c
Compare
712dee4 to
880730a
Compare
06c3636 to
4abe5b2
Compare
The same-file legacy migration excluded a legacy chunk from import whenever the canonical index already had a source row for its (path, source). That stranded a file whose canonical source was registered but had no chunks yet (indexing interrupted before chunks were written, or embedding pending/failed): the legacy chunks were its only searchable content, and the matching source hash stops sync from re-indexing, so the file went silently unsearchable. Re-key the chunk-coherence exclusion on canonical chunk ownership instead: snapshot the (path, source) pairs that already have canonical chunks before the import and skip legacy chunks only for those. A source with a canonical row but no chunks now imports its legacy chunks. The snapshot is taken pre-insert because the exclusion predicate reads the chunks table the import writes to. Add regressions: legacy chunks import for a chunk-less canonical source while a chunk-owning source still drops its stale legacy chunk; and restore abort coverage for the meta and chunks copy assertions (previously only files was exercised).
4abe5b2 to
8ccb0a1
Compare
|
@clawsweeper re-review Pushed a follow-up addressing the prior review's mixed-source-coherence finding at its root, plus rebased onto current main (now up to date).
AI-assisted: yes. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Thanks @Serhii-Leniv — this is now superseded by #110216, which merged as #110216 preserves your original same-file canonical-wins work and authorship, then extends it across the remaining convergence boundaries: ambiguous partial sources, unchanged/deleted session cleanup, body FTS disable/enable recovery, vector-disabled writes and deletes, pre-marker vector stores, retry-safe shadow publication, and indexed ownership joins for large databases. The landed squash commit includes your The supported path is therefore the implementation now on |
Related: #108532
Related: #107220
What Problem This Solves
Fixes an issue where operators whose per-agent memory database still contains the legacy
meta/files/chunkstables would have every Memory Core index open fail withlegacy memory meta rows conflict with canonical memory index rowsonce those legacy rows diverge from the canonicalmemory_index_*rows — for example after an upgrade → downgrade → upgrade cycle, where the downgraded build re-creates and re-indexes the legacy tables. The failure repeats on every open (runtime and doctor), andopenclaw doctor --fixcannot converge it.#108652 applied the canonical-wins recovery rule to the legacy sidecar import in memory-core's doctor contract, but the same-file legacy migration in
packages/memory-host-sdk/src/host/memory-schema.tskept the old hard-fail, so this sibling path still wedges — including from inside the sidecar migration itself, whereensureMemoryIndexSchemaruns outside the conflict-recovery catch.Why This Change Was Made
The same-file migration now follows the same rule the sidecar import adopted in #108652: every copied table is derived search state, so a same-identity value mismatch keeps the canonical row and the migration completes (legacy tables are dropped, normal sync rebuilds any skipped rows). The merge is coherent per source: a
(path, source)the canonical index already tracks keeps both its row and its whole chunk set — legacy chunk ids are never imported under a canonical-owned source, so stale legacy text cannot ride into a file that sync considers current (this addresses the review finding on mixed-source coherence). Legacy chunks migrate only together with their legacy-only sources. A legacy row that could not be placed at all by identity (e.g. STRICT rejected it) still aborts and leaves the legacy tables in place, so legacy rows are never silently dropped. Non-goal: the sidecar import path is untouched — it already recovers atomically.User Impact
Operators with diverged same-file legacy memory tables get a working memory index and a clean one-time migration on the next start, instead of a permanently failing index open that requires manual SQLite surgery. Canonical index rows and their chunk sets are preserved intact; legacy-only files still migrate with their chunks. Repeated opens are idempotent.
Evidence
Real behavior proof (real on-disk database, before/after)
Method: a driver script (kept outside the repo per the proof-asset rule) exercises the real production
ensureMemoryIndexSchemafrompackages/memory-host-sdk/src/host/memory-schema.tsagainst a real SQLite file on disk (node:sqliteDatabaseSync, Node 25.9, via tsx). Nothing is mocked. The database is shaped like the operator upgrade → downgrade → upgrade cycle: a new build creates the canonical index and indexes content (vectorDims: 1024,MEMORY.mdatnew-hashwith canonical chunkchunk-1"current canonical body"), then a downgraded build re-creates legacymeta/files/chunksin the same file with diverged values at the same identities (vectorDims: 512,old-hash, "stale legacy body") plus a distinct stale legacy chunk id under the canonical-owned file (chunk-old-7, "stale legacy tail body"), plus rows the canonical index does not have (legacy-only-key,old-note.mdwith its chunkchunk-old-2). The only variable between runs is thememory-schema.tsblob (git hash-object:a79b2e4a3835= origin/main,df34397c1e41= this PR).BEFORE — origin/main blob
a79b2e4a3835: wedged on every open, exactly the released failure from #108532:AFTER — this PR, blob
df34397c1e41(head880730ae8c): first open migrates and recovers; canonical values win; the stale legacy chunk id under the canonical-owned file is not imported; legacy-only rows import with their source; legacy tables drop once; second open is idempotent with identical state:Structural-failure retention (both versions): a legacy
filesrow with aNULLhash (uncopyable into the STRICT canonical table) still aborts and keeps the legacy tables in place, so legacy rows are never silently dropped:Focused tests and lanes
doc.mddiverged hash) with a distinct stale legacy chunk id (chunk-old-7) — asserts the canonical chunk set stays intact, the stale legacy chunk is not imported, the legacy-only source imports with its chunk, and the legacy tables drop. On unpatchedmainthis scenario fails with the exact production error string from [Bug]: Memory Core legacy migration fails on v2026.7.1 upgrade — 'legacy memory meta rows conflict with canonical memory index rows' #108532.pnpm test packages/memory-host-sdk/src/host/memory-schema.test.ts→ 24/24 passed (re-run after each rebase).pnpm test src/state/openclaw-database-maintenance.test.ts→ 12/12 passed.pnpm tsgo:coreandpnpm tsgo:core:test→ clean.node scripts/run-oxlint.mjsandpnpm format:checkon the two touched files → clean.extensions/memory-core/doctor-contract-api.test.tsfails identically on my machine on clean main (34× WindowsEBUSY: resource busyduring SQLite temp-dir cleanup), so that suite is environment-blocked locally, not affected by this change;pnpm check:changeddelegates to Blacksmith Testbox, which is not available to an external contributor — CI on this PR is the authoritative run for those lanes.build-artifacts→ "Check CLI startup memory" fails on thestatus --jsonRSS ceiling across runs of this PR on differentmainmerge-bases (427.6, 429.4, 427.8 MB vs the 425 MB limit), and unrelated open PRs currently fail the identical step with the same overage (e.g. fix(discord): cancel response body on webhook error path #109890 at 428.4 MB) while others pass at the same time — the metric is sitting at the ceiling on currentmainmerge commits and runner variance decides the outcome. This diff removes production lines in an existing migration function and adds no imports, so it cannot move startup RSS. Per CONTRIBUTING I am not attempting to fix or tune this knownmain-side gate in this PR. (Earliercheck-lintfailures were transient unformatted files landed onmain—test/scripts/test-install-sh-docker.test.ts, thensrc/infra/spawn-ps.ts— each fixed onmainshortly after; cleared by rebasing onto the fixes. Current head880730ae8con latestmain, source blobdf34397c1e41.)AI-assisted: yes — authored with an AI coding agent (Claude); I reviewed the migration ownership boundary, the #108652 sibling semantics, SQLite
INSERT OR IGNORE/STRICT behavior, and all touched tests. Theautoreviewskill was not available in my environment.