Skip to content

refactor(embeddings): unify provider contract - #130506

Merged
steipete merged 3 commits into
mainfrom
codex/refactor-canonical-embedding-contract-20260826
Aug 27, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/refactor-canonical-embedding-contract-20260826

Conversation

@steipete

@steipete steipete commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Embedding providers were forced through a private memory-specific adapter layer even though they already implemented the generic embedding operations consumed by memory, Gateway, CLI, and plugin registration. That round trip duplicated provider metadata, request-shape conversion, and lifecycle plumbing across the registry and memory runtime.

Why This Change Was Made

This refactor makes the existing generic embedding provider contract canonical across the private runtime. Provider plugins register that contract directly, memory consumes it directly, and the obsolete memory adapter and registry projection layers are removed.

Remote-provider request grouping is now an explicit provider capability rather than an adapter-side inference. Provider-specific query/document behavior remains owned by each provider, including Ollama's existing option handling and LM Studio's lifecycle lease behavior.

The five public generic embedding API paths and their exported shapes are unchanged. There is no SQLite, protocol, ownership, or public API migration.

User Impact

This is intended to preserve embedding behavior while removing a large internal translation layer. Memory search, Gateway embedding calls, CLI capability reporting, provider lifecycle handling, and provider-specific batching continue through one typed contract.

Evidence

  • 73 changed paths; production +225/-530 (net -305), tests +455/-415 (net +40), docs +1/-1, tooling +0/-2; total +681/-948 (net -267). No generated files.
  • The obsolete provider-adapters.ts and duplicate registry projection are deleted.
  • The five public generic embedding API paths remain unchanged: src/plugins/embedding-provider-types.ts, src/plugins/embedding-providers.ts, src/plugins/embedding-provider-runtime.ts, src/plugin-sdk/embedding-providers.ts, and src/plugins/types.ts. Private memory facade types are migrated to the canonical contract.
  • Focused provider and memory coverage passes 767 tests, the final LM Studio lifecycle set passes 16 tests, and the focused Ollama hook regression passes.
  • Production and test type checks pass. The full changed-path gate passes all routed lanes.
  • The package-boundary contract now explicitly inventories the private memory-host-sdk type-only alias to the canonical embedding provider contract; its focused RED 8/9 becomes GREEN 9/9, with 28/28 sibling guardrail tests green.
  • Five stale memory/LanceDB test fixtures now implement canonical embed/embedBatch methods instead of the deleted private embedQuery shape. Their focused failures become 220/220 green, with 237/237 wider retry and lifecycle coverage green.
  • Full build and runtime postbuild pass, including 147 SDK export checks.
  • Fresh autoreview over the original 67-path dataset reports no actionable findings; separate reviews of the bridge inventory and five-file fixture migration are each clean at 0.98 confidence; independent verification reports final PASS.
  • A pre-commit formatting hook collapsed one assertion layout in the new remote-provider test from 60 to 59 lines. A post-commit byte audit proved all other 66 paths unchanged and the assertion semantics identical.

Follow-up

The existing Ollama dimension-option hook remains intentionally unchanged. A separate provider-owner follow-up can evaluate that pre-existing behavior without coupling a semantic change to this contract consolidation.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete

Copy link
Copy Markdown
Contributor Author

Resolved the attributable exact-head plugin-contract failure on child commit 8cb3a14ef9c.

The canonical contract consolidation intentionally makes packages/memory-host-sdk/src/host/embeddings.types.ts a type-only alias of the unchanged core embedding provider contract. The package-boundary guard correctly discovered that new bridge, but its explicit private bridge inventory still listed only the prior six files.

The repair adds that exact type-only alias to MEMORY_HOST_SDK_ALLOWED_CORE_BRIDGE_FILES with a contract comment. The focused guard failed 8/9 before the repair and passes 9/9 afterward; 28/28 sibling boundary guardrails, formatting, lint, and diff checks pass. Fresh autoreview reports no actionable findings at 0.98 confidence. No runtime, scanner, public type, dependency, or API behavior changed.

Updated full PR metrics: 68 paths; production +225/-530 (net -305), tests +435/-372 (net +63), docs +1/-1, tooling +0/-2; total +661/-905 (net -244).

The prior exact-head lint cancellation was an infrastructure shutdown (exit 143, no diagnostic). This child head is receiving fresh exact-head CI; the failed old-head run will not be rerun.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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 Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 8:48 PM ET / August 27, 2026, 00:48 UTC.

ClawSweeper review

What this changes

This refactor lets provider plugins pass the shared embedding contract directly to memory, Gateway, and the CLI, deleting memory-specific contract translations.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. Current main still translates generic embedding providers through the memory-specific adapter, while this PR makes the generic contract direct; the central cleanup is therefore not already implemented. The maintainer label and incomplete exact-head checks require normal maintainer handling.

Priority: P2
Reviewed head: da49ca90d13ffdee8a5e143691760678ab70e8ad

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The direct contract design and focused coverage are credible, but exact-head CI and a complete local base/history comparison remain unavailable.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable: this maintainer-authored refactor is supported by focused runtime and transport test claims rather than an external-contributor proof gate.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable: this maintainer-authored refactor is supported by focused runtime and transport test claims rather than an external-contributor proof gate.
Evidence reviewed 6 items Current main still has the adapter layer: Current main wraps generic providers with memory-specific embedQuery, embedBatch, and embedBatchInputs operations, so the requested consolidation is not present there.
PR head removes the runtime projection: The proposed runtime now returns registered generic adapters directly to memory callers.
Canonical contract and provider semantics: The shared contract carries structured inputs and explicit query/document intent; inspected OpenAI, Gemini, Bedrock, Ollama, Voyage, Copilot, DeepInfra, LM Studio, and Mistral paths preserve provider-owned request behavior.
Findings None None.
Security None None.

Live Verification

Command: pnpm test packages/memory-host-sdk/src/host/embeddings-remote-provider.test.ts

Result: PASS (completed)

$ node --import tsx scripts/test-projects.mts packages/memory-host-sdk/src/host/embeddings-remote-provider.test.ts
[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130506-X03SKJ/target

 ✓  unit  packages/memory-host-sdk/src/host/embeddings-remote-provider.test.ts (3 tests) 27ms

 Test Files  1 passed (1)
      Tests  3 passed (3)
   Start at  00:49:07
   Duration  10.20s (transform 7.91s, setup 1.03s, import 8.77s, tests 27ms, environment 0ms)

[test] passed 1 Vitest shard in 23.12s
$ node --import tsx scripts/test-projects.mts packages/memory-host-sdk/src/host/embeddings-remote-provider.test.ts
[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130506-X03SKJ/target

 ✓  unit  packages/memory-host-sdk/src/host/embeddings-remote-provider.test.ts (3 tests) 20ms

 Test Files  1 passed (1)
      Tests  3 passed (3)
   Start at  00:49:31
   Duration  4.64s (transform 2.51s, setup 456ms, import 3.92s, tests 20ms, environment 0ms)

[test] passed 1 Vitest shard in 17.34s

Assertions:

  • NOT OBSERVED expect_output: remote embedding provider request grouping — command exited successfully; expected output was not observed in the captured pane

How this fits together

Provider plugins turn query or document inputs into vectors used by Memory Core indexing and search, plus Gateway and CLI embedding requests. The change consolidates the private contract that carries input type, batching, and provider lifecycle across those callers.

flowchart LR
  A[Memory indexing and search] --> C[Shared embedding contract]
  B[Gateway and CLI requests] --> C
  D[Provider plugins] --> C
  C --> E[Query or document handling]
  E --> F[Local or remote provider]
  F --> G[Embedding vectors]
Loading

Before merge

  • Resolve merge risk (P1) - This changes private provider creation and query/document dispatch across several bundled plugins; exact-head CI should complete before merge.
  • Resolve merge risk (P1) - The unavailable local base/parent objects prevent an independent full diff and history pass in this checkout.
  • Complete next step (P2) - This maintainer-authored, protected-label PR needs normal exact-head validation; no discrete automated repair is identified.
Agent review details

Security

None.

PR surface

Source -304, Tests +39, Docs 0, Other -2. Total -267 across 73 files.

View PR surface stats
Area Files Added Removed Net
Source 33 259 563 -304
Tests 38 421 382 +39
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 2 -2
Total 73 681 948 -267

Review metrics

Metric Value Why it matters
Production versus test delta production net -305; tests net +40 The PR body reports a substantial net reduction in production adapter code while adding focused contract and lifecycle coverage; local base objects were unavailable to independently recalculate it.

Stored data model

Persistent data-model change detected: unknown-data-model-change: extensions/amazon-bedrock/embedding-provider.ts, unknown-data-model-change: extensions/deepinfra/embedding-adapter.test.ts, unknown-data-model-change: extensions/deepinfra/embedding-adapter.ts, unknown-data-model-change: extensions/google/embedding-provider.test.ts, unknown-data-model-change: extensions/google/embedding-provider.ts, unknown-data-model-change: extensions/lmstudio/src/embedding-provider.test.ts, and 73 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete exact-head contract validation (recommended)
    Wait for the provider, memory, Gateway, CLI, package-boundary, and build checks on the current head before merging this compatibility-sensitive refactor.

Technical review

Best possible solution:

Land one canonical generic embedding contract only after exact-head provider, memory, Gateway, CLI, package-boundary, and build validation confirms existing query/document and lifecycle behavior remains intact.

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

Not applicable: this is a behavior-preserving refactor rather than a reported defect. The relevant preservation paths are source-visible, but this read-only review did not execute them.

Is this the best way to solve the issue?

Yes, subject to exact-head validation: current main has two adapter translations, while the PR uses the already-established generic contract directly and preserves provider-specific query/document handling at each provider owner.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: The PR changes a broad internal embedding integration surface, but no current user-facing failure is established.
  • merge-risk: 🚨 compatibility: Memory, Gateway, CLI, and bundled provider plugins now share one runtime contract, so an omitted provider semantic could affect existing embedding setups.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable: this maintainer-authored refactor is supported by focused runtime and transport test claims rather than an external-contributor proof gate.

Evidence

What I checked:

  • Current main still has the adapter layer: Current main wraps generic providers with memory-specific embedQuery, embedBatch, and embedBatchInputs operations, so the requested consolidation is not present there. (src/plugins/memory-embedding-provider-runtime.ts:32, 42112dd86ec3)
  • PR head removes the runtime projection: The proposed runtime now returns registered generic adapters directly to memory callers. (src/plugins/memory-embedding-provider-runtime.ts:6, da49ca90d13f)
  • Canonical contract and provider semantics: The shared contract carries structured inputs and explicit query/document intent; inspected OpenAI, Gemini, Bedrock, Ollama, Voyage, Copilot, DeepInfra, LM Studio, and Mistral paths preserve provider-owned request behavior. (src/plugins/embedding-provider-types.ts:44, da49ca90d13f)
  • Focused regression coverage: The new remote-provider tests cover default per-query request grouping, document calls, and explicitly batchable query providers; LM Studio coverage retains each local-service lease until concurrent query work settles. (packages/memory-host-sdk/src/host/embeddings-remote-provider.test.ts:34, da49ca90d13f)
  • Current-main and release provenance: The available current-main commit is later than the PR base and still contains the old adapter; no local release tag contains that current-main commit, while the PR head is unmerged. (42112dd86ec3)
  • Review infrastructure limitation: The local promisor checkout could read the PR head and selected current-main blobs, but could not retrieve the PR base or parent objects because github.com DNS resolution failed; a full local merge-base/history comparison was unavailable. (da49ca90d13f)

Likely related people:

  • steipete: Available blame attributes the proposed canonical provider type and memory create-option normalization to Peter Steinberger; the shallow promisor checkout could not trace earlier ownership further. (role: current contract contributor; confidence: low; commits: da49ca90d13f; files: src/plugins/embedding-provider-types.ts, extensions/memory-core/src/memory/embeddings.ts)

Rank-up moves

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

  • Let the current-head validation matrix complete.
  • Refresh the full base-to-head comparison once the promisor remote is reachable, then confirm no provider-specific behavior was omitted.

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-08-27T00:15:22.726Z sha 8cb3a14 :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Resolved the remaining attributable changed-extension failure on child commit da49ca90d13.

The broad memory shard correctly found five test fixtures that still modeled the deleted private embedQuery adapter shape. Production now consumes the canonical EmbeddingProvider.embed/embedBatch contract, so those stale fixtures failed with provider.embed is not a function; two explicitly narrowed string[] mock annotations also failed the owning extension type graph.

The repair migrates only those test fixtures to the canonical methods and lets the shared provider type infer the input shape. It preserves counters, thrown errors, return vectors, and assertions. No production fallback, compatibility shim, public API change, or runtime behavior was added.

Proof: genuine FTS, search, and LanceDB failures before the repair; changed suites 220/220 green; wider retry/lifecycle coverage 237/237 green; extension test types, format, lint, and diff checks green; fresh autoreview clean at 0.98 confidence.

Updated full PR metrics: 73 paths; production +225/-530 (net -305), tests +455/-415 (net +40), docs +1/-1, tooling +0/-2; total +681/-948 (net -267).

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 27, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Final exact-head merge gates are satisfied on da49ca90d13ffdee8a5e143691760678ab70e8ad.

  • Required ordinary pull-request CI run 33027595955 completed successfully on attempt 2. Attempt 1 had one unrelated OC Path wall-clock outlier; its failed-only retry passed without source changes.
  • The latest exact-head ClawSweeper review reports Findings None and Security None.
  • The review checkout's promisor/DNS limitation is not an unresolved code gap: the full base 99a2434f7b89c682f934326be9f7cc786f7ddeca through head comparison was completed locally with all objects present, and both root and independent reviews covered the complete 73-path result.
  • The five public generic embedding API files remain unchanged. Provider-specific query/document request behavior, LM Studio lease retention, lifecycle retry behavior, and current-main memory generation/lock/cache ownership were compared and preserved.
  • Full build, runtime postbuild, 147 SDK export checks, focused provider/memory suites, test type graphs, and changed-path gates are green. The PR body records the exact production/test/tooling deltas and the two attributable CI fixture/contract repairs.

Native preparation will refresh the current-main merge snapshot and fail closed on drift. No rebase, compatibility shim, or CI bypass is being used.

@steipete
steipete merged commit 67d22a5 into main Aug 27, 2026
352 of 354 checks passed
@steipete
steipete deleted the codex/refactor-canonical-embedding-contract-20260826 branch August 27, 2026 01:20
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
* refactor(embeddings): unify provider contract

* test(plugins): declare embedding type bridge

* test(memory): migrate embedding fixtures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes docs Improvements or additions to documentation extensions: amazon-bedrock extensions: deepinfra extensions: github-copilot extensions: google extensions: lmstudio extensions: memory-core Extension: memory-core extensions: memory-lancedb Extension: memory-lancedb extensions: mistral extensions: ollama extensions: openai extensions: voyage gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant