mirror of
https://ghproxy.cflmy.top/https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-12-01 09:39:36 +08:00
fix(cua-windows): 关闭连接时异步观察 UIA 退订结果
This commit is contained in:
1 parent
b3514c6b60
commit
b82e359cff
6 files changed
+23
-34
No files matched your search
@@ -24,8 +24,8 @@
|
||||
en: ecef6c0abc5ba8f9
|
||||
zh: 892a30733d95ac27
|
||||
/deepseek-ai-dsh-cua-windows/interface-semantics/application-and-window-selection:
|
||||
en: c9a5a447a5464dfb
|
||||
zh: d4389cd8e2bebc30
|
||||
en: 9c6e301b03b14e73
|
||||
zh: 0d6e44ae6bda16e2
|
||||
/deepseek-ai-dsh-cua-windows/interaction-rules:
|
||||
en: f76e73e5ef38aced
|
||||
zh: ad00327ec3607e0f
|
||||
|
||||
@@ -45,7 +45,7 @@ Each result contains `id`, `displayName`, `identity: null`, and `isRunning`. The
|
||||
- `app.getWindows()` reads the application's current window list. One application can have multiple windows across multiple processes. Previously admitted HWNDs remain listed while valid, including hidden windows.
|
||||
- `app.getWindow(windowId)` returns a Window object without reading accessibility state. Pass the opaque window ID returned by the provider unchanged. Windows checks application ownership on first admission, then trusts the HWND while it remains valid.
|
||||
- `window.getAccessibilityTree()` explicitly reads accessibility state. Element IDs belong to the current observation; reading another window of the same App replaces the facade's current snapshot. Do not mix elements or snapshots across windows.
|
||||
- Pass `showDiff: true` on successive reads to receive UI Automation structure, property and text notifications for one window. The initial read and the first read after a cancellation return the observed tree. Changing the window or read options, or reaching a traversal limit, also returns the observed tree. Set `maxDiffNotifications` in the Windows provider configuration to limit distinct (event type, RuntimeId) pairs per read interval (default 50). When the count exceeds the limit or the nonempty summary reaches the current tree’s UTF-8 byte count, the first line reads `Diff too large. Showing the current tree instead.`, followed by the current tree within the requested traversal limits. A notification names the current element when available. A removal can identify a previous element. Providers can omit changes or report a whole container. Omit the option or pass `false` to read the current tree and stop listening.
|
||||
- Pass `showDiff: true` on successive reads to receive UI Automation structure, property and text notifications for one window. The initial read and the first read after a cancellation return the observed tree. Changing the window or read options, or reaching a traversal limit, also returns the observed tree. Set `maxDiffNotifications` in the Windows provider configuration to limit distinct (event type, RuntimeId) pairs per read interval (default 50). When the count exceeds the limit or the nonempty summary reaches the current tree’s UTF-8 byte count, the first line reads `Diff too large. Showing the current tree instead.`, followed by the current tree within the requested traversal limits. A notification names the current element when available. A removal can identify a previous element. Providers can omit changes or report a whole container. Omit the option or pass `false` to read the current tree and stop listening. The helper can acknowledge connection close while unsubscription is queued on the UIA thread. It logs one diagnostic if removal fails.
|
||||
- Use `getActionSchema(action)` to query an action's parameter JSON Schema.
|
||||
- `window.getScreenshot()` captures that explicit window and does not read or replace its accessibility tree. Screenshots can remain usable when an accessibility read fails.
|
||||
- `app.launch()` requests a new application instance and waits for the selected application's HWND set to change or the launch wait limit to expire. A single-instance program may only activate its existing instance, and a launched instance may belong to another application ID.
|
||||
|
||||
@@ -45,7 +45,7 @@ kind: "package-reference"
|
||||
- `app.getWindows()` 读取应用当前的窗口列表。一个应用可以跨多个进程拥有多个窗口。已接纳的 HWND 在有效期间保留在列表中,包括隐藏窗口。
|
||||
- `app.getWindow(windowId)` 返回 Window 对象,不读取辅助功能树。窗口 ID 是提供方返回的不透明字符串,请原样传递。Windows 首次接纳窗口时检查应用归属,此后只要 HWND 有效就信任它。
|
||||
- `window.getAccessibilityTree()` 显式读取辅助功能树。元素 ID 属于当前观察;读取同一 App 的另一个窗口会替换门面当前使用的快照。不要跨窗口混用元素或快照。
|
||||
- 连续读取同一窗口时传入 `showDiff: true`,可查看 UI Automation 的结构、属性和文本通知。首次读取、取消读取后的下一次观察、更换窗口或读取选项、树被截断时,返回本次读到的树。Windows 提供方配置 `maxDiffNotifications` 限制两次读取之间的通知条数,默认 50 条,相同事件类型和 RuntimeId 只计一次。超过条数上限,或非空摘要的 UTF-8 字节数达到当前树的大小时,首行显示 `Diff too large. Showing the current tree instead.`,下一行起返回本次读取范围内的树。能定位到当前元素的通知会附上元素信息,删除通知可能带有旧元素的 ID。控件可能漏报变化,也可能只报告整个容器。省略该参数或传 `false` 可读取当前树并停止监听。
|
||||
- 连续读取同一窗口时传入 `showDiff: true`,可查看 UI Automation 的结构、属性和文本通知。首次读取、取消读取后的下一次观察、更换窗口或读取选项、树被截断时,返回本次读到的树。Windows 提供方配置 `maxDiffNotifications` 限制两次读取之间的通知条数,默认 50 条,相同事件类型和 RuntimeId 只计一次。超过条数上限,或非空摘要的 UTF-8 字节数达到当前树的大小时,首行显示 `Diff too large. Showing the current tree instead.`,下一行起返回本次读取范围内的树。能定位到当前元素的通知会附上元素信息,删除通知可能带有旧元素的 ID。控件可能漏报变化,也可能只报告整个容器。省略该参数或传 `false` 可读取当前树并停止监听。关闭连接时,退订仍在 UIA 线程上排队也能收到关闭应答。退订抛错时,helper 记录一次诊断。
|
||||
- 通过 `getActionSchema(action)` 查询动作的参数 JSON Schema。
|
||||
- `window.getScreenshot()` 截取明确指定的窗口,不读取或替换辅助功能树。辅助功能读取失败时,截图仍可能可用。
|
||||
- `app.launch()` 请求启动应用的新实例,等待所选应用的 HWND 集合变化或启动等待时限到达。单例程序可能仅激活已有实例,启动的实例也可能归属于另一个应用 ID。
|
||||
|
||||
@@ -300,8 +300,7 @@ internal sealed class DesktopExecutor(MtaDispatcher mta, StaDispatcher sta) : IA
|
||||
if (state.Notifications is { } notifications)
|
||||
{
|
||||
var removal = mta.Invoke(() => { notifications.Stop(); return true; }, CancellationToken.None);
|
||||
await NotificationCleanup.WaitForDisconnect(removal, TimeSpan.FromMilliseconds(graceMs),
|
||||
error => NativeServer.Report("NATIVE_CLEANUP", error));
|
||||
_ = NotificationCleanup.ObserveRemovalAsync(removal, error => NativeServer.Report("NATIVE_CLEANUP", error));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
// Disconnect bounds the acknowledgement wait. The MTA still owns any pending unsubscription.
|
||||
// The MTA owns the unsubscription after its connection closes.
|
||||
namespace DeepSeek.Cua.Windows;
|
||||
|
||||
internal static class NotificationCleanup
|
||||
{
|
||||
internal static async Task WaitForDisconnect(Task removal, TimeSpan grace, Action<Exception> report)
|
||||
internal static async Task ObserveRemovalAsync(Task removal, Action<Exception> report)
|
||||
{
|
||||
async Task ObserveRemoval()
|
||||
{
|
||||
try { await removal; }
|
||||
catch (Exception error) { report(error); }
|
||||
}
|
||||
|
||||
try { await ObserveRemoval().WaitAsync(grace); }
|
||||
catch (TimeoutException error) { report(error); }
|
||||
try { await removal; }
|
||||
catch (Exception error) { report(error); }
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,23 @@
|
||||
// A stalled MTA must not prevent an explicit close, even if removal later fails.
|
||||
// A queued UIA unsubscription reports only faults from the removal itself.
|
||||
using DeepSeek.Cua.Windows;
|
||||
|
||||
internal static class NotificationCleanupChecks
|
||||
{
|
||||
internal static async Task Run(Action<bool, string> check)
|
||||
{
|
||||
var failure = new AggregateException("UIA refused to remove a handler");
|
||||
Exception? reported = null;
|
||||
await NotificationCleanup.WaitForDisconnect(Task.CompletedTask, TimeSpan.Zero, error => reported = error);
|
||||
check(reported == null, "Completed unsubscription permits close without a diagnostic");
|
||||
await NotificationCleanup.WaitForDisconnect(Task.FromException(failure), TimeSpan.Zero, error => reported = error);
|
||||
check(reported == failure, "Failed unsubscription permits close and reports the failure");
|
||||
|
||||
var queued = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var lateFailure = new TaskCompletionSource<Exception>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var timeout = false;
|
||||
await NotificationCleanup.WaitForDisconnect(queued.Task, TimeSpan.Zero, error =>
|
||||
foreach (var fails in new[] { false, true })
|
||||
{
|
||||
if (error is TimeoutException) timeout = true;
|
||||
else lateFailure.TrySetResult(error);
|
||||
});
|
||||
check(timeout && !queued.Task.IsCompleted, "Close can proceed while unsubscription remains queued");
|
||||
queued.SetException(failure);
|
||||
check(await lateFailure.Task.WaitAsync(TimeSpan.FromSeconds(5)) == failure, "Late unsubscription faults are observed");
|
||||
var removal = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var diagnostics = new List<Exception>();
|
||||
var observation = NotificationCleanup.ObserveRemovalAsync(removal.Task, diagnostics.Add);
|
||||
check(!observation.IsCompleted && diagnostics.Count == 0, "Queued unsubscription has no diagnostic");
|
||||
|
||||
var failure = new AggregateException("UIA refused to remove a handler");
|
||||
if (fails) removal.SetException(failure);
|
||||
else removal.SetResult();
|
||||
await observation;
|
||||
if (fails) check(diagnostics.SequenceEqual([failure]), "Failed unsubscription reports its error exactly once");
|
||||
else check(diagnostics.Count == 0, "Successful unsubscription completes quietly");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user