Skip to content

fix(google): bound embedding batch response reads - #98692

Closed
ly85206559 wants to merge 1 commit into
openclaw:mainfrom
ly85206559:codex/bound-google-embedding-batch-responses
Closed

ly85206559 wants to merge 1 commit into
openclaw:mainfrom
ly85206559:codex/bound-google-embedding-batch-responses

Conversation

@ly85206559

@ly85206559 ly85206559 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes a sibling OOM risk to #98554 in Gemini/Google embedding batch handling. The Gemini batch upload/create error paths and completed output download path still had raw response body reads. A faulty or hostile Google-compatible endpoint could stream oversized error bodies, an oversized JSONL record, or extra/blank output records after a batch completed.

Why This Change Was Made

The Google embedding batch code now uses the shared bounded provider HTTP readers for upload/create error bodies, and streams completed JSONL output one record at a time instead of buffering the whole file.

The output reader keeps valid large batch outputs working by allowing files larger than the provider text cap, while bounding the unsafe shapes:

  • error response bodies are read with readResponseTextLimited
  • each JSONL output record is capped at 4 MiB
  • the number of output records is capped to the submitted request group size
  • blank/whitespace JSONL records count against that record budget
  • unknown custom_id rows are ignored instead of being stored in the result map

This follows the same invariant as the recent OpenAI embedding batch hardening: large valid JSONL output should stream successfully, but malformed single-record or unbounded provider output must be cancelled early.

User Impact

Users running large Gemini embedding batches can still process valid large result files, and a bad provider response cannot grow gateway memory through unbounded response buffering or unlimited small output rows.

Evidence

Loopback transport proof: I ran the production runGeminiEmbeddingBatches path against a local HTTP server on 127.0.0.1. This uses the real withRemoteHttpResponse / fetchWithSsrFGuard path, real HTTP Response streams, and no mocked fetch.

$ node --import tsx .automation/openclaw-gemini-loopback-proof.mjs
{
  "proof": "gemini embedding batch loopback",
  "valid": {
    "mode": "valid-jsonl-output-over-loopback",
    "ok": true,
    "vectors": 8,
    "downloadWrites": 8,
    "cancelObserved": false,
    "ms": 56
  },
  "oversized": {
    "mode": "oversized-output-line-cancel-over-loopback",
    "ok": false,
    "error": "gemini.batch-file-content: JSONL line exceeds 4194304 bytes",
    "downloadWrites": 7,
    "cancelObserved": true,
    "ms": 253
  }
}

Targeted unit proof: the tests drive runGeminiEmbeddingBatches through upload, batch create, status polling, and output download using real Response streams passed through the production withRemoteHttpResponse callback shape. They cover the large-output and record-budget cases that are cheaper to validate deterministically in-process.

$ node scripts/run-vitest.mjs extensions/google/embedding-batch.test.ts -- --reporter=verbose
 ✓ |extension-providers| extensions/google/embedding-batch.test.ts > Google embedding-batch bounded JSON reads > bounds oversized file-upload error bodies and cancels the stream
 ✓ |extension-providers| extensions/google/embedding-batch.test.ts > Google embedding-batch bounded JSON reads > bounds oversized batch-create error bodies and cancels the stream
 ✓ |extension-providers| extensions/google/embedding-batch.test.ts > Google embedding-batch bounded JSON reads > bounds oversized file-upload JSON response and cancels the stream
 ✓ |extension-providers| extensions/google/embedding-batch.test.ts > Google embedding-batch bounded JSON reads > bounds oversized batch-create JSON response and cancels the stream
 ✓ |extension-providers| extensions/google/embedding-batch.test.ts > Google embedding-batch bounded JSON reads > bounds oversized batch-status poll JSON response and cancels the stream
 ✓ |extension-providers| extensions/google/embedding-batch.test.ts > Google embedding-batch bounded JSON reads > parses small responses on all three JSON paths correctly
 ✓ |extension-providers| extensions/google/embedding-batch.test.ts > Google embedding-batch bounded JSON reads > streams valid batch output files larger than the provider text cap
 ✓ |extension-providers| extensions/google/embedding-batch.test.ts > Google embedding-batch bounded JSON reads > bounds oversized batch output downloads and cancels the stream
 ✓ |extension-providers| extensions/google/embedding-batch.test.ts > Google embedding-batch bounded JSON reads > bounds batch output record count to the submitted request group
 ✓ |extension-providers| extensions/google/embedding-batch.test.ts > Google embedding-batch bounded JSON reads > counts blank batch output records against the submitted request group

 Test Files  1 passed (1)
      Tests  10 passed (10)
[test] passed 1 Vitest shard
$ node_modules\.bin\oxfmt --check extensions/google/embedding-batch.ts extensions/google/embedding-batch.test.ts
Checking formatting...

