Skip to content

fix(google): bound Gemini batch embedding file content reads to prevent OOM - #97694

Closed
Alix-007 wants to merge 6 commits into
openclaw:mainfrom
Alix-007:fix/bound-google-embedding-batch-file-read
Closed

Alix-007 wants to merge 6 commits into
openclaw:mainfrom
Alix-007:fix/bound-google-embedding-batch-file-read

Conversation

@Alix-007

@Alix-007 Alix-007 commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Replaces Gemini batch embedding output download parsing with streaming JSONL parsing instead of whole-file res.text() buffering.
  • Allows valid batch output files larger than the generic 16 MiB text cap while bounding each individual JSONL record to 16 MiB.
  • Intentionally out of scope: changing Gemini batch submission/polling behavior or adding live Gemini credentials.
  • Review focus: the intentional per-record cap and the streamed output parsing strategy.

Linked context

Related context: #97687.

Related: provider response hardening series for successful provider/control-plane reads.

Maintainer request: not directly requested by a maintainer.

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: Gemini embedding batch output files were previously read with unbounded whole-body text parsing, which can OOM for large JSONL output files.

  • Real environment tested: local OpenClaw checkout on Node 22 using runGeminiEmbeddingBatches against a real node:http server bound to 127.0.0.1; no fetch mock on the streaming proof cases.

  • Exact steps or command run after this patch: PNPM_CONFIG_MODULES_DIR=/media/vdc/0668001470/workSpace/claw-campaign/openclaw/node_modules node scripts/run-vitest.mjs extensions/google/embedding-batch.test.ts -- --run -t "file-content streaming"

  • Evidence after fix: Live terminal output from real node:http loopback server (no fetch mock):

    [gemini-batch-proof] under-cap: streamed 16500 embeddings from >16 MiB JSONL output (real HTTP server, no fetch mock)
    [gemini-batch-proof] over-cap: oversized JSONL line (17 MiB) rejected before full buffering — gemini.batch-file-content: JSONL line exceeds 16777216 bytes
    

    All 6 scenarios passed against a real node:http server: upload/create/status JSON caps fire, small responses parse correctly, valid large JSONL output streams, and an oversized JSONL record is rejected.

  • Observed result after fix: a valid local JSONL output file with 16,500 embedding records and total size above 16 MiB streams successfully; a single oversized JSONL record rejects with gemini.batch-file-content: JSONL line exceeds 16777216 bytes.

  • What was not tested: a live Gemini batch run with real Google credentials.

  • Proof limitations or environment constraints: no live Gemini API key is available in this environment. The proof exercises the production batch runner and real HTTP transport locally, including upload/create/download routing.

  • Before evidence: source on main downloaded the successful output file as one full text body before parsing JSONL.

Tests and validation

  • PNPM_CONFIG_MODULES_DIR=/media/vdc/0668001470/workSpace/claw-campaign/openclaw/node_modules node scripts/run-vitest.mjs extensions/google/embedding-batch.test.ts -- --run -t "file-content streaming"
  • Existing bounded JSON response tests for upload/create/status paths remain in the same file.
  • Regression coverage proves both desired outcomes: total output larger than 16 MiB succeeds, but one oversized record fails closed.

Risk checklist

Did user-visible behavior change? (Yes/No) Yes. A single JSONL output record above 16 MiB now fails closed.

Did config, environment, or migration behavior change? (Yes/No) No.

Did security, auth, secrets, network, or tool execution behavior change? (Yes/No) Yes, provider response streaming/size enforcement changed.

What is the highest-risk area? A provider-valid single embedding record above 16 MiB would now fail.

How is that risk mitigated? Normal embedding records are far below 16 MiB, and large total batch output remains supported by streaming line-by-line instead of capping the whole file.

Current review state

Next action: ClawSweeper/maintainer re-review after this template/proof refresh.

Waiting on: maintainer acceptance of the 16 MiB per-JSONL-record guard or request for a different record cap.

Bot/reviewer comments addressed: the body now states that the cap is per line, not whole file, and documents the missing live Gemini proof as an environment limitation.

AI-assisted; implementation and validation reviewed before pushing.

@clawsweeper

clawsweeper Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close: the useful Google batch output streaming work is superseded by the open, proof-positive canonical PR that covers the same completed-output read plus upload/create error-body bounds and output record budgeting.

Root-cause cluster
Relationship: superseded
Canonical: #98692
Summary: This PR and the canonical open PR target the same Google embedding-batch response OOM class; the canonical PR is broader, proof-positive, and viable.

Members:

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

Canonical path: Use #98692 as the canonical Google embedding-batch response-boundary landing path and tune its caps there if needed.

So I’m closing this here and keeping the remaining discussion on #98692.

Review details

Best possible solution:

Use #98692 as the canonical Google embedding-batch response-boundary landing path and tune its caps there if needed.

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

Yes at source level: current main still uses raw res.text() for completed Gemini batch output, and this PR supplies loopback HTTP after-fix proof for large valid JSONL output plus oversized-line rejection.

Is this the best way to solve the issue?

No for this branch as the landing path: the streaming line cap is useful, but the broader open PR is the better canonical fix because it also bounds upload/create error bodies and output record count.

Security review:

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

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy applied: Root and extensions AGENTS.md were read; bundled provider runtime fail-closed response handling is compatibility-sensitive under repository review policy. (AGENTS.md:40, 5b06eba9fe9e)
  • Current main still has the underlying output-read problem: Current main downloads completed Gemini batch output with raw res.text() before parsing JSONL, so the problem is real and not already implemented on main. (extensions/google/embedding-batch.ts:223, 5b06eba9fe9e)
  • This branch is narrower than the canonical path: This PR head adds a 16 MiB per-line streaming reader and ignores unknown IDs, but upload/create error-body reads remain raw text and there is no submitted-record-count budget. (extensions/google/embedding-batch.ts:205, a81946ad377f)
  • Canonical PR covers the broader Google response boundary: The canonical open PR uses bounded upload/create error readers, streams completed output JSONL, applies a 4 MiB line cap, and enforces maxLines equal to the submitted group size. (extensions/google/embedding-batch.ts:130, fa3f0c5879e7)
  • Canonical PR is viable and proof-positive: Live GitHub metadata shows fix(google): bound embedding batch response reads #98692 is open, non-draft, mergeable clean, labeled proof: sufficient, and ready for maintainer look. (fa3f0c5879e7)
  • Merged adjacent Google JSON hardening: The merged same-file Google PR bounded successful JSON response reads but did not address this PR's output download and error-body follow-up scope. (extensions/google/embedding-batch.ts:132, 91297bf42082)

Likely related people:

  • steipete: The Gemini batch memory embedding path traces back through the provider-plugin memory embedding refactor and earlier Gemini batch additions. (role: feature-history contributor; confidence: medium; commits: 77e6e4cf87f7, 946477413372; 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 output-file and error-body 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 exposed 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 provides the closest sibling implementation pattern. (role: sibling-surface contributor; confidence: medium; commits: ce4a259485f2; files: extensions/openai/embedding-batch.ts, extensions/openai/embedding-batch.test.ts)

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

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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 Jun 29, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jun 29, 2026
@Alix-007

Copy link
Copy Markdown
Contributor Author

PR body refreshed to the full contributor template with the streaming proof and cap tradeoff made explicit.

The body now clarifies that this is a 16 MiB per-JSONL-record guard, not a whole-output-file cap: valid total output above 16 MiB streams successfully, while one oversized record fails closed.

Fresh validation:

  • node scripts/run-vitest.mjs extensions/google/embedding-batch.test.ts -- --run -t "file-content streaming"

No live Gemini credential is available in this environment; that proof limitation is now stated directly in the body.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 29, 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.

@Alix-007

Copy link
Copy Markdown
Contributor Author

Cleaned up the PR body metadata: changed the linked context from closing syntax to a non-closing reference so this PR will not accidentally close an unrelated item if merged. @clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 29, 2026
@Alix-007

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

3 similar comments
@Alix-007

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@Alix-007

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@Alix-007

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 30, 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 rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jun 30, 2026
@Alix-007
Alix-007 force-pushed the fix/bound-google-embedding-batch-file-read branch 3 times, most recently from 9d637c4 to dceca6a Compare July 5, 2026 12:43
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 5, 2026
@Alix-007
Alix-007 force-pushed the fix/bound-google-embedding-batch-file-read branch from edf803b to e620916 Compare July 6, 2026 04:04
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 6, 2026
@Alix-007
Alix-007 force-pushed the fix/bound-google-embedding-batch-file-read branch from e620916 to 64cd2c6 Compare July 6, 2026 06:05
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 6, 2026
@Alix-007
Alix-007 force-pushed the fix/bound-google-embedding-batch-file-read branch from 64cd2c6 to a81297c Compare July 6, 2026 16:06
Alix-007 added 5 commits July 7, 2026 00:23
Replace bare res.text() in fetchGeminiFileContent with
readProviderTextResponse (16 MiB cap, fail-closed).

Gemini batch output files can hold up to 50 000 embedding vectors
(JSONL), which makes unbounded res.text() a potential OOM vector.
The fix applies the same guard already present on the JSON paths
(file-upload, batch-create, batch-status) to the text-content path.

Tests added in embedding-batch.test.ts:
- Real node:http server streams 20 MiB without Content-Length →
  rejects with label gemini.batch-file-content
- Mutation: raw res.text() resolves on 17 MiB body (pre-fix
  behaviour), readProviderTextResponse rejects (post-fix), proving
  the fix is load-bearing
…test

Wrap the two implicit-return arrow-function Promise executors in block
bodies so server.listen() / server.close() return values are discarded,
satisfying the no-promise-executor-return oxlint rule.
@Alix-007
Alix-007 force-pushed the fix/bound-google-embedding-batch-file-read branch from a81297c to bee7d91 Compare July 6, 2026 16:23
@openclaw-barnacle openclaw-barnacle Bot added the channel: discord Channel integration: discord label Jul 6, 2026
@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

  • Action: closed this PR.
  • Close reason: duplicate or superseded.
  • Evidence: durable ClawSweeper review.
  • Coverage proof: PR B clearly carries PR A's core useful behavior and review concerns while broadening the same Google embedding-batch response-boundary fix. Any leftover PR A details are incidental or are better resolved on PR B, so PR A does not need independent review. Covering PR: fix(google): bound embedding batch response reads #98692.

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

Labels

channel: discord Channel integration: discord 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant