Skip to content

OpenClaw tasks audit 报告时间戳误报:startedAt 早于 createdAt

问题

执行 openclaw tasks audit 时,出现大量 inconsistent_timestamps 警告:

startedAt is earlier than createdAt

这个报错会出现在 succeeded、failed、running 等多种状态的任务上,看起来是个严重的数据异常,但实际上是一个误报(false positive)。

根本原因:任务的 startedAt 时间戳在工具调用发起时就被捕获,而 createdAt 是在 createTaskRecord 函数中稍后赋值。由于这段时间差是代码执行顺序导致的结构性问题,每一个通过这条路径注册的 running 状态任务都满足 startedAt < createdAt,因此 task-registry.audit.ts:50 中的不变式检查会被系统性地触发。

解决方案

临时规避:这是已知的 false positive,可以暂时忽略这些 audit 警告,不影响实际任务的执行结果。

官方修复方向(社区分析):在时间戳比较中添加约 100ms 的容差:

  • 允许 startedAtcreatedAt 前后 100ms 以内,视为正常
  • 允许 endedAtstartedAt 前后 100ms 以内,视为正常
  • 真正的时间戳违规(偏差 > 100ms)仍然会被标记

验证方法

bash
# 查看 audit 详细报告
openclaw tasks audit --verbose

# 确认是否为 running 状态任务导致
openclaw tasks audit 2>&1 | grep inconsistent_timestamps | head -20

如果所有警告都来自 running 状态或任务刚完成不久的记录,基本可以确认是这个 false positive。

等待官方修复:相关 PR 已有社区成员提交,关注 GitHub #69273 进展。