From d602624eb369d2f8d525bbab42d943ee671afb0d Mon Sep 17 00:00:00 2001 From: turtle1999 Date: Tue, 10 Nov 2026 11:11:58 +0800 Subject: [PATCH] refactor(cua): isolate raw registration and simplify initialization --- .../2026-11-09-cua-program-tool.i18n.yaml | 4 +- .../2026-11-09-cua-program-tool.md | 2 +- .../2026-11-09-cua-program-tool.zh.md | 2 +- packages/experimental/cua/README.i18n.yaml | 8 +- packages/experimental/cua/README.md | 4 +- packages/experimental/cua/README.zh.md | 4 +- .../experimental/cua/src/tool-registration.ts | 164 ++++++++------ .../cua/tests/agent-scopes.spec.ts | 208 +++++++++++++++++- .../ptc-runtime-node/README.i18n.yaml | 4 +- .../ptc-runtime/ptc-runtime-node/README.md | 2 +- .../ptc-runtime/ptc-runtime-node/README.zh.md | 2 +- .../ptc-runtime-node/src/process.ts | 52 +++-- .../tests/initialization.spec.ts | 2 + .../tests/persistent-process.spec.ts | 35 +++ 14 files changed, 383 insertions(+), 110 deletions(-) diff --git a/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.i18n.yaml b/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.i18n.yaml index 92a7e60bb6..9335972062 100644 --- a/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.i18n.yaml +++ b/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.i18n.yaml @@ -9,8 +9,8 @@ en: 87ce83e36a6ab68e zh: 8aa98dc7dae03c41 /agent-note-cua-programs-outside-the-ptc-preset/decision: - en: 9e6fca5bca1982c2 - zh: bf2d703707f12806 + en: 98e4a571dc7d4c10 + zh: 2465f2abff5eb64c /agent-note-cua-programs-outside-the-ptc-preset/alternatives-considered: en: b5d8e00cbe4b53ae zh: 4ef81611150a8d75 diff --git a/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.md b/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.md index d2a5a91bcd..0e7e4c2cde 100644 --- a/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.md +++ b/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.md @@ -10,7 +10,7 @@ Computer Use needs reusable application and window objects in Standard and other ## Decision -CUA keeps `agentPreset: ptc` as the default selector for its raw `cua` tool. Every other composed preset receives `cua_run_code`; Agents without a composed preset receive neither tool. `agentPreset: false` retains global raw-tool registration. Agent scopes own registration and disposal, so enabling and disabling the provider affects existing and later Agents without editing presets. +CUA keeps `agentPreset: ptc` as the default selector for its raw `cua` tool. Every other composed preset receives `cua_run_code`; Agents without a composed preset receive neither tool. `agentPreset: false` retains global raw-tool registration. A base owner uses Agent scopes for registration and disposal, so enabling and disabling the provider affects existing and later Agents without editing presets. Raw registration depends only on base CUA services and preset selection. The private program producer publishes and withdraws its definition by identity; private dependency loss or startup failure leaves raw tools and prompts available. `cua_run_code` composes the shared [program-tool factory](../../../../packages/core/tool-executor-ptc/README.md) with one isolated Node `persistent-in-memory` runtime owned by the CUA provider. Agent `stateOwner` identities select separate retained processes. Its only binding is the private `tools.cua` definition; the model calls ordinary session tools directly. Nested CUA operations retain tool policy, guards, dispatch events, and image admission. The provider releases held keys when either program tool settles. Provider unload drains its own CUA programs before native teardown; releasing input held by other PTC programs does not wait for their unrelated work. State is in memory, separate from the profile's PTC state, and released with its Agent or provider. diff --git a/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.zh.md b/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.zh.md index c30cb0830e..d39f5cde8f 100644 --- a/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.zh.md +++ b/.agents/notes/implemented/architecture/2026-11-09-cua-program-tool.zh.md @@ -10,7 +10,7 @@ Computer Use 需要在标准及其他 preset 中复用应用和窗口对象, ## 决策 -CUA 保留 `agentPreset: ptc`,用默认选择器指定获得原始 `cua` 工具的 preset。其他已组合的 preset 获得 `cua_run_code`;未组合 preset 的 agent(智能体)不获得这两个工具。`agentPreset: false` 保留全局原始工具注册。注册和销毁由 Agent 作用域负责,因此启停提供方会影响已有和后续 Agent,无需修改 preset。 +CUA 保留 `agentPreset: ptc`,用默认选择器指定获得原始 `cua` 工具的 preset。其他已组合的 preset 获得 `cua_run_code`;未组合 preset 的 agent(智能体)不获得这两个工具。`agentPreset: false` 保留全局原始工具注册。基础注册的所有者通过 Agent 作用域管理注册和销毁,因此启停提供方会影响已有和后续 Agent,无需修改 preset。原始工具的注册只依赖基础 CUA 服务和 preset 选择。私有程序工具的提供方按定义对象的身份发布和撤回其定义;私有依赖缺失或启动失败时,原始工具和提示词仍然可用。 `cua_run_code` 将共享[程序工具工厂](../../../../packages/core/tool-executor-ptc/README.zh.md)与 CUA 提供方持有的单个隔离 Node `persistent-in-memory` 运行时组合。Agent 的 `stateOwner` 身份选择各自独立的保留进程。它只绑定私有 `tools.cua` 定义;模型直接调用其他普通会话工具。嵌套 CUA 操作保留工具策略、guard、派发事件和图像接纳。任一程序工具结束时,提供方都会释放该程序仍按住的键。提供方卸载时,先等待自己持有的 CUA 程序结束再清理原生资源;释放其他 PTC 程序持有的输入时,不等待这些程序中的其他工作。状态保存在内存中,独立于 profile 的 PTC 状态,随所属 Agent 或提供方释放。 diff --git a/packages/experimental/cua/README.i18n.yaml b/packages/experimental/cua/README.i18n.yaml index a90f6b5b9a..f03b1c98d7 100644 --- a/packages/experimental/cua/README.i18n.yaml +++ b/packages/experimental/cua/README.i18n.yaml @@ -15,14 +15,14 @@ en: 5db4d4fea25493b9 zh: 65ab64fc24eb0d09 /deepseek-ai-dsh-cua/use-this-package: - en: e7f5b362465349cf - zh: 178c9550cdc0be5e + en: 8ca39a733b479dd3 + zh: 582c86bd18ef56fd /deepseek-ai-dsh-cua/use-this-package/permission-controls: en: 8941f2139fd1ca3a zh: 4c8fb953d821eaf1 /deepseek-ai-dsh-cua/understand-the-implementation: - en: 297d5ed174a9dd1d - zh: 543054b2e8b263e5 + en: d4393c136eba0fc6 + zh: 2f627de9d9c8fab4 /deepseek-ai-dsh-cua/further-exploration: en: c174fb5a00ea3681 zh: 039340042676881d diff --git a/packages/experimental/cua/README.md b/packages/experimental/cua/README.md index 7cb091d0eb..b5f190f7b0 100644 --- a/packages/experimental/cua/README.md +++ b/packages/experimental/cua/README.md @@ -35,7 +35,7 @@ Mount the [macOS provider](../cua-macos/README.md) to enable native operations o Configure runtime resources and launch settings through the provider's `standaloneRunCode.runtime` and program call limits through `standaloneRunCode.executor`. Runtime execution is fixed to `persistent-in-memory`; setting `executionMode` or `scriptPersistence` there is rejected. These settings do not change the profile's shared PTC runtime. -When `agentPreset` names a preset, registration of both tool forms waits for the dedicated Node runtime and its required services, including raw `cua` for the matching preset. Invalid `standaloneRunCode.runtime` settings or missing services can block Agent creation. Correct the configuration or supply the missing services and reload the provider; alternatively, disable Computer Use and retry creating the Agent. `agentPreset: false` registers raw `cua` without creating this runtime. +Raw `cua` registration uses the base CUA services and preset selection, independently of the private Node runtime and program-only `workingDirectory` dependency. Other presets receive `cua_run_code` only while its program services are available. Only program-mode Agent creation awaits private startup and reports its failures. Correct invalid settings and explicitly reload a failed plugin; restoring a missing dependency resumes a pending plugin. `agentPreset: false` registers raw `cua` globally without creating the private runtime. `cua` is installed once when its environment is created. Do not overwrite this global. To rebuild a damaged environment, run `process.exit(0)` in `cua_run_code`; that call reports a process-exit failure. The next call starts a fresh environment and restores `cua`. Recreate other variables and select applications and windows again. @@ -99,7 +99,7 @@ Providers register connection-owned resource cleanup with `NativeClient.register Graceful connection closure waits for registered cleanup. Native cleanup refusal or expiry invalidates the connection and its handles; cleanup failures remain visible while connection disposal proceeds. Ordinary native-request timeouts still request cancellation and wait for acknowledgement within `graceMs`. Provider unload drains its owned CUA programs; PTC programs using raw `cua` may continue unrelated work after their held input is released. -`agentPreset` defaults to `ptc`: matching Agents receive the raw `cua` tool and PTC guidance; every other composed preset receives only `cua_run_code` and its guidance. This includes Standard, Creator, Minimal, and custom presets. Registration uses `agent/created`, `agent-preset/selected`, and Agent-owned scopes, including Agents already present when the provider loads. Agent disposal removes its registrations and releases its retained environment. Provider unload also disposes the dedicated CUA runtime. Agents without a composed preset receive neither tool. Set `agentPreset: false` to register the raw `cua` tool globally in standalone compositions. The Host owns permissions, native connections, and cancellation; preset definitions remain unchanged. +`agentPreset` defaults to `ptc`: matching Agents receive the raw `cua` tool and PTC guidance; every other composed preset receives only `cua_run_code` and its guidance. This includes Standard, Creator, Minimal, and custom presets. A base owner uses `agent/created`, `agent-preset/selected`, and Agent-owned scopes, including Agents already present when the provider loads. It replaces each tool and prompt pair synchronously by definition identity; unavailable program services withdraw only the program definition, leaving raw registrations intact. Agent disposal removes its registrations and releases its retained environment. Provider unload also disposes the dedicated CUA runtime. Agents without a composed preset receive neither tool. Set `agentPreset: false` to register the raw `cua` tool globally in standalone compositions. The Host owns permissions, native connections, and cancellation; preset definitions remain unchanged. `cua_run_code` reuses the PTC program-tool factory with one isolated Node runtime owned by the CUA provider. Each Agent has a separate retained process selected by its `stateOwner`. CUA registers an environment initializer on that runtime; it installs `cua` once per new process, including temporary escalated runs. Its owner depends only on the runtime and retains the registration while program-tool dependencies reload. Program tools are disposed and drained before the initializer unregisters and the runtime closes. The factory binds only the private `cua` operation tool and preserves nested policy checks, guards, logs, cancellation, and screenshot delivery. The private tool is absent from the model's direct tool list. diff --git a/packages/experimental/cua/README.zh.md b/packages/experimental/cua/README.zh.md index 6f700331f3..1508e0d69d 100644 --- a/packages/experimental/cua/README.zh.md +++ b/packages/experimental/cua/README.zh.md @@ -35,7 +35,7 @@ kind: "package-reference" 通过提供方的 `standaloneRunCode.runtime` 配置运行时资源和启动设置,通过 `standaloneRunCode.executor` 配置程序调用上限。运行时固定使用 `persistent-in-memory`,在其中设置 `executionMode` 或 `scriptPersistence` 会被拒绝。这些设置不改变 profile 的共享 PTC 运行时。 -当 `agentPreset` 指定 preset 名称时,两种工具形态的注册都等待专用 Node 运行时及其所需服务,包括匹配 preset 的原始 `cua` 工具。无效的 `standaloneRunCode.runtime` 设置或缺少服务可能阻止 Agent 创建。修正配置或补齐服务后重载提供方;也可以先关闭 Computer Use,再重试创建 Agent。`agentPreset: false` 注册原始 `cua`,不创建该运行时。 +原始 `cua` 的注册使用基础 CUA 服务和 preset 选择,不依赖私有 Node 运行时,也不依赖仅供程序工具使用的 `workingDirectory`。其他 preset 仅在程序工具所需服务可用时获得 `cua_run_code`。只有创建使用程序形态的 Agent 时,才会等待私有运行时启动并报告其失败。修正无效设置后,显式重载已失败的插件;补齐缺失依赖会使等待中的插件继续启动。`agentPreset: false` 全局注册原始 `cua`,不创建私有运行时。 `cua` 在创建环境时安装一次。不要覆盖这个全局对象。需要重建损坏的环境时,在 `cua_run_code` 中执行 `process.exit(0)`;该次工具调用会因进程退出而返回失败。下一次调用启动新环境并恢复 `cua`。请重新创建其他变量,并重新选择应用和窗口。 @@ -99,7 +99,7 @@ Computer Use 详情页的权限卡片、组件列表和来源信息使用 l3 边 正常关闭连接会等待已注册的清理结束。原生清理被拒绝或超时会使连接及其句柄失效;连接释放仍会继续,清理失败也会被报告。普通原生请求超时仍然请求取消,并在 `graceMs` 内等待确认。提供方卸载会等待自己持有的 CUA 程序结束;使用原始 `cua` 的 PTC 程序可在释放其持有的输入后继续其他工作。 -`agentPreset` 默认为 `ptc`:匹配的 Agent 获得原始 `cua` 工具和 PTC 指引,其他已组合的 preset 只获得 `cua_run_code` 及其指引,包括标准、创造、极简和自定义 preset。注册使用 `agent/created`、`agent-preset/selected` 事件和 Agent 拥有的作用域,也处理提供方加载前已存在的 Agent。Agent 销毁会移除其注册并释放保留环境,提供方卸载还会释放专用 CUA 运行时。未组合 preset 的 Agent 不获得这两个工具。在独立组合中设置 `agentPreset: false` 可全局注册原始 `cua` 工具。Host 负责权限、本机连接和取消;preset 定义保持不变。 +`agentPreset` 默认为 `ptc`:匹配的 Agent 获得原始 `cua` 工具和 PTC 指引,其他已组合的 preset 只获得 `cua_run_code` 及其指引,包括标准、创造、极简和自定义 preset。基础注册的所有者使用 `agent/created`、`agent-preset/selected` 事件和 Agent 自有作用域,也处理提供方加载前已存在的 Agent。它按定义对象的身份同步替换每组工具及提示词;程序服务不可用时只撤回程序工具定义,保留原始工具的注册。Agent 销毁会移除其注册并释放保留环境,提供方卸载还会释放专用 CUA 运行时。未组合 preset 的 Agent 不获得这两个工具。在独立组合中设置 `agentPreset: false` 可全局注册原始 `cua` 工具。Host 负责权限、本机连接和取消;preset 定义保持不变。 `cua_run_code` 复用 PTC 程序工具工厂,由 CUA 提供方持有一个隔离的 Node 运行时。每个 Agent 通过自己的 `stateOwner` 选择独立的保留进程。CUA 在该运行时注册环境初始化程序,为每个新进程安装一次 `cua`,包括临时提权执行。初始化程序的所属作用域只依赖运行时,程序工具的依赖重载时仍保留这项注册。先销毁程序工具并等待其执行结束,再注销初始化程序并关闭运行时。工厂只绑定私有 `cua` 操作工具,保留嵌套策略检查、guard、日志、取消和截图交付。私有工具不会出现在模型可直接调用的工具列表中。 diff --git a/packages/experimental/cua/src/tool-registration.ts b/packages/experimental/cua/src/tool-registration.ts index 96e7d9026e..219d425fda 100644 --- a/packages/experimental/cua/src/tool-registration.ts +++ b/packages/experimental/cua/src/tool-registration.ts @@ -1,4 +1,4 @@ -/** Agent-scoped CUA transports sharing a provider-owned persistent program runtime. */ +/** Agent-scoped raw CUA and persistent program tool registrations. */ import { extname } from 'node:path' import type { Context, Fiber } from '@deepseek-ai/cordis' import type { Agent } from '@deepseek-ai/dsh-agent' @@ -45,70 +45,106 @@ var cua = connectCua(() => tools.cua, text => console.log(text)); } } const register = (scope: Context, definition: ToolDefinition, instructions: PromptSection): (() => void) => { const removeTool = scope.tools.register(definition) - const removePrompt = scope.systemPrompt.section(instructions) - return () => { removePrompt(); removeTool() } + let removePrompt: () => void + try { removePrompt = scope.systemPrompt.section(instructions) } + catch (error) { removeTool(); throw error } + return () => { try { removePrompt() } finally { removeTool() } } } if (config.agentPreset === false) return register(ctx, tool, rawPrompt) - return ctx.effect(function* () { - const runtimeCtx = ctx.isolate('ptcRuntime') - const runtime = runtimeCtx.plugin(NodePtcRuntime, { - ...config.standaloneRunCode.runtime, executionMode: 'persistent-in-memory', scriptPersistence: false, - }) - yield runtime.dispose - const programTools = { - name: 'cua-program-tools', inject: ['ptcRuntime', 'tools', 'workingDirectory', 'agentPresets', 'agents', 'systemPrompt'], - apply(consumer: Context) { - const program = createRunCodeTool(consumer, { - name: 'cua_run_code', description: programDescription, runtime: consumer.ptcRuntime, - tools: [tool], limits: config.standaloneRunCode.executor, - }) - const scopes = new Map void } }>() - consumer.effect(() => async () => { - await Promise.all([...scopes.values()].map(({ scope }) => scope.dispose())) - }, 'cua.agent-tools') - const sync = (agent: Agent): void => { - const preset = consumer.agentPresets.composedPreset(agent.ctx) - if (preset === undefined) return - const kind = preset === config.agentPreset ? 'raw' : 'program' - let entry = scopes.get(agent) - if (entry?.current?.kind === kind) return - if (entry?.current !== undefined) { entry.current.remove(); delete entry.current } - if (entry === undefined) { - const scope = createScope(agent.ctx, agent) - entry = { scope } - scopes.set(agent, entry) - scope.ctx.effect(() => () => { scopes.delete(agent) }, 'cua.agent-tools') - } - const remove = register(entry.scope.ctx, kind === 'raw' ? tool : program, - kind === 'raw' ? rawPrompt : { ...prompt, text: programGuidance }) - entry.current = { kind, remove } - } - consumer.on('agent/created', ({ agent }) => { sync(agent) }) - consumer.on('agent-preset/selected', (id) => { - const agent = consumer.agents.get(id) - if (agent === undefined) return - try { sync(agent) } catch (error) { consumer.logger.warn(`CUA tool scope update failed: ${String(error)}`) } - }) - for (const agent of consumer.agents.list()) sync(agent) - }, + return ctx.inject(['agentPresets', 'tools', 'agents', 'systemPrompt'], (base) => { + const scopes = new Map void } }>() + let program: ToolDefinition | undefined + let programs: Fiber | undefined + let closing = false + const modeOf = (agent: Agent): 'raw' | 'program' | undefined => { + const preset = base.agentPresets.composedPreset(agent.ctx) + return preset === undefined ? undefined : preset === config.agentPreset ? 'raw' : 'program' } - const initializer = runtimeCtx.plugin({ - name: 'cua-program-initializer', inject: ['ptcRuntime'], - async apply(owner: Context) { - let programs!: Fiber - owner.effect(function* () { - yield owner.ptcRuntime.registerEnvironmentInitializer( - `globalThis.cua = (await import(${programBridgeUrl})).connectCua(() => tools.cua, text => console.log(text));`, - ) - programs = owner.plugin(programTools) - yield programs.dispose - yield owner.on('agent/created', async () => { await programs.await() }) - }, 'cua.environment-initializer') - await programs.await() - }, - }) - yield initializer.dispose - // Creation can overlap the first provider activation; await its registered tools before the first turn. - yield ctx.on('agent/created', async () => { await initializer.await() }) - }, 'cua.program-runtime') + const sync = (agent: Agent): void => { + const mode = modeOf(agent) + const definition = mode === 'raw' ? tool : mode === 'program' ? program : undefined + let entry = scopes.get(agent) + if (entry?.current?.definition === definition) return + if (entry?.current !== undefined) { entry.current.remove(); delete entry.current } + if (definition === undefined) return + if (entry === undefined) { + const scope = createScope(agent.ctx, agent) + entry = { scope } + scopes.set(agent, entry) + scope.ctx.effect(() => () => { scopes.delete(agent) }, 'cua.agent-tools') + } + const remove = register(entry.scope.ctx, definition, + mode === 'raw' ? rawPrompt : { ...prompt, text: programGuidance }) + entry.current = { definition, remove } + } + const syncAll = (): void => { for (const agent of base.agents.list()) sync(agent) } + base.effect(function* () { + yield async () => { await Promise.all([...scopes.values()].map(({ scope }) => scope.dispose())) } + const runtimeCtx = base.isolate('ptcRuntime') + const runtime = runtimeCtx.plugin(NodePtcRuntime, { + ...config.standaloneRunCode.runtime, executionMode: 'persistent-in-memory', scriptPersistence: false, + }) + yield runtime.dispose + const initializer = runtimeCtx.plugin({ + name: 'cua-program-initializer', inject: ['ptcRuntime'], + apply(owner: Context) { + owner.effect(function* () { + yield owner.ptcRuntime.registerEnvironmentInitializer( + `globalThis.cua = (await import(${programBridgeUrl})).connectCua(() => tools.cua, text => console.log(text));`, + ) + const child = owner.plugin({ + name: 'cua-program-tools', inject: ['ptcRuntime', 'tools', 'workingDirectory'], + apply(consumer: Context) { + const definition = createRunCodeTool(consumer, { + name: 'cua_run_code', description: programDescription, runtime: consumer.ptcRuntime, + tools: [tool], limits: config.standaloneRunCode.executor, + }) + consumer.effect(function* () { + yield () => { + if (program !== definition) return + program = undefined + syncAll() + } + program = definition + syncAll() + }, 'cua.program-publication') + }, + }) + programs = child + yield () => { programs = undefined } + yield child.dispose + }, 'cua.environment-initializer') + }, + }) + yield initializer.dispose + yield base.on('agent/created', async ({ agent }) => { + if (closing) return + if (modeOf(agent) === 'program') { + if (runtime.uid !== null) await runtime.await() + await initializer.await() + await programs?.await() + // oxlint-disable-next-line typescript/no-unnecessary-condition -- Provider teardown can run while readiness awaits. + if (closing) return + if (modeOf(agent) === 'program' && program === undefined) { + throw new Error('CUA program tool is unavailable; restore its private runtime and workingDirectory services, or reload the provider') + } + } + sync(agent) + }) + yield base.on('agent-preset/selected', (id) => { + const agent = base.agents.get(id) + if (agent === undefined) return + try { sync(agent) } catch (error) { base.logger.warn(`CUA tool scope update failed: ${String(error)}`) } + }) + yield () => { + closing = true + program = undefined + for (const entry of scopes.values()) { + entry.current?.remove() + delete entry.current + } + } + syncAll() + }, 'cua.program-runtime') + }).dispose } diff --git a/packages/experimental/cua/tests/agent-scopes.spec.ts b/packages/experimental/cua/tests/agent-scopes.spec.ts index 01d79b6c7d..50b63cd168 100644 --- a/packages/experimental/cua/tests/agent-scopes.spec.ts +++ b/packages/experimental/cua/tests/agent-scopes.spec.ts @@ -1,8 +1,9 @@ /** CUA tool and prompt ownership follows live Agent presets and provider disposal. */ import { resolve } from 'node:path' -import { Context } from '@deepseek-ai/cordis' +import { Context, FiberState } from '@deepseek-ai/cordis' import Loader from '@deepseek-ai/cordis-plugin-loader' import AgentPresets from '@deepseek-ai/dsh-agent-preset-registry' +import type { Agent } from '@deepseek-ai/dsh-agent' import { mountAgentLoopTestDependencies, mountAgentLoopTestHarness } from '@deepseek-ai/dsh-agent-loop-testkit' import ComputerUseRegistry from '@deepseek-ai/dsh-computer-use' import NodeRuntime from '@deepseek-ai/dsh-ptc-runtime-node' @@ -14,6 +15,8 @@ import { SessionId } from '@deepseek-ai/dsh-session' import { expect, it, onTestFinished, vi } from 'vitest' import { CuaConfig, installCua } from '../src/index.ts' +const programPrompt = 'Fixture CUA program guidance\n\nAX read defaults: maxElements=2000, maxDepth=25.\n\nMaximum click holdMs: 5000 ms.' + const provider = { name: 'test-cua-scopes', inject: ['computerUse', 'subprocess', 'tools', 'systemPrompt', 'agents'], @@ -32,13 +35,13 @@ const provider = { }, } -async function setup(presetIds = ['standard', 'ptc']) { +async function setup(presetIds = ['standard', 'ptc'], withSandbox = true) { const ctx = new Context() onTestFinished(() => ctx.fiber.dispose()) ctx.baseUrl = import.meta.url await ctx.plugin(Loader) await mountAgentLoopTestDependencies(ctx, { workingDirectory: true }) - await ctx.plugin(Sandbox) + if (withSandbox) await ctx.plugin(Sandbox) await ctx.plugin(SandboxPolicy, { mode: 'danger-full-access' }) await mountAgentLoopTestHarness(ctx) await ctx.plugin(ComputerUseRegistry) @@ -55,6 +58,11 @@ async function setup(presetIds = ['standard', 'ptc']) { return { ctx, create } } +async function cuaPrompts(ctx: Context, agent: Agent): Promise { + return (await ctx.systemPrompt.assemble({ scope: agent })).sections + .filter(section => section.name === 'computer-use:dsh-cua').map(section => section.text) +} + it.each([ { executionMode: 'per-call' }, { executionMode: 'persistent-in-memory' }, @@ -141,17 +149,24 @@ it('keeps initialization registered while program tools reload their directory d const standard = await create('cua-dependency-standard', 'standard') const ptc = await create('cua-dependency-ptc', 'ptc') const previous = ctx.tools.get('cua_run_code', standard.agent) + const raw = ctx.tools.get('cua', ptc.agent) + const rawPrompts = await cuaPrompts(ctx, ptc.agent) expect(previous).toBeDefined() + expect(raw).toBeDefined() + expect(rawPrompts).toHaveLength(1) const directoryProvider = [...ctx.registry.get(WorkingDirectory)?.fibers ?? []][0] expect(directoryProvider).toBeDefined() await directoryProvider?.dispose() expect(ctx.tools.get('cua_run_code', standard.agent)).toBeUndefined() - expect(ctx.tools.get('cua', ptc.agent)).toBeUndefined() + expect(ctx.tools.get('cua', ptc.agent)).toBe(raw) + expect(await cuaPrompts(ctx, ptc.agent)).toEqual(rawPrompts) + expect(await cuaPrompts(ctx, standard.agent)).toEqual([]) await ctx.plugin(WorkingDirectory) await expect.poll(() => ctx.tools.get('cua_run_code', standard.agent)).toBeDefined() - expect(ctx.tools.get('cua_run_code', standard.agent)).not.toBe(previous) + expect(ctx.tools.get('cua_run_code', standard.agent) === previous).toBe(false) expect(register).toHaveBeenCalledOnce() - expect(ctx.tools.get('cua', ptc.agent)).toBeDefined() + expect(ctx.tools.get('cua', ptc.agent)).toBe(raw) + expect(await cuaPrompts(ctx, ptc.agent)).toEqual(rawPrompts) await ctx.agentPresets.select(standard.agent, 'ptc') expect(ctx.tools.get('cua_run_code', standard.agent)).toBeUndefined() expect(ctx.tools.get('cua', standard.agent)).toBeDefined() @@ -160,6 +175,187 @@ it('keeps initialization registered while program tools reload their directory d expect(ctx.tools.get('cua', standard.agent)).toBeUndefined() }) +it('keeps raw CUA and the shared runtime while the private runtime is absent', async () => { + const { ctx, create } = await setup() + const shared = { programFormat: 'repl', retainsState: true } + ctx.provide('ptcRuntime', shared) + await ctx.plugin(provider, {}) + const standard = await create('private-loss-standard', 'standard') + const ptc = await create('private-loss-ptc', 'ptc') + const raw = ctx.tools.get('cua', ptc.agent) + const rawPrompts = await cuaPrompts(ctx, ptc.agent) + const previous = ctx.tools.get('cua_run_code', standard.agent) + const privateRuntime = [...ctx.registry.get(NodeRuntime)?.fibers ?? []][0] + if (privateRuntime === undefined) throw new Error('missing private runtime fixture') + await privateRuntime.dispose() + expect(ctx.tools.get('cua', ptc.agent)).toBe(raw) + expect(await cuaPrompts(ctx, ptc.agent)).toEqual(rawPrompts) + expect(ctx.tools.get('cua_run_code', standard.agent)).toBeUndefined() + expect(await cuaPrompts(ctx, standard.agent)).toEqual([]) + expect(ctx.get('ptcRuntime')).toBe(shared) + const fresh = await create('private-loss-new-ptc', 'ptc') + expect(ctx.tools.get('cua', fresh.agent)).toBe(raw) + await privateRuntime.parent.plugin(NodeRuntime, { executionMode: 'persistent-in-memory' }) + await expect.poll(() => ctx.tools.get('cua_run_code', standard.agent)).toBeDefined() + expect(ctx.tools.get('cua_run_code', standard.agent) === previous).toBe(false) + expect(ctx.tools.get('cua', ptc.agent)).toBe(raw) + expect(ctx.get('ptcRuntime')).toBe(shared) +}) + +it('creates raw Agents while private runtime startup is pending', async () => { + const { ctx, create } = await setup(undefined, false) + await ctx.plugin(provider, {}) + const ptc = await create('private-pending-ptc', 'ptc') + const raw = ctx.tools.get('cua', ptc.agent) + expect(raw).toBeDefined() + expect((await cuaPrompts(ctx, ptc.agent)).join('')).toContain('Fixture CUA guidance') + await expect(create('private-pending-standard', 'standard')).rejects.toThrow('CUA program tool is unavailable') + await ctx.plugin(Sandbox) + const standard = await create('private-restored-standard', 'standard') + expect(ctx.tools.get('cua_run_code', standard.agent)).toBeDefined() + expect(ctx.tools.get('cua', ptc.agent)).toBe(raw) +}) + +it('uses a corrected private runtime after the failed instance is replaced', async () => { + const { ctx, create } = await setup() + const report = vi.spyOn(ctx.logger, 'error').mockImplementation(() => {}) + onTestFinished(() => { report.mockRestore() }) + await ctx.plugin(provider, { standaloneRunCode: { runtime: { maxOutputBytes: 1 } } }) + const ptc = await create('failed-node-ptc', 'ptc') + const raw = ctx.tools.get('cua', ptc.agent) + expect(raw).toBeDefined() + const failed = [...ctx.registry.get(NodeRuntime)?.fibers ?? []][0] + if (failed === undefined) throw new Error('missing failed private runtime') + await expect(create('failed-node-standard', 'standard')).rejects.toThrow('maxOutputBytes') + await failed.dispose() + await failed.parent.plugin(NodeRuntime, { executionMode: 'persistent-in-memory' }) + const standard = await create('replacement-node-standard', 'standard') + expect(ctx.tools.get('cua_run_code', standard.agent)).toBeDefined() + expect(ctx.tools.get('cua', ptc.agent)).toBe(raw) + expect((await cuaPrompts(ctx, ptc.agent)).join('')).toContain('Fixture CUA guidance') +}) + +it('ignores a queued raw creation listener after optional CUA unload', async () => { + const { ctx, create } = await setup() + const mounted = await ctx.plugin(provider, {}) + const entered: PromiseWithResolvers = Promise.withResolvers() + const resume: PromiseWithResolvers = Promise.withResolvers() + ctx.on('agent/created', async () => { entered.resolve(); await resume.promise }, { prepend: true }) + const creating = create('queued-raw-unload', 'ptc') + try { + await entered.promise + await mounted.dispose() + resume.resolve() + const handle = await creating + expect(ctx.tools.get('cua', handle.agent)).toBeUndefined() + expect(ctx.tools.get('cua_run_code', handle.agent)).toBeUndefined() + expect(await cuaPrompts(ctx, handle.agent)).toEqual([]) + } finally { resume.resolve(); await creating } +}) + +it('finishes Agent creation when optional CUA unloads during private readiness', async () => { + const { ctx, create } = await setup() + const mounted = await ctx.plugin(provider, {}) + const runtime = [...ctx.registry.get(NodeRuntime)?.fibers ?? []][0] + if (runtime === undefined) throw new Error('missing private runtime fixture') + const entered: PromiseWithResolvers = Promise.withResolvers() + const resume: PromiseWithResolvers = Promise.withResolvers() + const ready = runtime.await.bind(runtime) + const waiting = vi.spyOn(runtime, 'await').mockImplementationOnce(async () => { + entered.resolve() + await resume.promise + return ready() + }) + onTestFinished(() => { waiting.mockRestore(); resume.resolve() }) + const creating = create('waiting-program-unload', 'standard') + try { + await entered.promise + await mounted.dispose() + resume.resolve() + const handle = await creating + expect(ctx.tools.get('cua', handle.agent)).toBeUndefined() + expect(ctx.tools.get('cua_run_code', handle.agent)).toBeUndefined() + expect(await cuaPrompts(ctx, handle.agent)).toEqual([]) + } finally { resume.resolve(); await creating } +}) + +it('creates raw Agents even when private initialization registration fails', async () => { + const { ctx, create } = await setup() + const register = vi.spyOn(NodeRuntime.prototype, 'registerEnvironmentInitializer') + .mockImplementation(() => { throw new Error('private initializer failed') }) + const report = vi.spyOn(ctx.logger, 'error').mockImplementation(() => {}) + onTestFinished(() => { register.mockRestore(); report.mockRestore() }) + await ctx.plugin(provider, {}) + const ptc = await create('private-failed-ptc', 'ptc') + expect(ctx.tools.get('cua', ptc.agent)).toBeDefined() + expect((await cuaPrompts(ctx, ptc.agent)).join('')).toContain('Fixture CUA guidance') + await expect(create('private-failed-standard', 'standard')).rejects.toThrow('private initializer failed') + expect(ctx.tools.get('cua', ptc.agent)).toBeDefined() +}) + +it('switches modes synchronously without exposing both tools while programs are unavailable', async () => { + const { ctx, create } = await setup() + await ctx.plugin(provider, {}) + const owner = await create('unavailable-switch', 'ptc') + const directoryProvider = [...ctx.registry.get(WorkingDirectory)?.fibers ?? []][0] + if (directoryProvider === undefined) throw new Error('missing directory fixture') + await directoryProvider.dispose() + const counts: number[] = [] + ctx.on('tools/change', () => { + counts.push(ctx.tools.schemas(owner.agent).filter(tool => tool.name === 'cua' || tool.name === 'cua_run_code').length) + }) + await ctx.agentPresets.select(owner.agent, 'standard') + expect(ctx.tools.get('cua', owner.agent)).toBeUndefined() + expect(ctx.tools.get('cua_run_code', owner.agent)).toBeUndefined() + expect(await cuaPrompts(ctx, owner.agent)).toEqual([]) + await ctx.agentPresets.select(owner.agent, 'ptc') + expect(ctx.tools.get('cua', owner.agent)).toBeDefined() + expect((await cuaPrompts(ctx, owner.agent)).join('')).toContain('Fixture CUA guidance') + await ctx.plugin(WorkingDirectory) + await ctx.agentPresets.select(owner.agent, 'standard') + await expect.poll(() => ctx.tools.get('cua_run_code', owner.agent)).toBeDefined() + expect(ctx.tools.get('cua', owner.agent)).toBeUndefined() + expect(await cuaPrompts(ctx, owner.agent)).toEqual([programPrompt]) + expect(counts.length).toBeGreaterThan(0) + expect(counts.every(count => count <= 1)).toBe(true) +}) + +it('rolls back a partial program publication without withdrawing raw CUA', async () => { + const { ctx, create } = await setup() + await ctx.plugin(provider, {}) + const standard = await create('publication-standard', 'standard') + const ptc = await create('publication-ptc', 'ptc') + const raw = ctx.tools.get('cua', ptc.agent) + const directoryProvider = [...ctx.registry.get(WorkingDirectory)?.fibers ?? []][0] + if (directoryProvider === undefined) throw new Error('missing directory fixture') + await directoryProvider.dispose() + const attempted: PromiseWithResolvers = Promise.withResolvers() + const section = vi.spyOn(ctx.systemPrompt, 'section').mockImplementationOnce(() => { + attempted.resolve() + throw new Error('program prompt failed') + }) + const report = vi.spyOn(ctx.logger, 'error').mockImplementation(() => {}) + onTestFinished(() => { section.mockRestore(); report.mockRestore() }) + await ctx.plugin(WorkingDirectory) + await attempted.promise + expect(ctx.tools.get('cua_run_code', standard.agent)).toBeUndefined() + expect(await cuaPrompts(ctx, standard.agent)).toEqual([]) + expect(ctx.tools.get('cua', ptc.agent)).toBe(raw) + expect((await cuaPrompts(ctx, ptc.agent)).join('')).toContain('Fixture CUA guidance') + const fibers = [...ctx.registry.values()].flatMap(runtime => [...runtime.fibers]) + const failed = fibers.find(fiber => fiber.runtime?.name === 'cua-program-tools') + const initializer = fibers.find(fiber => fiber.runtime?.name === 'cua-program-initializer') + if (failed === undefined || initializer === undefined) throw new Error('missing program lifecycle fixture') + await expect(failed.await()).rejects.toThrow('program prompt failed') + expect(failed.state).toBe(FiberState.FAILED) + expect(initializer.state).toBe(FiberState.ACTIVE) + section.mockRestore() + await failed.update(failed.rawConfig) + await expect.poll(() => ctx.tools.get('cua_run_code', standard.agent)).toBeDefined() + expect(await cuaPrompts(ctx, standard.agent)).toEqual([programPrompt]) + expect(ctx.tools.get('cua', ptc.agent)).toBe(raw) +}) + it('ignores unloaded Session selections and reports a failed live scope update', async () => { const { ctx, create } = await setup() const handle = await create('active', 'ptc') diff --git a/packages/ptc-runtime/ptc-runtime-node/README.i18n.yaml b/packages/ptc-runtime/ptc-runtime-node/README.i18n.yaml index 02c1fa8f30..5e5173da74 100644 --- a/packages/ptc-runtime/ptc-runtime-node/README.i18n.yaml +++ b/packages/ptc-runtime/ptc-runtime-node/README.i18n.yaml @@ -33,8 +33,8 @@ en: 34a221d0f26b8e47 zh: 2fd20ac9c9953c7f /deepseek-ai-dsh-ptc-runtime-node/understand-the-implementation: - en: 50e6cd38e298da31 - zh: c8b252b3acf59147 + en: 8a9dddeafde30b6d + zh: d2c95d923f892cc8 /deepseek-ai-dsh-ptc-runtime-node/understand-the-implementation/launch-and-control: en: 5c93014a885ed89e zh: 21daedcd9de8cd7f diff --git a/packages/ptc-runtime/ptc-runtime-node/README.md b/packages/ptc-runtime/ptc-runtime-node/README.md index 074ba5a371..0d5569cff0 100644 --- a/packages/ptc-runtime/ptc-runtime-node/README.md +++ b/packages/ptc-runtime/ptc-runtime-node/README.md @@ -125,7 +125,7 @@ Program parse errors and thrown exceptions are `exception`; deadline expiry is ` The host owns policy, deadlines, binding lookup and process cleanup. The child owns program evaluation and binding proxies; model-written code is an untrusted peer even when its messages use the expected control descriptor. -`createExecution()` resolves the configured syntax, type erasure, model guidance and process lifetime once when the provider loads. The provider handles admission and cancellation. One execution owner creates temporary processes or reuses an enabled state owner's process; both use `ProgramWorker` for launch, deadlines, binding dispatch and cleanup. The shared child loop selects `createProgramEvaluator()` from the evaluation data; async-function, REPL and Script implementations expose globals, evaluation and cleanup operations independently of process lifetime. +`createExecution()` resolves the configured syntax, type erasure, model guidance and process lifetime once when the provider loads. The provider handles admission and cancellation. One execution owner creates temporary processes or reuses an enabled state owner's process; both use `ProgramWorker` for launch, deadlines, binding dispatch and cleanup. The shared child loop selects `createProgramEvaluator()` from the evaluation data; async-function, REPL and Script implementations expose globals, evaluation and cleanup independently of process lifetime. Initialization is awaited without adopting its completion value, followed by Host acknowledgement and the user program. The evaluator's completion callback settles the user program immediately; subsequent microtasks cannot log or invoke bindings. REPL diagnostics can also settle the active run. ### Launch and control diff --git a/packages/ptc-runtime/ptc-runtime-node/README.zh.md b/packages/ptc-runtime/ptc-runtime-node/README.zh.md index 4a629327a2..e94a811cc7 100644 --- a/packages/ptc-runtime/ptc-runtime-node/README.zh.md +++ b/packages/ptc-runtime/ptc-runtime-node/README.zh.md @@ -125,7 +125,7 @@ PTC 消费方按 [dsh-tool-executor-ptc](../../core/tool-executor-ptc/README.zh. Host 负责策略、截止时间、绑定查找和进程清理。子进程负责程序求值与绑定代理;即使使用预期的控制描述符,模型编写的代码仍是不可信对端。 -`createExecution()` 在提供方加载时一次性确定配置对应的语法、类型擦除、模型指导和进程生命周期。提供方处理执行准入与取消。统一的执行所有者创建临时进程,或在启用状态保留时复用所有者的进程;二者都由 `ProgramWorker` 负责启动、截止时间、绑定分派和清理。共用的子进程循环根据本次执行数据选择 `createProgramEvaluator()`;异步函数、REPL 和 Script 实现提供全局变量、求值与清理操作,与进程生命周期独立。 +`createExecution()` 在提供方加载时一次性确定配置对应的语法、类型擦除、模型指导和进程生命周期。提供方处理执行准入与取消。统一的执行所有者创建临时进程,或在启用状态保留时复用所有者的进程;二者都由 `ProgramWorker` 负责启动、截止时间、绑定分派和清理。共用的子进程循环根据本次执行数据选择 `createProgramEvaluator()`;异步函数、REPL 和 Script 实现提供全局变量、求值与清理操作,与进程生命周期独立。运行时等待初始化求值结束,不等待或展开其完成值;随后等待 Host 确认,再执行用户程序。求值器报告完成时立即结算用户程序;随后运行的微任务不能再输出内容或调用绑定。REPL 诊断也可以结算当前运行。 ### 启动与控制 diff --git a/packages/ptc-runtime/ptc-runtime-node/src/process.ts b/packages/ptc-runtime/ptc-runtime-node/src/process.ts index 617ebb3bb5..48ee0665ea 100644 --- a/packages/ptc-runtime/ptc-runtime-node/src/process.ts +++ b/packages/ptc-runtime/ptc-runtime-node/src/process.ts @@ -92,7 +92,13 @@ export async function runNodeMain( }, } current = evaluation - context.run(evaluation, () => { + const canContinue = (): boolean => { + if (!evaluation.active) return false + if (!evaluation.revoked) return true + evaluation.finish({}) + return false + } + void context.run(evaluation, async () => { try { processState.chdir(cwd) if (evaluator === undefined) { @@ -134,32 +140,30 @@ export async function runNodeMain( } } const programEvaluator = evaluator - const finish: Parameters[1] = (result) => { - if (!evaluation.active) return - if (evaluation.revoked) { evaluation.finish({}); return } + const initialization = data.initialization + if (initialization !== undefined) { + await new Promise((resolve, reject) => { + programEvaluator.evaluate(initialization, (result) => { + if (result.ok) resolve() + // oxlint-disable-next-line typescript/prefer-promise-reject-errors -- Programs may throw non-Error values. + else reject(result.error) + }) + }) + if (!canContinue()) return + if (logs.overflowed) { + evaluation.finish(outputLimit(data.maxOutputBytes)) + return + } + await connection.initialized() + } + if (!canContinue()) return + programEvaluator.evaluate(data.code, (result) => { + if (!canContinue()) return evaluation.finish(result.ok ? prepareCompletion(result.value, logs.remainingOutputBytes(), data.maxOutputBytes) : prepareException(result.error, logs.remainingOutputBytes(), data.maxOutputBytes)) - } - const runProgram = (): void => { - try { programEvaluator.evaluate(data.code, finish) } catch (error: unknown) { finish({ ok: false, error }) } - } - if (data.initialization === undefined) runProgram() - else { - const initialized = Promise.withResolvers[1]>[0]>() - void initialized.promise.then(async (result) => { - if (!result.ok || !acceptsCalls(evaluation)) { finish(result); return } - if (logs.overflowed) { - evaluation.finish(outputLimit(data.maxOutputBytes)) - return - } - await connection.initialized() - if (!acceptsCalls(evaluation)) { finish({ ok: true, value: undefined }); return } - runProgram() - }).catch((error: unknown) => { finish({ ok: false, error }) }) - programEvaluator.evaluate(data.initialization, initialized.resolve) - } + }) } catch (error: unknown) { - evaluation.finish(prepareException(error, logs.remainingOutputBytes(), data.maxOutputBytes)) + if (canContinue()) evaluation.finish(prepareException(error, logs.remainingOutputBytes(), data.maxOutputBytes)) } }) return await completion.promise diff --git a/packages/ptc-runtime/ptc-runtime-node/tests/initialization.spec.ts b/packages/ptc-runtime/ptc-runtime-node/tests/initialization.spec.ts index 067a4e5614..54a00faf37 100644 --- a/packages/ptc-runtime/ptc-runtime-node/tests/initialization.spec.ts +++ b/packages/ptc-runtime/ptc-runtime-node/tests/initialization.spec.ts @@ -166,6 +166,8 @@ describe('Node environment initialization', () => { it.each([ 'globalThis.cycle = {}; cycle.self = cycle; cycle', '({ get bad() { throw new Error("must not inspect") } })', + '({ get then() { throw new Error("must not adopt") } })', + 'new Promise(() => {})', ])('discards initialization completion without traversing it: %s', async (initialization) => { const { run } = await setup({}, initialization) expect(await run('42')).toMatchObject({ value: 42, logs: [] }) diff --git a/packages/ptc-runtime/ptc-runtime-node/tests/persistent-process.spec.ts b/packages/ptc-runtime/ptc-runtime-node/tests/persistent-process.spec.ts index 9d59278024..a719b8a0c5 100644 --- a/packages/ptc-runtime/ptc-runtime-node/tests/persistent-process.spec.ts +++ b/packages/ptc-runtime/ptc-runtime-node/tests/persistent-process.spec.ts @@ -60,9 +60,30 @@ it('runs initialization before the program in the same REPL and discards its com expect(decodePtcJsonWire((await h.run('42', [], 1024, '')).value)).toBe(42) }) +it.each([false, true])('closes program output and bindings before queued microtasks with initialization %s', async (initialize) => { + const h = await setup() + const namespaces = [{ global: 'tools', names: ['echo'] }] + const result = await h.run( + 'queueMicrotask(() => { console.log("late"); void tools.echo({}).catch(() => {}) }); 42', + namespaces, 1024, initialize ? 'globalThis.ready = true' : undefined, + ) + expect(decodePtcJsonWire(result.value)).toBe(42) + await setImmediate() + expect(h.seen.filter(item => item.type === 'log' || item.type === 'call')).toEqual([]) + expect(decodePtcJsonWire((await h.run('await tools.echo({})', namespaces)).value)).toBe(42) + expect(h.seen.filter(item => item.type === 'call')).toHaveLength(1) +}) + +it('does not adopt a REPL completion Promise without explicit await', async () => { + const h = await setup() + expect((await h.run('Promise.resolve(42)')).error?.kind).toBe('invalid-output') + expect(decodePtcJsonWire((await h.run('await Promise.resolve(42)')).value)).toBe(42) +}) + it('prevents the program after initialization exceptions and output overflow', async () => { const h = await setup() await h.run('var entered = 0;') + expect((await h.run('entered++', [], 4096, 'const =')).error?.kind).toBe('exception') const failed = await h.run('entered++', [], 1024, 'throw "initialization failed"') expect(failed.error?.kind).toBe('exception') expect(failed.error?.message).toContain('initialization failed') @@ -119,6 +140,20 @@ it('does not start the user program when Host acceptance rejects', async () => { expect(decodePtcJsonWire((await h.run('typeof programRan')).value)).toBe('undefined') }) +it('cancels initialization while its Host acceptance is pending', async () => { + const h = await setup() + const entered: PromiseWithResolvers = Promise.withResolvers() + const accepted: PromiseWithResolvers = Promise.withResolvers() + h.setInitialized(() => { entered.resolve(); return accepted.promise }) + const pending = h.run('globalThis.programRan = true', [], 1024, 'globalThis.helper = {}') + try { + await entered.promise + await h.peer.revoke() + expect(await pending).toEqual({}) + expect(decodePtcJsonWire((await h.run('typeof programRan')).value)).toBe('undefined') + } finally { accepted.resolve(); await pending } +}) + it('checks revocation after accepting an initialization reply', async () => { const h = await setup() const request: PromiseWithResolvers = Promise.withResolvers()