Skip to content

fix(gateway): abort embeddings when clients disconnect - #116146

Merged
Takhoffman merged 4 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-gateway-embeddings-client-disconnect
Jul 31, 2026
Merged

Takhoffman merged 4 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-gateway-embeddings-client-disconnect

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor
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/embeddings could 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 main snapshot failed because embedBatch received no AbortSignal after 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:

    gateway_ready=true
    embeddings_endpoint_ready=true
    upstream_embed_request_started=true
    gateway_client_socket_destroyed=true
    upstream_connection_aborted=true
    

    The emitted result record reported runtime_kind=openclaw_dev_gateway_with_openai_embedding_provider, route=POST /v1/embeddings, ok=true, near_real=true, and abort_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.ts suite: 48/48 tests passed across both configured projects.

  • CI-equivalent pnpm check:test-types passed 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.
  • Result: 4 selected executions passed across 2 projects; exit code 0.

Command: node scripts/run-vitest.mjs src/gateway/embeddings-http.test.ts -t <the two cancellation test names> --reporter=verbose

The run used only local loopback HTTP sockets and test providers. No credentials, private endpoints, or external addresses were involved.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Jul 30, 2026
@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. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 31, 2026, 5:20 PM ET / 21:20 UTC.

ClawSweeper review

What this changes

This PR makes the OpenAI-compatible POST /v1/embeddings route pass a client-disconnect abort signal through provider creation and embedding work, including cleanup-safe handling for queued requests.

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
Reviewed head: 48b1f8ee2db238ab0b559f31d1e701d9dc6eb008

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation and focused socket-level tests look solid, while the available live proof does not cover the final head’s queued-admission extension.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The PR body contains a credible redacted loopback terminal proof for cb182041, but the latest head 48b1f8e adds queued-admission cancellation after that run; provide refreshed exact-head output and redact any private endpoints or credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body contains a credible redacted loopback terminal proof for cb182041, but the latest head 48b1f8e adds queued-admission cancellation after that run; provide refreshed exact-head output and redact any private endpoints or credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main behavior remains uncancelled: Current main creates the provider lease and invokes embedBatch(texts) without passing an abort signal, so the reported abandoned-provider-work path remains unresolved on main.
Existing provider contract supports this boundary: The memory embedding-provider contract already accepts an optional per-call AbortSignal; the OpenAI-compatible implementation forwards it to its embedding request, so the route is the appropriate owner for client-disconnect cancellation.
Proposed route preserves the provider lifecycle fence: The branch creates one request-scoped controller, passes its signal into the admission path and embedBatch, suppresses disconnected-response writes, and retains the existing close/release ordering.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body contains a credible redacted loopback terminal proof for cb182041, but the latest head 48b1f8e adds queued-admission cancellation after that run; provide refreshed exact-head output and redact any private endpoints or credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Complete next step (P2) - The only remaining merge gate is contributor-supplied real behavior proof for the latest head, not a bounded repair that should be dispatched.
Agent review details

Security

None.

PR surface

Source +28, Tests +123. Total +151 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 43 15 +28
Tests 1 126 3 +123
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 169 18 +151

Review metrics

None.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/gateway/embeddings-http.test.ts, unknown-data-model-change: src/gateway/embeddings-http.ts, vector/embedding metadata: src/gateway/embeddings-http.test.ts, vector/embedding metadata: src/gateway/embeddings-http.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

  • The current head 48b1f8ee2db238ab0b559f31d1e701d9dc6eb008 extends behavior beyond the live proof recorded for cb18204164a030fc3031619dea93a287f1d6eebc; merge should wait for exact-head real-socket evidence and completion of the in-progress required checks.

Maintainer options:

  1. Decide the mitigation before merge
    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.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best 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 main calls embedBatch without the provider contract’s optional abort signal, while the proposed real-socket regression test destroys a client connection after provider work begins.

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.

Labels

Label justifications:

  • P2: This is a bounded Gateway reliability fix for abandoned embedding work, with no evidence of data loss, security bypass, or a broad runtime outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body contains a credible redacted loopback terminal proof for cb182041, but the latest head 48b1f8e adds queued-admission cancellation after that run; provide refreshed exact-head output and redact any private endpoints or credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current-main behavior remains uncancelled: Current main creates the provider lease and invokes embedBatch(texts) without passing an abort signal, so the reported abandoned-provider-work path remains unresolved on main. (src/gateway/embeddings-http.ts:454, e73250f54baf)
  • Existing provider contract supports this boundary: The memory embedding-provider contract already accepts an optional per-call AbortSignal; the OpenAI-compatible implementation forwards it to its embedding request, so the route is the appropriate owner for client-disconnect cancellation. (src/plugins/memory-embedding-providers.ts:54, e73250f54baf)
  • Proposed route preserves the provider lifecycle fence: The branch creates one request-scoped controller, passes its signal into the admission path and embedBatch, suppresses disconnected-response writes, and retains the existing close/release ordering. (src/gateway/embeddings-http.ts:475, 48b1f8ee2db2)
  • Regression coverage exercises both in-flight and queued work: The branch adds a real HTTP-client socket-disconnect test for provider abort and a separate case preventing provider creation for a disconnected request waiting behind cleanup. (src/gateway/embeddings-http.test.ts:616, 48b1f8ee2db2)
  • Final-head proof needs refresh: The PR body’s loopback proof identifies cb182041 as the tested head, while the current head is 48b1f8e, whose final commit adds queued-admission cancellation. The supplied live transcript therefore does not directly prove the complete current branch. (src/gateway/embeddings-http.ts:479, 48b1f8ee2db2)
  • Available current-main provenance: Available blame maps the existing admission and retirement logic to the current shallow-history boundary commit by Peter Steinberger; deeper historical objects were not locally available for a fuller ownership trail. (src/gateway/embeddings-http.ts:73, f18d619c025c)

Likely related people:

  • Peter Steinberger: Available blame assigns the current provider-admission and retirement lifecycle to the shallow-history boundary commit that last carries this implementation. (role: current Gateway-path provenance; confidence: medium; commits: f18d619c025c; files: src/gateway/embeddings-http.ts, src/gateway/embeddings-http.test.ts)
  • Tak Hoffman: Authored the current PR head commit that extends the patch to cancel a disconnected request while it waits behind provider cleanup. (role: recent change contributor; confidence: high; commits: 48b1f8ee2db2; files: src/gateway/embeddings-http.ts, src/gateway/embeddings-http.test.ts)

Rank-up moves

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

  • Re-run the existing loopback/socket proof at 48b1f8ee2db238ab0b559f31d1e701d9dc6eb008 and add redacted terminal output proving both abort and queued-admission behavior.
  • Let the exact-head required checks finish successfully before merge.

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 (4 earlier review cycles)
  • reviewed 2026-07-30T00:51:57.521Z sha 29a5a0a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T02:54:31.223Z sha ffadbcf :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T07:42:53.206Z sha cb18204 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T20:52:41.289Z sha cb18204 :: needs maintainer review before merge. :: none

@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. 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 30, 2026
@Takhoffman

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 31, 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: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed 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. labels Jul 31, 2026
@Takhoffman

Copy link
Copy Markdown
Contributor

Maintainer land-ready verification for exact head 48b1f8ee2db238ab0b559f31d1e701d9dc6eb008:

  • Before: on the pre-fix baseline, destroying the client socket did not provide an AbortSignal to embedding work, so abandoned provider work continued.
  • After: real-socket coverage proves both in-flight provider cancellation and cancellation while provider admission is queued; 4/4 exact-head cases passed across gateway-server and gateway-client.
  • Full focused route run: node scripts/run-vitest.mjs src/gateway/embeddings-http.test.ts — 25/25 passed in the focused gateway-server configuration.
  • Exact-head behavior run: node scripts/run-vitest.mjs src/gateway/embeddings-http.test.ts -t 'aborts provider work when the HTTP client disconnects|does not create a provider for a disconnected request waiting behind cleanup' --reporter=verbose — 4/4 passed across both configured projects.
  • Formatting/lint: targeted oxfmt --check, targeted oxlint, and git diff --check passed.
  • Mandatory autoreview: TruffleHog clean; no accepted/actionable findings.
  • GitHub CI: run 30665765670 is green, including openclaw/ci-gate.
  • Real behavior proof: run 30667634828 is green.
  • Canonical OPENCLAW_TESTBOX=1 scripts/pr prepare-run 116146 passed in hosted_exact_or_recent_parent mode; prepared head equals PR head.
  • ClawSweeper reviewed this exact head with no actionable code findings. Its proof-only item is satisfied by the exact-head evidence and green proof check; no redundant re-review was requested.

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.

@Takhoffman
Takhoffman merged commit 2614251 into openclaw:main Jul 31, 2026
202 of 212 checks passed
@Takhoffman

Copy link
Copy Markdown
Contributor

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 31, 2026
…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)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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.

2 participants