Skip to content

fix(memory): recover missing full-text index rows - #144641

Merged
steipete merged 2 commits into
openclaw:mainfrom
jinliyl:fix/memory-fts-partial-reconcile
Sep 11, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
jinliyl:fix/memory-fts-partial-reconcile

Conversation

@jinliyl

@jinliyl jinliyl commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Related: #115775

What Problem This Solves

Fixes an issue where users with a populated but incomplete memory full-text index could receive silently missing search results. Ordinary schema reconciliation only rebuilt a completely empty index, so one or more missing derived rows survived startup.

Why This Change Was Made

The existing Memory Host SDK FTS owner now compares canonical and derived row counts inside its existing savepoint and invokes the existing canonical rebuild operation only when they diverge. This is routine maintenance of the derived-index contract accepted in #115775; it adds no schema, version, configuration, migration, or public API.

User Impact

Memory search recovers missing FTS rows during normal schema reconciliation while leaving complete indexes and canonical memory rows unchanged.

Evidence

  • Regression proof before the fix: after deleting one row from a populated FTS table, schema reconciliation left only kept and failed to restore/search missing.
  • node scripts/run-vitest.mjs packages/memory-host-sdk/src/host/memory-schema-fts-reconcile.test.ts packages/memory-host-sdk/src/host/memory-schema.test.ts --maxWorkers=1 (33 passed across both selected projects)
  • Changed-path core gates passed: formatting, assertion ratchet, package/plugin boundaries, core and core-test typechecks, dead-export scan, lint, database-first guards, and runtime import-cycle checks.
  • Initial fresh local autoreview: scoped clean, confidence 0.94. Follow-up review after the CI-driven sibling assertion update: scoped clean, confidence 0.98.
  • CI's first revision exposed one attributable stale assertion in memory-schema.test.ts: it expected a newly canonical chunk-2 to remain absent from FTS. The assertion now requires both canonical chunks after reconciliation, and the full sibling test file passes.

Isolated real CLI proof

Used a fresh temporary state/config/workspace with two synthetic memory files and the normal supported CLI. pnpm openclaw memory index --agent main --force indexed both files. I then removed only the derived FTS row for memory/beta.md, producing this persisted precondition:

{
  "canonical": { "n": 2 },
  "derived": { "n": 1 },
  "missingMatch": []
}

Running normal initialization through pnpm openclaw memory search --agent main --query cobalt --json returned memory/beta.md with its synthetic cobalt-lantern-482 snippet. Read-only inspection after the command showed:

{
  "canonical": { "n": 2 },
  "derived": { "n": 2 },
  "match": [{ "path": "memory/beta.md" }]
}

Data-model and upgrade compatibility

The proof starts from an already persisted current-format agent database, removes a reconstructible derived row to model the affected existing state, and reopens it through the patched normal CLI path. The repair changes no table definition, columns, schema version, canonical rows, configuration, migration, downgrade behavior, or public API. It only rebuilds the existing derived FTS table from the existing canonical chunks when their cardinalities prove divergence. Equal-count databases retain their existing index.

@clawsweeper

clawsweeper Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@jinliyl
jinliyl marked this pull request as ready for review September 11, 2026 03:59
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 11, 2026
@clawsweeper

clawsweeper Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 11, 2026, 12:22 AM ET / 04:22 UTC (Revision 2).

ClawSweeper review

What this changes

Memory initialization now rebuilds an incomplete full-text search index when its row count differs from canonical memory chunks, with regression coverage for restored results.

Warning

SQLite table change

This PR modifies persisted SQLite tables in packages/memory-host-sdk/src/host/memory-schema-fts.ts. Prefer a design that avoids changing persisted SQLite tables. If the change is necessary, verify migration and upgrade compatibility against an existing database before merge.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR remains useful: current main and the latest release retain the reported gap. The new persisted-database CLI evidence resolves the previous proof blocker, and no actionable patch defects were found.

Priority: P2
Reviewed head: 1f7a83f3288f7743864d9e989a9b1a5ce04ee7c8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful SQLite regression coverage and sufficient persisted-state CLI proof.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied isolated CLI evidence exercises normal Memory Host SDK initialization against a persisted incomplete index, restores the missing keyword result, and shows derived rows returning from one to two while canonical rows remain two; it satisfies the previous proof request.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied isolated CLI evidence exercises normal Memory Host SDK initialization against a persisted incomplete index, restores the missing keyword result, and shows derived rows returning from one to two while canonical rows remain two; it satisfies the previous proof request.
Evidence reviewed 9 items Current main still has the defect: The body-index reconciliation inserts canonical chunks only when the derived table is completely empty; a populated table missing one row remains incomplete.
Latest release retains the same gap: The supplied latest-release revision for v2026.9.4 also uses empty-table-only reconciliation, so the partial-index recovery is not already shipped there.
Repair stays within the existing owner: The introduced count comparison invokes the existing canonical rebuild inside the existing savepoint. Schema checks, collision protection, rollback, configuration, and public interfaces remain unchanged.
Findings None None.
Security None None.

How this fits together

The Memory Host SDK maintains SQLite indexes used by OpenClaw’s memory search. During memory initialization, it reconciles derived full-text tables against canonical chunks before keyword queries use them.

flowchart TD
  A[Memory search command] --> B[Memory initialization]
  B --> C[Compare canonical and index counts]
  D[Canonical memory chunks] --> C
  C -->|Different| E[Rebuild within savepoint]
  C -->|Equal| F[Preserve existing index]
  E --> G[Keyword search results]
  F --> G
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +3, Tests +39. Total +42 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 12 9 +3
Tests 2 39 0 +39
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 51 9 +42

Review metrics

None.

Stored data model

Persistent data-model change detected: vector/embedding metadata: packages/memory-host-sdk/src/host/memory-schema-fts.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep automatic partial-index recovery in the existing reconciliation owner, rebuilding solely from canonical chunks without changing stored formats or user settings.

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

Yes: deleting one derived row while retaining another exposes the current-main empty-table guard. This is source-proven here; the contributor also supplies before/after CLI evidence, but this review did not execute it.

Is this the best way to solve the issue?

Yes: reusing the canonical rebuild inside the existing savepoint is a focused repair, and the persisted-database proof covers reopening affected state without a schema migration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8ddc4a1422c0.

Labels

Label justifications:

  • P2: This repairs silently missing keyword results for incomplete derived memory indexes, with a bounded recovery scope.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The supplied isolated CLI evidence exercises normal Memory Host SDK initialization against a persisted incomplete index, restores the missing keyword result, and shows derived rows returning from one to two while canonical rows remain two; it satisfies the previous proof request.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied isolated CLI evidence exercises normal Memory Host SDK initialization against a persisted incomplete index, restores the missing keyword result, and shows derived rows returning from one to two while canonical rows remain two; it satisfies the previous proof request.

Evidence

What I checked:

  • Current main still has the defect: The body-index reconciliation inserts canonical chunks only when the derived table is completely empty; a populated table missing one row remains incomplete. (packages/memory-host-sdk/src/host/memory-schema-fts.ts:178, 8ddc4a1422c0)
  • Latest release retains the same gap: The supplied latest-release revision for v2026.9.4 also uses empty-table-only reconciliation, so the partial-index recovery is not already shipped there. (packages/memory-host-sdk/src/host/memory-schema-fts.ts:178, 3a9d69db306c)
  • Repair stays within the existing owner: The introduced count comparison invokes the existing canonical rebuild inside the existing savepoint. Schema checks, collision protection, rollback, configuration, and public interfaces remain unchanged. (packages/memory-host-sdk/src/host/memory-schema-fts.ts:178, 1f7a83f3288f)
  • Meaningful regression coverage: The new real-SQLite test deletes one derived row from a populated index, invokes schema reconciliation, and checks restored MATCH results and preserved canonical identities. The sibling migration assertion now expects both canonical chunks. (packages/memory-host-sdk/src/host/memory-schema-fts-reconcile.test.ts:7, 1f7a83f3288f)
  • CLI proof addresses the earlier request: The complete supplied PR body, captured under sourceRevision da09b76cf30832935022dbc73f8dd7aa39e5fc9e42685a054c8b1b20bd99a7e8, reports an isolated supported CLI run: two files were indexed, one derived row was removed, and normal memory search restored the missing result. Posted database output changes canonical/derived counts from 2/1 to 2/2 and shows the recovered MATCH. This directly addresses the prior review’s sole rank-up request. (1f7a83f3288f)
  • Proof entrypoint reaches reconciliation: Memory manager initialization calls ensureSchema for the CLI path; that method calls ensureMemoryIndexSchema with the configured FTS enablement and tokenizer. The reported search command therefore exercises the changed production owner. (extensions/memory-core/src/memory/manager-sync-base.ts:620, 1f7a83f3288f)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vito Cappello: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-11T04:07:03.029Z sha 48fbfde :: needs real behavior proof before merge. :: none

@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. and removed 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. labels Sep 11, 2026
@jinliyl

jinliyl commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The requested compatibility evidence is already included in the PR body under Data-model and upgrade compatibility and Isolated real CLI proof.

This patch does not change the persisted data model: it adds no table, column, index option, schema version, migration, configuration, or public API. It only changes reconciliation of the existing fully derived memory_index_chunks_fts rows, using the existing rebuild operation and savepoint accepted in #115775.

The persisted-state proof starts with an existing current-format agent database containing 2 canonical rows and 1 derived FTS row, reopens it through the supported pnpm openclaw memory search CLI path, and ends with 2 canonical rows and 2 derived rows plus the recovered MATCH result. Canonical data remains unchanged. That exercises the upgrade/reopen path relevant to this repair without requiring a schema migration.

I also rechecked against current main (2e47020ebf87): the affected owner and tests are unchanged from the revision ClawSweeper reviewed, and the PR merges cleanly in a local merge-tree check.

Could the generic data-model compatibility checkbox be cleared based on that evidence?

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 11, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@steipete

Copy link
Copy Markdown
Contributor

Maintainer disposition of the SQLite-table warning at head 1f7a83f: this is not a persisted-format or schema change. The patch keeps the existing reconciliation owner in memory-schema-fts.ts and widens its trigger from "derived table completely empty" to "derived row count differs from canonical chunks", rebuilding the full-text index solely from canonical chunks inside the same savepoint. Stored formats, schema version, and user data are untouched; the index is derived and reconstructible, which is the design accepted in #115775. Upgrade compatibility is the ordinary reopen path: an incomplete index on an existing database is exactly the state this repair targets, and the supplied persisted-database CLI evidence exercises it. Warning accepted as non-material; no migration is required.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 11, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@steipete
steipete merged commit 2575d0d into openclaw:main Sep 11, 2026
187 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

@fuller-stack-dev

Copy link
Copy Markdown
Member

@jinliyl Narrow post-merge regression notice for the memory/FTS owner.

extensions/memory-core/src/memory/manager-temporal-ranking.test.ts, case through FTS unavailable, now fails at line 156: expected fts.available=false, received true.

Baseline reproducer:

node scripts/run-vitest.mjs extensions/memory-core/src/memory/manager-temporal-ranking.test.ts -t "through FTS unavailable"

Is an existing canonical follow-up already owned? Relaying here to avoid competing memory fixes in the lease or Wear PRs. This is not a request to waive their exact-head CI, restart automation, or weaken the fallback assertion.

obviyus added a commit that referenced this pull request Sep 11, 2026
Related: #136257 (F25), #142165.

## What Problem This Solves

Fixes an issue where the Watch model picker used the phone's current catalog instead of the session selected on the Watch. A valid Watch-session choice could be rejected before reaching the session owner. The Gateway also implemented session-scoped catalogs without advertising that capability in hello.

## Why This Change Was Made

The Wear bridge reads `models.list` for the requested session and uses the phone's existing result parser. The old phone-current catalog callback and selection veto are removed. Availability, unknown availability, search bounds, and partial-refresh warnings now flow from the same catalog result. Hello advertises the implemented capability, and the phone advertises model controls only when the Gateway supports it.

New Watches always send their selected session. Shipped protocol-v1 Watches that omit the field retain phone-active-session behavior through the same direct catalog owner. The protocol version is unchanged.

## User Impact

- The Watch lists models for its selected session and lets the session owner accept or reject a change.
- Partial refresh warnings preserve usable choices. Context changes clear old catalog and search state.
- Unsupported peers keep ordinary session navigation usable. Older Watches retain their existing request contract.

## Evidence

- Baseline hello regression: one expected failure, 30 passing cases; the implemented session-catalog capability was absent.
- Baseline selection regression: the phone-current catalog veto rejected a valid Watch-session choice before calling its owner.
- Candidate: 43 Gateway tests and 150 focused Android tests passed, including shared parser, real phone runtime/WebSocket dispatch, Watch repository, state transitions, proxy identity, and protocol coverage.
- Wear APK assembly, Kotlin formatting, and native localization verification passed.
- All 15 sanitized config-corpus fixtures passed actual Gateway startup with external networking disabled, fake credentials, and external Tailscale exposure disabled for isolation.
- A real Gateway client connection, also exercised by an independent validator, observed protocol 4, the published capability, and the requested fixture catalog.
- Wear API 34 and phone API 36 emulators booted with KVM. The normal Wear APK installed and launched. No paired Data Layer or live Watch picker result is claimed.
- Pairing proof gap, explicitly accepted for this change: **requires companion app + Play services; unit-covered**. The images have Play services but lack the required companion app; its official installation requires Google sign-in. Shared-parser, bridge, availability, and negotiation behavior are covered by the focused tests.

No provider inference, real credentials, protocol bump, or storage migration was used.

### Unrelated CI failure

Run [34567709488](https://github.com/openclaw/openclaw/actions/runs/34567709488) completed with every Android job passing. `checks-node-changed-extensions-config-49` failed the existing memory temporal-ranking `FTS unavailable` case at line 156; `openclaw/ci-gate` reports that child failure.

CI merged this head into main `2575d0d6356535a58d3a9798f08000caac856d0e` (#144641). That main change replaced the schema write probe with a row-count check, so the test's injected view now reports available. The exact CI base reproduces the same failure with five neighboring cases passing:

```sh
OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs --config test/vitest/vitest.extension-memory.config.ts extensions/memory-core/src/memory/manager-temporal-ranking.test.ts
# exit 1 on 2575d0d
```

The earlier base `ada8b5f65083` passes all six cases. This PR changes no memory implementation, schema, dependency, or test-runner code. The verified unrelated failure is retained as a separate follow-up; no CI retry or test weakening was used.

Co-authored-by: Ayaan Zaidi <[email protected]>
steipete added a commit that referenced this pull request Sep 11, 2026
)

* fix(memory): restore FTS fallback for same-name view collisions

Detect SQLite views before FTS schema reconciliation so matching row counts cannot falsely report an available body index. Preserve colliding views, canonical rows, and existing ordinary-table repairs.

Regression context: #144641. Validated with 53 focused tests and the full changed gate. P2 review raised only an unchanged path-trigger recovery limitation, confirmed with paired original/candidate SQLite proof and retained as a separate follow-up.

* fix(memory): preserve SQLite view-collision diagnostics

Keep the existing cannot-modify message when rejecting a colliding view before FTS reconciliation. This preserves the status diagnostic checked by the merged #144761 temporal-ranking fixture without changing schema or recovery behavior.

Validated with 53 focused tests using the exact merged fixture. Incremental P2 review found no actionable issues; the previously recorded path-trigger recovery limitation remains unchanged.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 12, 2026
* fix(memory): rebuild partial full-text indexes

* test(memory): expect reconciled full-text rows
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 12, 2026
Related: openclaw#136257 (F25), openclaw#142165.

## What Problem This Solves

Fixes an issue where the Watch model picker used the phone's current catalog instead of the session selected on the Watch. A valid Watch-session choice could be rejected before reaching the session owner. The Gateway also implemented session-scoped catalogs without advertising that capability in hello.

## Why This Change Was Made

The Wear bridge reads `models.list` for the requested session and uses the phone's existing result parser. The old phone-current catalog callback and selection veto are removed. Availability, unknown availability, search bounds, and partial-refresh warnings now flow from the same catalog result. Hello advertises the implemented capability, and the phone advertises model controls only when the Gateway supports it.

New Watches always send their selected session. Shipped protocol-v1 Watches that omit the field retain phone-active-session behavior through the same direct catalog owner. The protocol version is unchanged.

## User Impact

- The Watch lists models for its selected session and lets the session owner accept or reject a change.
- Partial refresh warnings preserve usable choices. Context changes clear old catalog and search state.
- Unsupported peers keep ordinary session navigation usable. Older Watches retain their existing request contract.

## Evidence

- Baseline hello regression: one expected failure, 30 passing cases; the implemented session-catalog capability was absent.
- Baseline selection regression: the phone-current catalog veto rejected a valid Watch-session choice before calling its owner.
- Candidate: 43 Gateway tests and 150 focused Android tests passed, including shared parser, real phone runtime/WebSocket dispatch, Watch repository, state transitions, proxy identity, and protocol coverage.
- Wear APK assembly, Kotlin formatting, and native localization verification passed.
- All 15 sanitized config-corpus fixtures passed actual Gateway startup with external networking disabled, fake credentials, and external Tailscale exposure disabled for isolation.
- A real Gateway client connection, also exercised by an independent validator, observed protocol 4, the published capability, and the requested fixture catalog.
- Wear API 34 and phone API 36 emulators booted with KVM. The normal Wear APK installed and launched. No paired Data Layer or live Watch picker result is claimed.
- Pairing proof gap, explicitly accepted for this change: **requires companion app + Play services; unit-covered**. The images have Play services but lack the required companion app; its official installation requires Google sign-in. Shared-parser, bridge, availability, and negotiation behavior are covered by the focused tests.

No provider inference, real credentials, protocol bump, or storage migration was used.

### Unrelated CI failure

Run [34567709488](https://github.com/openclaw/openclaw/actions/runs/34567709488) completed with every Android job passing. `checks-node-changed-extensions-config-49` failed the existing memory temporal-ranking `FTS unavailable` case at line 156; `openclaw/ci-gate` reports that child failure.

CI merged this head into main `0c892cac993095c0a95d7487f9f2e9123a835733` (openclaw#144641). That main change replaced the schema write probe with a row-count check, so the test's injected view now reports available. The exact CI base reproduces the same failure with five neighboring cases passing:

```sh
OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs --config test/vitest/vitest.extension-memory.config.ts extensions/memory-core/src/memory/manager-temporal-ranking.test.ts
# exit 1 on 0c892ca
```

The earlier base `0eb133df5ce0` passes all six cases. This PR changes no memory implementation, schema, dependency, or test-runner code. The verified unrelated failure is retained as a separate follow-up; no CI retry or test weakening was used.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 12, 2026
…claw#144783)

* fix(memory): restore FTS fallback for same-name view collisions

Detect SQLite views before FTS schema reconciliation so matching row counts cannot falsely report an available body index. Preserve colliding views, canonical rows, and existing ordinary-table repairs.

Regression context: openclaw#144641. Validated with 53 focused tests and the full changed gate. P2 review raised only an unchanged path-trigger recovery limitation, confirmed with paired original/candidate SQLite proof and retained as a separate follow-up.

* fix(memory): preserve SQLite view-collision diagnostics

Keep the existing cannot-modify message when rejecting a colliding view before FTS reconciliation. This preserves the status diagnostic checked by the merged openclaw#144761 temporal-ranking fixture without changing schema or recovery behavior.

Validated with 53 focused tests using the exact merged fixture. Incremental P2 review found no actionable issues; the previously recorded path-trigger recovery limitation remains unchanged.
obviyus added a commit that referenced this pull request Oct 17, 2026
…exes (#175555)

Related: #144641, #174438

## What Problem This Solves

Memory index admission counted rows of the FTS5 table with `SELECT COUNT(*)`. FTS5 serves that count as a full scan of its `%_content` shadow table. On large stores this added up to about 1.7 s of cold I/O, inside the agent database write transaction.

## User Impact

User impact: memory stores with a large full-text index open faster and hold the agent database write lock for less time. Search results, config, schema and stored data do not change.

## Why This Change Was Made

The admitted body FTS DDL keeps the default `columnsize=1`, so FTS5 stores one `%_docsize` row per document. The reconcile check now counts `<fts>_docsize`, which gives the same number from a much smaller table (211 pages instead of 20,567 on a 43,490-chunk store). Admission drops and recreates any FTS table with different DDL before the count runs, so the docsize table is always present. The rebuild decision and its repair are unchanged.

## Evidence

- Focused test `memory-schema-fts-reconcile.test.ts`: 16/16 pass. The new test checks that the query plan reads `memory_index_chunks_fts_docsize`, not the virtual table, and that the count equals `COUNT(*)` of the FTS table after deletes, re-inserts, edits and empty rows.
- Built CLI on this head, isolated state: `openclaw memory index` on 31 memory files gave 31 chunks, 31 docsize rows, 31 content rows. Deleting 12 FTS rows left 19/19. The next `openclaw memory search zebracorn` admission saw the mismatch, rebuilt the index back to 31/31, and returned all 30 matching notes.
- Contributor benchmark on two real stores: cold first admission 2,003-2,060 ms to 317-325 ms (43,490 chunks) and 220-230 ms to 72 ms (6,012 chunks).
- Hosted CI green and ClawSweeper `ready` on the merged head.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…exes (openclaw#175555)

Related: openclaw#144641, openclaw#174438

## What Problem This Solves

Memory index admission counted rows of the FTS5 table with `SELECT COUNT(*)`. FTS5 serves that count as a full scan of its `%_content` shadow table. On large stores this added up to about 1.7 s of cold I/O, inside the agent database write transaction.

## User Impact

User impact: memory stores with a large full-text index open faster and hold the agent database write lock for less time. Search results, config, schema and stored data do not change.

## Why This Change Was Made

The admitted body FTS DDL keeps the default `columnsize=1`, so FTS5 stores one `%_docsize` row per document. The reconcile check now counts `<fts>_docsize`, which gives the same number from a much smaller table (211 pages instead of 20,567 on a 43,490-chunk store). Admission drops and recreates any FTS table with different DDL before the count runs, so the docsize table is always present. The rebuild decision and its repair are unchanged.

## Evidence

- Focused test `memory-schema-fts-reconcile.test.ts`: 16/16 pass. The new test checks that the query plan reads `memory_index_chunks_fts_docsize`, not the virtual table, and that the count equals `COUNT(*)` of the FTS table after deletes, re-inserts, edits and empty rows.
- Built CLI on this head, isolated state: `openclaw memory index` on 31 memory files gave 31 chunks, 31 docsize rows, 31 content rows. Deleting 12 FTS rows left 19/19. The next `openclaw memory search zebracorn` admission saw the mismatch, rebuilt the index back to 31/31, and returned all 30 matching notes.
- Contributor benchmark on two real stores: cold first admission 2,003-2,060 ms to 317-325 ms (43,490 chunks) and 220-230 ms to 72 ms (6,012 chunks).
- Hosted CI green and ClawSweeper `ready` on the merged head.

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

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

3 participants