[P0/严重] TaskOrchestrator abort 路径未清理 sessionDepth 导致后续任务深度错乱 #5

Closed
opened 2026-07-21 21:55:37 +08:00 by thzxx · 1 comment
Owner

问题类型

缺陷 / 严重 / Agent 引擎

文件位置

electron/harness/orchestration/orchestrator.ts

问题描述

sessionDepth 用于限制嵌套委派深度(防止无限递归)。abort 中断时:

  • 主 Engine 调用 orchestrator.abort()
  • abort 方法仅设置 aborted = true 并 abort 当前 SubEngine
  • sessionDepth 在 SubEngine 完成回调中才递减,abort 路径跳过了递减

影响

  • 用户中断一次委派后,sessionDepth 永久 +1
  • 后续正常委派可能因深度超限被拒绝
  • 严重情况下用户必须重启应用

建议修复

abort() {
  this.aborted = true;
  if (this.currentSubEngine) {
    this.currentSubEngine.abort();
    this.currentSubEngine = null;
  }
  // 关键:清理 sessionDepth
  this.sessionDepth = 0;
}

并在 finally 块中兜底:

try {
  await subEngine.runStream(...);
} finally {
  this.sessionDepth = Math.max(0, this.sessionDepth - 1);
  this.currentSubEngine = null;
}
## 问题类型 缺陷 / 严重 / Agent 引擎 ## 文件位置 `electron/harness/orchestration/orchestrator.ts` ## 问题描述 `sessionDepth` 用于限制嵌套委派深度(防止无限递归)。abort 中断时: - 主 Engine 调用 `orchestrator.abort()` - abort 方法仅设置 `aborted = true` 并 abort 当前 SubEngine - 但 `sessionDepth` 在 SubEngine 完成回调中才递减,abort 路径跳过了递减 ## 影响 - 用户中断一次委派后,sessionDepth 永久 +1 - 后续正常委派可能因深度超限被拒绝 - 严重情况下用户必须重启应用 ## 建议修复 ```ts abort() { this.aborted = true; if (this.currentSubEngine) { this.currentSubEngine.abort(); this.currentSubEngine = null; } // 关键:清理 sessionDepth this.sessionDepth = 0; } ``` 并在 finally 块中兜底: ```ts try { await subEngine.runStream(...); } finally { this.sessionDepth = Math.max(0, this.sessionDepth - 1); this.currentSubEngine = null; } ```
thzxx added the Agent?????? labels 2026-07-21 21:55:37 +08:00
Author
Owner

修复说明

文件: electron/harness/orchestration/orchestrator.ts

问题: delegate()sessionDepth 恢复逻辑分散在 try 和 catch 块中(重复代码),且 abort 路径(handle.abort())跳过了恢复。abortAll() 中的 sessionDepth.clear() 会被各 delegate 的 finally 块覆盖,导致深度错乱。

修复方案:

  1. sessionDepth 恢复逻辑统一移到 finally 块,覆盖正常完成/异常/abort 所有路径
  2. abortAll() 移除 sessionDepth.clear() — 各 delegate 的 finally 块会自行恢复深度。之前 clear() 会被 finally 的 set(currentDepth) 覆盖,移除后让 finally 统一处理,最终 sessionDepth 正确归零
  3. activeSubAgents.delete() 也移入 finally 块,确保资源清理不遗漏

验证: tsc --noEmit 类型检查通过。

## 修复说明 **文件**: `electron/harness/orchestration/orchestrator.ts` **问题**: `delegate()` 的 `sessionDepth` 恢复逻辑分散在 try 和 catch 块中(重复代码),且 abort 路径(`handle.abort()`)跳过了恢复。`abortAll()` 中的 `sessionDepth.clear()` 会被各 delegate 的 finally 块覆盖,导致深度错乱。 **修复方案**: 1. 将 `sessionDepth` 恢复逻辑统一移到 `finally` 块,覆盖正常完成/异常/abort 所有路径 2. `abortAll()` 移除 `sessionDepth.clear()` — 各 delegate 的 finally 块会自行恢复深度。之前 `clear()` 会被 finally 的 `set(currentDepth)` 覆盖,移除后让 finally 统一处理,最终 sessionDepth 正确归零 3. `activeSubAgents.delete()` 也移入 finally 块,确保资源清理不遗漏 **验证**: `tsc --noEmit` 类型检查通过。
thzxx closed this issue 2026-07-22 09:14:50 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MetonaTeam/metona-ai-desktop#5