openclaw - ✅(Solved) Fix [Bug] Gateway timeout after 120ms blocks antfarm cron creation [1 pull requests, 2 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#44562Fetched 2026-04-08 00:45:12
View on GitHub
Comments
2
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
commented ×2closed ×1cross-referenced ×1locked ×1

Antfarm workflow cron creation fails with 'gateway timeout after 120ms' error when using OpenClaw CLI fallback, preventing workflows from running autonomously.

Error Message

Cannot start workflow run: cron setup failed.
Failed to create cron job for agent "scanner":
CLI fallback failed: Error: gateway timeout after 120ms
Gateway target: ws://127.0.0.1:18789

Root Cause

OpenClaw CLI has a hardcoded 120ms timeout for gateway WebSocket connections. Real-world operations take 500ms-2000ms, especially when:

  • Gateway is under load
  • Multiple cron jobs created sequentially
  • System is resource-constrained

Fix Action

Fixed

PR fix notes

PR #2: OpenClaw 紧急未修复

Description (problem / solution / changelog)

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: The Gateway crashes with an unhandled promise rejection when the Discord API returns a 503 error, as response.json() is called without checking response.ok.
  • Why it matters: This causes the entire gateway process to exit, leading to a complete service interruption for all connected Discord channels for several minutes.
  • What changed: Added a check for response.ok before attempting to parse the JSON response. Errors are now emitted via this.emitter.emit("error") and this.handleReconnectionAttempt() is called to trigger a graceful reconnection attempt, preventing a full process crash. Updated tests to cover the 503 error path.
  • What did NOT change (scope boundary): Other identified issues (#44544, #44611, #44562, #44549) were either already fixed, determined not to be code bugs, or required a dedicated test environment for safe implementation and are not part of this PR.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #44529
  • Related #

User-visible / Behavior Changes

The gateway will no longer crash when the Discord API returns a 503 error during client registration. Instead, it will log the error and attempt to reconnect gracefully.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: Linux (typical Node.js environment)
  • Runtime/container: Node.js
  • Model/provider: N/A
  • Integration/channel (if any): Discord
  • Relevant config (redacted): N/A

Steps

  1. Configure OpenClaw Gateway with a Discord integration.
  2. During the GatewayPlugin.registerClient() call (e.g., when the health monitor triggers a Discord bot reconnection), simulate a Discord API returning a 503 HTTP status code with a non-JSON body.
  3. Observe the gateway process.

Expected

  • The gateway logs an error about the Discord 503 response.
  • The gateway attempts to reconnect to Discord without crashing the entire Node.js process.

Actual

  • The gateway process crashes with an unhandled promise rejection.

Evidence

  • Failing test/log before + passing after (New test should handle 503 response gracefully without crashing added to provider.proxy.test.ts which now passes.)
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: Added and passed a new unit test specifically for the 503 error case in provider.proxy.test.ts, ensuring the response.ok check and error handling logic are correctly implemented.
  • Edge cases checked: Specifically addressed the case where response.json() would throw an error on a non-2xx response.
  • What you did not verify: Did not verify in a live production environment with an actual Discord 503 error.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Revert this PR.
  • Files/config to restore: N/A
  • Known bad symptoms reviewers should watch for: Gateway still crashing on Discord 503, or Discord reconnection issues.

Risks and Mitigations

  • Risk: The error handling or reconnection logic might not fully cover all edge cases of Discord API errors.
    • Mitigation: The current fix addresses the immediate crash by preventing response.json() on bad responses and uses existing reconnection mechanisms. Further monitoring of Discord integration health is always recommended.
<div><a href="https://cursor.com/agents/bc-7023bdfd-1d36-48c0-818c-2346ec9378b5"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/background-agent?bcId=bc-7023bdfd-1d36-48c0-818c-2346ec9378b5"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div> <!-- CURSOR_AGENT_PR_BODY_END -->

Changed files

  • .detect-secrets.cfg (modified, +19/-4)
  • .github/FUNDING.yml (removed, +0/-1)
  • .github/ISSUE_TEMPLATE/bug_report.yml (modified, +31/-0)
  • .github/actions/ensure-base-commit/action.yml (added, +47/-0)
  • .github/actions/setup-node-env/action.yml (modified, +8/-4)
  • .github/actions/setup-pnpm-store-cache/action.yml (modified, +9/-7)
  • .github/codeql/codeql-javascript-typescript.yml (added, +18/-0)
  • .github/pull_request_template.md (modified, +7/-0)
  • .github/workflows/auto-response.yml (modified, +55/-0)
  • .github/workflows/ci.yml (modified, +85/-50)
  • .github/workflows/codeql.yml (added, +134/-0)
  • .github/workflows/docker-release.yml (modified, +77/-10)
  • .github/workflows/install-smoke.yml (modified, +63/-19)
  • .github/workflows/labeler.yml (modified, +256/-82)
  • .github/workflows/openclaw-npm-release.yml (added, +79/-0)
  • .github/workflows/sandbox-common-smoke.yml (modified, +1/-1)
  • .github/workflows/stale.yml (modified, +62/-3)
  • .gitignore (modified, +10/-0)
  • .npmignore (added, +1/-0)
  • .pi/prompts/reviewpr.md (modified, +37/-8)
  • .pre-commit-config.yaml (modified, +27/-1)
  • .secrets.baseline (modified, +229/-316)
  • .swiftformat (modified, +1/-1)
  • .swiftlint.yml (modified, +3/-1)
  • AGENTS.md (modified, +38/-0)
  • CHANGELOG.md (modified, +717/-137)
  • CONTRIBUTING.md (modified, +36/-4)
  • Dockerfile (modified, +165/-50)
  • Dockerfile.sandbox (modified, +6/-3)
  • Dockerfile.sandbox-browser (modified, +7/-5)
  • Dockerfile.sandbox-common (modified, +6/-4)
  • README.md (modified, +1/-1)
  • SECURITY.md (modified, +9/-0)
  • appcast.xml (modified, +499/-328)
  • apps/android/README.md (modified, +1/-1)
  • apps/android/app/build.gradle.kts (modified, +49/-4)
  • apps/android/app/proguard-rules.pro (modified, +1/-1)
  • apps/android/app/src/main/AndroidManifest.xml (modified, +1/-9)
  • apps/android/app/src/main/java/ai/openclaw/android/InstallResultReceiver.kt (removed, +0/-33)
  • apps/android/app/src/main/java/ai/openclaw/android/ScreenCaptureRequester.kt (removed, +0/-65)
  • apps/android/app/src/main/java/ai/openclaw/android/node/AppUpdateHandler.kt (removed, +0/-295)
  • apps/android/app/src/main/java/ai/openclaw/android/node/ScreenHandler.kt (removed, +0/-25)
  • apps/android/app/src/main/java/ai/openclaw/android/node/ScreenRecordManager.kt (removed, +0/-165)
  • apps/android/app/src/main/java/ai/openclaw/app/CameraHudState.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/DeviceNames.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/LocationMode.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/MainActivity.kt (renamed, +3/-7)
  • apps/android/app/src/main/java/ai/openclaw/app/MainViewModel.kt (renamed, +11/-10)
  • apps/android/app/src/main/java/ai/openclaw/app/NodeApp.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/NodeForegroundService.kt (renamed, +6/-28)
  • apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt (renamed, +64/-44)
  • apps/android/app/src/main/java/ai/openclaw/app/PermissionRequester.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/SecurePrefs.kt (renamed, +45/-6)
  • apps/android/app/src/main/java/ai/openclaw/app/SessionKey.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/VoiceWakeMode.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/WakeWords.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/chat/ChatController.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/chat/ChatModels.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/gateway/BonjourEscapes.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/gateway/DeviceAuthPayload.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/gateway/DeviceAuthStore.kt (renamed, +4/-3)
  • apps/android/app/src/main/java/ai/openclaw/app/gateway/DeviceIdentityStore.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayDiscovery.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayEndpoint.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewaySession.kt (renamed, +225/-20)
  • apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayTls.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/gateway/InvokeErrorParser.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/node/A2UIHandler.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/node/CalendarHandler.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/node/CameraCaptureManager.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/node/CameraHandler.kt (renamed, +4/-4)
  • apps/android/app/src/main/java/ai/openclaw/app/node/CanvasController.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/node/ConnectionManager.kt (renamed, +9/-9)
  • apps/android/app/src/main/java/ai/openclaw/app/node/ContactsHandler.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/node/DebugHandler.kt (renamed, +4/-4)
  • apps/android/app/src/main/java/ai/openclaw/app/node/DeviceHandler.kt (renamed, +3/-18)
  • apps/android/app/src/main/java/ai/openclaw/app/node/DeviceNotificationListenerService.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/node/GatewayEventHandler.kt (renamed, +3/-3)
  • apps/android/app/src/main/java/ai/openclaw/app/node/InvokeCommandRegistry.kt (renamed, +14/-22)
  • apps/android/app/src/main/java/ai/openclaw/app/node/InvokeDispatcher.kt (renamed, +14/-24)
  • apps/android/app/src/main/java/ai/openclaw/app/node/JpegSizeLimiter.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/node/LocationCaptureManager.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/node/LocationHandler.kt (renamed, +4/-20)
  • apps/android/app/src/main/java/ai/openclaw/app/node/MotionHandler.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/node/NodeUtils.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/node/NotificationsHandler.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/node/PhotosHandler.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/node/SmsHandler.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/node/SmsManager.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/node/SystemHandler.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/protocol/OpenClawCanvasA2UIAction.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/protocol/OpenClawProtocolConstants.kt (renamed, +1/-12)
  • apps/android/app/src/main/java/ai/openclaw/app/tools/ToolDisplay.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/ui/CameraHudOverlay.kt (renamed, +1/-1)
  • apps/android/app/src/main/java/ai/openclaw/app/ui/CanvasScreen.kt (renamed, +2/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/ui/ChatSheet.kt (renamed, +3/-3)
  • apps/android/app/src/main/java/ai/openclaw/app/ui/ConnectTabScreen.kt (renamed, +5/-2)
  • apps/android/app/src/main/java/ai/openclaw/app/ui/GatewayConfigResolver.kt (renamed, +24/-6)
  • apps/android/app/src/main/java/ai/openclaw/app/ui/MobileUiTokens.kt (renamed, +2/-2)

Code Example

Cannot start workflow run: cron setup failed.
Failed to create cron job for agent "scanner":
CLI fallback failed: Error: gateway timeout after 120ms
Gateway target: ws://127.0.0.1:18789

---

// Before
const WS_CONNECT_TIMEOUT_MS = 120;

// After  
const WS_CONNECT_TIMEOUT_MS = 10000; // 10 seconds

---

node ~/.openclaw/workspace/antfarm/dist/cli/cli.js workflow run security-audit "Test"
openclaw cron list | grep antfarm
RAW_BUFFERClick to expand / collapse

Summary

Antfarm workflow cron creation fails with 'gateway timeout after 120ms' error when using OpenClaw CLI fallback, preventing workflows from running autonomously.

Environment

  • OpenClaw: 2026.3.11
  • OS: Linux (VPS)
  • Node: v22.22.0
  • Gateway: local, loopback, token auth
  • Antfarm: 0.5.1

Problem

When starting an antfarm workflow, cron creation fails:

  1. Antfarm tries HTTP POST to /tools/invoke
  2. Falls back to OpenClaw CLI: openclaw cron add
  3. CLI WebSocket connection times out after 120ms (too short)
  4. Workflow fails to start

Error

Cannot start workflow run: cron setup failed.
Failed to create cron job for agent "scanner":
CLI fallback failed: Error: gateway timeout after 120ms
Gateway target: ws://127.0.0.1:18789

Root Cause

OpenClaw CLI has a hardcoded 120ms timeout for gateway WebSocket connections. Real-world operations take 500ms-2000ms, especially when:

  • Gateway is under load
  • Multiple cron jobs created sequentially
  • System is resource-constrained

Proposed Fix

Increase WebSocket connection timeout from 120ms to 10000ms (10 seconds).

Location: Likely in gateway client code Change:

// Before
const WS_CONNECT_TIMEOUT_MS = 120;

// After  
const WS_CONNECT_TIMEOUT_MS = 10000; // 10 seconds

Impact

Current: Antfarm workflows cannot start, CLI fallback unreliable After Fix: Workflows start successfully, better reliability on slower systems

Related Issues

  • #20288 - cron run WS timeout (30s)
  • #17000 - Sub-agent announcements timeout (60s)
  • #16729 - Gateway timeout causes message loss

Testing

node ~/.openclaw/workspace/antfarm/dist/cli/cli.js workflow run security-audit "Test"
openclaw cron list | grep antfarm

Priority: High - Blocks antfarm automation Severity: Major - Core functionality broken

extent analysis

Fix Plan

To resolve the issue, we need to increase the WebSocket connection timeout in the OpenClaw CLI. Here are the steps:

  • Locate the WS_CONNECT_TIMEOUT_MS constant in the gateway client code.
  • Update the value from 120 to 10000 (10 seconds) as shown below:
// Before
const WS_CONNECT_TIMEOUT_MS = 120;

// After
const WS_CONNECT_TIMEOUT_MS = 10000; // 10 seconds
  • Save the changes and rebuild the OpenClaw CLI.
  • Restart the Antfarm workflow to test the fix.

Verification

To verify that the fix worked, run the following commands:

node ~/.openclaw/workspace/antfarm/dist/cli/cli.js workflow run security-audit "Test"
openclaw cron list | grep antfarm

Check that the workflow starts successfully and the cron job is created without any errors.

Extra Tips

  • Monitor the system resources and gateway load to ensure that the increased timeout does not cause other issues.
  • Consider implementing a retry mechanism for WebSocket connections to improve reliability.
  • Review related issues (#20288, #17000, #16729) to ensure that similar timeouts are adjusted accordingly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING