fix(memory): gracefully degrade when embedding provider is unregistered#91862
fix(memory): gracefully degrade when embedding provider is unregistered#91862xydt-tanshanshan wants to merge 1 commit into
Conversation
When a configured embedding provider (e.g. 'openai') has no registered adapter—typically because the provider plugin is not installed— ensureProviderInitialized() previously let the 'Unknown memory embedding provider' error propagate, crashing the CLI on . Now the error is caught and the manager gracefully degrades to FTS-only mode, setting providerUnavailableReason so that still works and shows the real problem instead of a stack trace. Refs openclaw#91778
|
Codex review: needs maintainer review before merge. Reviewed June 10, 2026, 2:53 AM ET / 06:53 UTC. Summary PR surface: Source +15, Tests +105. Total +120 across 2 files. Reproducibility: yes. at source level: current main's adapter lookup throws for an unregistered provider and ensureProviderInitialized rethrows that into probe/status callers. I did not run the CLI in this read-only review. Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Next step before merge
Security Review detailsBest possible solution: Land the narrow diagnostic degradation after ordinary maintainer review and CI, while keeping #91778 open for the remaining index-metadata and vector-search recovery work. Do we have a high-confidence way to reproduce the issue? Yes at source level: current main's adapter lookup throws for an unregistered provider and ensureProviderInitialized rethrows that into probe/status callers. I did not run the CLI in this read-only review. Is this the best way to solve the issue? Yes for the narrow crash path: the manager is the right boundary to translate provider initialization failure into lifecycle state, and the existing sync/search required-provider guards still prevent silent vector-index downgrade. It is not a complete fix for the broader linked memory_search issue. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against a3d5e5bc7247. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +15, Tests +105. Total +120 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@vincentkoc this is the prerequisite for the FTS-only providerKey auto-fix (#92079). ensureProviderInitialized() currently throws on unknown providers instead of degrading gracefully. Mind taking a look? |
|
Closing this PR since the linked issue #91778 was closed as not_planned. The project direction appears to prefer fail-fast on unknown providers over graceful degradation — a reasonable choice that avoids silently masking configuration errors. Dependent PR #92079 is also paused accordingly. Happy to revisit if the direction changes. |
Summary
When a configured embedding provider (e.g.
openai) has no registered adapter — typically because the provider plugin is not installed —ensureProviderInitialized()previously let theUnknown memory embedding providererror propagate, crashing the CLI onopenclaw memory status --index.Now the error is caught and the manager gracefully degrades to FTS-only mode, setting
providerUnavailableReasonso thatopenclaw memory statusstill works and shows the real problem instead of a stack trace.This addresses the unregistered-provider crash path reported in #91778. The broader index-metadata/vector-search failure tracked in that issue remains outside this diff.
Change Type
Scope
Linked Issue
Motivation
Issue #91778 reports
memory_searchvector search broken since v2026.6.1. Users withprovider: "openai-compatible"orprovider: "openai"configured but without the corresponding provider plugin installed get a CLI crash onopenclaw memory status --index, preventing any diagnosis or recovery.Root cause:
createEmbeddingProvider()→getAdapter()throwsError("Unknown memory embedding provider: <id>")when the provider plugin is not installed. This error propagates throughloadProviderResult()→ensureProviderInitialized()→probeEmbeddingAvailability()→ CLI crash. The user never gets to see what is wrong.This PR only fixes the unregistered-provider crash path. The remaining index-metadata and vector-search recovery behavior in #91778 is outside the scope of this diff.
Changes
File:
extensions/memory-core/src/memory/manager.tsIn
ensureProviderInitialized(), catchUnknown memory embedding provider:errors specifically and degrade to FTS-only mode instead of propagating the error:message.startsWith("Unknown memory embedding provider:")applyProviderResult({ provider: null, requestedProvider, providerUnavailableReason: message })to set the correct FTS-only lifecycle stateFile:
extensions/memory-core/src/memory/manager.unknown-provider-degradation.test.ts(new)2 tests covering the degradation path:
probeEmbeddingAvailability()returns{ ok: false, error }instead of throwingstatus().custom.providerStateis{ mode: "fts-only", reason: "Unknown memory embedding provider: ..." }No new imports, no config changes, no default surface changes.
Real Behavior Proof
openclaw memory status --indexcrashes withUnknown memory embedding provider: <id>when the configured embedding provider plugin is not installed, preventing any diagnosis or recovery.fix/memory-index-metadata-missing-91778at commitdf80fe7, dev build vianode scripts/run-node.mjs.agents.defaults.memorySearch.providerto"nonexistent-embedding-provider"in~/.openclaw/openclaw.json, then runnode scripts/run-node.mjs memory status --indexdf80fe7) showing CLI no longer crashes when an unregistered embedding provider is configured. The manager degrades to FTS-only mode with a clear error message instead of a stack trace. Copied live output fromnode scripts/run-node.mjs memory status --indexwithprovider: "nonexistent-embedding-provider":Before-fix comparison (installed build without the openai provider plugin,
provider: "openai"configured):ensureProviderInitialized()catches theUnknown memory embedding providererror and degrades to FTS-only mode. The CLI no longer crashes; users seeEmbeddings: unavailable,Embeddings error: Unknown memory embedding provider: ...,Index identity: index metadata is missing, andSemantic vectors: unavailable. FTS search still works. The lifecycle state is correctly set to{"mode":"fts-only","reason":"Unknown memory embedding provider: ...","attemptedProviderId":"..."}.assertRequiredProviderAvailablepath in sync is intentionally unchanged: explicit provider requests that fail should still block sync from silently downgrading an existing vector index.Risks
Unknown memory embedding provider:errors are caught and degraded. All other provider init errors (auth, network, timeout) still propagate as before.getAdapter()throws for an unregistered provider. Previously this was a guaranteed crash; now it is a graceful FTS-only fallback with a clear error message.