Skip to content

fix(memory): keep gateway search read-only and reuse managers - #139013

Closed
saladinyao-cyber wants to merge 2 commits into
openclaw:mainfrom
saladinyao-cyber:fix/memory-search-read-only-reusable
Closed

saladinyao-cyber wants to merge 2 commits into
openclaw:mainfrom
saladinyao-cyber:fix/memory-search-read-only-reusable

Conversation

@saladinyao-cyber

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway and tool memory_search can currently acquire maintenance-capable managers. That may trigger index mutation during a read request and repeatedly construct/close managers, adding latency and creating avoidable SQLite/provider lifecycle races.

Why This Change Was Made

Add an explicit read-only manager mode that opens the existing index without running sync or migration work, validates the persisted schema/index identity, and fails closed when maintenance is required. Retain and reuse those read-only managers through the existing scoped registry lifecycle while preserving one-shot behavior for explicit CLI searches.

User Impact

Normal gateway memory searches remain read-only, avoid surprise indexing work, and reuse healthy managers. Dirty, incomplete, or identity-mismatched indexes return actionable unavailable state instead of being silently mutated by search.

Evidence

  • 106/106 focused memory-core tests passed.
  • 15/15 gateway memory.search tests passed.
  • Covers read-only reuse, incomplete schema, identity mismatch, dirty vector marker, close/replacement races, lifecycle isolation, and explicit CLI one-shot behavior.
  • Extensions Memory Core TypeScript check passed.
  • Oxlint: 0 warnings, 0 errors.
  • Oxfmt and git diff --check passed.
  • Rebased on current upstream main.

This PR intentionally excludes the separate 30-second deadline change in #139003.

@clawsweeper

clawsweeper Bot commented Sep 5, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime extensions: memory-core Extension: memory-core size: M labels Sep 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 5, 2026, 7:42 AM ET / 11:42 UTC.

ClawSweeper review

What this changes

Gateway memory searches acquire reusable read-only index managers, validate persisted index readiness, and stop closing managers after each request.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 10 items remain

The PR remains useful, but its readiness checks introduce three search regressions. Current main still uses transient Gateway managers, so closure as implemented is unsupported.

Priority: P2
Reviewed head: 3d8428538f55ba1d03535e1af74f11e2332528e4
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful lifecycle work is present, but supported search states regress and real Gateway behavior remains unproven.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The supplied evidence covers fixture-backed managers and a mocked Gateway handler, but does not show the changed Gateway acquisition path returning correct results in a real setup. Add redacted after-fix terminal output, logs, or a recording covering reuse and relevant fallback/recovery behavior; screenshots help when they show the result. Remove credentials, IPs, private endpoints, and other private details. Updating the PR body should trigger review; otherwise ask a maintainer for @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 3 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The supplied evidence covers fixture-backed managers and a mocked Gateway handler, but does not show the changed Gateway acquisition path returning correct results in a real setup. Add redacted after-fix terminal output, logs, or a recording covering reuse and relevant fallback/recovery behavior; screenshots help when they show the result. Remove credentials, IPs, private endpoints, and other private details. Updating the PR body should trigger review; otherwise ask a maintainer for @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 11 items Pinned patch and repository identity: The origin identifies openclaw/openclaw. The inspected merge-base-to-head delta matches the supplied introduced files; production grows by 137 lines and tests/test support by 103. The checkout remains clean.
Current main and release retain the previous lifecycle: Both fetched main and v2026.9.1 acquire purpose cli and close the manager after the Gateway request. No verified merged replacement was supplied or established.
Fallback identity is rejected before adoption: The constructor validates against the configured primary before provider initialization. The existing search lifecycle can adopt a matching configured fallback index, but construction now prevents reaching that path.
Findings 3 actionable findings [P1] Resolve the configured fallback before rejecting index identity
[P1] Preserve searches when only the native vector index needs repair
[P2] Validate the full FTS schema before accepting a search reader
Security None None.

How this fits together

The Control UI sends memory queries to the Gateway, which obtains a search manager from the active memory plugin. Memory Core searches the agent’s SQLite index and returns ranked snippets or an unavailable response.

flowchart LR
  A[Memory search UI] --> B[Gateway search request]
  B --> C[Memory plugin registry]
  C --> D[Reusable read-only manager]
  D --> E{Index ready?}
  E -->|Yes| F[Keyword and vector retrieval]
  E -->|No| G[Unavailable response]
  F --> H[Ranked memory snippets]
Loading

Decision needed

Question Recommendation
Should Gateway memory.search require an already-prepared index, or retain automatic preparation through a separate writer lifecycle? Preserve automatic preparation: Keep queries read-only while assigning preparation and maintenance to the existing writer lifecycle, with visible recovery when preparation fails.

Why: The patch intentionally removes bootstrap and maintenance behavior used by the existing Gateway path and adds a plugin-runtime lifetime contract; code inspection cannot establish acceptance of that operator-facing change.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The supplied evidence covers fixture-backed managers and a mocked Gateway handler, but does not show the changed Gateway acquisition path returning correct results in a real setup. Add redacted after-fix terminal output, logs, or a recording covering reuse and relevant fallback/recovery behavior; screenshots help when they show the result. Remove credentials, IPs, private endpoints, and other private details. Updating the PR body should trigger review; otherwise ask a maintainer for @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve the configured fallback before rejecting index identity (P1) - When maintenance has published an index using the configured fallback provider, initialIndexIdentity compares it with the primary provider and reports a mismatch. This new constructor assertion then rejects acquisition before adoptPublishedFallbackProviderIfMatched() can run. The existing fallback-adoption test explicitly preserves this supported state. Resolve the effective provider identity before rejecting an otherwise valid published index.
  • Preserve searches when only the native vector index needs repair (P1) - A native-vector rebuild marker can mean SQLite vector writes were unavailable while canonical chunk embeddings were successfully stored: manager-embedding-ops.ts records exactly that state. Existing searchVector() safely scans those embeddings when native vectors are unavailable. Rejecting the entire manager here disables both that cosine fallback and usable keyword results. Gate native KNN on completeness without rejecting the other read-only retrieval paths.
  • Validate the full FTS schema before accepting a search reader (P2) - With the default tokenizer, USING fts5(wrong) and contentless FTS definitions pass these checks. The previous writable acquisition reconciles those shapes through ftsTableMatchesSchema(), and existing reconciliation tests cover them. The new reader skips reconciliation, marks FTS available, then keyword-query failures are caught as empty results. Share the canonical column and option validation so incompatible tables produce an actionable unavailable response instead of successful empty searches.
  • Resolve merge risk (P1) - Fresh or reset indexes can now make Gateway searches unavailable until another writer prepares them; fresh-install and upgrade recovery are unproven.
  • Resolve merge risk (P1) - The new plugin-runtime purpose also changes manager lifetime expectations, without maintainer-visible agreement on the acquisition and cleanup contract.
  • Resolve merge risk (P1) - Production growth includes a separate schema-validation policy whose necessity beyond the canonical schema owner is not established.
  • Complete next step (P2) - Address the three findings, resolve the prepared-index and manager-lifetime contract, and provide after-fix real Gateway proof.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P1] Resolve the configured fallback before rejecting index identity — extensions/memory-core/src/memory/manager.ts:251-258
  • [P1] Preserve searches when only the native vector index needs repair — extensions/memory-core/src/memory/manager-db.ts:542-550
  • [P2] Validate the full FTS schema before accepting a search reader — extensions/memory-core/src/memory/manager-db.ts:513-519
Agent review details

Security

None.

PR surface

Source +137, Tests +103. Total +240 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 10 161 24 +137
Tests 4 108 5 +103
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 269 29 +240

Review metrics

Metric Value Why it matters
Production versus tests production net +137; tests and test support net +103 Reader lifecycle isolation has a concrete purpose, but parallel schema validation adds avoidable policy duplication.
Plugin lifecycle contract 1 manager purpose added; 1 Gateway caller changes cleanup ownership Plugin implementations must understand whether the returned manager is retained or request-owned.

Stored data model

Persistent data-model change detected: unknown-data-model-change: extensions/memory-core/src/memory/manager-db.ts, unknown-data-model-change: extensions/memory-core/src/memory/manager.ts, vector/embedding metadata: extensions/memory-core/src/memory/manager-db.ts, vector/embedding metadata: extensions/memory-core/src/memory/manager.ts, vector/embedding metadata: extensions/memory-core/src/tools.shared.ts, vector/embedding metadata: src/gateway/server-methods/memory-search.ts, and 1 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Preserve supported search states (recommended)
    Repair the readiness checks and settle writer-owned preparation before adopting the reusable reader contract.
  2. Pause the lifecycle change
    Keep the current acquisition path until maintainers accept the prepared-index requirement and contributor runtime evidence covers recovery.

Technical review

Best possible solution:

Consolidate validation into the existing schema owner, preserve supported fallback searches, and pair reusable readers with writer-owned initialization and visible index recovery.

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

Yes, source establishes failing paths for a configured-fallback index, native-vector rebuild debt, and malformed FTS tables; existing tests define the corresponding expected behavior. No runtime reproduction was executed in this read-only review.

Is this the best way to solve the issue?

No. Registry reuse and isolated readers are reasonable, but readiness checks bypass established fallback behavior and duplicate a stronger schema validator.

Full review comments:

  • [P1] Resolve the configured fallback before rejecting index identity — extensions/memory-core/src/memory/manager.ts:251-258
    When maintenance has published an index using the configured fallback provider, initialIndexIdentity compares it with the primary provider and reports a mismatch. This new constructor assertion then rejects acquisition before adoptPublishedFallbackProviderIfMatched() can run. The existing fallback-adoption test explicitly preserves this supported state. Resolve the effective provider identity before rejecting an otherwise valid published index.
    Confidence: 0.99
  • [P1] Preserve searches when only the native vector index needs repair — extensions/memory-core/src/memory/manager-db.ts:542-550
    A native-vector rebuild marker can mean SQLite vector writes were unavailable while canonical chunk embeddings were successfully stored: manager-embedding-ops.ts records exactly that state. Existing searchVector() safely scans those embeddings when native vectors are unavailable. Rejecting the entire manager here disables both that cosine fallback and usable keyword results. Gate native KNN on completeness without rejecting the other read-only retrieval paths.
    Confidence: 0.98
  • [P2] Validate the full FTS schema before accepting a search reader — extensions/memory-core/src/memory/manager-db.ts:513-519
    With the default tokenizer, USING fts5(wrong) and contentless FTS definitions pass these checks. The previous writable acquisition reconciles those shapes through ftsTableMatchesSchema(), and existing reconciliation tests cover them. The new reader skips reconciliation, marks FTS available, then keyword-query failures are caught as empty results. Share the canonical column and option validation so incompatible tables produce an actionable unavailable response instead of successful empty searches.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded memory-search improvement with substantive compatibility defects, without evidence of a current widespread outage.
  • add merge-risk: 🚨 compatibility: Gateway searches gain index-readiness prerequisites and a new plugin manager-lifetime contract.
  • add merge-risk: 🚨 auth-provider: The constructor rejects valid configured-fallback indexes before existing provider adoption can run.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The supplied evidence covers fixture-backed managers and a mocked Gateway handler, but does not show the changed Gateway acquisition path returning correct results in a real setup. Add redacted after-fix terminal output, logs, or a recording covering reuse and relevant fallback/recovery behavior; screenshots help when they show the result. Remove credentials, IPs, private endpoints, and other private details. Updating the PR body should trigger review; otherwise ask a maintainer for @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: This is a bounded memory-search improvement with substantive compatibility defects, without evidence of a current widespread outage.
  • merge-risk: 🚨 compatibility: Gateway searches gain index-readiness prerequisites and a new plugin manager-lifetime contract.
  • merge-risk: 🚨 auth-provider: The constructor rejects valid configured-fallback indexes before existing provider adoption can run.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The supplied evidence covers fixture-backed managers and a mocked Gateway handler, but does not show the changed Gateway acquisition path returning correct results in a real setup. Add redacted after-fix terminal output, logs, or a recording covering reuse and relevant fallback/recovery behavior; screenshots help when they show the result. Remove credentials, IPs, private endpoints, and other private details. Updating the PR body should trigger review; otherwise ask a maintainer for @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Pinned patch and repository identity: The origin identifies openclaw/openclaw. The inspected merge-base-to-head delta matches the supplied introduced files; production grows by 137 lines and tests/test support by 103. The checkout remains clean. (3d8428538f55)
  • Current main and release retain the previous lifecycle: Both fetched main and v2026.9.1 acquire purpose cli and close the manager after the Gateway request. No verified merged replacement was supplied or established. (src/gateway/server-methods/memory-search.ts:132, ad6fe23aecb9)
  • Fallback identity is rejected before adoption: The constructor validates against the configured primary before provider initialization. The existing search lifecycle can adopt a matching configured fallback index, but construction now prevents reaching that path. (extensions/memory-core/src/memory/manager.ts:252, 3d8428538f55)
  • Established fallback contract: The test “adopts a configured fallback index published by detached maintenance” requires searches to return results after reopening an index built by the configured fallback. This coverage also exists in v2026.9.1. (extensions/memory-core/src/memory/manager-provider-lifecycle-fallback.test.ts:107, ad6fe23aecb9)
  • Native vector debt does not invalidate stored embeddings: The indexing owner marks native-vector rebuild debt when embeddings exist but native vector writes are unavailable. The existing searchVector path can instead scan stored chunk embeddings; the new acquisition check blocks that fallback. (extensions/memory-core/src/memory/manager-embedding-ops.ts:782, e55f25b15ea6)
  • Canonical FTS validation already exists: The schema owner validates column declarations, UNINDEXED metadata, and supported storage/tokenizer options. Its reconciliation tests cover wrong-column and contentless tables, which the new regex-only validator accepts. (packages/memory-host-sdk/src/host/memory-schema-fts.ts:12, 3d8428538f55)

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Repair provider fallback, native-vector fallback, and complete FTS validation with regression coverage.
  • Resolve prepared-index requirements and document the plugin manager-lifetime and recovery contract.
  • Provide redacted after-fix Gateway evidence for repeated searches, fresh or upgraded indexes, and supported fallback states.

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.

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 gateway Gateway runtime merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant