Skip to content

fix(dashboard): handle missing OpenClaw CLI during dispatch - #290

Merged
cft0808 merged 1 commit into
cft0808:mainfrom
luoyanglang:wolf/fix-windows-auto-dispatch-openclaw
Apr 19, 2026
Merged

fix(dashboard): handle missing OpenClaw CLI during dispatch#290
cft0808 merged 1 commit into
cft0808:mainfrom
luoyanglang:wolf/fix-windows-auto-dispatch-openclaw

Conversation

@luoyanglang

Copy link
Copy Markdown
Contributor

Summary

Issue: #289 — 自动派发异常: [WinError 2] 系统找不到指定的文件
Type: Bug Fix
Severity: Medium

This PR makes dashboard auto-dispatch handle a missing OpenClaw CLI explicitly. Instead of surfacing a raw Windows [WinError 2] message to users, the scheduler now records an actionable openclaw-missing status and explains how to fix PATH / OPENCLAW_BIN.


Root Cause

dashboard/server.py::dispatch_for_state() builds the auto-dispatch command with a hardcoded executable name:

cmd = ['openclaw', 'agent', '--agent', agent_id, '-m', msg, '--timeout', '300']
result = subprocess.run(cmd, capture_output=True, text=True, timeout=310)

On Windows, if openclaw is not on PATH, or if the npm-installed CLI is exposed through an openclaw.cmd shim that is not resolved, subprocess.run() raises FileNotFoundError / [WinError 2]. The old dashboard path only caught the generic Exception, so the task scheduler displayed a non-actionable dispatch error.

This is different from OpenClaw runtime failures: the process never starts.


Fix Description

Changed files:

  • dashboard/server.py — add _resolve_openclaw_bin() using OPENCLAW_BIN or shutil.which('openclaw')
  • dashboard/server.py — preflight the CLI before dispatching, recording lastDispatchStatus = openclaw-missing if it is unavailable
  • dashboard/server.py — add a dedicated FileNotFoundError fallback for invalid configured paths
  • tests/test_dashboard_dispatch.py — add a regression test for the missing CLI path

Rationale:

  • shutil.which() resolves Windows npm .cmd shims more reliably than passing a bare command name directly
  • OPENCLAW_BIN gives Windows users a direct escape hatch if their shell PATH differs from the dashboard process PATH
  • The fix is scoped to dashboard auto-dispatch error handling and does not change the state machine or OpenClaw command arguments

Test Results

Test Description Status
pytest tests/test_dashboard_dispatch.py tests/test_server.py Covers missing OpenClaw CLI dispatch path plus existing server health route ✅ PASS
python -m py_compile dashboard/server.py tests/test_dashboard_dispatch.py Syntax check for changed Python files ✅ PASS
git diff --check Whitespace / patch formatting check ✅ PASS

Disprove Analysis

是否已有其他地方修复

edict/backend/app/workers/dispatch_worker.py already catches FileNotFoundError and reports openclaw command not found, but the stdlib dashboard server still had its own legacy auto-dispatch path without the same protection. #289 maps to the dashboard scheduler message, so that path still needed a fix.

影响范围

This only affects dashboard auto-dispatch when the OpenClaw CLI cannot be resolved or launched. Successful dispatch still uses the same command shape:

openclaw agent --agent <agent_id> -m <message> --timeout 300

边界情况

  • If openclaw is available on PATH, dispatch proceeds as before.
  • If Windows exposes openclaw.cmd, shutil.which('openclaw') can resolve it.
  • If users need a custom path, they can set OPENCLAW_BIN.
  • If OPENCLAW_BIN points to a bad path, FileNotFoundError is still converted to openclaw-missing.

已知局限

This does not install OpenClaw automatically. It only turns a raw [WinError 2] into an actionable dashboard error so users can fix their CLI/PATH setup.


Checklist

  • 代码遵循项目现有风格
  • 相关 issue 编号在 PR 描述中已引用
  • 有测试覆盖
  • 无硬编码路径、密钥、调试输出

Found during issue triage. Happy to adjust the status wording if you prefer a different dashboard label.

@luoyanglang
luoyanglang requested a review from cft0808 as a code owner April 15, 2026 17:15
@cft0808
cft0808 merged commit 78f5465 into cft0808:main Apr 19, 2026
1 of 2 checks passed
@luoyanglang
luoyanglang deleted the wolf/fix-windows-auto-dispatch-openclaw branch April 25, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants