Skip to content

将 DSH Desktop 基线分叉(#23)移植到中心 Hub,并改为无明文凭证交接 - #48

Open
Fei2411 wants to merge 15 commits into
mainfrom
devin/1795442873-port-pr23-onto-hub
Open

Fei2411 wants to merge 15 commits into
mainfrom
devin/1795442873-port-pr23-onto-hub

Conversation

@Fei2411

@Fei2411 Fei2411 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

替代 #23(原分支未改动,提交保留 renjieah <renjieah@163.com> 与 renjie <jessemichaell11111@gmail.com> 的 Co-authored-by 署名),基于 #42 的 devin/hub-api。

为什么不能直接移植: #23 的 Desktop connector 把带 token 的 authenticatedUrl 写进 JSON 交接文件;DSH 0.1.7-rc.2 只通过 URL 查询参数签发 Cookie,不接受 Hub bearer token。即使把 URL 放进 keychain,token 仍会出现在 URL 中,违反「key/token 绝不明文保存」的要求。

改为:

  • 新 dsh-desktop-connector/ 在 DSH 进程内直接调用 sessionController(create / fork / prompt / follow),经同用户 IPC 与 Hub 通信(desktop_ipc.py、desktop_pipe.py、adapters/dsh_desktop.py)。
    • 不监听网络端口,不生成/交换 URL token 或 Cookie,不读写旧交接文件。
    • Unix:0700 目录 + 0600 socket;Windows:命名管道仅当前用户 ACL,拒绝远程客户端。
  • baselines.py / registry.py / models.py / api.py / hub.py / hub_client.py / server.py / cli.py:不可变命名基线、项目默认基线、分叉与结果元数据接入 Hub API。
  • Desktop 不可用时:普通 DSH 任务回退 ACP;基线分叉明确报错,不静默开空会话。
  • README.md / SETUP.md / HUB.md:安装、升级时清理旧交接文件、Hub API 用法。

验证: pytest 849 passed / 3 skipped;Ruff、mypy、uv build 通过;真实 DSH 0.1.7-rc.2 经 Unix socket 跑通 create / rename / follow,以及「未完成回合前拒绝 fork」。

未验证: Windows 命名管道与 ACL 未实机测试;成功分叉仅集成测试覆盖,未用真实模型推理跑通;未手动检查 Desktop Plugins 界面。


AB Product Engineer opened this PR for Stull
Implemented in session Port DSH Desktop baseline forks onto hub
Review with Devin · Open in Devin Desktop


Replace the credential-bearing Desktop URL handoff with same-user local IPC and call the in-process DSH session controller.

Co-authored-by: renjieah <renjieah@163.com>
Co-authored-by: renjie <jessemichaell11111@gmail.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

Fei2411 and others added 8 commits November 23, 2026 14:23
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Fei2411 and others added 3 commits November 23, 2026 14:50
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot changed the base branch from devin/hub-api to main November 24, 2026 07:10
Fei2411 and others added 3 commits November 24, 2026 07:10
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@klarkxy klarkxy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed via Gemini App · Model: Gemini · Commit: 2ea802f4c16035b5272843d7298c620df27cf66c

整体评估

本 PR 将 #23 的 DSH Desktop 命名基线与会话分叉(Fork)能力移植到中心 Hub 架构上,并改用进程内插件 dsh-desktop-connector/ 配合同用户本地 IPC(Unix 0700/0600 套接字 + O_NOFOLLOW 锁、Windows 当前用户 SID 专属 DACL 命名管道 + PIPE_REJECT_REMOTE_CLIENTS)彻底消除了明文 URL/Token 交接文件。不可变 BaselineStore、Worker/Remote 基线读取隔离与 4 平台 CI 矩阵均已就位,但在 Windows 命名管道重连竞争、remote_origin 宿主隔离、turn/end 错误空值处理及空返回值 IPC 帧兼容上存在 4 处问题建议修复。

1. 建议修复(逻辑缺陷 / 潜在风险)

  1. Windows 命名管道每次重建均携带 FILE_FLAG_FIRST_PIPE_INSTANCE 且未捕获 accept_pipe 异常,重连时会导致后台监听协程永久退出

    • 位置:src/agent_bridge/desktop_pipe.py 第 45–57 行(_private_pipe)与第 73–91 行(serve_pipe 内嵌 accept 协程)
    • 触发条件与影响:根据 Win32 CreateNamedPipeW 规范,命名管道实例须等服务端与客户端句柄全部关闭后才会销毁,此前携带 FILE_FLAG_FIRST_PIPE_INSTANCE(且 nMaxInstances=1)重建同名管道会直接抛出 ERROR_ACCESS_DENIED(OSError)。当服务端因 3 秒握手超时、单连接互斥或异常帧先主动关闭连接而客户端 _dsh-ipc 尚未完成内核句柄回收时,第 90 行重建管道或第 79 行未捕获瞬断的 accept_pipe 抛出的 OSError 会使无人 await 的后台 accept() 任务静默终止,导致 Hub 此后永久无法接受 DSH Desktop 重连。
    • 修改建议:参考标准库 asyncio.windows_events.PipeServer,仅在首次创建监听管道时附带 FILE_FLAG_FIRST_PIPE_INSTANCE,将 nMaxInstances 设为 2(或 PIPE_UNLIMITED_INSTANCES),并在关闭旧连接句柄前先创建下一待命实例(保持相同的当前用户 SID DACL/Owner 与 PIPE_REJECT_REMOTE_CLIENTS);同时在 accept() 循环内捕获 accept_pipe 的 OSError 并安全关闭失效句柄后继续监听。
  2. 远程网关请求(remote_origin=True)在 Desktop 在线时会被路由至 DesktopAdapter,绕过子进程权限模式与 env.deny 隔离

    • 位置:src/agent_bridge/registry.py 第 934、984–1001 行(Registry.dispatch_task)及 src/agent_bridge/adapters/dsh_desktop.py 第 30–43 行
    • 触发条件与影响:当开启 [hub.remote] 并将 dsh 加入 remote_callable_agents(配置 DSH_PERMISSION_MODE = "workspace-write" 等)且本机 DSH Desktop 在线时,restricted_caller 虽阻断了基线读取,但第 934 行 desktop_connected 仍为 True,使远程任务以 backend="desktop" 直接在用户交互式 DSH Desktop 进程内运行,绕过了 config.agents["dsh"].env、config.env.deny 与 AGENT_BRIDGE_HUB=off 子进程隔离。
    • 修改建议:将 registry.py 第 934 行收紧为 desktop_connected = desktop_worker and not remote_origin and self.desktop.connected,确保 remote_origin=True 始终走受控子进程 AcpAdapter,并在 tests/test_remote.py 补充断言。
  3. DesktopAdapter.run_turn 处理 turn/end 错误事件时未防御空/非字典 error 字段,可能抛 AttributeError 或将失败回合误判为 completed

    • 位置:src/agent_bridge/adapters/dsh_desktop.py 第 108–117 行(DesktopAdapter.run_turn)
    • 触发条件与影响:第 117 行 reason.get("error", {}).get("message") 在 reason["error"] 为 None 或字符串时会抛 AttributeError;若返回 {"kind": "error"} 或空 message,TurnResult.error 为空,导致 Registry._run_task 落入成功分支将任务置为 TaskStatus.completed 并递增 session.turns,进而允许基于失败回合创建基线。
    • 修改建议:校验 isinstance(raw_error, dict) 提取消息,并在 stop == "error" 时提供非空兜底消息(如 "DeepSeek Harness Desktop turn failed")。
  4. Connector 对返回 undefined/null 的控制器方法省略或置空 value,触发 Python 端 invalid IPC frame 报错

    • 位置:dsh-desktop-connector/index.js 第 56–67 行与 src/agent_bridge/desktop_ipc.py 第 74–76 行
    • 触发条件与影响:当 controller.selectModel、cancel 或 rename 返回 undefined(Promise<void>)或 null 时,JSON.stringify 会省略 value 键或发出 "value": null,而 desktop_ipc.py 第 75 行要求 isinstance(value, dict),否则直接抛出 DesktopUnavailable("DeepSeek Harness Desktop sent an invalid IPC frame")。
    • 修改建议:在 dsh-desktop-connector/index.js 第 58 行将非对象返回值归一化为 value: (payload && typeof payload === 'object') ? payload : {},并在 dsh_desktop_fixture.mjs / test_dsh_desktop.py 补齐 selectModel、modelCatalog 与 cancel 测试。

2. 建议改进(边界条件 / 健壮性)

  • DesktopIPC.request 中 except OSError: 范围过大吞掉 TimeoutError(src/agent_bridge/desktop_ipc.py 第 79–88 行):Python 3.11+ 中 TimeoutError 继承自 OSError,将 yield read() 包在 except OSError: 内会把调用方等待快照或 prompt 的超时改写为 "request delivery could not be confirmed";建议仅对 peer.write / peer.drain 捕获 OSError。
  • 前置校验 Desktop provider/model 格式(adapters/dsh_desktop.py 第 44–52 行、registry.py 第 975–1006 行):建议在写入 session.model 及调用 ensure_session 真实创建/分叉会话之前校验 "/" in task.model,避免残留空会话并污染同一会话后续重试。
  • Unix 主目录符号链接兼容与错误帧诊断信息(desktop_ipc.py 第 112–132 行、dsh-desktop-connector/index.js 第 24–28、79–83 行):建议统一 Python stat() 与 Node lstat() 对符号链接 AGENT_BRIDGE_HOME 的处理,在 serve_desktop 降级日志与 Connector error 帧中附带脱敏后的具体错误原因。

3. 小细节(Nits)

  • create_baseline 同毫秒时间戳排序(src/agent_bridge/registry.py 第 797 行):Windows 时钟粒度下连续两轮可能共享同一 created_at,建议用 (task.created_at, idx) 取最后一条任务。
  • 文档与 CLI 帮助同步:建议在 HUB.zh-CN.md、src/agent_bridge/cli.py 的 HELP(--baseline / --fork-label)及 skills/agent-bridge/SKILL.md 中同步补齐新参数与工具说明。

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