Repository navigation
fix(subagent): preserve delegated memory tools under PTC root registries - #778
Conversation
|
Thanks for this fix — I can confirm it resolves the PTC case end-to-end on a real install. Environment: DSH Before (dsh-mnemon 0.5.59 and 0.5.60, both unpatched): every {"delegated": true, "provider": "spawn", "action": "skipped", "summary": "... this run only exposed the result channel, no memory-space write tool was provided ..."}i.e. After building this branch ( {"delegated": true, "provider": "spawn", "action": "added", "memoryBodyIds": ["default"]}The insight was actually persisted, and Mnemon linked it to an existing related entry. The fast-fail path also never triggered, which is the behaviour I'd expect on a healthy install. One data point for scope: plain 0.5.60 does not fix this. Its only change over 0.5.59 is adding Happy to re-test any follow-up revision on the same setup. |
摘要 / Summary
修复在 DSH 0.2.3(
setRoot()根工具注册表)PTC 预设下,MnemonSubagentCoordinator.availableTools()调用parent.ctx.tools.get(name, parent)将所有记忆工具误滤为空、导致mnemon_remember等委派写入与空闲审查子会话只剩mnemon_subagent_result且MNEMON VIEW TOOLS被清空的问题;同时按父会话的实际绑定展示工具。只读会话可继续检索,跳过写入提示和写入型复盘。权限变化会刷新工具提示。普通 PTC 的委派写入继续使用 DSH 的作用域和执行守卫。Fixes delegated write and review tool loss under DSH 0.2.3 PTC root tool registries (
setRoot()), whereparent.ctx.tools.get(name, parent)returns onlyrun_codeandundefinedfor every bound memory tool.MnemonSubagentCoordinatornow resolves PTC-root delegated allowlists from the intersection of live Mnemon registrations and the parent's scoped bindings,modelMemoryWakepreservesMNEMON VIEW TOOLSlistings,usesToolBatchExecutionand text-only PTC transport detection recognizesetRoot(), and delegated operations fail fast with an actionable error before spawning a child if required memory tools are unavailable.关联 Issue 或背景 / Related Issue or Context
Fixes #777
在 DSH 0.2.3-alpha.3 中,
@deepseek-ai/dsh-tools用根工具注册表(setRoot())替代了setExecutor(),其中@deepseek-ai/dsh-tool-registry-ptc的get(name, scope)仅返回程序入口run_code,对所有绑定在 PTC SDK 内的注册工具(包括mnemon_*)一律返回undefined。原有逻辑出现以下连锁缺陷:MnemonSubagentCoordinator.availableTools(parent, tools)用parent.ctx.tools.get(name, parent) !== undefined过滤候选工具,结果全部被滤掉,使allowedTools退化为['mnemon_subagent_result'],进而经child.ctx.tools.restrict({ allow })把所有继承的记忆工具剥离,造成mnemon_remember等委派写入恒定失败、空闲审查直接被跳过。availableMemoryTools(agent)在src/host/view-presentation.ts中同样依赖tools.get(name, agent),导致 PTC 根下每轮记忆快照里的MNEMON VIEW TOOLS与路由提示被清空。usesToolBatchExecution(tools)仅识别setExecutor而未识别setRoot。delegate()仍会启动空工具子会话而非提前给出可操作错误。关于 #777 中观察到的
cua出现在子会话声明中的说明:@deepseek-ai/dsh-cua在agent/created时把cua注册到子 Agent 自身的 scope 层(DSH 的tools.restrict()按设计仅过滤继承层,不影响自身层注册),而dsh-mnemon的childGuard(tools.guard())已在执行边界拦截所有不在allowedTools中的非允许工具(包括cua),本 PR 亦补充回归测试明确验证该拦截。涉及区域 / Affected Areas
PR 类型 / PR Type
最新代码确认 / Latest Codebase Confirmation
main分支开发,或在提交前已 rebase 或合并最新main。 / I developed from the latestmain, or rebased or merged the latestmainbefore submitting.同步命令 / Sync command:
AI 编码披露 / AI Coding Disclosure
使用的 AI 模型 / AI model used:
Gemini (original implementation), GPT-6 (maintainer follow-up)
使用的编码 Agent 工具 / Coding Agent tool used:
Antigravity (original implementation), Codex (maintainer follow-up)
仓库规范检查 / Repository Rules
@deepseek-ai/*NPM 契约。 / I did not modify DSH source or point tsconfig at a DSH source checkout, and used only published@deepseek-ai/*NPM contracts.src/host/protocol.ts为准,没有在两侧重复定义 wire DTO。 / The Client and Host boundary still uses browser-safesrc/host/protocol.tsas the source for wire DTOs.lib/文件。 / I did not commit tokens, credentials, private memory, unredacted logs, or generatedlib/files.兼容性与数据安全 / Compatibility and Data Safety
0.2.1/0.2.2/0.2.3-alpha.3+):0.2.1(legacy single-calltools.execute,presentAs) and DSH0.2.2(setExecutorbatch execution) are completely unchanged becauseusesRootToolRegistry(tools)checkstypeof tools?.setRoot === 'function'.0.2.3+with a Native root (setRootpresent,tools.get('run_code', agent)isundefined),isPtcRootRegistryisfalse, so scopedtools.get(name, agent)filtering and per-agent restriction visibility continue to work identically.0.2.3-alpha.3PTC root (setRootpresent andtools.get('run_code', agent)defined),MnemonSubagentCoordinator.availableTools()intersects live registrations with the scoped tool bindings. Mnemon prefersexecutable(name, agent)when provided, and uses the optionalregistered(name, agent)lookup present in the tested alpha. When a PTC host provides neither, Mnemon hides unverified tools and skips automatic write reviews. Explicit delegation retains DSH’s normal execution guards.ToolsServicecontinues to intersect all ancestor scope restrictions on the child, and Mnemon'schildGuardcontinues to block execution of any tool outsideallowedTools(including own-scope tools such ascua, andrun_codeon text-only non-PTC children).mnemon_remember) is available to the parent Agent.本地验证 / Local Validation
执行的命令 / Commands run:
pnpm vitest run tests/subagent.spec.ts tests/memory-tools.spec.ts -t "#777" pnpm vitest run tests/subagent.spec.ts tests/memory-tools.spec.ts tests/source-tool-lifecycle.spec.ts tests/source-tool-lifecycle-host.spec.ts pnpm run verify node scripts/check-release-intent.mjs --base origin/main git diff --check origin/main..HEAD结果摘要 / Result summary:
Maintainer follow-up on
66da7c1f@deepseek-ai/dsh@0.2.3-alpha.3, Node 24, real PTC preset and scripted offline model. All seven scenarios passed. The restricted parent retained recall, advertised no writers in the current View and prompt, and started zero automatic review children across two eligible turns. Both snapshot modes refreshed when permissions changed. A normal PTC child wrote a synthetic entry into the selected Memory Space and a read-back returned the exact content.pnpm run verifypassed, including 3,032 passing root tests (22 conditional skips), workspace packages, deterministic builds, Headless, and package validation.Contributor validation on the earlier head
pnpm vitest run tests/subagent.spec.ts tests/memory-tools.spec.ts -t "#777"reproduced#777with 5 expected failures (delegated write allowlist collapsed to['mnemon_subagent_result'], PTC-root review skipped, missing fail-fast on unavailable write tools,MNEMON VIEW TOOLSdropped under PTC root, andusesToolBatchExecutionreturningfalseonsetRoot).tests/subagent.spec.ts(120/120),tests/memory-tools.spec.ts(78/78),tests/source-tool-lifecycle.spec.ts(26/26), andtests/source-tool-lifecycle-host.spec.ts(28/28) — 252/252 passed.pnpm run verify: passed (exit code 0)verify:docs: passed (1047 local links, 313 Markdown anchors, bilingual paths, media hygiene, official plugin coverage)typecheckandpnpm -r build/pnpm -r typecheck/pnpm -r test: passedverify:build: passed (reproducible double build)test:root: 82 passed, 2 skipped (84 files); 3020 passed, 22 skipped (3042 tests) — the 2 skipped files / 22 skipped tests are pre-existing optional-environment skips unchanged by this PRverify:headless: passed (38 total tools, 8 representative Mnemon tools)verify:package: passed (92 packaged files,publint --strict,attw --pack . --profile esm-only)node scripts/check-release-intent.mjs --base origin/main: passed (Verified changeset coverage for dsh-mnemon.)git diff --check origin/main..HEAD: passed用户可见变更证据 / Local Feature Evidence
证据 / Evidence:
N/A — Host-only subagent tool-availability and DSH 0.2.3 root-tool-registry compatibility fix with no WebUI changes. Behavior across PTC roots, Native roots, dynamic optional-Source tool registration, fail-fast missing-tool errors,
childGuardblocking of foreign own-scope tools (such ascua), View tool listings, andsetRoot()batch execution is covered intests/subagent.spec.tsandtests/memory-tools.spec.ts, alongside the existing real-Host suite intests/source-tool-lifecycle-host.spec.ts.