Skip to content

fix(memory): embeddings fail when providers reject oversized batches - #138992

Closed
saladinyao-cyber wants to merge 1 commit into
openclaw:mainfrom
saladinyao-cyber:fix/memory-embedding-provider-item-limit
Closed

saladinyao-cyber wants to merge 1 commit into
openclaw:mainfrom
saladinyao-cyber:fix/memory-embedding-provider-item-limit

Conversation

@saladinyao-cyber

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users of OpenAI-compatible embedding providers could not index memory when a provider rejected an oversized item batch with an explicit numeric maximum. The request failed permanently instead of being split into smaller batches.

Why This Change Was Made

Recognize the provider-neutral error form batch size is invalid, it should not be larger than <N> and route it through the existing recursive batch splitter. The classifier requires an explicit numeric maximum and does not depend on a provider name.

User Impact

Memory indexing now automatically recovers from this explicit provider batch-size limit instead of failing with HTTP 400. Other input-validation errors remain permanent and are not retried or split.

Evidence

  • Focused extension-memory Vitest: 24/24 passed.
  • Verified recursive splitting of 33 inputs until every request is at or below the provider limit.
  • Negative cases remain unsplittable: unknown maximum, minimum-size wording, input-size wording, and generic input validation.
  • Oxlint: 0 warnings, 0 errors.
  • Oxfmt and git diff --check passed.

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

@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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 7:00 AM ET / 11:00 UTC.

ClawSweeper review

What this changes

Memory Core recognizes another explicit embedding batch-size rejection and uses its existing splitter to recover, with classifier, ordering, and HTTP coverage.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary on current main, with no blocking findings. The contributor’s added HTTP recovery evidence addresses the previous proof concern.

Priority: P2
Reviewed head: eb610016289238812b996b9764845760a6c0b725

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-neutral production repair with relevant HTTP recovery evidence and no blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The contributor-reported local HTTP run exercises MemoryManagerEmbeddingOps through the real generic embedding client: injected numeric-limit HTTP 400 responses produce smaller requests and 33 returned vectors. The inspected head covers this scenario, satisfying the internal-reliability proof requirement without requiring a full indexing run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The contributor-reported local HTTP run exercises MemoryManagerEmbeddingOps through the real generic embedding client: injected numeric-limit HTTP 400 responses produce smaller requests and 33 returned vectors. The inspected head covers this scenario, satisfying the internal-reliability proof requirement without requiring a full indexing run.
Evidence reviewed 10 items Verified introduced change: The pinned base-to-head delta changes one production classifier and three test files. Raw commit inspection confirms the original head's recorded parent and the test merge's base/head parents.
Current main still misses the rejection: Current main recognizes other numeric item-limit errors, but not the added wording. Its splitter rethrows this HTTP 400 instead of splitting.
Latest release comparison: The supplied latest release also lacks this error wording; its existing recursive splitter does not address the reported rejection.
Findings None None.
Security None None.

How this fits together

Memory Core turns memory chunks into vectors for semantic search. Its embedding manager sends batches to the configured provider, handles failures, and returns ordered vectors to the indexer.

flowchart TD
  A[Memory chunks] --> B[Embedding manager]
  B --> C[Provider HTTP request]
  C --> D{Explicit batch limit?}
  D -->|Yes| E[Split into smaller batches]
  E --> C
  D -->|Success| F[Ordered vectors]
  D -->|Other permanent error| G[Report failure]
  F --> H[Memory index]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +49. Total +49 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 3 51 2 +49
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 52 3 +49

Review metrics

Metric Value Why it matters
Production versus test LOC Production net 0 (+1/-1); tests and test support net +49 (+51/-2) The repair extends the existing classifier without growing production control flow; added lines cover rejection and recovery.

Technical review

Best possible solution:

Keep batch-limit recovery in the shared classifier and existing bounded splitter, preserving input order and permanent-error handling.

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

Yes, from source: send 33 inputs to an endpoint that rejects batches above ten with the reported HTTP 400 wording; current main propagates the error because neither classifier accepts it. The reviewer did not execute this scenario.

Is this the best way to solve the issue?

Yes. Extending the existing classifier repairs the owning boundary without duplicating batching logic or introducing a provider-specific cap; the HTTP scenario covers error propagation through the real client.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The contributor-reported local HTTP run exercises MemoryManagerEmbeddingOps through the real generic embedding client: injected numeric-limit HTTP 400 responses produce smaller requests and 33 returned vectors. The inspected head covers this scenario, satisfying the internal-reliability proof requirement without requiring a full indexing run.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The contributor-reported local HTTP run exercises MemoryManagerEmbeddingOps through the real generic embedding client: injected numeric-limit HTTP 400 responses produce smaller requests and 33 returned vectors. The inspected head covers this scenario, satisfying the internal-reliability proof requirement without requiring a full indexing run.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Repairs memory embedding failures for providers emitting this specific batch-limit response, with limited blast radius.
  • 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 (live_output): The contributor-reported local HTTP run exercises MemoryManagerEmbeddingOps through the real generic embedding client: injected numeric-limit HTTP 400 responses produce smaller requests and 33 returned vectors. The inspected head covers this scenario, satisfying the internal-reliability proof requirement without requiring a full indexing run.
  • proof: sufficient: Contributor real behavior proof is sufficient. The contributor-reported local HTTP run exercises MemoryManagerEmbeddingOps through the real generic embedding client: injected numeric-limit HTTP 400 responses produce smaller requests and 33 returned vectors. The inspected head covers this scenario, satisfying the internal-reliability proof requirement without requiring a full indexing run.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • shin4141: 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-05T09:59:08.040Z sha 1b734c9 :: needs real behavior proof before merge. :: none

@saladinyao-cyber
saladinyao-cyber force-pushed the fix/memory-embedding-provider-item-limit branch from 1b734c9 to 0253155 Compare September 5, 2026 10:11
@saladinyao-cyber

Copy link
Copy Markdown
Contributor Author

Added real behavior proof in 025315585f: a local HTTP server now returns the provider's actual JSON HTTP 400 (batch size is invalid, it should not be larger than 10) to the real OpenAI-compatible embedding client. The integration test verifies the observed request sequence 33, 17, 9, 8, 16, 8, 8 and successful completion of all 33 embeddings. Focused result: 27/27 tests passed; Oxlint 0/0; Oxfmt and git diff --check passed.

@clawsweeper re-review

@clawsweeper

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

Re-review progress:

@saladinyao-cyber
saladinyao-cyber force-pushed the fix/memory-embedding-provider-item-limit branch from 0253155 to eb61001 Compare September 5, 2026 10:28
@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 5, 2026

@Yigtwxx Yigtwxx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head eb610016289. The classifier change is correct and the HTTP test proves the recovery path end to end; I re-ran the same scenario through the real splitter on both arms and the control matches the description (on main the first request rethrows as a permanent failure, on this head it recovers). One non-blocking observation that the review bot did not cover, plus one nit.

The classifier now requires the numeric limit, but the splitter discards it.

The new alternative in SPLITTABLE_MEMORY_EMBEDDING_BATCH_ERROR_RE (manager-embedding-policy.ts:58) only accepts the message when it carries larger than\s+\d+, and the PR body makes that a deliberate part of the contract ("requires an explicit numeric maximum"). Every numeric form in that regex, including the two pre-existing OpenAI-style ones, therefore tells us the exact limit N. runMemoryEmbeddingBatchRetryWithSplit never reads it: manager-embedding-policy.ts:124 always halves (splitAt = Math.ceil(items.length / 2)), and onSplit receives message but not N.

Halving is correct, but every non-leaf node of the recursion is a request the provider is guaranteed to reject, and each of those re-sends the full payload of its subtree. I measured this with the real runMemoryEmbeddingBatchRetryWithSplit and a run that rejects any batch above N = 10 with the exact wording this PR recognizes (10 is also the real cap for the provider that emits this message, so it is not a synthetic worst case):

batch requests (rejected + ok) item payloads sent direct ceil(B/N) chunking overhead
33 7 (3 + 4) 99 4 requests, 33 payloads 3.0x payload, 1.8x requests
64 15 (7 + 8) 256 7, 64 4.0x, 2.1x
160 31 (15 + 16) 800 16, 160 5.0x, 1.9x
1000 255 (127 + 128) 8000 100, 1000 8.0x, 2.5x

The 33-row is exactly the [33, 17, 9, 8, 16, 8, 8] sequence the new test asserts, so the test is already encoding the cost. Batch sizes in this path are byte-bounded, not count-bounded (EMBEDDING_BATCH_MAX_TOKENS = 8000, manager-embedding-ops.ts:75), so the item count per batch is inversely proportional to chunk size; short entries under perEntry chunking reach the upper rows easily, and each rejected request also counts against the provider's rate limit.

This is pre-existing behavior for the two OpenAI-style forms and is not a reason to hold this PR. I am raising it here because this change is the one that turns "the message carries a number" into a requirement, which makes it the natural place to start using that number. A follow-up could parse N from the match and, when present, chunk items into ceil(len / N) groups in one step (each group still going through the retry loop, and still falling back to halving if the provider rejects it again, so a wrong or stale N cannot break correctness). Note that only changing splitAt to N would not be enough: that peels one accepted group off per level and still sends one rejected request per group.

Nit (tests). The retry.test.ts fixture and the policy test both cover the accept/reject wording well. One shape that is not covered and that the regex does accept: the same message with a trailing period (larger than 10.), which is how at least one OpenAI-compatible endpoint formats it. \d+\b matches it, so nothing is wrong, but pinning it would make the classifier's contract explicit if the regex is ever tightened.

obviyus added a commit that referenced this pull request Sep 6, 2026
Recover explicit numeric embedding row caps through the existing ordered splitter so full memory rebuilds finish and semantic search can use the complete index. Preserve terminal ambiguous and singleton errors and the shared text/structured recovery policy.

Verified with a full 33-chunk rebuild and semantic search, native-batch fallback, service and connection-reset controls, independent behavior validation, and the memory-plugin test suite.

Additional negative-case coverage: @saladinyao-cyber (#138992).

Closes #137864.

Co-authored-by: Ayaan Zaidi <[email protected]>
@saladinyao-cyber

Copy link
Copy Markdown
Contributor Author

Superseded by #138391, which has now been merged into main and covers the same explicit numeric embedding row-cap recovery. Closing this duplicate. The separate direct-limit batching optimization is tracked in #140508.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
…w#138391)

Recover explicit numeric embedding row caps through the existing ordered splitter so full memory rebuilds finish and semantic search can use the complete index. Preserve terminal ambiguous and singleton errors and the shared text/structured recovery policy.

Verified with a full 33-chunk rebuild and semantic search, native-batch fallback, service and connection-reset controls, independent behavior validation, and the memory-plugin test suite.

Additional negative-case coverage: @saladinyao-cyber (openclaw#138992).

Closes openclaw#137864.

Co-authored-by: Ayaan Zaidi <[email protected]>
necromman pushed a commit to necromman/openclaw that referenced this pull request Sep 20, 2026
…w#138391)

Recover explicit numeric embedding row caps through the existing ordered splitter so full memory rebuilds finish and semantic search can use the complete index. Preserve terminal ambiguous and singleton errors and the shared text/structured recovery policy.

Verified with a full 33-chunk rebuild and semantic search, native-batch fallback, service and connection-reset controls, independent behavior validation, and the memory-plugin test suite.

Additional negative-case coverage: @saladinyao-cyber (openclaw#138992).

Closes openclaw#137864.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 36d4827)
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 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.

2 participants