DeepSeek-Reasonix icon indicating copy to clipboard operation
DeepSeek-Reasonix copied to clipboard

[Feature]: 界面卡死、卡顿问题

Open July-X opened this issue 5 months ago • 6 comments

Version line

v2 — Go rewrite (1.x), main-v2 (active development)

What problem does this solve?

Image

建议社区在Desktop的性能问题上面多投入点时间,现在这个体验需要重视一下了,从1.9.X好几个版本下来,还是没有看到有修复的苗头,希望大佬们能看到这个issue,也同时感谢社区的付出 @GTC2080 @SivanCola

Proposed solution

No response

July-X avatar Jun 25 '26 14:06 July-X

Image 无法停止

July-X avatar Jun 25 '26 23:06 July-X

Image

July-X avatar Jun 25 '26 23:06 July-X

已定位到一个和这组卡顿截图高度相关的前端渲染问题:恢复较长会话时,Transcript 的 warm/cold 分页公式写反了,首屏会把所有历史 warm turns 都渲染出来;长历史下这会阻塞主线程,触发 event loop lag 报告,也会让 Stop 等前台交互看起来不响应。

已在 #5355 修复:初始只渲染最近一页 warm 历史,点击“展开更早历史”时再逐页增加;同时补了回归测试覆盖这个边界。

验证:

  • PASS corepack pnpm --dir desktop/frontend exec tsx src/__tests__/transcript-grouping.test.ts
  • PASS corepack pnpm --dir desktop/frontend exec tsx src/__tests__/app-chrome-tabs.test.ts
  • corepack pnpm --dir desktop/frontend test:typecheck 当前仍被一个既有的无关类型错误挡住:src/__tests__/capabilities-panel-actions.test.ts(127,5): error TS2322: Type '"auto"' is not assignable to type 'Mode'.

合入后可以重点验证:打开/切换长历史会话时是否不再在启动后立即出现 event loop lag 报告,以及 Stop 按钮是否恢复响应。如果仍然出现“无法停止”,请再补充完整性能报告 payload、系统/版本、shell、模型,以及点击 Stop 后是否还有后台任务,我会继续沿 cancellation 路径单独排查。

GTC2080 avatar Jun 26 '26 07:06 GTC2080

已定位到一个和这组卡顿截图高度相关的前端渲染问题:恢复较长会话时,Transcript 的 warm/cold 分页公式写反了,首屏会把所有历史 warm turns 都渲染出来;长历史下这会阻塞主线程,触发 event loop lag 报告,也会让 Stop 等前台交互看起来不响应。

已在 #5355 修复:初始只渲染最近一页 warm 历史,点击“展开更早历史”时再逐页增加;同时补了回归测试覆盖这个边界。

验证:

  • PASS corepack pnpm --dir desktop/frontend exec tsx src/__tests__/transcript-grouping.test.ts
  • PASS corepack pnpm --dir desktop/frontend exec tsx src/__tests__/app-chrome-tabs.test.ts
  • corepack pnpm --dir desktop/frontend test:typecheck 当前仍被一个既有的无关类型错误挡住:src/__tests__/capabilities-panel-actions.test.ts(127,5): error TS2322: Type '"auto"' is not assignable to type 'Mode'.

合入后可以重点验证:打开/切换长历史会话时是否不再在启动后立即出现 event loop lag 报告,以及 Stop 按钮是否恢复响应。如果仍然出现“无法停止”,请再补充完整性能报告 payload、系统/版本、shell、模型,以及点击 Stop 后是否还有后台任务,我会继续沿 cancellation 路径单独排查。

这两天如果没发正式版,我周末抽空弄个dev版测试一下

July-X avatar Jun 26 '26 15:06 July-X

好的,已经收到类似的问题,会重视前端交互这方面的维护和修复

SivanCola avatar Jun 26 '26 17:06 SivanCola

#5355 已经合入,修复了长历史会话恢复时 Transcript warm/cold 分页导致的首屏渲染过多问题。这个问题会让长会话打开/切换时主线程被历史消息渲染卡住,从而更容易出现 event loop lag,前台交互也可能表现为 Stop 按钮不响应。

这次合入前又补了两个边界修复:

  • 切换 tab/session 时重置 warm/cold 分页状态,避免在一个长会话里展开过旧历史后,打开另一个长会话时复用旧的 coldPage,重新把大量历史 turn 渲染出来。
  • QuestionJumpBar 跳到更早的 cold-zone 问题时,会先 reveal 到包含目标 turn 的 warm page,再滚动到目标节点,避免收紧渲染窗口后旧问题跳转失效。

最新验证:

  • corepack pnpm -C desktop/frontend --ignore-workspace exec tsx src/__tests__/transcript-grouping.test.ts passed
  • corepack pnpm -C desktop/frontend --ignore-workspace exec tsx src/__tests__/app-chrome-tabs.test.ts passed
  • corepack pnpm -C desktop/frontend --ignore-workspace exec tsc --noEmit passed
  • GitHub Actions for #5355 passed

等 dev build 或下个正式版可用后,麻烦重点复测这两点:打开/切换长历史会话时是否还会立即出现 event loop lag,以及卡顿场景下 Stop 按钮是否恢复响应。如果仍然能复现“无法停止”,请继续补充复现路径、版本、系统、模型/提供商、以及点击 Stop 后是否还有后台任务日志;那样我会把剩余问题按 cancellation/任务中断链路继续单独排查。

SivanCola avatar Jun 26 '26 18:06 SivanCola

Image

使用的版本427658bc866f72f3e96a9e444cc5b2ea0b7def69

  1. 跨工作目录展开历史对话,似乎也会出现。当前工作目录,不同的长会话(50轮+)之间切换有改善,但是内容渲染还是有点慢。
  2. 关于“无法停止”,之前有几次是模型给的脚本hang住了,点击结束关闭不了,只能退出应用、kill相关进程。我感觉这个更多是bash调用的意外情况处理机制
  3. 还需要考虑启动的时候,双屏切换下会卡顿:默认启动在A屏(小),手动拖拽窗口到B屏(大),就容易触发卡顿

July-X avatar Jun 28 '26 01:06 July-X

Image [performance.lag]

UI responsiveness degraded because the app observed long tasks, event-loop lag, or high JS heap pressure.

--- performance context --- reason: event loop lag 3306ms uptime: 2784.6s visibility: visible focused: true online: true hardware concurrency: 8 event loop lag: current 3306ms, max 3306ms, avg 135ms over 60 samples

--- breadcrumbs --- -12.4s [bridge] nav CloseTab -12.3s [tab.hydrate] start startup tab_9f030577017ce64be5630de0638d6d67 -12.2s [bridge] turn ReplayPendingPrompts -12.0s [tab.hydrate] history done tab_9f030577017ce64be5630de0638d6d67 count=286 ms=275 -11.8s [tab.hydrate] done startup tab_9f030577017ce64be5630de0638d6d67 ms=503 -10.3s [bridge] nav OpenProjectTab -10.0s [tab.hydrate] start open-topic tab_1a635b99c4ffd44b33e0f594b4e46b99 -10.0s [bridge] turn ReplayPendingPrompts -9.4s [tab.hydrate] history done tab_1a635b99c4ffd44b33e0f594b4e46b99 count=519 ms=583 -9.0s [tab.hydrate] done open-topic tab_1a635b99c4ffd44b33e0f594b4e46b99 ms=1049 -9.0s [tab.hydrate] start startup tab_1a635b99c4ffd44b33e0f594b4e46b99 -8.7s [tab.hydrate] history skipped tab_1a635b99c4ffd44b33e0f594b4e46b99 reason=cached-transcript -8.6s [tab.hydrate] done startup tab_1a635b99c4ffd44b33e0f594b4e46b99 ms=317 -7.0s [bridge] nav RenameTopic -6.6s [bridge] nav OpenProjectTab -6.2s [tab.hydrate] start open-topic tab_c3f25312b980df0ff9649c42feeabbaa -6.2s [bridge] turn ReplayPendingPrompts -5.5s [bridge] nav OpenProjectTab -5.3s [tab.hydrate] start startup tab_c3f25312b980df0ff9649c42feeabbaa -5.1s [tab.hydrate] start open-topic tab_1a635b99c4ffd44b33e0f594b4e46b99 -4.4s [bridge] turn ReplayPendingPrompts -4.3s [tab.hydrate] history done tab_1a635b99c4ffd44b33e0f594b4e46b99 count=518 ms=722 -4.3s [tab.hydrate] history done tab_c3f25312b980df0ff9649c42feeabbaa count=1590 ms=1007 -4.3s [tab.hydrate] done open-topic tab_1a635b99c4ffd44b33e0f594b4e46b99 ms=794 -4.2s [tab.hydrate] done startup tab_c3f25312b980df0ff9649c42feeabbaa ms=1137 -3.7s [bridge] nav OpenProjectTab -3.5s [tab.hydrate] start open-topic tab_c3f25312b980df0ff9649c42feeabbaa -0.4s [bridge] turn ReplayPendingPrompts -0.2s [tab.hydrate] history done tab_c3f25312b980df0ff9649c42feeabbaa count=1590 ms=3323 -0.0s [performance] event loop lag 3306ms

build 20e99f6 反复切换历史对话,也会复现问题 v 1.13.0

July-X avatar Jun 28 '26 13:06 July-X

已根据这份新的 performance.lag payload 继续排查,当前这一段卡顿可以从代码路径确认:反复切换/打开同一个长历史 topic 时,前端会再次请求整段 HistoryForTab,即使该 tab 的 transcript 已经在内存里。1590 条历史消息场景下,这会把 Go 侧 history 转换、Wails 传输和前端同步 reducer 处理再次串到主线程上,和 payload 里的 history done ... count=1590 ms=3323 / event loop lag 3306ms 对得上。

已在 #5495 处理这一层:

  • 切回已 hydrated 的 idle tab 时,如果 session 没变,不再重新拉全量 history。
  • 重新打开已 hydrated 的 project/global/topic session 时,如果 sessionPath 没变,复用当前 transcript。
  • 如果同一个 tab 被后端 rebind 到新的 sessionPath,仍会重新加载 history,避免显示旧会话内容。

验证:

  • PASS corepack pnpm -C desktop/frontend --ignore-workspace exec tsx src/__tests__/tab-switch-hydration.test.tsx
  • PASS corepack pnpm -C desktop/frontend --ignore-workspace exec tsx src/__tests__/open-topic-coalescing.test.tsx
  • PASS corepack pnpm -C desktop/frontend --ignore-workspace exec tsc --noEmit

合入后可以重点复测:反复切换同一批长历史会话时,第二次及后续打开同一 session 的 breadcrumbs 应该出现 history skipped ... reason=cached-transcript,不再重复出现同一个 1500+ count 的 history done ... ms=...。

“bash 脚本 hang 住后无法停止”看起来是另一条 cancellation / 子进程处理路径;这次 PR 没把它混进来。如果这个问题仍能稳定复现,麻烦再补一份具体命令、系统、shell、点击 Stop 后后台进程状态,我会按停止链路单独排查。

GTC2080 avatar Jun 28 '26 14:06 GTC2080

📢Powered by MiniMax

