Skip to content

fix(cli,ui): connection recovery for stale Electron and daemon port changes#32

Merged
Shadow-Azure merged 7 commits into
mainfrom
fix/debug-connection-issue
Jun 7, 2026
Merged

fix(cli,ui): connection recovery for stale Electron and daemon port changes#32
Shadow-Azure merged 7 commits into
mainfrom
fix/debug-connection-issue

Conversation

@Shadow-Azure

Copy link
Copy Markdown
Owner

Problem

When running cli-box start <command>, the CLI could hang indefinitely if:

  • A stale Electron process was running but its renderer was disconnected
  • The daemon restarted on a different port, breaking the renderer's WebSocket connection

Solution

CLI: Stale Electron Detection and Respawn

  • Added kill_stale_electron() helper to detect and kill unresponsive Electron processes
  • Modified cmd_start_daemon() to retry renderer connection after killing stale Electron
  • Maximum 1 retry to prevent infinite loops

Electron: Port Change Detection on Reconnect

  • Modified renderer WebSocket onclose handler to check daemon.json for port changes
  • If daemon port changed (e.g., daemon restarted), renderer reconnects with new port

Test Plan

  • Unit tests for kill_stale_electron() (no file, dead PID)
  • All Rust tests pass (37 tests)
  • All frontend tests pass (36 tests)
  • TypeScript type check passes
  • Manual test: fresh start works
  • Manual test: stale Electron recovery works

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

🔒 门禁检查结果

检查项 状态
Rust 格式化 ✅ success
Rust Clippy ✅ success
Rust 测试 & 覆盖率 ✅ success
前端测试 & 覆盖率 ✅ success
Playwright E2E ✅ success
统一测试 (test.sh) ✅ success
安全检查 ✅ success

Rust 测试覆盖率

指标 覆盖率
行覆盖率 69.8%
分支覆盖率 0.0%
模块 行覆盖率
crates.cli-box-core.src.daemon ███████████░░░░░░░░░ 56.2%
crates.cli-box-core.src.instance ███████████████████░ 99.1%
crates.cli-box-core.src.process █████████████░░░░░░░ 65.7%
crates.cli-box-core.src.server █████████████████░░░ 87.7%
crates.cli-box-core.src.capture ████████████████████ 100.0%
crates.cli-box-core.src.automation ███████████░░░░░░░░░ 58.8%
crates.cli-box-core.src.sandbox ███████████████████░ 98.8%
crates.cli-box-core.src ███████████░░░░░░░░░ 55.3%

详细报告见 Rust 覆盖率 artifact

前端测试覆盖率

指标 覆盖率
行覆盖率 ████████████████░░░░ 82.3%
分支覆盖率 68.9%
函数覆盖率 80.0%
语句覆盖率 80.0%
文件 行覆盖率
src/tests/mocks/websocket.ts ██████████████████░░ 88.0%
src/tests/mocks/xterm.ts ████████████████████ 100.0%
src/renderer/api.ts ██████████████░░░░░░ 68.2%
src/renderer/tabState.ts ████████████████████ 100.0%

详细报告见前端覆盖率 artifact

✅ 所有检查通过,可以合入

点击 Squash and merge 合并此PR

@Shadow-Azure
Shadow-Azure merged commit 9615c05 into main Jun 7, 2026
9 checks passed
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.

1 participant