Repository navigation
Conversation
There was a problem hiding this comment.
Devin Review found 4 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| return TurnResult(text="".join(text_parts), stop_reason=stop, | ||
| native_session_id=native_id, observed_model=task.model, | ||
| observed_effort=task.effort, | ||
| error=reason.get("error", {}).get("message") if stop == "error" else None) |
There was a problem hiding this comment.
🔴 Failed Desktop turns reported as successful
When turn/end reports an error without reason.error.message, TurnResult.error stays empty. The registry marks that turn completed and permits a baseline from failed work.
Learn more
A Desktop turn reports its outcome in turn/end.data.reason. The adapter passes the error message only when it appears at reason.error.message. If Desktop reports kind: error without that nested field, Registry._run_task treats the returned turn as completed because its error is null. The completed status also passes create_baseline, so a failed turn can be saved as a fork point.
Example: For reason={"kind":"error"}, the adapter returns stop_reason="error", error=None; the task becomes completed instead of failed.
Recommended fix: Always set a nonempty error for an error-kind Desktop turn, falling back to the reason kind when no message is available. Add a test for an error reason without a nested message.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if kind == "user/message" and data.get("source", {}).get("rpcId") == request_id: | ||
| active_turn = latest_turn |
There was a problem hiding this comment.
🔴 Queued prompts capture another Desktop turn
When session.prompt queues behind an active turn, its user/message can arrive before its turn/start. active_turn then tracks the other turn, returning its answer instead of Bridge's.
Learn more
The adapter subscribes to events before sending its prompt in queue mode. It identifies its own user message by requestId, but stores the most recent turn/start number as its turn. If a separate Desktop actor is already working, a queued user message can be emitted while the earlier turn is still running. The adapter then accepts the earlier turn's assistant output and exits at its turn/end.
Example: Desktop turn 7 is active. Bridge queues a prompt and receives its user/message before turn 8 starts; latest_turn=7 makes the adapter return turn 7's response as its own.
Recommended fix: Match the queued prompt to the turn in which it actually executes, using an explicit turn identifier in the event or waiting for the next matching turn/start after the queued message; test a busy Desktop session with interleaved events.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if kind == "assistant/message": | ||
| text_parts.append(_message_text(event)) |
There was a problem hiding this comment.
🟡 Desktop transcripts omit assistant output
During Desktop turns, assistant/message text only reaches text_parts, never the session transcript. get_transcript and live activity show no worker output, even when the final result contains it.
Learn more
The Desktop follow stream carries assistant messages during the turn. The adapter collects those messages into its eventual TurnResult, but only writes prompt_sent and turn_end to the transcript. get_transcript reads just those recorded events, and recent_activity cannot show the assistant's progress.
Example: A Desktop agent sends three assistant messages over five minutes; the final result contains all three, but transcript polling during the turn shows only the prompt.
Recommended fix: Append assistant messages and other relevant follow events as transcript entries when processed; preserve incremental text semantics if Desktop emits revisions rather than full messages.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if path.exists(): | ||
| raise FileExistsError(f"baseline {baseline_id} already exists") | ||
| atomic_write_json(path, record.model_dump(mode="json")) |
There was a problem hiding this comment.
🟡 Concurrent writes overwrite saved baselines
When two Bridge instances add the same baseline ID, both can pass path.exists() before either write. The second atomic_write_json replaces the first record, changing that ID's fork source.
Learn more
The baseline store exposes immutable records by ID. The existence check and the write are separate operations, while atomic_write_json ultimately uses os.replace to overwrite a destination. Separate Bridge instances share the same home and do not share the registry lock, so a colliding ID can overwrite an already accepted baseline.
Example: Two instances both choose base_same; each sees no file. Instance A writes source A, then B replaces it with source B; calls using A's returned ID now fork B.
Recommended fix: Publish records with an atomic no-replace operation, such as writing a unique temporary file and hard-linking it to the final path, treating an existing destination as FileExistsError.
Was this helpful? React with 👍 or 👎 to provide feedback.
A forked DSH session replays its whole history in the first follow snapshot. With the websockets default max_size of 1 MiB, a long fork (observed 1.39 MB) was closed with 1009 and surfaced as "DeepSeek Harness Desktop disconnected during turn" before the turn started. Connect with max_size=None and assert it in the Desktop turn test. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
klarkxy
left a comment
There was a problem hiding this comment.
Reviewed via Gemini App · Model: Gemini · Commit:
50aca1dc87acd706ce7bbe1f95cd5be3c6e63b3b
整体评估
本 PR 探索了通过 DSH Desktop sessionController 实现命名基线分叉(create_baseline / fork_label)以支持多并行子任务共享前置调研上下文的完整工作流。不过自基线 823e77a2 以来,main 已合入中心 Hub 重构 #42(20a0882a)及严格的零明文凭证落盘规范,且关联移植 PR #48 已在保留原作者署名的基础上将该能力迁移至中心 Hub + 同用户私有本地 IPC(消除了明文 dsh-desktop.json 凭证交接)。建议直接由 #48 替代并关闭本 PR,同时将下方核验出的共性状态机与参数校验问题同步收敛至 #48。
1. 建议修复(安全阻断与核心状态机缺陷)
-
明文
authenticatedUrl落盘、异常链日志泄密与 WebSocket 环境代理旁路(已由 #48 架构消除)- 位置:
src/agent_bridge/adapters/dsh_desktop.py:24-42, 52-70, 170-172 - 触发场景:外部连接器将带
?token=<secret>的登录 URL 明文写入~/.agent-bridge/dsh-desktop.json(Windows 下无单用户 DACL 隔离且宿主崩溃后长期残留);当client.get(auth_url)网络异常执行raise DesktopUnavailable(...) from exc时,httpx.RequestError消息中的完整?token=...会经外层log.exception写入磁盘日志;此外websockets.connect未传proxy=None,在自定义代理环境下存在将回环会话Cookie发往外部代理的风险。
- 位置:
-
回合错误兜底缺失与
mode: "queue"回合归属错绑(同样存在于#48,建议同步修复)- 位置:
src/agent_bridge/adapters/dsh_desktop.py:182-218(印证并扩展已有讨论#discussion_r4109675028、#discussion_r4109675077) - 触发场景:
- (a)
turn/end收到{"kind": "error"}但缺少嵌套error.message时TurnResult.error为None,任务被误判为completed(甚至允许create_baseline将失败现场固化为基线);若reason["error"]为非字典值还会直接抛AttributeError; - (b)
user/message到达时直接令active_turn = latest_turn:若 Desktop 会话中已有其他进行中回合会串台窃取他人结果,若user/message早于对应turn/start到达(latest_turn为None)则会使active_turn永远停在None直至超时挂死。
- (a)
- 具体修改建议:对一切非
completed/end_turn/cancelled的结束原因强制生成非空兜底错误信息并对reason/error做isinstance(..., dict)守卫;在发提示词前拒绝抢占忙碌会话(或基于消息事件精确关联紧随其后的专属turn/start)。
- 位置:
-
create_baseline期间并发调用list_sessions或基线文件缺失时触发未捕获KeyError崩溃(#48已修复)- 位置:
src/agent_bridge/registry.py:576-587, 1122-1123, 1265-1267 - 触发场景:
create_baseline先将带baseline_id的child写入self.sessions,随后await adapter.ensure_session(child)挂起等待远端 RPC,最后才调用self.baselines.add(record);挂起期间任何不持锁的list_sessions()读取self.baselines.get(session.baseline_id).name必抛KeyError。
- 位置:
-
DesktopAdapter.cancel未捕获 RPCRuntimeError、effort="medium"未经dsh_effort()映射及task.model滞后校验污染会话(建议同步核查#48)- 位置:
src/agent_bridge/adapters/dsh_desktop.py:89-91, 143-158, 222-225、src/agent_bridge/registry.py:692-729 - 触发场景:(a) 回合刚结束时调用
cancel_task使session/cancel返回业务错误抛RuntimeError,DesktopAdapter.cancel仅捕获DesktopUnavailable,导致Registry.cancel_task中断;(b)run_turn未调用models.dsh_effort(task.effort)将标准档位"medium"映射为 DSH 支持的"high",且仅传effort时对空的modelCatalog["default"]未做空值防御;(c) 不含/的裸模型名在ensure_session远端建好会话后才校验抛错,并永久污染持久化的session.model。
- 位置:
2. 建议改进(锁粒度与存储原子性)
- 缩小
create_baseline持有全局Registry._lock的范围(src/agent_bridge/registry.py:545-600):避免在全局锁内执行fork/rename远端 RPC 阻塞其他无关 Worker 派发;BaselineStore.add(src/agent_bridge/baselines.py:138-141,#discussion_r4109675163)可改用排他创建模式防止覆盖。
DeepSeek Harness Desktop exposes Session Controller session creation, prompting, and forking, but Agent Bridge previously sent DSH work only through ACP. Parallel tasks therefore could not start from a shared, named investigation point. This change connects Bridge to the official Desktop Host through the separately published Desktop connector and routes new DSH sessions through
session.create/fork,prompt, andfollow.After a completed investigation,
create_baseline(session_id, name)saves an immutable fork point. A project can select it as the default or pass its ID todispatch_task;fork_labelidentifies each child. When Desktop is disconnected, new ordinary DSH tasks use the existing ACP adapter, while baseline forks fail explicitly. Existing sessions stay on the backend where they were created. No DeepSeek Harness core patch is required.Validation:
prompt/followAPI. No files changed.ruff check src testspassed.pytest -q -k 'not test_probe_agent_resolves_command_off_loop': 582 passed, 1 deselected. The excluded existing Windows timer test failed twice because it observed 9 ticks against a threshold of 10; it is unrelated to this change.npm test: 2 passed.