Skip to content

Use official DSH Desktop sessions for named baseline forks - #23

Open
renjieah wants to merge 2 commits into
Fei-Craft:mainfrom
renjieah:codex/desktop-baseline-fork
Open

renjieah wants to merge 2 commits into
Fei-Craft:mainfrom
renjieah:codex/desktop-baseline-fork

Conversation

@renjieah

@renjieah renjieah commented Sep 26, 2026 •

Copy link
Copy Markdown

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, and follow.

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 to dispatch_task; fork_label identifies 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:

  • Live DSH Desktop 0.1.7-rc.2 smoke test: created a session, saved a baseline, forked a labeled child, and confirmed that the child inherited the earlier answer through the official prompt/follow API. No files changed.
  • ruff check src tests passed.
  • 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.
  • Connector npm test: 2 passed.

Devin Review

@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 found 4 potential issues.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

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)

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.

🔴 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +198 to +199
if kind == "user/message" and data.get("source", {}).get("rpcId") == request_id:
active_turn = latest_turn

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.

🔴 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +203 to +204
if kind == "assistant/message":
text_parts.append(_message_text(event))

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.

🟡 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +139 to +141
if path.exists():
raise FileExistsError(f"baseline {baseline_id} already exists")
atomic_write_json(path, record.model_dump(mode="json"))

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.

🟡 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.

Devin Review


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 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: 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. 建议修复(安全阻断与核心状态机缺陷)

  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 发往外部代理的风险。
  2. 回合错误兜底缺失与 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 直至超时挂死。
    • 具体修改建议:对一切非 completed/end_turn/cancelled 的结束原因强制生成非空兜底错误信息并对 reason/error 做 isinstance(..., dict) 守卫;在发提示词前拒绝抢占忙碌会话(或基于消息事件精确关联紧随其后的专属 turn/start)。
  3. 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。
  4. DesktopAdapter.cancel 未捕获 RPC RuntimeError、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. 建议改进(锁粒度与存储原子性)

  1. 缩小 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)可改用排他创建模式防止覆盖。

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