fix: v0.5.1 工具调用链路复检修复 — SubAgent 孤儿工具拦截 + 确认弹框会话隔离
背景:v0.5.0 发布后对工具调用链路(adapter 流式 tool_call → 引擎 PARSING → preToolHooks 管道 → ToolRegistry → 结果回填)做全链路复检,发现并修复两处问题。 安全修复: - SubAgent 中止时 pending 确认未清理(安全回归):SubEngine 以 taskId 为 sessionId 写入 ConfirmationHook,abortSession 的 clearPending(sessionId) 清不到它们。后果:中止会话后残留弹框若被补批,孤儿工具会真实执行副作用 (v0.4.x 的全局清空反而能拦截)。修复:abortByParent 返回被中止的 taskId 列表,abortSession 一并 clearPending(taskId)。 确认弹框会话隔离(前端对齐后端 v0.5.0 语义): - ConfirmationRequest 新增 sessionId 字段(主会话为 sessionId,SubAgent 为 taskId),弹框在会话 INIT/TERMINATED 时只清除该会话的请求 —— 修复并发 会话下任意会话结束误清其他会话等待中确认的问题 - 选中计数按当前 requests 收敛(selectedIds 残留 id 无害化) 测试(207 → 215 用例): - 新增引擎级工具调用链路集成测试 ×6(engine-toolchain.test.ts):真实 PermissionCheckHook + RateLimitHook + ConfirmationHook 管道 + 真实 ToolRegistry,覆盖 SAFE 工具直通 / HIGH 工具批准执行 / 拒绝以 Blocked 错误回传 LLM / 会话隔离端到端 / 工具异常不中断循环 / 策略拦截系统路径 - 新增 FTS 触发器 × NULL content 删除安全性测试 ×2:验证 truncateAfter (编辑重发/重新生成)删除 content=NULL 的 assistant 消息(模型仅发 tool_calls 的标准场景)不抛错且索引保持一致 - agent.test.ts 的 orchestrator mock 适配 abortByParent 新返回类型 验证: lint 0 problems / typecheck 双工程 0 errors / test:electron 215 全过 / build 成功
This commit is contained in:
@@ -356,19 +356,26 @@ export class TaskOrchestrator extends EventEmitter {
|
||||
/**
|
||||
* P2-10: 中断指定父会话派生的所有 SubAgent
|
||||
* (用户中断会话时由 IPC abort handler 联动调用,消除"会话停了子任务还在跑")
|
||||
*
|
||||
* v0.5.1: 返回值从数量改为被中止的 taskId 列表 — 调用方需据此清理这些
|
||||
* SubAgent 的 pending 工具确认(SubEngine 以 taskId 为 sessionId 写入
|
||||
* ConfirmationHook,父会话的 clearPending(sessionId) 清不到它们;不清理
|
||||
* 会导致中止后孤儿工具在用户补批时执行副作用)
|
||||
*/
|
||||
abortByParent(parentSessionId: string): number {
|
||||
let aborted = 0;
|
||||
abortByParent(parentSessionId: string): string[] {
|
||||
const abortedTaskIds: string[] = [];
|
||||
for (const handle of this.activeSubAgents.values()) {
|
||||
if (handle.parentSessionId === parentSessionId && handle.status === 'running') {
|
||||
handle.abort();
|
||||
aborted++;
|
||||
abortedTaskIds.push(handle.taskId);
|
||||
}
|
||||
}
|
||||
if (aborted > 0) {
|
||||
log.info(`[Orchestrator] Aborted ${aborted} SubAgent(s) of session ${parentSessionId}`);
|
||||
if (abortedTaskIds.length > 0) {
|
||||
log.info(
|
||||
`[Orchestrator] Aborted ${abortedTaskIds.length} SubAgent(s) of session ${parentSessionId}`,
|
||||
);
|
||||
}
|
||||
return aborted;
|
||||
return abortedTaskIds;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user