diagnose-wg-tui

Diagnose: wg tui consumes 55% CPU sustained — likely related to scrollback duplication bug

Metadata

Statusdone
Assignedagent-1077
Agent identity3184716484e6f0ea08bb13539daf07686ee79d440505f1fdf2de0357707034c3
Created2026-04-29T11:44:38.010908088+00:00
Started2026-04-29T11:45:00.581584584+00:00
Completed2026-04-29T11:50:41.293687689+00:00
Tagsbug,tui,perf, eval-scheduled
Eval score0.81
└ blocking impact0.80
└ completeness0.82
└ coordination overhead0.85
└ correctness0.85
└ downstream usability0.90
└ efficiency0.85
└ intent fidelity0.71
└ style adherence0.85

Description

Description

User report: wg tui is using 55% CPU sustained.

Verified 2026-04-29 morning: ps -o pid,pcpu,etime,args showed:

PID     %CPU  ELAPSED  COMMAND
2535288 55.5  15:11    wg tui

This is alongside an active scrollback duplication symptom the user is reporting on initial chat-tab render (filed as fix-pty-scrollback). Hypothesis: same root cause — a render path running far more often than it should, which both burns CPU and re-emits buffer content faster than the diff reconciler handles, producing visible duplication.

Goal

Profile wg tui under typical idle conditions (graph open, one chat tab visible, no user input) and identify what's running every frame. Output should be a list of hotspots with suggested fixes.

Specific things to check

  • Is the render loop event-driven (waits for input/event) or polling-driven (busy-loop with sleep_ms)?
  • Are there any tight loops without proper backoff in: PTY reader, chat event stream parser, graph watcher consumer, scrollback re-wrap?
  • Is the layout/wrap recomputed every frame even when content hasn't changed?
  • Any uncached file reads on every tick (chat history file, graph.jsonl, registry)?
  • Is the daemon socket being polled by the TUI separately from the fs-watcher?

Tools

  • perf record -p $(pgrep -f 'wg tui') -F 99 -- sleep 30 && perf report — sample profile
  • Or samply record if perf is unavailable
  • strace -c -p <pid> for syscall breakdown — high syscall rate during idle = busy-loop somewhere

Validation

  • Profile captured (perf or samply) and saved as a flame-graph or top-functions list in the task log
  • Hotspot identified — function + estimated % of CPU spent
  • Hypothesis confirmed or refuted: is this the same root cause as fix-pty-scrollback's symptom? If yes, propose merging the fixes; if no, document why they're separate
  • Recommended fix(es) noted with file/function pointers — the actual fix lands in a follow-up task (fix-tui-cpu or rolled into fix-pty-scrollback)
  • No source modifications — diagnose only

Depends on

Required by

Log