Skip to content

v1.5.8:Trae 日志解析阻塞导致 aiusage serve 启动慢、首页卡在加载状态 #40

Description

@willtse

Description

aiusage serve 启动后,浏览器打开首页会长时间停留在加载状态。初步定位后发现问题不是浏览器渲染或静态资源加载失败,而是 Trae 日志解析耗时过长,阻塞了
serve 启动和首页 /api/refresh 请求。

在当前环境中,Trae 解析单次约耗时 40 秒,导致:

  • aiusage serve 端口监听延迟
  • 首页首屏等待 /api/refresh 返回
  • /api/refresh 同步等待完整解析完成
  • 浏览器表现为页面卡住

Steps to Reproduce

  1. 安装并运行 aiusage v1.5.8:

    npm install -g @juliantanx/aiusage
    aiusage parse
    aiusage serve
    
  2. 打开浏览器访问:

    http://localhost:3847/

  3. 页面长时间停留在加载状态。

Expected Behavior

aiusage serve 应该快速启动并监听端口。

首页应优先展示已有数据库中的数据,即使后台正在解析日志,也不应阻塞首屏加载。

Actual Behavior

页面长时间卡在加载状态。

实测:

[serve] parsing logs...
[serve] parsed 2 records, 2 tool calls.
aiusage serve listening on http://localhost:3867
ROOT status=200 ms=20
REFRESH status=200 ms=40815

单独执行解析:

Parsed 6 records, 8 tool calls.
EXIT=0 MS=40252

隔离所有真实日志源后:

Parsed 0 records, 0 tool calls.
EXIT=0 MS=411

按工具单独计时:

opencode MS=397
codex MS=427
claude-code MS=401
pi MS=398
kimi MS=382
trae MS=40688
qoder MS=379
kiro MS=381

主要耗时来自 trae。

Environment

  • OS: Windows,PowerShell 环境
  • Node.js version: v24.15.0
  • npm version: 11.18.0
  • aiusage version: 1.5.8
  • Global command path: D:\soft\scoop\apps\fnm\current\aliases\default\aiusage.cmd

Additional Context

Trae snapshot 规模:

{
"snapshotDirs": 72,
"gitRepos": 72,
"looseTags": 696,
"packedTags": 0,
"totalTags": 696,
"maxTagsPerRepo": 95
}

初步定位到 packages/cli/src/commands/parse-trae.ts 中 Trae parser 会对 snapshot git 仓库执行大量同步 git 子进程调用:

spawnSync('git', ['tag', '-l'], ...)
spawnSync('git', ['log', '-1', '--format=%at', t], ...)

当前环境中有 72 个 snapshot git 仓库、696 个 tag,每次解析都会重复扫描这些 tag。并且 already imported 判断发生在昂贵的 tag 扫描之后,所以旧 session
也会反复承担 git 扫描成本。

可能的修复方向:

  • Trae parser 在执行昂贵 git 操作前,尽早跳过已导入 session
  • 避免对每个 tag 单独执行一次 git log,改成批量读取 tag/ref/时间
  • 对 snapshot repo 增加 watermark,例如 repo mtime、HEAD、tag count 或最新 tag 时间
  • serve 优先监听端口,再后台解析
  • 首页先加载已有数据库摘要,再后台触发 refresh
  • /api/refresh 返回任务状态,而不是同步等待完整解析完成

临时绕过方式:

$env:AIUSAGE_TRAE_PATH = 'D:\tmp\aiusage-no-such-path'
aiusage serve

或者只解析指定工具:

aiusage parse --tool codex --no-progress


当前 v1.5.8 版本
npm install -g @juliantanx/aiusage
aiusage parse
aiusage serve
启动后打开网页 http://localhost:3847/ 一直是 Landing, 上面是 AI 帮我分析的情况,麻烦大佬看看呢。

按下面的方式可以启动

$env:AIUSAGE_TRAE_PATH = 'D:\tmp\aiusage-no-such-path'
aiusage serve

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions