Skip to content

fix(memory): explain rejected embedding responses - #168035

Merged
steipete merged 2 commits into
mainfrom
fix/memory-embedding-diagnostics
Oct 10, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/memory-embedding-diagnostics

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Related: #146985 (diagnostics only).

What Problem This Solves

Fixes: memory indexing reports the same malformed-JSON error for several distinct invalid embedding responses, without enough request context to diagnose the provider.

User Impact

Errors identify the provider, model, batch size, and rejected condition. OPENCLAW_DEBUG_MEMORY_EMBEDDINGS=1 now shows request/response shape for OpenAI and generic OpenAI-compatible embeddings without logging headers, URLs, input text, or vector contents.

A bad batch still aborts indexing. Successful-work retention and atomic publication of complete indexes remain unchanged; this PR does not implement partial searchable indexes.

Why This Change Was Made

The shared vector validator owns count, coordinate, and index errors; memory-core retains ownership of dimension validation and cache recovery. Both remote HTTP paths reuse the existing diagnostic owner while keeping their different response limits and redacted provider-error formats. Retry classification retains the original response error text, so model names and batch counts resembling HTTP status codes cannot create new retries or batch splits.

Thanks @jzmudzinski for the report.

Evidence

Real CLI proof used pnpm openclaw --profile embed-diagnostics memory index --force --verbose, isolated state/config/workspace, and a loopback proxy forwarding to Ollama /v1/embeddings. OPENCLAW_DEBUG_MEMORY_EMBEDDINGS=1 enabled the existing diagnostic switch. The proxy mutated genuine bge-m3 output after Ollama computed it.

Proxy condition Before After (provider/model/batch size also included)
Drop one vector malformed JSON response expected 40 vectors, got 39
Shorten one vector combined count/dimensions/coordinates error expected 1024 dimensions, got 1023 at position 39
Non-finite coordinate malformed JSON response non-finite coordinate at position 0, coordinate 0
Duplicate index malformed JSON response duplicate index 0 at position 1
Missing index in indexed response malformed JSON response missing index at position 1 (mixed indexed and positional entries)
Empty data malformed JSON response empty data array; expected 40 vectors
Provider HTTP 400 body body without model/batch context same provider body with model/batch context

Healthy indexing and the final healthy reindex both succeeded with 40 chunks and 1024-dimensional vectors. All seven failures preserved the exact published-row hash and 40-chunk count. The non-finite wire case used valid JSON 1e999 (parsed as infinity); a direct-provider regression also covers NaN, which JSON cannot encode as a numeric literal.

The full live matrix ran at 535d8531bc96871c226e4fbe7cfbcbc4443a6979; the remaining commit only replaces global NaN with Number.NaN to satisfy lint. Final-head nomic-embed-text healthy indexing and reindexing passed with 40 chunks and 768 dimensions; the duplicate-index failure preserved the published-row hash and reported its exact index/position. The bge-m3 and nomic-embed-text baselines both reproduced the generic duplicate-index message on unchanged main code.

Nine focused files passed: 148 tests, using node scripts/run-vitest.mjs <files> --maxWorkers=1, 1560.56 s total wall time on the loaded shared host. The final-head fetch suite separately passed 24 tests in 10.62 s wall (4.75 s Vitest). Reported test time for the changed fetch/policy suites was 0.071/0.228 s. Existing HTTP/auth and SQLite recovery files took 1.15–389.88 s of test time; their existing lifecycle fixtures were retained and no process boots, timers, or sleeps were added. Regression controls failed on pre-fix code: 19 fetch cases, two recovery assertions, and four retry/split cases.

Core production and core-test typechecks pass. The required fast ratchets, config docs, plugin inventory, import/dead-export checks, docs links, and core lint pass. The mock-export baseline shrinks by exactly one retired mock. Broad extension typechecking is limited by the missing QA Lab workspace dependency @openclaw/crabbox-provider/cli-runtime-api.js; those files and dependency declaration are unchanged. The deprecation guard also reports an unchanged direct-config import in src/gateway/server-methods/agents.ts, already present at the base commit. Extension lint passes after SDK declaration preparation with its documented build timeout set to 900000 ms; the default 300000 ms preparation budget had expired before lint could run. The declaration-enabled full build spent over 20 minutes in workspace declarations; the supported runtime-only OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm build passed on the final head in 570.7 s.

Independent Codex autoreview of the final head is scoped-clean at P0–P2, with no actionable findings. ClawSweeper reviewed 2a607eebcb10a813a7c0304053171027a8df531c: no findings, no Before merge items, ready for maintainer review; live proof rated sufficient. CI run 38010006201 passed on the same head (41 successful jobs, 23 skipped, zero failures), and openclaw/ci-gate is successful. All nine selected Node test jobs passed in 62–214 s each (1152 aggregate job-seconds including setup); the fast baseline-ratchet job passed in 94 s. CI production types, test types, and extension lint passed, despite the noted broader local QA dependency limitation.

Production: +176/-52 lines (net +124). Tests: +291/-197 (net +94). Docs: +7; baseline: -1. Production could not remain neutral without collapsing intentionally different HTTP-reader contracts or removing existing validation/recovery checks; the added branches distinguish failures, share safe metadata, and preserve retry classification.

@clawsweeper

clawsweeper Bot commented Oct 10, 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 docs Improvements or additions to documentation extensions: memory-core Extension: memory-core extensions: openai size: L labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds specific embedding-response errors and safe remote request and response diagnostics.

Example: A 40-input bge-m3 indexing request returns duplicate index 0 at position 1.

  • Before: Indexing fails with “malformed JSON response.”
  • After: The error includes provider, model, batch size, and “duplicate index 0 at position 1.”

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong shipped-entry-point proof and a correct diagnostic patch; the overall tier reflects its deliberately partial coverage of the linked umbrella report.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied CLI before/after matrix exercises isolated memory indexing against genuine Ollama output with injected response faults, records condition-specific errors and unchanged published rows, and includes final-head healthy indexing and duplicate-index rejection; the prior-head matrix remains applicable because the intervening change only uses Number.NaN.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Users cannot distinguish several provider-response failures and get no OpenAI remote shape diagnostics from the existing debug switch.
Reason: The diagnostic scope has clear user value and preserves existing behavior; it intentionally repairs only part of the linked umbrella report.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current diagnostic gap with a useful, focused change; no actionable introduced defects or unresolved merge concerns were found.

Priority: P2
Reviewed head: 2a607eebcb10a813a7c0304053171027a8df531c

Before merge

None.

Findings

None.

Agent review details

How this fits together

Memory indexing sends document batches through embedding providers, validates returned vectors, and retains successful embeddings before publishing a complete searchable index.

flowchart TD
A[Memory document batches] --> B[Embedding provider HTTP request]
B --> C[Shared vector validator]
C --> D[Memory cache and dimension validation]
D --> E[Complete index publication]
B --> F[Safe diagnostics]
C --> F
Loading

Technical review

Best possible solution:

Land the diagnostic repair while preserving successful-work retention and complete-index publication.

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

Current-main source deterministically reports duplicate indexes and other invalid vectors through the same generic error; the supplied CLI baseline independently records that behavior, but this review executed no target code.

Is this the best way to solve the issue?

The change fits the existing validator, HTTP diagnostic, and memory-cache owners, preserves validation and retry contracts, and avoids expanding into incomplete-index publication.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0d3cfe67d3a3.

Provenance checked

  • Shared vector validation changes intended behavior with a stated reason (bcd3834: Restore request order, enforce complete index associations, and preserve compatible indexless responses.)
  • Embedding cooldown and retry classification keeps the original intent (b4ef26c: Honor bounded provider cooldowns while preserving short transient and interactive retry budgets.)
  • Successful embedding retention and provider error metadata keeps the original intent (cd9be2b: Reuse completed embedding work after failed rebuilds and retain structured HTTP errors without replacing atomic publication.)
  • Cache dimension recovery and worker writes keeps the original intent (1ec7b42: Move cache mutations to the existing SQLite worker while preserving generation invalidation, recovery, and stored formats.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit bcd3834 adds packages/memory-host-sdk/src/host/embedding-vectors.ts:36 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: bcd383496cf2; files: packages/memory-host-sdk/src/host/embedding-vectors.ts)
  • Sho Jikumaru: Raw commit b4ef26c adds extensions/memory-core/src/memory/manager-embedding-policy.ts:108 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b4ef26c40094; files: extensions/memory-core/src/memory/manager-embedding-policy.ts)
  • Josh Lehman: Raw commit cd9be2b adds src/plugins/openai-compatible-embedding-provider.ts:317 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cd9be2bbe7d8; files: src/plugins/openai-compatible-embedding-provider.ts)

PR surface

Source +124, Tests +94, Docs +7, Other -1. Total +224 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 176 52 +124
Tests 7 291 197 +94
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 16 474 250 +224

Review metrics

Metric Value Why it matters
Production versus test changes Production +176/-52; tests +291/-197. Production growth distinguishes rejected conditions and shares safe context while retaining different HTTP-reader contracts; test changes consolidate validator cases and protect retry and redaction behavior.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Specific errors and safe debug output reduce the diagnosis burden for bounded embedding-provider failures.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-10T00:24:18.338Z sha 2a607ee :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T00:45:30.358Z sha 2a607ee :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 9:10 PM ET / October 10, 2026, 01:10 UTC (Revision 3).

@steipete
steipete marked this pull request as ready for review October 10, 2026 00:39
@steipete steipete self-assigned this Oct 10, 2026
@steipete
steipete merged commit 08e9c14 into main Oct 10, 2026
214 of 217 checks passed
@steipete
steipete deleted the fix/memory-embedding-diagnostics branch October 10, 2026 01:16
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core extensions: openai P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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