Repository navigation
fix(gateway): abort embeddings when clients disconnect - #116146
Takhoffman merged 4 commits into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 31, 2026, 5:20 PM ET / 21:20 UTC. ClawSweeper reviewWhat this changesThis PR makes the OpenAI-compatible Merge readiness⛔ Blocked until stronger real behavior proof is added - 2 items remain Keep open: the cancellation path is a focused, plausible repair with targeted real-socket coverage, but the current head adds queued-admission cancellation after the PR body’s live proof was recorded at an earlier SHA. Refresh the redacted real-behavior proof on the exact head before merge. Likely related people: Peter Steinberger is the strongest current-main routing candidate from the Gateway file’s available blame history; Tak Hoffman authored the final queued-admission change. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway exposes an OpenAI-compatible embeddings HTTP endpoint that resolves an agent’s configured memory provider and returns vectors to API clients. Provider creation and cleanup are serialized per agent/provider scope so local resources are not replaced before retirement completes. flowchart TD
Client[Embedding API client] --> Route[Gateway embeddings endpoint]
Route --> Disconnect[Client disconnect watcher]
Route --> Admission[Provider admission and cleanup queue]
Disconnect --> Signal[Request abort signal]
Signal --> Admission
Admission --> Provider[Configured embedding provider]
Signal --> Provider
Provider --> Response[Embedding response or clean cancellation]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +28, Tests +123. Total +151 across 2 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk options
Maintainer options:
Technical reviewBest possible solution: Keep the request-scoped abort design, then attach a redacted exact-head terminal or live-loopback run proving both upstream provider cancellation and that a disconnected queued request never creates a provider. Do we have a high-confidence way to reproduce the issue? Yes, from source: current Is this the best way to solve the issue? Yes. The Gateway HTTP route owns client lifetime, and the existing provider call contract already carries cancellation; threading one request-scoped signal through admission and provider work is narrower than adding provider-specific cancellation policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e73250f54baf. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Maintainer land-ready verification for exact head
Known gap: no separate manual Testbox job was necessary because the preparation gate accepted exact-head hosted CI/proof. No docs, schema, configuration, or changelog changes are required. |
|
Merged via squash.
|
…odels-20260729 * origin/main: fix(tui): canonical terminal outcomes, cancellation, and error privacy (#117044) fix(cron): avoid phantom message tool guidance (#116908) fix(test): avoid macOS release gate deadlocks (#116972) fix(openai): canonical Chat cache-hit and billing accounting (#117043) fix(memory-wiki): salvage human Notes before pruning imported source pages (#102294) fix(memory): suggest reindex, not --fix, for a missing qmd index (#116958) chore(msteams): add private Gateway QA adapter fix(ui): make session controls and failures accessible (#117019) docs: fix tilde paths in CLI output examples (#114595) fix(plugins): canonical discovery diagnostics and deterministic lifecycles (#117025) fix(ui): honor Gateway readiness abort and subscription ownership (#117048) fix(updater): harden launchd replacement timing (#117030) fix(gateway): preserve static asset HEAD representation metadata (#117049) fix(gateway): abort embeddings when clients disconnect (#116146) fix(googlechat): retain fallback thread continuity (#117053)
Co-authored-by: Tak Hoffman <[email protected]>
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
Fixes an issue where callers of
POST /v1/embeddingscould disconnect while the Gateway continued running the abandoned embedding request against the configured provider.Why This Change Was Made
The embeddings handler now watches the request connection with a request-scoped abort controller and passes its signal to
embedBatch, matching the cancellation boundary already used by adjacent Gateway routes. Disconnect-triggered aborts no longer attempt to write or log an internal-error response, while provider lease release and cleanup remain unchanged.User Impact
Cancellation-aware embedding providers can stop expensive or blocked work promptly when the requesting client goes away. This does not change the embeddings API, configuration, schema, or behavior of completed requests.
Evidence
Fresh-red regression check on the pre-fix
mainsnapshot failed becauseembedBatchreceived noAbortSignalafter the client socket was destroyed.A live OpenClaw development Gateway using the OpenAI embedding provider sent an embedding request to a blocking OpenAI-compatible upstream. On the final repaired HEAD (
cb182041), destroying the Gateway client socket after the upstream request began aborted the in-flight upstream connection in 28 ms. The bounded proof runner passed with exit code 0 and completed process cleanup.Redacted terminal transcript from the after-fix run:
The emitted result record reported
runtime_kind=openclaw_dev_gateway_with_openai_embedding_provider,route=POST /v1/embeddings,ok=true,near_real=true, andabort_latency_ms=28. The proof used only local loopback endpoints; no credentials, private endpoints, or external addresses are included above.Full
src/gateway/embeddings-http.test.tssuite: 48/48 tests passed across both configured projects.CI-equivalent
pnpm check:test-typespassed after correcting the abort-listener callback signature.Focused formatting validation passed for the changed Gateway source and test files.
Exact-head maintainer verification (48b1f8e)
The final head was re-verified with real loopback HTTP sockets using the Gateway embeddings E2E harness:
aborts provider work when the HTTP client disconnects: passed in both Gateway projects (84–85 ms).does not create a provider for a disconnected request waiting behind cleanup: passed in both Gateway projects (61 ms); the disconnected queued request did not create a replacement provider.Command:
node scripts/run-vitest.mjs src/gateway/embeddings-http.test.ts -t <the two cancellation test names> --reporter=verboseThe run used only local loopback HTTP sockets and test providers. No credentials, private endpoints, or external addresses were involved.