[P1/高] AuditLogHook 未 try-catch,异常会中断工具执行链 #17

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

问题类型

缺陷 / 高 / 后端服务

文件位置

electron/harness/hooks/audit-log-hook.ts

问题描述

AuditLogHook 在 preExecute / postExecute 中直接调用 auditService.log()
若数据库写入失败(如磁盘满、WAL 锁定),异常会冒泡到 ToolRegistry,导致:

  1. 整个工具执行链中断
  2. 用户工具调用失败,但实际工具可能已部分执行
  3. 状态不一致

AuditHook 应该是 "fire and forget",不应影响主流程。

影响

  • 审计日志失败导致工具不可用
  • 用户体验严重受损

建议修复

async preExecute(context) {
  try {
    await this.auditService.log({
      // ...
    });
  } catch (err) {
    log.error('[AuditLogHook] Failed to log audit:', err);
    // 不抛出,让工具继续执行
  }
}

所有 hook 都应该 try-catch,确保 hook 失败不影响主流程。

## 问题类型 缺陷 / 高 / 后端服务 ## 文件位置 `electron/harness/hooks/audit-log-hook.ts` ## 问题描述 AuditLogHook 在 `preExecute` / `postExecute` 中直接调用 `auditService.log()`。 若数据库写入失败(如磁盘满、WAL 锁定),异常会冒泡到 ToolRegistry,导致: 1. 整个工具执行链中断 2. 用户工具调用失败,但实际工具可能已部分执行 3. 状态不一致 AuditHook 应该是 "fire and forget",不应影响主流程。 ## 影响 - 审计日志失败导致工具不可用 - 用户体验严重受损 ## 建议修复 ```ts async preExecute(context) { try { await this.auditService.log({ // ... }); } catch (err) { log.error('[AuditLogHook] Failed to log audit:', err); // 不抛出,让工具继续执行 } } ``` 所有 hook 都应该 try-catch,确保 hook 失败不影响主流程。
thzxx added the ??????? labels 2026-07-21 21:55:46 +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#17