Skip to content

fix(browser): 修复 DSH 0.2.2 下 browser_read 和 browser_act 一律失败 - #367

Merged
freedomkk-qfeng merged 2 commits into
ECNU:mainfrom
JunieXD:fix/browser-tools-dsh-022
Nov 26, 2026
Merged

freedomkk-qfeng merged 2 commits into
ECNU:mainfrom
JunieXD:fix/browser-tools-dsh-022

Conversation

@JunieXD

@JunieXD JunieXD commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

问题

桌面版里,Agent 调用 browser_read、browser_act 时一律返回 “Error: Tool batch execution failed”,网页既读不到,也没法操作。

根因:#250 合入时 DSH 还是 0.2.1,它的 runner 用 ctx.tools.execute({ callId, name, arguments, agent, parent, signal }) 逐个派发 Playwright MCP 调用。同一天 #276 把 DSH 升级到 0.2.2,之后 ctx.tools.execute 只接受模型批次 { calls, signal, agent, toolSet },但 runner 没有跟着改。执行器读取 calls.map 时抛出 TypeError,再被包装成上面的错误。插件测试用的是手写的 ctx.tools.execute 替身,read-act.test.mjs 也不在 CI 里,所以一直没有发现。

修改

  • runner 改用 @deepseek-ai/dsh-tools/pipeline 的 ToolExecutionPipeline,对每个调用依次执行 prepare、dispatch、complete。DSH 自己的 tool-executor-ptc 派发程序化调用也是这样做的。
    • 子调用带上这次运行的根调用 ID、Agent、步骤工具集和取消信号,并以这次运行的 token 作为 parent。
    • 浏览器权限因此仍能认出运行自己发起的调用:运行开始前问过一次以后,子调用不再询问。
  • 按 DSH 对组合工具的约定,钩子(例如 PostToolUse)附加给子调用的上下文转交到运行的结果里;子调用结束本轮时,运行也结束本轮。
  • 不保留 0.2.1 的兼容分支,因为产品锁定的是 0.2.2-rc.3。

测试

  • read-act.test.mjs 改为在锁定 Runtime 的真实 DSH 注册表、native 执行器和 pipeline 里运行,只有 Playwright MCP 的工具是替身。测试像插件的 apply 一样装上 guard、权限和截图说明。新增的检查:
    • 每个 MCP 调用都挂在这次运行的调用树下(parent、根调用、Agent 都对得上);
    • 一次运行只询问一次,用户拒绝时不执行;
    • 条件注册的工具只有经步骤工具集才找得到;
    • 中途停止后不再派发调用;
    • 钩子附加的上下文到达批次结果,失败的子调用也一样。
  • CI:validate-pinned-dsh-source.yml 的侧栏浏览器那一步,在 sidebar.test.mjs 之外加跑 read-act.test.mjs。这一步已经设置了 EDUWORK_TEST_RUNTIME。
  • source-receipt.json:这个测试文件原有一条合成内网地址的审查记录,只更新了其中的哈希。

验证

  • 本地环境为 Node 24.22.1,锁定 Runtime 中的 DSH 为 0.2.2-rc.3:
    • read-act.test.mjs 13/13 通过;按 CI 的写法跑 17/17 通过;
    • plugin-locale.test.mjs 5/5 通过,permission.test.mjs 3/3 通过。
  • 反向验证:
    • 换回 main 的 runner,11 项失败,报错与产品里相同(“Tool batch execution failed”);
    • 分别去掉 toolSet、去掉 parent、改错根调用 ID,各有 11 项失败;
    • 分别改用独立的取消信号、不转交上下文、让权限认不出运行的 token,各有对应的 1 项失败。
  • 在 macOS 本地构建的候选包上用真实产品加模拟模型测试。候选包从 侧栏浏览器:清除浏览数据(用户与 Agent) #359 的分支构建,其中的这个修复与本 PR 相同:
    • browser_read 返回带编号的网页;
    • browser_act 先输入文字再点链接,返回新网页;
    • 连续读本机地址时只弹一次“允许一次”;
    • 截图带文件名时,模型收到完整路径的说明。

…0.2.2 tool pipeline

Since the upgrade to DSH 0.2.2 (ECNU#276), ctx.tools.execute takes only a model
batch ({ calls, signal, agent, toolSet }). The runner behind browser_read and
browser_act still passed one call ({ callId, name, arguments, parent }), so
every page read or action in the desktop app failed with "Tool batch
execution failed". The plugin's test replaced ctx.tools.execute with a
hand-written stand-in and was not in CI, so it kept passing.

The runner now prepares, dispatches and completes each Playwright MCP call
through ToolExecutionPipeline, as DSH's program tool calls do
(tool-executor-ptc): under the run's root call, Agent, step tool set, signal
and token as parent, so the browser permission still lets the run's own
calls through without asking again. Context that hooks add to those calls is
deferred to the run's result, and a call that concludes the turn concludes
it.

read-act.test.mjs now runs the tools in DSH's real registry, executor and
pipeline from the pinned Runtime, with only Playwright MCP's tools as
stand-ins, and installs the plugin's guard, permission and screenshot note as
its apply does. It checks each MCP call's place in the run's call tree, one
approval per run, a rejected run not running, step admission, stopping a
run, and hook context reaching the batch. CI runs it next to the Sidebar
launch test.
@freedomkk-qfeng
freedomkk-qfeng merged commit 2e3b13e into ECNU:main Nov 26, 2026
14 checks passed
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