Skip to content

fix(openai): keep embedding batch waits within timeout - #111675

Merged
steipete merged 2 commits into
openclaw:mainfrom
ZengWen-DT:fix/openai-embedding-batch-timeout
Aug 1, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
ZengWen-DT:fix/openai-embedding-batch-timeout

Conversation

@ZengWen-DT

@ZengWen-DT ZengWen-DT commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users waiting for OpenAI embedding batches could exceed the configured total timeout in either the normal pending-status path or the retryable status-error backoff path.

Why This Change Was Made

Both waiter branches now share one provider operation deadline across backoff sleeps and status-request aborts while preserving the retry error as the timeout cause. Risk note: retry timing is user-visible for transient provider failures, so both pending and retry branches are covered through expiration.

User Impact

OpenAI remote embedding batch waits now stop within the configured total budget, including after transient status errors.

Evidence

I drove the real exported runOpenAiEmbeddingBatches() and real provider deadline/backoff code. A temporary loader replaced only upload/HTTP transport seams; the timer and status loop remained production code. The same harness against the pre-fix source showed the pending wait at 1000 ms and retry waits at [500,1000]; the fixed source clamps both remaining waits to 500 ms:

$ node --import /tmp/openai-proof-register.mjs --import tsx --no-warnings /tmp/openai-timeout-proof.mts
before: {"pending":{"waits":[1000]},"retry":{"waits":[500,1000]}}
after:  {"pending":{"waits":[500]},"retry":{"waits":[500,500]}}

The regression cases keep each operation pending through expiration, verify no extra status request is sent, and retain the original retry failure as the timeout cause.

$ node scripts/run-vitest.mjs extensions/openai/embedding-batch.test.ts
Test Files  1 passed (1)
Tests  11 passed (11)

$ CI=1 OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 pnpm check:changed --base upstream/main -- extensions/openai/embedding-batch.ts extensions/openai/embedding-batch.test.ts
exit 0

Live OpenAI credentials were not available; the proof exercises the deadline and retry behavior before provider-specific output processing.

AI-assisted: Codex helped implement and review the change; the behavior proof and validation above were run manually.

Maintainer real-transport verification (rebased head df7d68ae08f1183ba3d2f724e348bcb36b0fadae)

Ran the unchanged production OpenAI embedding owner plus actual shared SSRF-guarded HTTP transport against a real localhost provider. Every request used an isolated synthetic bearer credential; multipart uploads, batch creation, status replies, real HTTP 503 errors, output downloads, abort signals, TCP socket cleanup, wall-clock timers, and retry loops were real—not mocked.

scenario                         configured   untouched current main    exact rebased PR head
stalled status HTTP/TCP          120 ms       368 ms; socket unbounded  127 ms; socket aborted/closed; cause=TimeoutError
pending status poll              100 ms       203 ms; 2 status GETs     103 ms; 1 status GET; no post-deadline request
actual HTTP 503 retry/backoff    100 ms       146 ms; 2 status GETs     103 ms; 1 status GET; cause=ProviderHttpError(status=503)
healthy upload/create/output     100 ms       embedding=[1,2,3]         embedding=[1,2,3]

Focused changed-surface proof: OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/private/tmp/openclaw-vitest-s02-111675-openai-repaired node scripts/run-vitest.mjs extensions/openai/embedding-batch.test.ts — 11 passed. Fresh Codex Sol xhigh structured review: clean (0.98). Exact-head hosted run IDs: CI 30720195761; Workflow Sanity 30720195766.

Contributor commit 0ef01bcfc43cbbcff09a4853d8f86527ca6e48da preserves @ZengWen-DT's original name, email, July 20 author date and unchanged production patch. Separately attributed maintainer test-only commit df7d68ae08f1183ba3d2f724e348bcb36b0fadae accounts for newer main's independent provider error-body timers, keeps exact pending/retry poll assertions, and adds explicit retained HTTP 503 cause coverage.

There is no persisted data model, SQLite schema, migration, embedding metadata, or embedding output change; this patch changes only in-memory provider request/poll timeout enforcement, despite generic filename-based embedding/storage heuristics.

Official provider Batch API/status contract: https://developers.openai.com/api/reference/resources/batches . Detailed maintainer evidence: #111675 (comment) .

@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. P2 Normal backlog priority with limited blast radius. labels Jul 20, 2026
@clawsweeper

clawsweeper Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 6:05 PM ET / 22:05 UTC.

ClawSweeper review

What this changes

The PR makes OpenAI embedding-batch status requests, pending polls, and retry backoff waits share one configured operation timeout and adds regression coverage for both wait paths.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open: current main contains the matching timeout repair for Voyage batches, not OpenAI batches, so this remains the needed OpenAI counterpart. The patch uses the existing shared provider-deadline contract, has strong exact-head transport proof, and has no actionable correctness finding; wait for the in-progress exact-head build and lint checks before maintainer landing.

Priority: P2
Reviewed head: df7d68ae08f1183ba3d2f724e348bcb36b0fadae

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, owner-boundary repair with strong real-transport proof and no identified correctness defect; remaining merge gating is routine exact-head CI completion.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body and maintainer comment provide exact-head, real localhost transport proof for stalled status requests, pending polling, retryable HTTP 503 backoff, socket abort/cleanup, and healthy output behavior; no contributor action is needed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body and maintainer comment provide exact-head, real localhost transport proof for stalled status requests, pending polling, retryable HTTP 503 backoff, socket abort/cleanup, and healthy output behavior; no contributor action is needed.
Evidence reviewed 7 items Current OpenAI behavior: The current OpenAI wait loop records a start time, but its status fetch has no abort signal and its pending/retry waits use unbounded full delays before checking elapsed time; this permits the configured budget to be exceeded.
Patch uses the shared deadline contract: The contributor commit creates one provider deadline, resolves each status-request timeout from the remaining budget, passes the abort signal through the guarded HTTP wrapper, and uses the shared bounded poll wait for both pending and retry paths.
HTTP boundary accepts cancellation: The guarded remote HTTP helper explicitly accepts a top-level AbortSignal and passes it to the SSRF-guarded fetch, so the proposed status-request signal reaches the transport owner.
Findings None None.
Security None None.

How this fits together

The OpenAI plugin uploads embedding input, creates a remote batch, then polls its status before downloading output. This PR changes the polling stage so requests and waits cannot extend past the timeout supplied by the embedding caller.

flowchart LR
  A[Embedding request] --> B[OpenAI batch upload and creation]
  B --> C[Batch status polling]
  C --> D{Pending or retryable error?}
  D --> E[Shared operation deadline]
  E --> F[Bounded wait or abortable request]
  F --> G[Embedding output or timeout error]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is mergeable but behind current main, and its exact-head build-artifact and lint checks were still in progress in the supplied status; landing should use the completed current-head checks or a refreshed clean merge result.
  • Resolve merge risk (P2) - The fix intentionally makes users who previously exceeded their configured embedding-batch timeout receive a timeout within that budget; this is the stated correction, but it is observable provider behavior.
Agent review details

Security

None.

PR surface

Source +21, Tests +98. Total +119 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 41 20 +21
Tests 1 99 1 +98
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 140 21 +119

Review metrics

None.

Stored data model

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

Merge-risk options

Maintainer options:

  1. Land the bounded timeout behavior (recommended)
    After the exact-head build and lint checks complete successfully, accept the intended change that OpenAI batch polling no longer exceeds the caller-configured timeout.
  2. Pause for a different timeout contract
    Keep the PR open only if maintainers intend OpenAI batch polling to retain its prior ability to overrun the configured total timeout.

Technical review

Best possible solution:

Land the OpenAI owner-level repair after the current-head checks complete successfully, keeping the shared provider deadline as the sole timeout mechanism and preserving the retry failure as the timeout cause.

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

Yes: the maintainer’s exact-head real-transport comparison exercises the OpenAI batch owner through upload, status polling, retryable HTTP 503, abort, and output download. Current main differs from that tested base only in the sibling Voyage batch files, so the OpenAI reproduction path remains applicable.

Is this the best way to solve the issue?

Yes: the patch fixes the timeout at the OpenAI polling owner by reusing the existing provider operation deadline and guarded HTTP cancellation contract, rather than adding a local timer or downstream workaround.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This corrects a bounded OpenAI embedding-batch polling defect without evidence of broader runtime outage or data loss.
  • merge-risk: 🚨 compatibility: Existing users with stalled OpenAI batch polls will now receive the configured timeout instead of a longer retry or poll overrun.
  • 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 (live_output): The PR body and maintainer comment provide exact-head, real localhost transport proof for stalled status requests, pending polling, retryable HTTP 503 backoff, socket abort/cleanup, and healthy output behavior; no contributor action is needed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body and maintainer comment provide exact-head, real localhost transport proof for stalled status requests, pending polling, retryable HTTP 503 backoff, socket abort/cleanup, and healthy output behavior; no contributor action is needed.

Evidence

What I checked:

  • Current OpenAI behavior: The current OpenAI wait loop records a start time, but its status fetch has no abort signal and its pending/retry waits use unbounded full delays before checking elapsed time; this permits the configured budget to be exceeded. (extensions/openai/embedding-batch.ts:250, 6cb833314bc3)
  • Patch uses the shared deadline contract: The contributor commit creates one provider deadline, resolves each status-request timeout from the remaining budget, passes the abort signal through the guarded HTTP wrapper, and uses the shared bounded poll wait for both pending and retry paths. (extensions/openai/embedding-batch.ts:263, 0ef01bcfc43c)
  • HTTP boundary accepts cancellation: The guarded remote HTTP helper explicitly accepts a top-level AbortSignal and passes it to the SSRF-guarded fetch, so the proposed status-request signal reaches the transport owner. (packages/memory-host-sdk/src/host/remote-http.ts:19, 6cb833314bc3)
  • Shared helper provenance: Blame attributes the provider operation deadline helpers to the recent shared provider-timeout work; their remaining-time calculation throws on expiry and clamps each per-request timeout to the deadline. (src/media-understanding/shared.ts:131, a14ada134f91)
  • Current-main sibling evidence: Current main commit 9a3db65 has parent 6cb8333 and changes only Voyage embedding-batch files under the same timeout-fix title. It confirms the architectural pattern but does not implement this OpenAI PR's changed files. (extensions/voyage/embedding-batch.ts:1, 9a3db656381d)
  • Exact-head behavior proof: The supplied maintainer comment reports a real localhost transport comparison on head df7d68a: pending polling and a real HTTP 503 retry stopped near the configured deadline, while a healthy upload/create/output flow still returned embeddings; the focused regression suite reported 11 passing tests. (extensions/openai/embedding-batch.test.ts:1, df7d68ae08f1)

Likely related people:

  • steipete: Recent history attributes the shared provider-deadline implementation to Peter Steinberger; he also authored the exact-head test adjustment and the current-main Voyage counterpart. (role: recent shared-timeout and sibling-path contributor; confidence: high; commits: a14ada134f91, df7d68ae08f1, 9a3db656381d; files: src/media-understanding/shared.ts, extensions/openai/embedding-batch.test.ts, extensions/voyage/embedding-batch.ts)
  • ZengWen-DT: Authored the production patch that applies the shared deadline pattern to the OpenAI embedding-batch owner. (role: OpenAI timeout-fix author; confidence: high; commits: 0ef01bcfc43c; files: extensions/openai/embedding-batch.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for the in-progress exact-head build-artifact and lint checks to complete, or refresh them if the branch is rebased.

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 (2 earlier review cycles)
  • reviewed 2026-07-20T05:33:51.863Z sha 46a9e8b261ec52ab89425f3b1a206f088aa9a793 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T09:17:07.360Z sha 46a9e8b261ec52ab89425f3b1a206f088aa9a793 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jul 31, 2026
@steipete
steipete force-pushed the fix/openai-embedding-batch-timeout branch from 46a9e8b to df7d68a Compare August 1, 2026 21:56
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Maintainer verification on exact rebased head df7d68ae08f1183ba3d2f724e348bcb36b0fadae: original @ZengWen-DT commit 0ef01bcfc43cbbcff09a4853d8f86527ca6e48da retains its original author, email, July 20 author date and unchanged production patch; one separately attributed maintainer commit updates only the contributor regression test for newer main.

  • Exercised the actual OpenAI provider owner and actual SSRF-guarded, authenticated localhost multipart upload → batch creation → status → output HTTP path, comparing untouched current main to this exact head: stalled status request 368 ms → 127 ms for a configured 120 ms deadline, now aborts/closes the real socket and retains TimeoutError; pending status 203 ms/2 requests → 103 ms/1 request for a 100 ms deadline; real HTTP 503 retry 146 ms/2 requests → 103 ms/1 request, preserving the ProviderHttpError cause; successful output still returns [1,2,3]. Every request carried its isolated synthetic credential.
  • Newer main introduced independent 10,000 ms provider error-body chunk timers, so the original test's global setTimeout count was no longer valid. The separate test-only adjustment asserts the exact owner poll delays, no post-deadline status request, and additionally verifies the preserved HTTP 503 cause; production files are unchanged from the contributor patch.
  • OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/private/tmp/openclaw-vitest-s02-111675-openai-repaired node scripts/run-vitest.mjs extensions/openai/embedding-batch.test.ts — 11 passed.
  • Fresh .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --engine codex --thinking xhigh — Sol xhigh clean, confidence 0.98.
  • Provider contract: https://developers.openai.com/api/reference/resources/batches ; exact-head hosted CI 30720195761 and Workflow Sanity 30720195766.

No production follow-up, dependency, config, changelog, or unrelated edits.

@steipete
steipete merged commit d03a43a into openclaw:main Aug 1, 2026
91 checks passed
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

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

Labels

extensions: openai 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: 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