Skip to content

install during active CC session triggers launchctl spawn-fail loop #41

Description

@AmberCXX

复现

  1. 起一个 Claude Code session,加载 hub-client(claude --dangerously-load-development-channels server:hub)→ hub-client 自动 spawn hub-server on port 9900
  2. 在另一个终端 cd ~/forge-hub && git pull && bun cli.ts install
  3. install 完成后,tail -f ~/.forge-hub/hub.log 观察

现象

launchctl bootstrap 在 install 末尾试着重新加载 plist,但 hub-client 已经在管 hub-server(占着端口 9900)。launchctl 每 30s(ThrottleInterval)重试 spawn,每次都失败:

```
[2026-06-03 08:03:48] [hub] Forge Hub v0.2.0 · PID 36794 · 上次 PID 36785
[2026-06-03 08:03:48] [hub] ERROR: Fatal: Error: Failed to start server. Is port 9900 in use?
[2026-06-03 08:04:18] [hub] Forge Hub v0.2.0 · PID 36806 · 上次 PID 36794
[2026-06-03 08:04:18] [hub] ERROR: Fatal: Error: Failed to start server. Is port 9900 in use?
... (此后 ~50min 每 30s 一条)
```

日志快速膨胀,hub-stderr.log 也涨。功能本身没坏(hub-client 管的那个 hub-server 还在跑),但 launchctl 持续误报 spawn 失败。

根因猜测

hub-server 在当前架构下有两个潜在 owner:

  1. launchctl(plist 部署管理)
  2. hub-client(CC MCP,自动 spawn hub-server 如果发现没有)

install 重写 plist 并 bootstrap,但没有先让 hub-client 退让出端口。两个 owner 互相不知道对方,launchctl 永远输给 hub-client 反应速度。

应急消音

```
launchctl bootout gui/$(id -u)/com.forge-hub
```
hub-client 继续管 Hub,launchctl 退场,日志安静。代价:plist 不再受 launchd 保护,重启电脑后需手动重新 bootstrap。

建议修法

install 脚本在 `launchctl bootstrap` 前:

  • 检测是否有运行中的 hub-client(PID 文件 / `lsof -i :9900` / `fh hub ps`)
  • 若有 → 先发信号让 hub-client 把 hub-server 让出(或直接 kill 端口持有进程)
  • 再 bootstrap,确保 launchctl 拿到端口
  • 然后 hub-client 下次 send 会自动连到 launchctl-managed hub,不重复 spawn

或者反向:让 hub-client 在 launchctl plist 存在时自动 spawn,只连接。

环境

  • macOS 14.6.1 (23G93)
  • Bun 1.3.13
  • forge-hub `main` @ 6441bb8(今早 FF)
  • `bun cli.ts doctor`: ✅ All checks passed(功能正常,问题在 launchctl 噪音)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions