Skip to content

fix(google): cap Gemini embedding request batches - #134173

Open
linhongyu510 wants to merge 1 commit into
openclaw:mainfrom
linhongyu510:fix/gemini-embedding-batch-limit
Open

linhongyu510 wants to merge 1 commit into
openclaw:mainfrom
linhongyu510:fix/gemini-embedding-batch-limit

Conversation

@linhongyu510

@linhongyu510 linhongyu510 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Closes #134015

What Problem This Solves

Fixes an issue where Gemini-backed memory indexing aborted when a token-bounded group contained more than 100 short chunks. The provider sent the full group to batchEmbedContents, exceeding Gemini's per-request limit instead of completing the sync.

Why This Change Was Made

The Gemini provider now owns its API-specific limit and sends document embeddings in sequential batches of at most 100 requests. It preserves input/output order and reuses the existing authentication, SSRF, abort, response-validation, and vector-sanitization path for every sub-batch. Generic memory batching and other providers are unchanged.

User Impact

Memory sync and openclaw memory index can process large sets of short chunks with the default inline Gemini embedding path instead of failing at 101 requests. If a later sub-batch fails, the original provider error is still surfaced and no further batches are sent.

Evidence

  • TDD regression proof before the fix: the new 101-input test failed with expected [101] to deeply equal [100, 1] while the other 40 provider tests passed.
  • Focused Google provider suite after the fix: 44/44 passed.
  • Boundary coverage verifies 100, 101, and 201 inputs split as [100], [100, 1], and [100, 100, 1], with exact output ordering.
  • Failure coverage verifies a rejected second sub-batch prevents a third request.
  • Full pnpm build: passed on the rebased head.
  • oxfmt --check: passed.
  • oxlint: 0 warnings / 0 errors.
  • git diff --check: passed.

Review Follow-up

  • The P3 finding is addressed on the current head by documenting that the 100-item value is the external Gemini batchEmbedContents API contract and linking the Google API documentation.
  • The focused provider suite remained green after that documentation change: 44/44 passed; oxfmt --check also passed.
  • No simulated run is presented as real Gemini API evidence. A redacted post-fix run against Google's actual endpoint is still pending, so this PR intentionally remains in Draft.

Risk

Low and provider-scoped. Calls with at most 100 inputs retain the existing single-request behavior. Larger calls become sequential requests, avoiding extra concurrency and preserving rate-limit and cancellation semantics.

AI Assistance Disclosure

TRAE assisted with issue and source inspection, implementation planning, test drafting, the provider-scoped code change, and local verification. The contributor selected and approved the provider-boundary design, reviewed the resulting scope, and retains responsibility for the contribution. No credentials or private production data were provided to the assistant.

@clawsweeper

clawsweeper Bot commented Aug 31, 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 Aug 31, 2026
@clawsweeper

clawsweeper Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The PR splits Gemini document embeddings into sequential requests containing at most 100 inputs.

Example: Memory indexing submits 250 short document chunks to Gemini.

  • Before: One 250-input request is rejected by Gemini’s 100-request limit.
  • After: Requests contain 100, 100, and 50 inputs, with results concatenated in order.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The repair has clear user value, but duplicates an existing owner and lacks qualifying production-path proof.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Gemini memory indexing aborts when byte-bounded groups contain more than 100 short chunks.
Reason: Multiple affected-release reports establish a real indexing failure, and the existing provider-cap contract permits a focused repair without new settings.

Merge readiness

⛔ Blocked before merge - 3 items remain

This PR addresses a confirmed Gemini indexing failure that remains on current main, but should use Memory Core’s existing request-cap contract instead of adding another batching owner.

Priority: P2
Reviewed head: 8f724458c95d7f3ba3dbe7911cc9b4ba118fd2fc

Before merge

  • Add real behavior proof - The contributor records ordered 250-input recovery over a local HTTP server, but the suite mocks withRemoteHttpResponse and the body acknowledges that post-fix Gemini verification remains pending; provide the requested production-path run with IPs, API keys, phone numbers, and non-public endpoints redacted. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Use the existing provider cap instead of a second splitting loop (P1) - For the reported 250-chunk indexing group, Memory Core already performs ordered proactive splitting when the provider declares maxInputsPerRequest. This loop leaves that field absent and hides all three requests inside one host operation, so the host cannot apply its per-slice timeout and successful-slice persistence lifecycle. The documented contract added by fix(memory): split embedding requests at provider input-array limits #141686 is present in this PR’s merge base. Declare maxInputsPerRequest: 100 on the Gemini provider, remove this duplicate splitter, and exercise the existing Memory Core path with the Google adapter.
  • Complete next step - The contributor should resolve GitHub’s reported merge conflicts while preserving current-main Google request formatting.

Findings

  • [P1] Use the existing provider cap instead of a second splitting loop — extensions/google/embedding-provider.ts:368-370

Tests

  • Low-value test extensions/google/embedding-provider.test.ts: Remove the mocked 201-input case when consolidating coverage: it repeats the multi-slice ordering scenario already exercised by the 250-input HTTP case; retain distinct exact-limit, overflow, and failure coverage at the owning boundary.
  • Missing end-to-end proof: Provide a redacted post-fix memory-index run with more than 100 short Gemini document inputs through the unmocked production transport, showing capped requests and successful indexing.
Agent review details

How this fits together

Memory Core groups uncached chunks and invokes the Google embedding provider, which sends authenticated HTTP requests and returns validated vectors for indexing.

flowchart LR
  A[Memory chunks] --> B[Memory Core request splitter]
  B --> C[Google embedding provider]
  C --> D[Shared HTTP transport]
  D --> E[Gemini API]
  E --> F[Validated vectors]
  F --> G[Memory index]
Loading

Technical review

Best possible solution:

Declare Gemini’s 100-input cap on the existing provider contract and let Memory Core own splitting, retries, timeouts, and successful-slice persistence.

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

Affected-release reports and current source establish oversized requests and terminal handling of Google’s rejection; this read-only review executed no target code.

Is this the best way to solve the issue?

The API limit belongs in Google’s provider metadata, while the already approved shared splitter supplies the requested behavior with less production code and consistent slice lifecycle handling.

Full review comments:

  • [P1] Use the existing provider cap instead of a second splitting loop — extensions/google/embedding-provider.ts:368-370
    For the reported 250-chunk indexing group, Memory Core already performs ordered proactive splitting when the provider declares maxInputsPerRequest. This loop leaves that field absent and hides all three requests inside one host operation, so the host cannot apply its per-slice timeout and successful-slice persistence lifecycle. The documented contract added by fix(memory): split embedding requests at provider input-array limits #141686 is present in this PR’s merge base. Declare maxInputsPerRequest: 100 on the Gemini provider, remove this duplicate splitter, and exercise the existing Memory Core path with the Google adapter.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 18892937f802.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test extensions/google/embedding-provider.test.ts extensions/google/embedding-provider.network.test.ts extensions/memory-core/src/memory/manager-embedding-policy.test.ts
  • pnpm check:changed
  • git diff --check
  • Review contributor-supplied redacted production-path memory-index output for more than 100 short Gemini inputs.

What I checked:

PR surface

Source +11, Tests +147. Total +158 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 29 18 +11
Tests 1 147 0 +147
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 176 18 +158

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #134015
Summary: This PR targets the canonical Gemini limit failure; merged generic improvements provide reusable machinery but leave Gemini undeclared and its rejection unrecognized.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The defect blocks Gemini indexing for groups of short chunks, with a provider-scoped repair and an existing asynchronous-batch workaround.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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 execution lanes are retired.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-31T16:09:41.206Z sha 84fd8790c333f2715bdd272fc4b972d29bf19fb7 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-31T22:20:33.358Z sha 0f03c3e919fc6cd7b94c839eeeac7e80e356f3fb :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-01T00:52:16.901Z sha 0f03c3e919fc6cd7b94c839eeeac7e80e356f3fb :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-02T03:27:40.708Z sha 0f03c3e919fc6cd7b94c839eeeac7e80e356f3fb :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-19T18:54:47.883Z sha efa22e3a9413c71954557e0d303538f69be73da6 :: needs real behavior proof before merge. :: none
  • reviewed September 25, 2026, 8:51 AM ET / 12:51 UTC (Revision 7) sha unknown :: needs real behavior proof before merge. :: none
  • reviewed September 25, 2026, 8:51 AM ET / 12:51 UTC (Revision 8) sha unknown :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-03T09:45:18.812Z sha d68d599752d7d6a73d87d56cf0e7633daf9c6521 :: needs real behavior proof before merge. :: none

Reviewed November 14, 2026, 6:57 AM ET / 11:57 UTC (Revision 10).

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. labels Aug 31, 2026
@linhongyu510
linhongyu510 force-pushed the fix/gemini-embedding-batch-limit branch from 84fd879 to 0f03c3e Compare August 31, 2026 22:13
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 31, 2026
@linhongyu510
linhongyu510 marked this pull request as ready for review September 2, 2026 03:22
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Sep 17, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 17, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Sep 18, 2026
@linhongyu510
linhongyu510 force-pushed the fix/gemini-embedding-batch-limit branch from 0f03c3e to efa22e3 Compare September 19, 2026 18:47
@linhongyu510

Copy link
Copy Markdown
Contributor Author

Not stale, and the status: 📣 needs proof blocker is addressed. Rebased onto current main (was 9828 behind); new head efa22e3a9, 0 commits behind.

@clawsweeper's objection was correct and worth taking literally: the existing cases stub fetch, and a stub accepts any body. They can show the provider slices its input; they cannot show the slicing is what stops the call from being rejected. That is a real gap, not a formality.

So the proof is now a node:http server that enforces the documented batchEmbedContents limit the way the API does — 400 INVALID_ARGUMENT for any request carrying more than 100 entries. The request has to survive a real socket, a real JSON body and a real rejection path. Nothing about the transport is faked.

With the cap removed, the server rejects exactly as Gemini would:

ProviderHttpError: gemini embeddings failed (400):
  Batch size 250 exceeds maximum allowed batch size 100. [code=INVALID_ARGUMENT]

With the cap in place, over the same server: batches observed [100, 100, 50], rejected === 0, and all 250 embeddings return in input order. The test asserts the rejection counter is zero rather than only asserting success — otherwise it would still pass if the server had never been reached.

extensions/google/embedding-provider.test.ts    60 passed

One thing I want to be straight about rather than overclaim: this is a faithful local reproduction of the documented API contract, not a capture against live Gemini — I do not have a key I can attach output from here. If the gate specifically requires a transcript from the real endpoint, that needs someone with credentials, and I am happy to hand over the exact script. But the failure mode this PR fixes is now demonstrated end to end over real HTTP instead of asserted against a mock.

Both commits cherry-picked onto current main with no conflicts — the provider's batching path has not drifted.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 19, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Sep 28, 2026
@linhongyu510
linhongyu510 requested a review from a team as a code owner October 3, 2026 17:52
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XL and removed extensions: google size: M stale Marked as stale due to inactivity labels Oct 3, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 4, 2026
@clawsweeper clawsweeper Bot removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 9, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Oct 10, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

Gemini batchEmbedContents accepts at most 100 requests per call
(https://ai.google.dev/api/embedding#method:-models.batchembedcontents).
Slice document inputs into <=100-request sub-batches, concatenate the
ordered embeddings, and stop on the first sub-batch failure.

Rebased onto current main.
@linhongyu510
linhongyu510 force-pushed the fix/gemini-embedding-batch-limit branch from 45ee899 to 8f72445 Compare October 25, 2026 18:29
@openclaw-barnacle openclaw-barnacle Bot added extensions: google size: S and removed docs Improvements or additions to documentation size: XL labels Oct 25, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 14, 2026

This branch has not been deployed

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

Labels

extensions: google P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S stale Marked as stale due to inactivity 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.

[Bug]: Memory sync with Gemini embeddings aborts — inline batchEmbedContents exceeds Google's 100-request limit and is not classified as splittable

2 participants