fix(agentruntime,tui): cut startup section-collector stall; add slow-handler instrumentation - #2538
Merged
Merged
Conversation
…handler instrumentation User-reported: after startup renders, the TUI freezes for seconds (keys dead, cursor static) before becoming responsive. Profiling a fresh instance with macOS 'sample' during the window plus a 600k-line session resume reproduction (3.3s pure encoding/json parse + 1.7s GC on the main thread inside REPL.loadSession) confirmed the freeze is real and startup-path-bound, while the 2026-09-18 debug log pinned the smoking gun: a 250ms input-drain tea.Tick landing 17.4s after program start - the single-threaded Bubble Tea loop was blocked for 17s with no attribution of which handler/frame paid for it. Two changes: 1. section_collector: firstRefreshBudget 5s -> 800ms. The synchronous first refresh sits on the interactive startup path BEFORE the Bubble Tea loop starts - past-budget machines paid a multi-second dead black screen. The background refresh loop already fills empty sections after the budget (designed-in fallback), so dropping the wait only trades prompt-section freshness for startup latency on slow filesystems. Warm-cache machines finish well under 300ms and see no behavior change. 2. tui dispatch: slow-handler instrumentation. Any Update handler over 100ms logs 'slow update handler: type=%T duration=...' to the debug log. This turns the next freeze reproduction into a one-line attribution instead of requiring a profiler attach; it is what will pinpoint the remaining 17s blockage (suspects: first-frame render with uncached multi-KB chat items, startup message storm from LAN Chat presence + MCP connects each triggering a full View frame). No behavior change for fast paths; tests green in both packages. Co-Authored-By: ggcode <noreply@ggcode.dev>
This was referenced Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
用户报告
启动渲染完成后 TUI freeze 几秒(按键失效/光标静止),过一会恢复。/usage 面板同窗口无响应。
取证
修复
验证
internal/tui + internal/agentruntime 两包测试绿。
Co-Authored-By: ggcode noreply@ggcode.dev