Skip to content

fix(memory-core): include path in FTS indexed text so filename tokens are searchable - #94114

Closed
zhangguiping-xydt wants to merge 10 commits into
openclaw:mainfrom
zhangguiping-xydt:feat/issue-94102
Closed

zhangguiping-xydt wants to merge 10 commits into
openclaw:mainfrom
zhangguiping-xydt:feat/issue-94102

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

openclaw memory search can rank filename/date-token queries poorly or miss them when the filename token only lives in the derived path FTS index. The current PR was also stale against the canonical memory_index_* table migration, so the original fix needed to be rebased onto the current schema owner instead of keeping the old chunks_* wiring.

Why does this matter now?

The linked issue is a user-visible memory lookup failure: a clean memory index and working content search still did not reliably return the expected memory file for a filename/date-token query such as 2026-06-17-1649. Without this repair, users can have the right memory file indexed but still fail to retrieve it by the filename/date token they know.

What is the intended outcome?

Filename/date-token keyword searches should find the matching memory file while body-text BM25 ranking remains based on body text only. memory_index_chunks remains canonical, and both derived FTS tables are repaired or published from that canonical table.

What is intentionally out of scope?

This does not change memory file format, vector search scoring, providers, auth, network behavior, gateway startup behavior, or the public memory API contract.

Summary

  • Fix classification: root-cause compatibility and reliability repair for memory FTS path search on the current canonical memory index schema.
  • Maintainer-ready confidence: high for the local memory code path because current head 6e0e06e3acb7 has CLI proof for the filename/date-token lookup, passes the focused memory schema/search regression suite, passes the extension test typecheck, and has a final ClawSweeper commit review result of nothing_found.
  • Root cause: filename/date-token matches live in a derived path FTS index, but search/schema/publish paths were not consistently treating memory_index_chunks as the source of truth for both memory_index_chunks_fts and memory_index_chunks_fts_path. The repair path also needed to rebuild derived FTS rows atomically so an interrupted upgrade cannot drop previously usable lexical rows.
  • What changed: memory indexing now writes both the body FTS table and the separate path FTS table; stale cleanup removes both derived FTS rows; schema repair rebuilds missing or unmarked derived FTS rows from memory_index_chunks inside a savepoint with set-based SQL; full shadow reindex publishing copies memory_index_chunks_fts_path; keyword search merges body/path rows, keeps the best rank per chunk id, sorts the merged rows, and only then applies the final limit.
  • Why it matters / User impact: openclaw memory search "2026-06-17-1649" can find memory/2026-06-17-1649.md by filename/date token without prepending path text into the body index or weakening body BM25 relevance.
  • Architecture / source-of-truth check: memory_index_chunks remains canonical; FTS tables are derived indexes; schema setup and full reindex publish own derived-index repair; search owns merging body/path keyword candidates before result limiting.
  • Patch quality notes: the larger diff is from carrying the existing PR through the current canonical table migration, not from adding an unrelated feature. The repair marker is stored in memory_index_meta and keyed by the derived FTS table names, so legacy or unmarked indexes rebuild once while clean current indexes avoid repeated correlated scans over UNINDEXED FTS metadata columns.
  • Related open PR scan: this updates my existing open PR fix(memory-core): include path in FTS indexed text so filename tokens are searchable #94114 for linked issue memory_search ranks filename/date-token queries poorly despite clean index and working content search #94102. Sibling PR fix(memory-core): index memory path in FTS text for filename queries (fixes #94102) #94135 remains a maintainer selection signal; this PR now uses the current canonical memory_index_* schema rather than the stale pre-rebase table shape.

Linked context

Closes #94102

Related #94114

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: memory search should find indexed memory files by filename/date tokens through the memory index/search path while preserving body BM25 ranking and keeping schema repair safe for existing local memory indexes.

  • Real environment tested: isolated local OpenClaw CLI memory indexing/search on current head 6e0e06e3acb7, using a temporary OpenClaw home/workspace and memorySearch.provider: "none". This exercises the local memory indexing/search/schema code path changed by this PR.

  • Exact steps or command run after this patch:

    node ./openclaw.mjs memory index --force
    node ./openclaw.mjs memory search "2026-06-17-1649" --json --max-results 3
    node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions-test-repro.tsbuildinfo
    OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree node scripts/run-vitest.mjs run packages/memory-host-sdk/src/host/memory-schema.test.ts extensions/memory-core/src/memory/manager-search.test.ts extensions/memory-core/src/memory/manager-db.test.ts extensions/memory-core/src/memory/index.test.ts
  • Evidence after fix:

    HEAD=6e0e06e3acb7
    $ node ./openclaw.mjs memory index --force
    Memory index updated (main).
    $ node ./openclaw.mjs memory search "2026-06-17-1649" --json --max-results 3
    {
      "results": [
        {
          "id": "2fc0e5052cd30a063fe293b5c42bfbf822471f493651c3926068b82dad822d8c",
          "path": "memory/2026-06-17-1649.md",
          "startLine": 1,
          "endLine": 2,
          "score": 0.9000039999839999,
          "textScore": 0.000003999984000064,
          "snippet": "OAuth token notes and Google testing mode details.\n",
          "source": "memory"
        }
      ]
    }
    
    Validation result: check-test-types-head-final pass, exit_code=0.
    
    Test Files  4 passed (4)
    Tests  99 passed (99)
    
  • Observed result after fix: the current head returns memory/2026-06-17-1649.md for the CLI filename/date-token query and passes the canonical memory search/schema regressions, including date-token filename lookup, merge-before-limit behavior, unmarked FTS repair from memory_index_chunks, rollback preservation when unmarked FTS repair fails, clean-index scan skipping after the repair marker is current, legacy source migration, and shadow path FTS publication.

  • This update did not exercise provider auth, external OAuth, gateway session delivery, or network behavior because the changed path is local memory indexing/search/schema repair.

Tests and validation

Which commands did you run?

node ./openclaw.mjs memory index --force
node ./openclaw.mjs memory search "2026-06-17-1649" --json --max-results 3
node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions-test-repro.tsbuildinfo
OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree node scripts/run-vitest.mjs run packages/memory-host-sdk/src/host/memory-schema.test.ts extensions/memory-core/src/memory/manager-search.test.ts extensions/memory-core/src/memory/manager-db.test.ts extensions/memory-core/src/memory/index.test.ts

Target test files:

  • packages/memory-host-sdk/src/host/memory-schema.test.ts
  • extensions/memory-core/src/memory/manager-search.test.ts
  • extensions/memory-core/src/memory/manager-db.test.ts
  • extensions/memory-core/src/memory/index.test.ts

What regression coverage was added or updated?

  • Body/path FTS candidates are merged before the requested result limit is applied, so a filename hit is not dropped when body matches fill the limit.

  • memory_index_chunks_fts / memory_index_chunks_fts_path row-count mismatch or missing repair marker rebuilds derived rows from canonical memory_index_chunks.

  • Unmarked FTS repair now preserves previous derived FTS rows if the repair fails before completion.

  • Clean FTS schema setup skips repeated WHERE NOT EXISTS virtual-table drift scans after the repair marker is current.

  • Full shadow memory reindex publication copies memory_index_chunks_fts_path, so filename/date-token rows survive in-place reindex publish.

  • Legacy memory stores without source columns migrate into canonical rows with the default memory source before rebuilding derived FTS rows.

  • Merged keyword rows use toSorted, avoiding in-place ordering mutation while preserving rank order.

  • Focused regression command after this patch: the four memory manager/schema test files above were run together against the current head and passed 99 tests.

  • Scenario locked in: canonical chunk rows remain the source of truth while body and path FTS tables are repaired/published separately, marked after repair, and merged before result limiting.

  • Why this is the smallest reliable guardrail: these tests exercise the changed search merge/rank behavior, the schema-owner repair path, the repair-marker skip path, the repair rollback path, the legacy migration path, and the full reindex publish path directly without requiring provider embeddings or gateway-only startup proof.

CI attribution

  • Current proof is bound to PR head 6e0e06e3acb7.
  • check-test-types was PR-introduced: the new filename-token test passed an unsupported storePath field to createCfg, causing TS2353. Current head removes that invalid test-only field and passes the same extension test typecheck.
  • The earlier checks-node-core-tooling failure was in src/scripts/test-projects.test.ts, outside this PR's memory-core/memory-host-sdk diff. I did not change tooling code for that failure.
  • The earlier checks-node-agentic-agents-core-runtime failure was in src/agents/code-mode.test.ts, outside this PR's memory-core/memory-host-sdk diff. I did not change agent runtime code for that failure.
  • Final local pre-submit review: ClawSweeper commit review on 6e0e06e3acb7 reported nothing_found with check_conclusion=success.
  • Fresh remote checks should be evaluated against the current PR head.

Risk checklist

Did user-visible behavior change? Yes

Did config, environment, or migration behavior change? Yes

Did security, auth, secrets, network, or tool execution behavior change? No

What is the highest-risk area?

Existing local memory SQLite stores may have derived FTS tables that are missing rows, use older FTS layouts, or were built before source existed on legacy memory tables.

How is that risk mitigated?

The repair treats memory_index_chunks as source of truth and rebuilds derived FTS rows when row counts differ or the repair marker is missing. The rebuild runs inside a SQLite savepoint and uses set-based INSERT ... SELECT, so a failed repair rolls back to the previous derived FTS rows instead of leaving lexical search empty. After the marker is current, clean schema setup avoids repeated correlated scans over FTS virtual tables. It does not rewrite memory files, vectors, auth/config, provider state, or canonical chunk rows. Body-text FTS remains separate from path FTS, so filename lookup no longer changes body BM25 document-length normalization.

Current review state

Which bot or reviewer comments were addressed?

  • RF-001 / path FTS strategy choice: disclosed as a maintainer decision; this PR presents the separate derived path FTS table strategy on the canonical memory_index_* schema.
  • RF-002 / persistent derived SQLite FTS table and repair-marker upgrade risk: addressed with atomic set-based repair, rollback coverage for failed repair, current-head CLI proof, and focused schema/search tests; the remaining upgrade-shape choice is still visible for maintainer review.
  • RF-003 / sibling PR fix(memory-core): index memory path in FTS text for filename queries (fixes #94102) #94135 competing strategy: disclosed as a maintainer selection signal; this PR should be compared against that approach before merge.
  • RF-004 / canonical memory FTS strategy and upgrade shape: disclosed as a maintainer decision; contributor-side proof and local safety checks are current.
  • ClawSweeper commit review finding / FTS repair can drop lexical search state and spike memory on upgrade: fixed by replacing JS-materialized row-by-row repair with savepoint-protected set-based SQL rebuild, plus a regression that forces repair failure and verifies previous FTS rows remain available.

What is the next action?

Maintainers can compare this canonical-table approach with sibling PR #94135 and evaluate the normal remote checks on the current PR head.

@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core size: XS triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 17, 2026
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. and removed triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 17, 2026
@zhangguiping-xydt
zhangguiping-xydt marked this pull request as draft June 18, 2026 03:21
@clawsweeper

clawsweeper Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep this PR open as a meaningful candidate fix, but not an auto-close or automerge path: it changes persistent memory SQLite FTS state and has an open sibling PR with a competing strategy, so maintainers need to choose the canonical upgrade shape before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #94102
Summary: The linked issue is the canonical filename/date-token memory search report; this PR and the sibling PR are competing candidate fixes for the same FTS path-token gap.

Members:

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

Canonical path: Close this PR as superseded by #94135.

So I’m closing this here and keeping the remaining discussion on #94135.

Review details

Best possible solution:

Close this PR as superseded by #94135.

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

Yes. Current main and v2026.6.8 store memory paths as UNINDEXED FTS metadata while writing only chunk body text into the indexed FTS column, and the linked issue plus PR proof show the filename/date-token query behavior.

Is this the best way to solve the issue?

Unclear as the final merge choice. The separate path-table design is coherent and has current-head CLI proof, but maintainers still need to choose it over the sibling path-prefixed payload design.

Security review:

Security review cleared: No concrete security or supply-chain concern was found; the diff changes local memory indexing/schema/tests and adds no dependencies, workflows, downloads, permissions, or secret handling.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • vincentkoc: Current blame for the central memory schema, search, FTS write, and publish lines points to recent memory area work by Vincent Koc, making this a strong routing signal even though the commit is broad. (role: recent area contributor; confidence: medium; commits: 8265acaacb00, 844f405ac1be; files: packages/memory-host-sdk/src/host/memory-schema.ts, extensions/memory-core/src/memory/manager-search.ts, extensions/memory-core/src/memory/manager-embedding-ops.ts)
  • steipete: Peter Steinberger carried the memory-host move into the SDK package and several adjacent memory-core refactors that define the current schema/search ownership boundary. (role: memory architecture refactor contributor; confidence: medium; commits: eebce9e9c7cb, a9b982c95429, dbf78de7c680; files: packages/memory-host-sdk/src/host/memory-schema.ts, extensions/memory-core/src/memory/manager-search.ts, extensions/memory-core/src/memory/manager-embedding-ops.ts)
  • Takhoffman: Tak Hoffman authored the configurable FTS5 tokenizer work across the same memory schema/search/sync surface involved in filename tokenization. (role: FTS feature contributor; confidence: medium; commits: 3ce48aff660a; files: packages/memory-host-sdk/src/host/memory-schema.ts, extensions/memory-core/src/memory/manager-search.ts, extensions/memory-core/src/memory/manager-sync-ops.ts)
  • vignesh07: Vignesh Natarajan authored recent FTS-only indexing and reindex work in the memory write/sync paths that this upgrade behavior touches. (role: adjacent FTS-only indexing contributor; confidence: medium; commits: 598f539be5e1, 1a0c3bf40068; files: extensions/memory-core/src/memory/manager-embedding-ops.ts, extensions/memory-core/src/memory/manager-sync-ops.ts, extensions/memory-core/src/memory/index.test.ts)

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

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: L proof: supplied External PR includes structured after-fix real behavior proof. and removed size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 18, 2026
@zhangguiping-xydt
zhangguiping-xydt marked this pull request as ready for review June 18, 2026 08:15
@zhangguiping-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@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. 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 18, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed 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. labels Jun 19, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 20, 2026
@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: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jun 20, 2026
@clawsweeper

clawsweeper Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory_search ranks filename/date-token queries poorly despite clean index and working content search

1 participant