[P1/高] Agent Engine waitForAbort 总是返回 true,无法检测实际 abort 完成状态 #29

Open
opened 2026-07-21 21:55:56 +08:00 by thzxx · 0 comments
Owner

问题类型

缺陷 / 高 / Agent 引擎

文件位置

electron/harness/agent-loop/engine.ts

问题描述

waitForAbort 实现:

async waitForAbort(timeoutMs = 5000): Promise<boolean> {
  if (!this.currentRunPromise) return true;
  try {
    await Promise.race([
      this.currentRunPromise.catch(() => {}),
      new Promise<void>(resolve => setTimeout(resolve, timeoutMs)),
    ]);
    return true; // 总是返回 true
  } catch {
    return false;
  }
}

问题:

  1. Promise.race 永远不抛(catch 已处理),所以总是返回 true
  2. 超时返回 true,但 currentRunPromise 可能仍在运行
  3. 调用方(IPC handler)误以为 abort 完成,立即重发消息
  4. 新消息会卡在 runStream 的 currentRunPromise 等待中

影响

  • 用户中断后立即重发,新消息卡住
  • 用户体验差

建议修复

async waitForAbort(timeoutMs = 5000): Promise<boolean> {
  if (!this.currentRunPromise) return true;
  let timedOut = false;
  const timer = new Promise<void>(resolve =>
    setTimeout(() => {
      timedOut = true;
      resolve();
    }, timeoutMs)
  );

  await Promise.race([
    this.currentRunPromise.catch(() => {}),
    timer,
  ]);

  return !timedOut; // 超时返回 false
}

调用方应根据返回值决定是否提示用户"上一次操作未完成,请稍候"。

## 问题类型 缺陷 / 高 / Agent 引擎 ## 文件位置 `electron/harness/agent-loop/engine.ts` ## 问题描述 waitForAbort 实现: ```ts async waitForAbort(timeoutMs = 5000): Promise<boolean> { if (!this.currentRunPromise) return true; try { await Promise.race([ this.currentRunPromise.catch(() => {}), new Promise<void>(resolve => setTimeout(resolve, timeoutMs)), ]); return true; // 总是返回 true } catch { return false; } } ``` 问题: 1. Promise.race 永远不抛(catch 已处理),所以总是返回 true 2. 超时返回 true,但 currentRunPromise 可能仍在运行 3. 调用方(IPC handler)误以为 abort 完成,立即重发消息 4. 新消息会卡在 runStream 的 currentRunPromise 等待中 ## 影响 - 用户中断后立即重发,新消息卡住 - 用户体验差 ## 建议修复 ```ts async waitForAbort(timeoutMs = 5000): Promise<boolean> { if (!this.currentRunPromise) return true; let timedOut = false; const timer = new Promise<void>(resolve => setTimeout(() => { timedOut = true; resolve(); }, timeoutMs) ); await Promise.race([ this.currentRunPromise.catch(() => {}), timer, ]); return !timedOut; // 超时返回 false } ``` 调用方应根据返回值决定是否提示用户"上一次操作未完成,请稍候"。
thzxx added the Agent????? labels 2026-07-21 21:55:56 +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#29