Background / 背景
当前 AgentBridge 存在三个相互关联的限制,合并 #33 、#48 、#49 统一解决:
多 Claude 会话互踢 (Bug: multiple Claude Code sessions cause infinite reconnect loop #33 ) — daemon 只有一个 attachedClaude 槽位,新连接踢掉旧连接,触发无限重连循环
需要 broker/多会话支持 (feat: broker pattern for multi-session support / Broker 模式支持多 Claude 会话 (resolves #33) #48 ) — 同一 workspace 内多个 Claude 会话应能共享一个 Codex runtime
需要 workspace 隔离 (feat: workspace-scoped state for multi-project support / Workspace 作用域支持多项目并行 #49 ) — 固定端口 + 单例 state 目录,无法多项目并行
Root Cause Analysis / 根因分析
daemon.ts:334-336:新 claude_connect 直接关闭旧 socket(code 4001),被踢的 client 自动重连形成无限循环
daemon.ts:47:单个 attachedClaude 槽位,不支持多前端
config-service.ts + state-dir.ts:runtime state 是 machine-global,不按 workspace 分桶
固定端口分配,多项目实例端口冲突
Implementation Plan / 实施计划
Phase 1: 止血 — 多会话重连风暴修复
client 识别 close code 4001 后不自动重连,进入 dormant 状态
最小改动,立即见效
Phase 2: Workspace-scoped runtime state
用 canonical workspace root(git repo root / realpath(cwd))生成 workspaceId
runtime state 按 workspace hash 分桶:~/.agentbridge/workspaces/<hash>/(daemon.pid, status.json, ports.json, logs)
端口动态分配,写回 scoped ports.json
agentbridge kill、health check 只作用于当前 workspace
.agentbridge/ 项目配置目录不变
Phase 3: 多 Claude 会话支持(Broker 模式)
daemon 支持多个 Claude 前端 attach
每个 Claude 会话分配独立 session
消息路由根据 session ID 分发
Stream 所有权追踪:只有发起方收到对应 notification
Non-goals / 不在范围
单 workspace 内多 Codex adapter(属于 v2 multi-agent topology)
Unix socket 替代 HTTP/WebSocket(可作为后续优化,不阻塞本 issue)
References / 参考
codex-plugin-cc/plugins/codex/scripts/app-server-broker.mjs(broker 模式)
codex-plugin-cc/plugins/codex/scripts/lib/state.mjs、workspace.mjs(workspace 隔离)
Replaces #33 , #48 , #49
Background / 背景
当前 AgentBridge 存在三个相互关联的限制,合并 #33、#48、#49 统一解决:
attachedClaude槽位,新连接踢掉旧连接,触发无限重连循环Root Cause Analysis / 根因分析
daemon.ts:334-336:新claude_connect直接关闭旧 socket(code 4001),被踢的 client 自动重连形成无限循环daemon.ts:47:单个attachedClaude槽位,不支持多前端config-service.ts+state-dir.ts:runtime state 是 machine-global,不按 workspace 分桶Implementation Plan / 实施计划
Phase 1: 止血 — 多会话重连风暴修复
4001后不自动重连,进入 dormant 状态Phase 2: Workspace-scoped runtime state
workspaceId~/.agentbridge/workspaces/<hash>/(daemon.pid, status.json, ports.json, logs)ports.jsonagentbridge kill、health check 只作用于当前 workspace.agentbridge/项目配置目录不变Phase 3: 多 Claude 会话支持(Broker 模式)
Non-goals / 不在范围
References / 参考
codex-plugin-cc/plugins/codex/scripts/app-server-broker.mjs(broker 模式)codex-plugin-cc/plugins/codex/scripts/lib/state.mjs、workspace.mjs(workspace 隔离)Replaces #33, #48, #49