Skip to content

fix(memory): large legacy memory index stalls and restarts instead of finishing - #96184

Closed
rm0nroe wants to merge 1 commit into
openclaw:mainfrom
rm0nroe:fix/memory-legacy-migration-verify
Closed

rm0nroe wants to merge 1 commit into
openclaw:mainfrom
rm0nroe:fix/memory-legacy-migration-verify

Conversation

@rm0nroe

@rm0nroe rm0nroe commented Jun 23, 2026 •

Copy link
Copy Markdown

AI-assisted PR (Claude Code). I understand the change and have validated the touched surface; details below.

What Problem This Solves

Fixes an issue where an agent with a large pre-existing memory index (tens of thousands of chunks / embedding-cache rows) sees openclaw memory index appear to hang and vector search never reach ready after upgrading to the canonicalized memory schema. The one-time legacy→canonical migration runs inside a single transaction on every memory-store open; on a large store it runs long enough that any interruption (gateway restart, redeploy) rolls it back, leaving the legacy tables in place — so it restarts from scratch on the next open and never finishes.

Why This Change Was Made

The migration verifies the copy by re-scanning every legacy row with a full-tuple anti-join that byte-compares the large text/embedding columns it just copied. When the canonical table was empty before the copy, an INSERT OR IGNORE from a single legacy source cannot collide, so that check can only ever return zero — it is provably unnecessary work, and it dominates (and outgrows) migration time as the store grows.

This change verifies the empty-canonical case with a row-count match, and keeps the full anti-join only when the canonical table already held rows (the real conflict case that the existing "keeps legacy tables when canonical rows conflict" test guards). What gets migrated, and conflict handling, are unchanged. Scope is intentionally limited to the verification step; relocating the migration out of the hot store-open path entirely is a larger, separate change.

User Impact

Agents with large legacy memory stores complete the one-time migration far faster and reliably reach Vector search: ready after upgrade, instead of looping. No configuration or user action is required, and there is no behavior change for normal-size stores.

Evidence

Touched surface is packages/memory-host-sdk/src/host/memory-schema.ts (+ its test).

  • Unit tests — packages/memory-host-sdk/src/host/memory-schema.test.ts passes 7/7. The existing migrate + conflict-keep tests are unchanged; added one test asserting the new empty-canonical path still fails closed (keeps the legacy tables) when a copy would lose rows.

  • Typecheck / lint / format — tsgo:test:packages clean (0 errors); prod typecheck reports nothing in memory-host-sdk; oxlint and oxfmt clean on the changed files.

  • Benchmark — file-backed SQLite, canonical rows are exact copies of legacy rows (the migration's real worst case, where every blob comparison must read the full value):

    rows (chunks + cache) DB size copy (INSERT OR IGNORE) old verify (blob anti-join) new verify (count match)
    15,000 985 MB 1099 ms 182 ms ~0 ms
    40,000 2.6 GB 7649 ms 4459 ms 1 ms

    The old verification grows super-linearly (≈24× slower for ≈2.7× the rows) and reaches 37% of migration time at 40k rows and climbing; on a ~6 GB / 90k-chunk store it is tens of seconds to minutes, which is what exceeds the interrupt window and drives the restart loop. The new row-count check is constant-time.

  • codex review (local, --base upstream/main) — no actionable findings.

Full pnpm build && pnpm check && pnpm test is left to CI on this PR; local validation focused on the touched memory-host-sdk surface above.

… finishing

An agent with a large pre-existing memory index could see `openclaw memory
index` appear to hang and vector search never reach ready after upgrading to
the canonicalized memory schema. The one-time legacy->canonical migration runs
in a single transaction on every store open and verifies the copy with a
full-tuple anti-join that byte-compares the text/embedding columns it just
copied. On a large store that verification dominates migration time and grows
super-linearly, so any interruption rolls the transaction back, leaving the
legacy tables in place to restart from scratch on the next open.

When the canonical table was empty before the copy, INSERT OR IGNORE from a
single legacy source cannot collide, so the anti-join can only ever return
zero. Verify that case with a row-count match instead, and keep the full
anti-join only when the canonical table already held rows (the real conflict
case). What gets migrated and conflict handling are unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed June 27, 2026, 11:12 PM ET / 03:12 UTC.

Summary
The PR changes legacy memory-index copy verification to use row-count checks for empty canonical tables and adds a regression test for lost-row detection.

PR surface: Source +54, Tests +45. Total +99 across 2 files.

Reproducibility: no. not with a high-confidence live current-main large-store run in this read-only review. Source inspection shows current main still performs full tuple anti-joins over legacy memory rows, and the PR body provides file-backed benchmark evidence for the bottleneck.

Review metrics: 1 noteworthy metric.

  • Migration verifier coverage: 1 PR path changed; 2 current-main import helpers share the invariant. Maintainers need the refreshed fix to cover both same-database legacy tables and the merged doctor sidecar migration path.

Stored data model
Persistent data-model change detected: database schema: packages/memory-host-sdk/src/host/memory-schema.test.ts, unknown-data-model-change: packages/memory-host-sdk/src/host/memory-schema.ts, vector/embedding metadata: packages/memory-host-sdk/src/host/memory-schema.test.ts, vector/embedding metadata: packages/memory-host-sdk/src/host/memory-schema.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🐚 platinum hermit
Patch quality: 🦪 silver shellfish
Result: blocked by patch quality or review findings.

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

Rank-up moves:

  • Refresh the branch against current main and resolve the dirty/conflicting state.
  • Port the verifier shortcut to the current Memory Core doctor sidecar import path as well as the same-database helper.
  • Rerun focused memory-schema and memory-core doctor migration tests after the refresh.

Risk before merge

  • [P1] The PR changes verification that gates dropping or archiving legacy memory tables, so a wrong shortcut can preserve conflicts incorrectly or remove the user's retry copy after a partial import.
  • [P1] The branch predates the merged doctor sidecar migration and is currently conflicting, so carrying the old diff forward without retargeting would leave the current sidecar import bottleneck unchanged.

Maintainer options:

  1. Refresh and port the verifier (recommended)
    Update the branch for current main, apply the shortcut to both current import helpers, and keep the full tuple check for prefilled canonical tables before maintainer review.
  2. Accept a narrow stale-base repair manually
    A maintainer can resolve the conflict by hand if they want to keep the PR author’s exact shape while deciding which current helper should own the shared verifier logic.
  3. Close after opening a replacement
    If the stale branch is too awkward to rebase, close it only after a narrower current-main replacement preserves the useful performance fix and links back here.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Refresh this PR against current main, apply the empty-canonical row-count verifier to the current memory-schema and Memory Core doctor sidecar copy helpers, preserve the full anti-join for prefilled canonical tables, add regression coverage for same-database legacy tables and sidecar import, and avoid public config or migration-ownership changes.

Next step before merge

  • [P2] A narrow automated repair can refresh the branch and port the verifier shortcut to the current same-database and doctor sidecar import helpers, but maintainer review remains needed for the migration risk.

Security
Cleared: No concrete security or supply-chain issue was found; the diff changes local SQLite migration logic and a unit test without dependencies, workflows, secrets, permissions, or downloaded code.

Review findings

  • [P2] Refresh verifier for current sidecar migration — packages/memory-host-sdk/src/host/memory-schema.ts:77-97
Review details

Best possible solution:

Refresh the PR against current main and apply the empty-canonical verifier optimization to the current same-database and Memory Core doctor sidecar import helpers, with conflict-preservation tests for both paths.

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

No, not with a high-confidence live current-main large-store run in this read-only review. Source inspection shows current main still performs full tuple anti-joins over legacy memory rows, and the PR body provides file-backed benchmark evidence for the bottleneck.

Is this the best way to solve the issue?

No for the branch as-is: the row-count shortcut is a good narrow fix, but the branch must be refreshed after #95631 and ported to the current sidecar import path before it is the best solution.

Full review comments:

  • [P2] Refresh verifier for current sidecar migration — packages/memory-host-sdk/src/host/memory-schema.ts:77-97
    This patch optimizes the old memory-schema migration path, but current main now also imports legacy sidecars through extensions/memory-core/doctor-contract-api.ts, which still performs the same full tuple anti-joins over large text/embedding rows. Please refresh against main and apply the shortcut to the current sidecar import helper too, otherwise the large upgrade migration path can still stall.
    Confidence: 0.82

Overall correctness: patch is incorrect
Overall confidence: 0.84

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a normal-priority memory migration performance/upgrade fix with limited but real impact for users carrying large legacy indexes.
  • merge-risk: 🚨 compatibility: The diff changes legacy-to-canonical migration verification before legacy memory tables are dropped or preserved.
  • merge-risk: 🚨 session-state: The affected persisted memory index is per-agent recall/search state, and a bad migration can lose or mis-associate indexed memory.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body includes after-fix file-backed SQLite benchmark output plus focused unit/type/lint validation for the changed verifier behavior, which is sufficient proof for this non-visual local migration path.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix file-backed SQLite benchmark output plus focused unit/type/lint validation for the changed verifier behavior, which is sufficient proof for this non-visual local migration path.
Evidence reviewed

PR surface:

Source +54, Tests +45. Total +99 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 74 20 +54
Tests 1 45 0 +45
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 119 20 +99

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs packages/memory-host-sdk/src/host/memory-schema.test.ts extensions/memory-core/doctor-contract-api.test.ts.
  • [P1] pnpm tsgo:test:packages.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • vincentkoc: Authored and merged the database-first memory/proxy alignment PR and later posted maintainer land-ready proof for the sidecar migration path now overlapping this PR. (role: recent storage migration owner; confidence: high; commits: 65eb2ccd4ae2, 414c250af90d; files: src/agents/memory-search.ts, packages/memory-host-sdk/src/host/memory-schema.ts, extensions/memory-core/doctor-contract-api.ts)
  • mushuiyu886: Authored the merged PR that added the current Memory Core doctor sidecar migration helper sharing the verifier invariant with this PR. (role: merged sidecar migration contributor; confidence: high; commits: 414c250af90d; files: extensions/memory-core/doctor-contract-api.ts, extensions/memory-core/doctor-contract-api.test.ts, packages/memory-host-sdk/src/host/memory-schema.ts)
  • jalehman: Prior review and changelog evidence connect this handle to adjacent memory index and source-key schema work around the database-first transition. (role: adjacent memory-index contributor; confidence: medium; commits: 69c76f53b893, ade7b3ea87ec; files: extensions/memory-core/src/memory/manager-db.ts, extensions/memory-core/src/memory/manager-sync-ops.ts, packages/memory-host-sdk/src/host/memory-schema.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.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jun 24, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 28, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 12, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

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

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S stale Marked as stale due to inactivity 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.

1 participant