Repository navigation
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 17, 2026, 9:09 PM ET / July 18, 2026, 01:09 UTC. Summary PR surface: Source +59, Tests +432. Total +491 across 3 files. Reproducibility: yes. with medium confidence: the PR describes a concrete real on-disk per-agent SQLite fixture with colliding legacy and canonical identities, and reports the current failure plus exact-head Gateway/Doctor recovery. This read-only review could not independently execute the fixture. 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:
Next step before merge
Maintainer decision needed
Security Review detailsBest possible solution: Adopt one canonical same-file migration fix after Memory Core owners compare this branch with #109865, retaining the branch that preserves canonical state, imports only safely representable legacy-only data, and forces rebuild for ambiguous partial sources. Do we have a high-confidence way to reproduce the issue? Yes, with medium confidence: the PR describes a concrete real on-disk per-agent SQLite fixture with colliding legacy and canonical identities, and reports the current failure plus exact-head Gateway/Doctor recovery. This read-only review could not independently execute the fixture. Is this the best way to solve the issue? Yes, provisionally: aligning same-file schema initialization with the existing canonical-wins sidecar recovery is a narrow repair, and the branch adds a safer rebuild path for ambiguous partial sources. The remaining question is which of the two overlapping open PRs should own that final migration contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0e3afe62c650. Label changesLabel justifications:
Evidence reviewedPR surface: Source +59, Tests +432. Total +491 across 3 files. View PR surface stats
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 (3 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
c0e42f7 to
01d034f
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
01d034f to
7ea8bb6
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
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).
7ea8bb6 to
60cb875
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Thanks for picking these up, @VACInc genuinely glad they were useful. Happy however you and the maintainers want to take it from here. |
Patrick-Erichsen
left a comment
There was a problem hiding this comment.
I reproduced two persisted-index correctness bugs on the exact head. The focused schema and source-state suites are green, but the selective merge does not maintain the full source/chunk/FTS cleanup invariant.
Best-fix judgment: the current implementation is not the best fix yet. The simpler sibling-consistent option is atomic canonical-wins on any divergence; if safe legacy-only rows are retained, the migration must update every derived index and fully remove or track invalidated source rows.
| SELECT path, source, hash, mtime, size | ||
| FROM ${schema}.files; | ||
|
|
||
| INSERT OR IGNORE INTO main.${MEMORY_INDEX_CHUNKS_TABLE} ( |
There was a problem hiding this comment.
[P1] Backfill imported chunks into an existing FTS index
When the canonical FTS table already contains any row, this inserts a safe legacy-only chunk into memory_index_chunks, but the later backfill is all-or-nothing (WHERE NOT EXISTS (SELECT 1 FROM fts LIMIT 1)). The imported source row keeps its legacy hash, so normal sync can consider the file current and skip it forever. On this exact head I reproduced the chunk being present while MATCH returned zero rows. Either copy the corresponding FTS rows during this migration or force a real per-source rebuild, and cover the non-empty canonical FTS case.
| WHERE excluded.path = legacy.path AND excluded.source IS legacy.source | ||
| ); | ||
|
|
||
| DELETE FROM main.${MEMORY_INDEX_SOURCES_TABLE} |
There was a problem hiding this comment.
[P1] Do not remove the only cleanup identity while retaining chunks
force_reindex deletes the source row but preserves its canonical chunk and FTS rows. Normal stale cleanup enumerates memory_index_sources; if the underlying file was deleted before this upgrade, there is then neither an active file nor a source row to drive cleanup, so the old chunk remains searchable indefinitely. I reproduced the source row disappearing while the chunk and FTS row survived the normal cleanup predicate. Delete all derived rows for an invalidated source, or make sync explicitly purge orphan chunks, and add a deleted-file regression.
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: fix(memory): recover from same-file legacy index divergence This is item 1/1 in the current shard. Shard 0/1. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: fix(memory): recover from same-file legacy index divergence This is item 1/1 in the current shard. Shard 0/1. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
|
Maintainer refinement is complete on exact head The final patch carries same-file migration invalidations through memory and session cleanup, rebuilds body FTS after disabled periods, replaces one-sided vector orphan pruning with a retry-safe full-rebuild marker, handles pre-marker vector stores, and marks vectors clean only after the shadow index publishes. Legacy ownership joins now use migration-scoped indexes. Validation:
Proof gap: the contributor's isolated live Gateway/Doctor WAL scenario was run on the earlier migration head; the final maintainer convergence changes are covered by focused on-disk SQLite and manager integration tests plus exact-head CI rather than a repeated live Gateway run. The remaining ClawSweeper rank-up move is resolved by treating this PR as the canonical implementation. After merge, #109865 should close as superseded with credit to @Serhii-Leniv. |
|
Merged via squash.
|
…#110216) * fix(memory): keep canonical rows when same-file legacy memory tables diverge * fix(memory): keep canonical-owned sources' chunk sets coherent during legacy import * fix(memory): import legacy chunks when canonical source has no chunks 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). * fix(memory): harden same-file legacy conflict recovery * fix(memory): rebuild ambiguous partial legacy sources * fix(memory): reconcile migrated derived indexes * fix(memory): close migrated index ownership gaps * test(memory): align migration expectations * test(tooling): match routed test order * test(memory): exercise vector reload cleanup * test(memory): prove real vector reload cleanup * fix(memory): make migrated indexes converge --------- Co-authored-by: Serhii Leniv <[email protected]> Co-authored-by: VACInc <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
Related: #108532
Continues #109865. This supersedes that stalled PR because its contributor branch cannot be updated from this environment. Credit to @Serhii-Leniv for the original fix; the first three commits preserve Serhii Leniv's authorship.
What Problem This Solves
Fixes a Gateway crash loop when legacy and canonical Memory Core rows live in the same per-agent SQLite database with the same identities but different values. In this state,
openclaw doctor --fixcould exit successfully without repairing the database, and the next Gateway start failed again.The original issue is closed as #108532, but its Docker reproduction and doctor evidence show that this same-file failure remained. This PR preserves that paper trail without reopening the issue.
Summary
High Level TLDR
Same-file migration now keeps canonical rows authoritative, imports safe legacy-only rows, and drops legacy tables only after identity/ownership checks. Chunk migration snapshots source ownership before copying so stale chunks cannot be mixed into a canonical-owned chunk set.
A chunkless canonical source imports legacy chunks only when its source metadata still matches. Divergent chunkless sources are invalidated for normal sync. If a canonical source has some chunks but legacy exposes additional chunk identities, its canonical chunks still win, but its source metadata is invalidated so hash-based sync cannot mistake a partial chunk set for a complete index.
The migration tests were split into
memory-schema.legacy-migration.test.ts, keeping both files under max-lines without a suppression or loss of migration-boundary coverage.Reviewer-driven follow-up closes the same invariant across every derived store: existing body FTS is rebuilt from canonical chunks; imported, ambiguous, or newly adopted sources receive an impossible hash so runtime sync cannot skip them; ownerless legacy chunks are rejected; canonical chunks missing a source receive a cleanup identity; and vector rows orphaned while vectors were disabled are pruned when sqlite-vec loads again.
Root Cause
The same-file migration compared complete row values after conflict-ignored inserts. A canonical/legacy
meta,files,chunks, orembedding_cacherow with the same key but different values therefore threw a plainError("legacy memory <table> rows conflict with canonical memory index rows").Runtime startup reaches that assertion through Memory Core schema initialization. Doctor reaches it before entering the sidecar recovery block. The #108652 recovery catches
LegacyMemoryDerivedRowsConflictErrorfrom the sidecar import only, so it cannot recover this plain same-file error. Startup refuses readiness; doctor leaves the same conflict in place.This change validates canonical identity coverage rather than duplicate derived-row values. Rows that cannot be represented by the canonical STRICT schema still fail closed and retain the legacy tables.
User Impact
Memory Core starts when an older same-file index contains stale values for identities already present canonically. Canonical content wins, safe legacy-only content remains searchable, ambiguous partial sources are marked for rebuild, and repeated schema initialization is idempotent.
Genuinely uncopyable legacy rows—for example, values rejected by canonical STRICT constraints—still hard-fail. That residual case is intentionally unchanged follow-up work.
Evidence
Real behavior proof
Environment: Linux source checkout, Node
v25.9.0, isolated session-owned state directories and free loopback ports, real on-diskDatabaseSyncfiles in WAL mode. Earlier behavior-proof base:1ca26c508db14b141935c8f1c7c71660c8a14273. Earlier behavior-proof head:60cb875d203d26d6a417084e386de5211c9cdd7c. Current exact PR head:826e9f9753d1fbd64bbb942ba3db16b9cdc16680. The reviewer-driven exact-head follow-up used repository tests and source review only; no new live Gateway proof was run.Each fixture placed the affected database at
$STATE_DIR/agents/main/agent/openclaw-agent.sqlite. That one file held canonicalmemory_index_*tables plus partially migrated legacymeta,files,chunks, andembedding_cachetables. Every legacy table had a same-identity/different-value conflict. It also had a legacy-onlyLEGACY_ONLY.mdsource/chunk containing the unique termsaffronquasar, absent from canonical rows. A normal$STATE_DIR/memory/main.sqlitesidecar exercised the real startup/doctor state-migration path.This reproduces the important mounted-state constraint: the divergent tables are inside the canonical agent database, so doctor cannot recover by renaming that database aside as a derived sidecar. No Docker daemon, container, bind mount, or OS-level rename denial was used.
Current-main failure
The crash reproduction was run on
cc0a977dd5b12f12d56516478f2f97a30b814c1f. The later base delta through1ca26c508db14b141935c8f1c7c71660c8a14273was audited and contained nomemory-core,memory-host-sdk, doctor, agent-DB, or state-migration changes.Redacted transcript;
$STATE_DIR,$PORT, and fixture paths replace temporary local values.Gateway failed, doctor exited 0 without changing the memory-row hash, and the next Gateway failed identically.
Earlier Gateway-first behavior path (head
60cb875d203d)The full Gateway-first matrix was also repeated on the immediately preceding patch-identical rebased head: a clean doctor run, second Gateway readiness, second actual FTS query, and unchanged row-state hash.
Earlier doctor-first behavior path (head
60cb875d203d)A separately seeded fixture proved the repair does not depend on Gateway running first.
The real memory search command used the built-in FTS path (
provider: none, vector disabled), so the searchability assertion did not depend on a mock, a SQL-only assertion, a model download, or a provider credential.Current exact-head non-live follow-up proof
Current head:
826e9f9753d1fbd64bbb942ba3db16b9cdc16680. A secretless fork Plugin Prerelease run checked out that exact SHA withcontents: read, no provider/channel credentials, and Docker/live suites disabled. The repository-native Memory Core extension config ran in extension shard 3:That focused regression uses a real on-disk per-agent SQLite database and the real pinned sqlite-vec extension. It seeds nonempty canonical chunks, body FTS, and vector rows; same-file legacy tables; deleted-source state; and a pre-existing canonical ownerless chunk. Normal cleanup runs first with vectors disabled, leaving two real vec0 rows in place. After closing and reopening Memory Core with vectors enabled, production
loadVectorExtension()loads sqlite-vec,vec_version()succeeds, and the production reconciliation removes both orphan vector rows. The same fixture asserts removal from sources, chunks, body FTS, and vectors. Schema regressions separately cover nonempty FTS rebuild, rejected ownerless legacy chunks, cleanup identities, idempotence, and rollback when authoritative rows cannot be copied.Fresh pre-commit autoreview on the exact final diff reported TruffleHog clean, no accepted/actionable findings, and
patch is correctat 0.90 confidence. A separate adversarial exact-head review also reported no actionable findings after checking constructor/provider behavior, real sqlite-vec load, authoritative/derived ownership, disabled-to-enabled vectors, rollback, idempotence, custom FTS naming, sibling reindex paths, and sqlite-vec 0.1.9 DELETE behavior.git diff --checkwas clean before commit.Canonical PR CI passed 79 checks, including build, lint, production/test types, package boundaries, memory critical quality, and the host migration tests. Its only non-aggregate failure was an unrelated untouched
src/system-agent/tui-backend.test.ts120-second timeout; the shard passed its other 1,504 tests. The broader fork workflow also exercised unrelated plugins and is not claimed as aggregate proof; the completed Memory Core config above is the exact changed-surface result.Current-main merge-result proof (no rebase)
At proof time, current upstream
mainwas849ffb8a994b822739cf8a1b503443ec07e6dfbeand the unchanged PR head was826e9f9753d1fbd64bbb942ba3db16b9cdc16680.git merge-tree --write-tree origin/main HEADcompleted without conflicts and produced tree9b94ab71c12d3fc0dddeb28b7520a8630eb8012f. A temporary validation-only merge commit,85c5e5fef6ca7ea44386576916c0cfe1cc5c0222, used those two commits as its parents. It did not move, rewrite, or rebase the PR branch.A second secretless fork Plugin Prerelease run checked out that current-main merge result with
contents: read, no provider/channel credentials, and Docker/live suites disabled. The repository-native Memory Core config ran in extension shard 8:This supplies focused current-main merge-result validation without rebasing the contributor branch. The broad workflow's aggregate failure came only from untouched Signal, Browser, and QQBot tests in unrelated shards; the complete Memory Core config and the exact real-vector regression passed.
Verification
Tests include an interrupted source with one canonical chunk and an additional legacy identity. Migration keeps the canonical chunk and removes source metadata so normal sync must rebuild rather than accepting an incomplete set.
Fresh branch autoreview found the ambiguous partial-source case above. After the source invalidation fix and regression test:
What was not tested