补充几条对 #5306 / #5355 / #5495 这条修复链的额外观察,重点放在 #5495 之后仍然会存在的卡顿路径 和你最新 3 条现象的根因方向。

(升级自上一版的弱标记 "powered by MiniMax"——按新规则统一为带 emoji + 标题层级的强标记。原内容以下同。)


一、即便 #5495 合入,3.3s first-load 尖刺基本仍在

#5495 解决的是「同 session 重复拉全量 history」(切回已 hydrated 的 tab、reopen 同 sessionPath 的 topic)。但 第一次 hydrate 1590 条 history 的代码路径完全没动,尖刺还会发生:

1. Wails IPC 走同步通道,1MB+ payload 串行序列化 desktop/app.go:3096 HistoryForTab → historyMessagesWithPlannerDisplays (app.go:3132) 是 O(n) 同步循环,里面还叠了 4 个 O(n) map 构建:

  • replayedTodoArgs := historyTodoArgsWithCompleteSteps(msgs) —— 全扫
  • toolResults := historyToolResultsByID(msgs) —— 建 map
  • plannerByUserHash := plannerTurnsByUserHash(plannerTurns) —— 建 map
  • 主循环 1590 次

Go 默认 encoding/json 是单 goroutine 同步的,序列化完才能把 payload push 给 Wails 通道。1590 条 HistoryMessage(含 ToolCalls / Reasoning / MemoryCitations)单次序列化大约 200-500ms。

2. 前端 dispatch 同步触发完整 reconciliation desktop/frontend/src/lib/useController.ts:1020-1026:

const messages = asArray(history);
dispatchTo(tabId, { type: "history", messages });
addBreadcrumb("tab.hydrate", `history done ... count=${messages.length} ms=...`);

1590 条消息一次性进 reducer,React 触发完整 reconciliation,没有分批、没有 idle 切片。3.3s 大头在这。

3. Go runtime GOMAXPROCS 跟 cgroup 抢调度 项目全局 grep GOMAXPROCS 零结果,依赖 Go 默认 = runtime.NumCPU()。在受限容器(k8s cpu.quota)里跑会反复被 cgroup throttle,反而比手动设小慢。建议在 cmd/reasonix/main.go 启动时加 go.uber.org/automaxprocs 一行解决。


二、PR #5355 的覆盖 vs 这次 3.3s 的关系

  • ✅ 覆盖到的:长 transcript(>100 turn)初次进入或切 tab 时,WarmZone 渲染量从 70 turns 压到 20 turns(3.5x 减少)
  • ❌ 没覆盖到的:1590 条 messages 的 IPC 同步序列化 + React 同步 dispatch —— 是 trace 里 event loop lag 3306ms 的真主因

所以 #5355 是相邻层级的修复,跟 #5495 一起能避免「第二次打开同样长会话」的卡顿;但第一次打开 1590 条消息的会话仍会触发这个尖刺。


三、对最近 3 条现象的根因方向

1. 「跨工作目录,50 轮+ 长会话切换仍有改善但内容渲染慢」

改善的部分来自 #5355(warm/cold 分页生效);残留的慢主要在 useController.ts:986-1059 loadSessionDataForTab 的 phase 2 5 个并行 IPC 之后的整次 hydrate(trace 里 done open-topic ms=1137,其中 history 阶段 1007ms)。如果跨工作目录还触发多 tab 同时 hydrate,IPC 通道会串行化,叠加更明显。

2. 「双屏切换:A 屏小 → 拖到 B 屏大」

这条不在 #5306 已修复的代码路径上。Wails OnResize 会触发 webview 整体 reflow;如果刚好赶上 LLM stream chunk 到达 / heartbeat tick 30s 命中 / HistoryForTab 还在 IPC 通道里,三者叠加会把 B 屏的大 viewport 全量 layout 推到主线程。desktop/main.go:80-90 的 linuxWebviewGpuPolicy 是启动期决定的,运行时切屏不重判 —— 这是个观察方向:把 ReconfigureWebview 包成可重入的,让切屏时主动把 GPU 策略 review 一次。

3. 「bash 脚本 hang,点击 Stop 关闭不了,只能 kill 进程」

不在 #5306 修复链上,但跟前几轮分析的 internal/jobs 直接相关:

  • internal/jobs/jobs.go:43 DefaultTeardownGrace = 15s —— 关闭会话时只等 15s
  • internal/jobs/jobs.go:1339 CloseWithGrace 走的是 context.CancelFunc 通知子进程,但 stdio 子进程(bash run_in_background)的 stdin/stdout 通道关闭 ≠ 子进程退出 —— 如果子进程持有 OS 文件描述符(比如 tail -f、python -u http.server 之类)无视 SIGPIPE,Go 端 cancel 后子进程还在跑
  • Stop 按钮走的是 Kill 工具(internal/tool/builtin/kill_shell.go),但 kill 默认发 SIGTERM,子进程没装 trap 就直接靠默认行为退出,对 hang 住的 bash 不可靠

建议排查方向(不开 PR,先单独复测):

  • 抓 Stop 按钮按下到子进程实际退出的时间差,看是 Kill 调用路径卡住,还是 SIGTERM 没送达
  • 抓 hang 住的子进程 ps -o pid,ppid,stat,wchan,cmd,看是 D 状态(uninterruptible sleep)还是 S/R(普通阻塞)—— D 状态 Stop 按钮物理上杀不掉,必须等内核
  • 抓 jobs.Manager.emitTeardownTimeout 的 level=warn notice,看是 15s 内退出了还是 15s 后超时

四、上一轮给的 3 个修复建议的现状

建议 当前状态
修复 1:同 tab 防抖/取消上一轮 hydrate(AbortController + seq check) ✅ #5495 已覆盖(session 不变就 skip,session 变就重 hydrate)
修复 2:history 分批 dispatch + react-virtual 🟡 #5355 部分覆盖(warm/cold 分页压到 20 turns),但消息级分批 + virtual list 还没做
修复 3:Go 端增量 / 摘要 history 接口 ❌ 未动,HistoryForTab 还是全量 O(n) 返回

如果 #5495 合入后还看到 history done count=1590 ms=2000+,建议:

  • 加一个 HistoryForTabSummary 接口,只返回 message count + 最新 N 条
  • 长会话 UI 走 summary 渲染 + 滚动加载("load older messages"),让 IPC payload 从 1MB+ 降到 < 50KB
  • Go 端 historyMessagesWithPlannerDisplays 改成 stream 模式(chan HistoryMessage),不一次性 make([]HistoryMessage, n)

五、再加一条不显眼但值得看的隐患

desktop/frontend/src/lib/useController.ts:1043-1049 phase 2 的 5 个并行 IPC:

const [effort, jobs, checkpoints, context, balance] = await Promise.all([
  app.EffortForTab(tabId)...,
  app.JobsForTab(tabId)...,
  app.CheckpointsForTab(tabId)...,
  app.ContextUsageForTab(tabId)...,
  app.BalanceForTab(tabId)...,    // ← 这一个是网络调用
]);

BalanceForTab 是真实 HTTP 请求(desktop/app.go:3778 → 调 DeepSeek balance endpoint)。Promise.all 不代表并行执行——Wails IPC 走同一条 channel,这 5 个在 Go 端是串行处理的。BalanceForTab 走网络 → 慢的话会阻塞后面 4 个的 dispatch,但因 phase 2 紧跟 phase 1 之后,会被算进 hydrate 整体 ms。

建议把 BalanceForTab 推迟到 hydrate_done 之后用 fire-and-forget 单独跑,phase 2 只保留本地的 4 个。


TL;DR:#5355 + #5495 已经把"warm 渲染量"和"重复拉 history"两层修好,但 first-load 1590 条消息的主线程阻塞仍在。要彻底消化这次 3.3s 尖刺,需要 (a) Go 端 history 增量/分页接口,(b) 前端 history dispatch 分批/虚拟化,(c) BalanceForTab 推迟到 hydrate_done 之后。

July-X avatar Jun 28 '26 14:06 July-X

收到,这条补充我先按几个独立路径拆开处理,避免把不同问题混在一个修复里。

目前可以从代码路径确认的是:#5495 只覆盖“同一个已 hydrated session 反复切换/打开时重复拉全量 HistoryForTab”这一层;如果是第一次打开 1000+ / 1500+ 条消息的长历史,当前仍然会走完整 HistoryForTab → Wails payload → 前端 history reducer 这条链路。所以 #5495 合入后,如果仍能看到新的 history done ... count=1500+ ms=2000+,那会是下一层 first-load history hydrate 问题,而不是 #5495 的重复加载问题。

我也核了一下你提到的几个方向:

  • HistoryForTab 首次全量转换/传输:方向成立,当前还没做增量/分页接口。
  • 前端一次性 dispatch history:方向成立,当前仍是一次性把 history messages 转成 transcript items。
  • BalanceForTab:确实是可选网络调用,并且现在在 hydrate phase 2 里;它可能拖慢 hydrate done,但上一份 payload 里的 history done ... ms=3323 发生在 phase 2 之前,所以它不是那次 3.3s history spike 的主因。
  • kill_shell.go 这个文件名和当前代码不一致;真实路径在 internal/tool/builtin/bash_kill_* 和 internal/jobs。Stop / bash hang 应该单独按 cancellation / background job 路径排查。
  • GOMAXPROCS/automaxprocs 暂时没有足够证据指向桌面端这次卡顿,先不把它混进 UI history 修复里。

下一步建议先等 #5495 合入或 dev build 可用后复测一次。如果还能复现,请尽量补两类信息:

  1. first-load 卡顿:新的完整 [performance.lag] payload,尤其看是否仍有 history done count=... ms=...,以及它是第一次打开该 session,还是第二次/反复打开。
  2. bash 无法停止:具体命令、系统、shell、点击 Stop 后是否还有后台 job、以及如果方便的话 ps -o pid,ppid,stat,wchan,cmd 看到的子进程状态。这个我会按 Stop/cancellation 链路单独处理,不跟 history hydrate 混在同一个 PR。

如果确认 #5495 后剩余主要是 first-load 长历史,我倾向于先设计一个小的 history 初始窗口/按需加载方案,而不是继续在渲染层贴补丁;那样才能从源头减少 Go 转换、IPC payload 和前端同步 reducer 的总量。

GTC2080 avatar Jun 28 '26 14:06 GTC2080

已在 #5512 继续补齐这条 Desktop 卡顿修复链:首次打开长历史不再一次性拉取/转换/传输整段 transcript,而是先加载最新可见用户轮次窗口,旧历史按需继续加载;同时保留 #5495 的 cached transcript 复用,避免同一 session 反复切换时重复拉全量 history,并把 turn_done checkpoint 刷新和 BalanceForTab 从阻塞 hydrate 路径里拆开。

验证已经通过:GitHub Actions 全绿,包括 test (ubuntu-latest), test (macos-latest), test (windows-latest), desktop, race, lint, coverage, govulncheck, CodeQL, cache-impact。本地也跑过 go test ./internal/control、desktop history 分页测试和相关 frontend hydration 测试。

这个修复目前还在 PR #5512 中,尚未包含在当前已发布版本里;需要等 #5512 合并并进入后续 dev build / release 后再复测。

SivanCola avatar Jun 28 '26 15:06 SivanCola

#5512 has been merged and closed this issue.

What changed:

  • Long-session Desktop history now hydrates the latest visible user-turn window first and loads older history on demand.
  • Cached transcript reuse from #5495 is preserved for same-session tab/topic reopens.
  • Hydration no longer waits on the optional balance request, and checkpoint refresh is aligned with the paged history window.
  • Adjacent Stop/cancellation cleanup was also included for shell/tool and interrupted-turn paths.

Verification:

  • #5512 passed cache-impact, desktop, lint, race, coverage, CodeQL, and ubuntu/macos/windows tests.

Availability:

  • The fix is on main-v2 via #5512. It is not in the previously published 1.13.0-rc.1 build; please retest with a dev build or release that includes #5512.

SivanCola avatar Jun 28 '26 16:06 SivanCola

1.13.1

[performance.lag]

UI responsiveness degraded because the app observed long tasks, event-loop lag, or high JS heap pressure.

--- performance context --- reason: event loop lag 1543ms uptime: 59.3s visibility: visible focused: true online: true hardware concurrency: 8 event loop lag: current 1543ms, max 1543ms, avg 149ms over 38 samples

--- breadcrumbs --- -22.9s [tab.hydrate] history page tab_f97322f6d3f954a48fcc65ff9abf345a messages=213 turns=0-4/4 ms=590 -22.1s [tab.hydrate] done open-topic tab_f97322f6d3f954a48fcc65ff9abf345a ms=1372 -18.1s [bridge] nav OpenProjectTab -18.0s [tab.hydrate] start open-topic tab_9bd7a43e55e4704f0205e6cf34cba4d8 -17.5s [bridge] turn ReplayPendingPrompts -17.5s [tab.hydrate] history skipped tab_9bd7a43e55e4704f0205e6cf34cba4d8 reason=cached-transcript -16.9s [tab.hydrate] done open-topic tab_9bd7a43e55e4704f0205e6cf34cba4d8 ms=1024 -13.0s [bridge] nav OpenProjectTab -12.9s [tab.hydrate] start open-topic tab_f97322f6d3f954a48fcc65ff9abf345a -12.3s [bridge] turn ReplayPendingPrompts -12.2s [tab.hydrate] history skipped tab_f97322f6d3f954a48fcc65ff9abf345a reason=cached-transcript -12.0s [tab.hydrate] done open-topic tab_f97322f6d3f954a48fcc65ff9abf345a ms=927 -7.6s [bridge] nav OpenProjectTab -7.5s [tab.hydrate] start open-topic tab_7b578a21cfb3f7509ce5b71824edaa6b -7.4s [bridge] turn ReplayPendingPrompts -7.1s [tab.hydrate] history page tab_7b578a21cfb3f7509ce5b71824edaa6b messages=771 turns=0-6/6 ms=398 -6.2s [tab.hydrate] done open-topic tab_7b578a21cfb3f7509ce5b71824edaa6b ms=1241 -4.9s [bridge] nav OpenProjectTab -4.7s [tab.hydrate] start open-topic tab_25878346b60619f7e202ed64c3205846 -4.7s [bridge] turn ReplayPendingPrompts -4.4s [tab.hydrate] history page tab_25878346b60619f7e202ed64c3205846 messages=216 turns=0-2/2 ms=305 -3.6s [tab.hydrate] done open-topic tab_25878346b60619f7e202ed64c3205846 ms=1104 -3.3s [bridge] nav OpenProjectTab -3.0s [tab.hydrate] start open-topic tab_c84802c2e9b202dcc02bc01b7de4f364 -3.0s [bridge] turn ReplayPendingPrompts -2.2s [tab.hydrate] history page tab_c84802c2e9b202dcc02bc01b7de4f364 messages=612 turns=0-6/6 ms=818 -2.2s [tab.hydrate] start startup tab_c84802c2e9b202dcc02bc01b7de4f364 -0.6s [tab.hydrate] history skipped tab_c84802c2e9b202dcc02bc01b7de4f364 reason=cached-transcript -0.5s [tab.hydrate] done startup tab_c84802c2e9b202dcc02bc01b7de4f364 ms=1642 -0.0s [performance] event loop lag 1543ms

build aaaf863

@GTC2080 @SivanCola

July-X avatar Jun 29 '26 07:06 July-X

📢Powered by MiniMax

build 1.13.1 / aaaf863 的新 performance.lag payload,uptime 59s、max 1543ms,补充几条观察(以及一个对 #5512 修复链的二次回归)。


一、#5355 + #5495 + #5512 都生效了,这点先确认

crumbs 里出现 history page 而不是 history done,说明分页接口上线了。history skipped reason=cached-transcript 出现两次,说明缓存路径走通。event loop lag 从 3.3s 降到 1.5s,数量级变化对得上。

但 1.5s 还在阈值之上,继续看下面。


二、新 trace 暴露的两条 #5512 没修干净的线

1. tab_c84802... 在 0.7s 内被 hydrate 了两次

-2.2s [tab.hydrate] start open-topic tab_c84802c2e9b202dcc02bc01b7de4f364
-2.2s [tab.hydrate] history page ... messages=612 turns=0-6/6 ms=818
-2.2s [tab.hydrate] start startup tab_c84802c2e9b202dcc02bc01b7de4f364
-0.6s [tab.hydrate] history skipped ... reason=cached-transcript
-0.5s [tab.hydrate] done startup ... ms=1642

第二次 startup 路径触发了,虽然 history 被 cached-transcript 跳过了(功劳是 #5495),但 phase 2 的 5 个并行 IPC 跑了两遍——done startup ms=1642 跟 event loop lag 1543ms 几乎完全对齐,所以这次尖刺就是它。

这跟「同 tab 重复拉 history」不是同一个问题。这次是「同 tab 走了两条不同的 hydrate 路径」,#5512 解决的是 cached,没解决「两条路径并存」。源头在 useController.ts:1089 / 1117 / 1202 这三处 loadSessionDataForTab 调用——startup reason 和 open-topic reason 在某些条件下都会被触发。tabSnapshotLoop (tabs.go:2435) 启动时也会再触发一次。

2. 启动期 5 个 tab 在 23s 内连续 hydrate,无 stagger

T-22.9  tab_f97322...  open-topic, history page 213msg, done 1372ms
T-17.5  tab_9bd7a4...  open-topic, history SKIPPED cached-transcript     ← #5495 工作
T-12.9  tab_f97322...  open-topic, history SKIPPED cached-transcript     ← #5495 工作
T-7.5   tab_7b578a...  open-topic, history page 771msg, done 1241ms
T-4.7   tab_25878...   open-topic, history page 216msg, done 1104ms
T-3.3   tab_c8480...   open-topic, history page 612msg, done 1642ms     ← 这次尖刺
T-0.0   event loop lag 1543ms

bridge nav OpenProjectTab 由后端主动 fire,不是用户点击。23s 内 5 个 tab 全部走 open-topic。每个 1100-1700ms,Wails IPC 跨 5 个 tab 顺序处理。

avg 149ms over 38 samples 38 个样本跨 38s,意味着启动 1 分钟内持续高 lag,不是孤立尖刺——这是 5 tab 持续派发 IPC 的总和。

restoreOrBuildTabs() (app.go:366) 是冷启动恢复逻辑,我没看完整实现,但没有 stagger / debounce 这件事在 trace 上能看出来。给所有 tab 同步 await loadSessionDataForTab,IPC 排队,平均 lag 上去了。


三、phase 2 的 BalanceForTab 路径

useController.ts:1043-1049:

const [effort, jobs, checkpoints, context, balance] = await Promise.all([
  app.EffortForTab(tabId)...,
  app.JobsForTab(tabId)...,
  app.CheckpointsForTab(tabId)...,
  app.ContextUsageForTab(tabId)...,
  app.BalanceForTab(tabId)...,    // ← 网络调用
]);

SivanCola 在 #5512 描述里提到「把 turn_done checkpoint 刷新和 BalanceForTab」放到了某种延迟路径——具体怎么处理的要再看 #5512 实际代码。如果只是「turn_done 触发时才跑」,那 open-topic 路径第一次进 tab 仍然跑 BalanceForTab,而 done open-topic ms=1241 里的 200-300ms 后置延迟,很可能就是它。

如果 #5512 还没把 BalanceForTab 推迟到 hydrate_done 之后 fire-and-forget,推荐合上去。BalanceForTab 走真实 HTTP 到 DeepSeek balance endpoint,网络抖动 1s 是常见的,放在 hydrate critical path 上风险高。


四、给后续诊断的几条具体建议

  1. 查 useController.ts:1089 / 1117 / 1202 / 1999 这几个 loadSessionDataForTab 调用点,看 tab_c84802... 这次的 start open-topic + start startup 是哪两个点同时 fire 的——修法是在 loadSessionDataForTab 入口加 if (inFlight.has(tabId)) return,跟 bumpSessionLoadSeq 配合

  2. 在 tab.hydrate done breadcrumb 里加 phase_1_ms / phase_2_ms 两个细分字段——把 phase 1 history page 和 phase 2 5 IPC 的时间分开记,定位 BalanceForTab 拖累是不是 1.5s 尖刺的主要贡献

  3. 在 restoreOrBuildTabs() 里加 stagger——5 个 tab 不要同步 await,改成 for tab of tabs { await hydrate(tab); await sleep(50ms) },让 IPC 通道在 23s 内不堆 5 个 hydrate 排队

  4. bridge nav OpenProjectTab 触发源头——查 restoreOrBuildTabs 是怎么调起 OpenProjectTab 的,可能它在冷启动时把「所有 tab 标记为 active」触发全部 fire;如果是这样,应该改成「只 hydrate 当前 active tab + 把其它 tab 的 hydrate 延后到 idle / 可见时」


五、对比表

维度 #5306 上次 trace (3.3s) 这次 trace (1.5s)
uptime 2784s 59s
avg / max 135 / 3306 ms 149 / 1543 ms
history 阶段 history done count=1590 ms=3323 history page 612msg 6turns ms=818 (分页)
同 tab 重复拉 history 是(5 次) 否(#5495)
启动期多 tab 风暴 是 仍在(新证据)
startup + open-topic 双路径触发 是 仍在(同 tab 0.7s 内两次)
BalanceForTab phase 2 后置 估计 200-300ms 仍 ~240ms

主线卡顿从「单次同步大 IPC」迁移到「启动期多 tab 持续 IPC 风暴 + 同 tab 双 hydrate 路径」。#5355 + #5495 + #5512 把第一条解决了,第二条还没动。


TL;DR

build 1.13.1 上复测,#5512 修了 first-load 长历史的 window 加载和 BalanceForTab 推迟(部分),#5306 关闭后这条新 trace 暴露的是启动期 5 tab 连续 hydrate 风暴 + 同 tab open-topic + startup 双路径并存——这两条不在已合入的 PR 覆盖范围。下一步可以查 useController.ts 三个 loadSessionDataForTab 调用点和 restoreOrBuildTabs 的 fire 策略。

July-X avatar Jun 29 '26 07:06 July-X

已根据 1.13.1 / aaaf863 这份新 payload 继续做了一个 follow-up 修复,PR 在 #5580。

这次问题可以从代码路径确认:open-topic hydrate 仍在进行时,agent:ready 会对同一个 active tab 再触发一次 startup hydrate。虽然第二轮 history 会因为 cached transcript 被跳过,但 phase 2 的本地 IPC(effort/jobs/checkpoints/context)仍会再跑一遍,并且会 bump session load seq,让前一轮 hydrate 变旧。这和 payload 里的同 tab history page ... 后立刻 start startup / done startup ms=1642 对得上。

#5580 的修复范围很小:

  • 在 loadSessionDataForTab 入口复用同 tab、同 sessionPath 的 in-flight hydrate,让后续非 reset startup 加入正在进行的 open-topic hydrate。
  • reset / session 变更仍会打断旧 hydrate,避免显示旧会话内容。
  • live-turn skip hydrate 仍保持独立,不改变当前切 tab 的 live transcript 行为。
  • 增加了回归测试,覆盖 openProjectTab 后 phase 2 尚未结束时收到 agent:ready 的场景,确保不会再发第二轮 context/phase 2 IPC。

验证:

  • PASS corepack pnpm -C desktop/frontend --ignore-workspace exec tsx src/__tests__/tab-switch-hydration.test.tsx
  • PASS corepack pnpm -C desktop/frontend --ignore-workspace exec tsx src/__tests__/open-topic-coalescing.test.tsx
  • PASS corepack pnpm -C desktop/frontend --ignore-workspace exec tsc --noEmit

等包含 #5580 的 dev build / release 可用后,可以重点复测这条路径:快速打开/切换 topic 后,同一个 tab 不应再在 history page ... 后马上出现一轮新的 start startup / done startup hydrate。如果仍能看到 event loop lag,麻烦继续贴完整 [performance.lag] payload,尤其是 tab.hydrate breadcrumbs,我会继续按剩余的启动期多 tab hydrate 风暴单独拆。

GTC2080 avatar Jun 29 '26 12:06 GTC2080

[performance.lag]

UI responsiveness degraded because the app observed long tasks, event-loop lag, or high JS heap pressure.

--- performance context --- reason: event loop lag 1253ms uptime: 36674.7s visibility: visible focused: true online: true hardware concurrency: 8 event loop lag: current 1253ms, max 1253ms, avg 47ms over 61 samples

--- breadcrumbs --- -36673.1s [tab.hydrate] start startup tab_891c137c486ed9c34285c26bf67a5c4a -36673.1s [tab.hydrate] start startup tab_891c137c486ed9c34285c26bf67a5c4a -36672.5s [tab.hydrate] start startup tab_891c137c486ed9c34285c26bf67a5c4a -36671.4s [tab.hydrate] start startup tab_891c137c486ed9c34285c26bf67a5c4a -36671.4s [tab.hydrate] start startup tab_891c137c486ed9c34285c26bf67a5c4a -36670.3s [tab.hydrate] start startup tab_891c137c486ed9c34285c26bf67a5c4a -36662.0s [tab.hydrate] history page tab_891c137c486ed9c34285c26bf67a5c4a messages=367 turns=0-18/18 ms=8255 -36662.0s [tab.hydrate] done startup tab_891c137c486ed9c34285c26bf67a5c4a ms=8337 -36554.8s [bridge] turn SubmitToTab -35745.0s [bridge] turn SubmitToTab -35694.8s [bridge] turn SteerForTab -35667.6s [bridge] update CheckUpdate -35217.9s [bridge] turn SteerForTab -34314.2s [bridge] turn SteerForTab -34124.0s [bridge] turn SubmitToTab -33839.6s [bridge] turn SubmitDisplayToTab -33551.6s [bridge] turn SubmitToTab -32320.4s [bridge] turn SubmitDisplayToTab -28275.6s [bridge] turn SubmitToTab -28160.5s [bridge] turn SubmitToTab -27994.7s [bridge] turn SubmitDisplayToTab -12896.1s [network] offline -12876.2s [network] online -14.5s [bridge] turn SubmitToTab -2.1s [bridge] nav OpenProjectTab -1.9s [tab.hydrate] start open-topic tab_9bd7a43e55e4704f0205e6cf34cba4d8 -1.8s [bridge] turn ReplayPendingPrompts -1.4s [tab.hydrate] history page tab_9bd7a43e55e4704f0205e6cf34cba4d8 messages=291 turns=0-41/41 ms=455 -0.0s [tab.hydrate] done open-topic tab_9bd7a43e55e4704f0205e6cf34cba4d8 ms=1892 -0.0s [performance] event loop lag 1253ms

build aaaf863

@GTC2080 @SivanCola

July-X avatar Jun 30 '26 00:06 July-X

#5619 has been merged into main-v2 as the next follow-up in this Desktop performance chain.

这次修复聚焦 1.13.1 复测 payload 里暴露的 hydration 风暴,不把所有 Desktop 性能问题混在一个 PR 里:

  • 当 open-topic hydrate 还在进行时,后续同 tab / 同 sessionPath 的非 reset startup / agent:ready hydrate 会复用正在进行的加载,不再重复跑 phase-2 IPC。
  • 后端 agent:ready 现在会带上完成构建的 tab id;前端会忽略后台 tab 的 ready 事件,避免后台 tab ready 误触发当前 active tab 的 hydrate。
  • meta/history 到达后先解除可见 transcript loading;effort/jobs/checkpoints/context 延后执行,并在 tab 已切走时跳过 ancillary phase。

这版保留并扩展了 @GTC2080 在 #5580 中提出的 in-flight hydration coalescing 方案。#5619 的 PR body 已明确把 @GTC2080 记为这条仓库修复的共同贡献者。

验证:

  • #5619 GitHub Actions 全绿,包括 cache-impact, desktop, lint, race, coverage, CodeQL, test (ubuntu-latest), test (macos-latest), test (windows-latest)。
  • 本地验证包括 tab-switch-hydration.test.tsx, open-topic-coalescing.test.tsx, tsc --noEmit, desktop frontend full test, and (cd desktop && go test ./...)。

可用性和复测建议:

  • 修复已在 main-v2,需要等包含 #5619 的 dev build / release 后复测;它不在之前贴出的 1.13.1 / aaaf863 构建里。
  • 复测时请重点看:快速打开/切换 topic 后,同一个 tab 是否还会在 open-topic 后马上出现新的 start startup / 长时间 done startup,以及后台 tab ready 是否还会触发当前 tab hydrate。
  • 如果仍然能看到 event loop lag,请继续贴完整 [performance.lag] payload;剩余问题可能属于 first-load/history render、启动期多 tab hydrate 队列、或 Stop/cancellation 链路,我会继续拆开处理。

SivanCola avatar Jun 30 '26 03:06 SivanCola

[performance.lag]

UI responsiveness degraded because the app observed long tasks, event-loop lag, or high JS heap pressure.

--- performance context --- reason: event loop lag 2857ms uptime: 284.1s visibility: visible focused: true online: true hardware concurrency: 8 event loop lag: current 2857ms, max 2857ms, avg 110ms over 61 samples

--- breadcrumbs --- -18.2s [bridge] turn ReplayPendingPrompts -17.4s [tab.hydrate] history page tab_265778865df4bc34b2058d1c1e8bc71a messages=551 turns=0-39/39 ms=836 -17.4s [tab.hydrate] done open-topic tab_265778865df4bc34b2058d1c1e8bc71a ms=836 -16.6s [tab.hydrate] ancillary open-topic tab_265778865df4bc34b2058d1c1e8bc71a ms=795 -15.9s [tab.hydrate] start startup tab_265778865df4bc34b2058d1c1e8bc71a -15.1s [tab.hydrate] history skipped tab_265778865df4bc34b2058d1c1e8bc71a reason=cached-transcript -15.1s [tab.hydrate] done startup tab_265778865df4bc34b2058d1c1e8bc71a ms=799 -14.6s [tab.hydrate] ancillary startup tab_265778865df4bc34b2058d1c1e8bc71a ms=394 -8.0s [bridge] nav CloseTab -8.0s [bridge] nav CloseTab -8.0s [bridge] nav CloseTab -8.0s [bridge] nav CloseTab -8.0s [bridge] nav CloseTab -7.9s [bridge] nav CloseTab -7.9s [bridge] nav CloseTab -7.7s [tab.switch] click tab_265778865df4bc34b2058d1c1e8bc71a -7.7s [tab.switch] active-rendered tab_265778865df4bc34b2058d1c1e8bc71a ms=0 -7.7s [bridge] nav SetActiveTab -7.7s [tab.switch] set-active-done tab_265778865df4bc34b2058d1c1e8bc71a ms=18 -7.0s [tab.hydrate] start switch-tab tab_265778865df4bc34b2058d1c1e8bc71a -6.7s [tab.hydrate] history skipped tab_265778865df4bc34b2058d1c1e8bc71a reason=cached-transcript -6.7s [tab.switch] history-done tab_265778865df4bc34b2058d1c1e8bc71a skipped ms=267 -6.7s [tab.hydrate] done switch-tab tab_265778865df4bc34b2058d1c1e8bc71a ms=267 -6.7s [tab.hydrate] ancillary switch-tab tab_265778865df4bc34b2058d1c1e8bc71a ms=13 -3.8s [bridge] nav OpenProjectTab -3.4s [tab.hydrate] start open-topic tab_e46902e80296412d84404164239f379c -3.4s [bridge] turn ReplayPendingPrompts -3.0s [tab.hydrate] history page tab_e46902e80296412d84404164239f379c messages=865 turns=0-16/16 ms=427 -3.0s [tab.hydrate] done open-topic tab_e46902e80296412d84404164239f379c ms=427 -0.0s [performance] event loop lag 2857ms

build 97a6d61

v 1.14.0 还会触发 @SivanCola @GTC2080

July-X avatar Jun 30 '26 14:06 July-X

[performance.lag]

UI responsiveness degraded because the app observed long tasks, event-loop lag, or high JS heap pressure.

--- performance context --- reason: event loop lag 1982ms uptime: 1170.2s visibility: visible focused: true online: true hardware concurrency: 8 event loop lag: current 1982ms, max 1982ms, avg 70ms over 60 samples

--- breadcrumbs --- -1170.0s [app] start -1169.5s [view] visible -1169.3s [bridge] turn ReplayPendingPrompts -1169.0s [tab.hydrate] start startup tab_7c5440f2ccb240397320cf44e59cbe51 -1168.9s [bridge] turn ReplayPendingPrompts -1167.9s [tab.hydrate] history page tab_7c5440f2ccb240397320cf44e59cbe51 messages=699 turns=0-8/8 ms=1135 -1167.9s [tab.hydrate] done startup tab_7c5440f2ccb240397320cf44e59cbe51 ms=1135 -1167.1s [tab.hydrate] ancillary startup tab_7c5440f2ccb240397320cf44e59cbe51 ms=830 -3.1s [bridge] settings SetDesktopLayoutStyle -0.0s [performance] event loop lag 1982ms

build 56a5323

v 1.14.1 @SivanCola @GTC2080

July-X avatar Jul 01 '26 06:07 July-X