Repository navigation
fix(gateway): add GatewayClient connection pool to prevent WS reconnect flood - #85462
samson1357924 wants to merge 8 commits into
Conversation
…ected into config Two-part fix: A (onboarding-plugin-install.ts): add bundled root guard in addPluginLoadPath(). Before writing a plugin path to plugins.load.paths, check whether it resolves to OpenClaw's bundled plugin directory via resolvePackagedBundledLoadPathAlias. Bundled plugins are auto-discovered and do not need a config entry. B (repair-sequencing.ts): move maybeRepairBundledPluginLoadPaths to the end of the repair sequence so it runs after all plugin install/enable/auto-enable mutations are complete. Without this, plugin repair steps could re-add the bundled path after the mid-sequence cleanup, leaving a dirty config to be persisted. References: openclaw#85334
…ct flood Repeated callGateway calls each created a fresh GatewayClient then stopped it immediately. Each new client started WS exponential backoff from 1s, so background agents polling sessions.list (~2/sec) never let backoff converge to 30s, creating a sustained auth flood. Fix: pool GatewayClients by (method + token + password) key. acquirePooledClient() reuses a live client from the pool. releasePooledClient() keeps the client alive for 10s TTL then cleans up, letting WS backoff converge properly. Also adds GatewayClient.isShutdown public getter for pool liveness check without reaching into the private closed field. References: openclaw#85333
|
Codex review: needs real behavior proof before merge. Latest ClawSweeper review: 2026-05-22 17:53 UTC / May 22, 2026, 1:53 PM ET. Workflow note: Future ClawSweeper reviews update this same comment in place. How this review workflow works
Summary Reproducibility: yes. for the PR defects from source inspection: current main forwards abort/accepted callbacks and stops each client, while the PR returns pooled clients with one-shot callbacks and no teardown. No live upgraded doctor reproduction or after-fix proof was provided for the original regression. PR rating Rank-up moves:
What the crustacean ranks mean
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. Real behavior proof Risk before merge
Maintainer options:
Next step before merge Security Review findings
Review detailsBest possible solution: Replace the global pool with a narrow gateway lifecycle fix that preserves per-request callbacks, teardown, and the full connection/security context, then add focused lifecycle tests plus redacted before/after Do we have a high-confidence way to reproduce the issue? Yes for the PR defects from source inspection: current main forwards abort/accepted callbacks and stops each client, while the PR returns pooled clients with one-shot callbacks and no teardown. No live upgraded doctor reproduction or after-fix proof was provided for the original regression. Is this the best way to solve the issue? No; this is not the best way to solve the issue because a global Label justifications:
Full review comments:
Overall correctness: patch is incorrect Security concerns:
What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against c9b17c51427e. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
Reviewed on behalf of Argus. Core fix is sound — the connection pool correctly solves the WS reconnect flood. The guard and TTL unref pattern are right. Gaps worth addressing:
Overall: solid fix, needs tests and a pool size cap to be merge-ready. |
- Add CLIENT_POOL_MAX_SIZE=64 to prevent unbounded Map growth - Remove TTL-based cleanup (TTL race with in-flight requests) - Pool entries live until disconnected; stale entries evicted on acquire - Addresses PR openclaw#85462 review feedback from Argus
|
Addressed review feedback:
|
|
This PR is now also available as |
|
Withdrawing — code review discovered a critical bug: Problem: acquirePooledClient reuses existing GatewayClient instances, but client.request() is embedded inside the onHelloOk lifecycle callback. onHelloOk fires only once during initial WS handshake, so pooled clients never actually send requests — they hang until timeout. This causes silent performance degradation (requests timing out) rather than the intended WS flood prevention. The pool design needs to be fundamentally rethought so that client.request() can be called independently of onHelloOk. See issue #85333 comment thread for full analysis. |
Background
Issue #85333: Doctor performance regression. Background agents call
callGateway({method: "sessions.list"})every ~500ms. Each call creates a fresh GatewayClient, which starts WS exponential backoff from 1s. When 5.20 introduced token auth for WS connections, every connection is rejected — new client → backoff from 1s → flood → event loop starvation.Changes
src/gateway/call.tsAdded a connection pool for GatewayClient instances:
clientPoolMap keyed by(method, token, password)— calls with the same method and auth share a connectionacquirePooledClient()— returns an existing live client from the pool, or creates a new onereleasePooledClient()— instead of stopping immediately, keeps the client alive for a 10s TTL. Subsequent calls within 10s reuse the same connection, letting the WS backoff properly converge to 30sModified
executeGatewayRequestWithScopes()to use the pool instead of create+stop per call.src/gateway/client.tsAdded
isShutdownpublic getter so the pool can check liveness without reaching into the privateclosedfield.Testing
npx vitest run src/gateway/call.test.ts