All matched files use the correct format.
$ node_modules\.bin\oxlint --tsconfig config/tsconfig/oxlint.core.json extensions/google/embedding-batch.ts extensions/google/embedding-batch.test.ts
# passed
$ git diff --check -- extensions/google/embedding-batch.ts extensions/google/embedding-batch.test.ts
# passed
$ F:\Program\Python\Python313\python.exe .agents\skills\autoreview\scripts\autoreview --mode local
autoreview clean: no accepted/actionable findings reported

Notes for reviewers:

  • The 4 MiB per-line cap and submitted-request-count record budget are intentional fail-closed bounds. They match the safety shape of the merged OpenAI sibling hardening in fix(openai): bound embedding batch file downloads #98554: valid multi-record output can stream, but one malformed record or unlimited extra provider rows cannot grow memory without bound.
  • This PR does not add or migrate persistent state. The ClawSweeper stored-data-model warning appears to be a keyword false positive from embedding metadata terminology in extensions/google/embedding-batch.ts and its tests.

AI-assisted: built with Codex. I understand the change: it replaces unbounded Gemini batch response reads with bounded error reads plus a streaming JSONL output reader capped by per-record byte size and submitted record count.

@openclaw-barnacle openclaw-barnacle Bot added extensions: google size: M triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 6, 2026, 12:15 PM ET / 16:15 UTC.

Summary
The PR replaces unbounded Google embedding batch error/output response reads with bounded error readers, streaming JSONL output parsing, and regression tests.

PR surface: Source +81, Tests +289. Total +370 across 2 files.

Reproducibility: yes. at source level: current main and v2026.6.11 still use unbounded Google batch upload/create error-body reads and completed-output response.text() downloads. I did not run a current-main OOM reproduction because this review was read-only.

Review metrics: 2 noteworthy metrics.

  • Output Download Bounds: 2 added: 4 MiB per-line cap and submitted-record-count budget. These limits define the new fail-closed contract for Google batch output compatibility.
  • Error Response Readers: 2 changed from response.text() to readResponseTextLimited. The upload/create error paths now use the shared bounded diagnostic reader instead of buffering untrusted provider bodies.

Stored data model
Persistent data-model change detected: unknown-data-model-change: extensions/google/embedding-batch.test.ts, unknown-data-model-change: extensions/google/embedding-batch.ts, vector/embedding metadata: extensions/google/embedding-batch.test.ts, vector/embedding metadata: extensions/google/embedding-batch.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #98692
Summary: This PR is the strongest open Google embedding-batch response-boundary candidate; related merged PRs cover sibling or partial surfaces, and the older open output-file-only PR is narrower.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Maintainers should accept or tune the 4 MiB per-line cap and submitted-record-count budget before merge.

Risk before merge

  • [P1] The parser can reject outputs that current main tolerated, including extra or blank rows and any single output record over the chosen 4 MiB cap.
  • [P1] The hardening prevents unbounded response growth but can also fail Google embedding batch jobs when a compatible endpoint exceeds the new output limits.

Maintainer options:

  1. Accept the Google output budgets (recommended)
    Maintain the PR's 4 MiB per-line and submitted-record-count caps as the intended malformed-output safety boundary.
  2. Tune the parser contract first
    Change the caps or blank/extra-row tolerance before merge while keeping bounded reads and early stream cancellation.
  3. Pause in favor of a narrower landing path
    Use this only if maintainers want to split output streaming from upload/create error-body hardening or prefer another canonical PR.

Next step before merge

  • [P1] The remaining action is maintainer acceptance or tuning of compatibility-sensitive fail-closed output budgets; no narrow automated repair is indicated.

Maintainer decision needed

  • Question: Should Google embedding batch output fail closed at 4 MiB per JSONL line and at the submitted request-group record count, including blank or extra rows?
  • Rationale: The code repair is narrow, but those budgets define new compatibility and availability behavior for existing Google-compatible batch endpoints.
  • Likely owner: steipete — The affected provider-plugin memory embedding path traces back to that feature area and the remaining choice is provider compatibility policy.
  • Options:
    • Accept strict output budgets (recommended): Keep the PR's 4 MiB per-line cap and submitted-record-count budget as the intended malformed-output safety boundary.
    • Tune tolerance before merge: Adjust the cap or blank/extra-row tolerance in code and tests before landing if existing compatible outputs must remain accepted.
    • Pause for narrower scope: Pause this broader PR only if maintainers want to split output streaming from upload/create error-body hardening.

Security
Cleared: The diff hardens untrusted provider response handling and does not change dependencies, workflows, secrets, permissions, packaging, or other supply-chain surfaces.

Review details

Best possible solution:

Land the bounded streaming parser once maintainers accept or adjust the 4 MiB per-line and submitted-record-count budgets while preserving bounded error reads and early stream cancellation.

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

Yes at source level: current main and v2026.6.11 still use unbounded Google batch upload/create error-body reads and completed-output response.text() downloads. I did not run a current-main OOM reproduction because this review was read-only.

Is this the best way to solve the issue?

Yes for the fix shape: bounded error reads plus streaming JSONL at the Google batch output-file boundary is the narrow provider-local repair. The exact fail-closed budgets are a maintainer compatibility choice, not an automated code defect.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a normal-priority Google provider hardening PR with limited bundled-plugin scope and no evidence of a current widespread outage.
  • merge-risk: 🚨 compatibility: The parser can reject outputs that current main tolerated, including extra or blank rows and any single output record over the chosen cap.
  • merge-risk: 🚨 availability: The fail-closed output bounds prevent memory growth but can also stop Google embedding batch jobs when an endpoint exceeds the new limits.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes loopback HTTP terminal proof through the production Gemini batch path for valid JSONL output and oversized-line cancellation, plus targeted regression output.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes loopback HTTP terminal proof through the production Gemini batch path for valid JSONL output and oversized-line cancellation, plus targeted regression output.
Evidence reviewed

PR surface:

Source +81, Tests +289. Total +370 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 121 40 +81
Tests 1 301 12 +289
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 422 52 +370

What I checked:

Likely related people:

  • steipete: The Google memory embedding batch path appears to come from the provider-plugin memory embedding refactor. (role: feature-history contributor; confidence: medium; commits: 77e6e4cf87f7; files: extensions/google/embedding-batch.ts, extensions/google/memory-embedding-adapter.ts)
  • hugenshen: Authored the merged same-file Google embedding-batch JSON response hardening that left this PR's error-body and output-file follow-up scope. (role: recent adjacent contributor; confidence: high; commits: 91297bf42082; files: extensions/google/embedding-batch.ts, extensions/google/embedding-batch.test.ts)
  • joshavant: Authored the shared provider bounded-response reader convention reused through the plugin SDK provider HTTP facade. (role: shared helper contributor; confidence: high; commits: 0a14444924e3; files: src/agents/provider-http-errors.ts, src/plugin-sdk/provider-http.ts)
  • sunlit-deng: Authored the merged OpenAI embedding batch output-file hardening that this Google change mirrors at the sibling provider surface. (role: sibling-surface contributor; confidence: medium; commits: ce4a259485f2; files: extensions/openai/embedding-batch.ts, extensions/openai/embedding-batch.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • 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.
Review history (4 earlier review cycles)
  • reviewed 2026-07-03T15:14:50.533Z sha 0ac23eb0ad5987889105b014094f5e5e5d23a2e2 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T07:26:29.733Z sha 0ac23eb0ad5987889105b014094f5e5e5d23a2e2 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T09:03:45.110Z sha 537104406301c9e359d3ba7601a91e35f18bcc39 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T09:13:50.436Z sha 537104406301c9e359d3ba7601a91e35f18bcc39 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 1, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 1, 2026
@ly85206559

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

I updated the PR body to remove the hidden BOM that made the Real behavior proof check miss the authored sections, and added loopback HTTP proof for the production Gemini embedding batch path.

@clawsweeper

clawsweeper Bot commented Jul 1, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 Jul 1, 2026
@ly85206559
ly85206559 force-pushed the codex/bound-google-embedding-batch-responses branch from 6ff4d1d to 0ac23eb Compare July 1, 2026 16:36
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 🔁 re-review loop A fresh ClawSweeper review was explicitly requested after the latest review. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 2, 2026
@ly85206559

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Current head is 0ac23eb0ad5987889105b014094f5e5e5d23a2e2. I updated the PR body with loopback HTTP proof, including the valid JSONL path and oversized-line cancellation path, and the Real behavior proof check is green. Please re-review the current head.

@clawsweeper

clawsweeper Bot commented Jul 3, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 🔁 re-review loop A fresh ClawSweeper review was explicitly requested after the latest review. labels Jul 3, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 3, 2026
@ly85206559

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 5, 2026
@ly85206559
ly85206559 force-pushed the codex/bound-google-embedding-batch-responses branch from 0ac23eb to 5371044 Compare July 5, 2026 08:49
@steipete

Copy link
Copy Markdown
Contributor

Superseded by #103472, now landed as fb702e5.

The landed rewrite preserves this PR's core safety goals—bounded Google response reads, streaming JSONL output, record/byte budgets, early cancellation, and unknown/duplicate response handling—while moving the generic contract into the shared memory host SDK and applying it consistently to Google, OpenAI, and Voyage. Exact-head focused tests, a real loopback Google lifecycle, and hosted CI are green. Thank you @ly85206559 for the original report and implementation work.

If a distinct remaining case reproduces on current main, please open a focused report with the exact provider output and batch size.

@steipete steipete closed this Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: google merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: M 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