Skip to content

v0.8.68 Performance: TUI lag and memory pressure from high agent fan-out sessions #4014

Description

@Hmbown

Problem

When 30+ sub-agents are running in parallel (as in the v0.8.68 development session on 2026-07-03), the terminal UI becomes increasingly laggy. Observed symptoms:

  • Typing latency increases significantly
  • Terminal rendering stalls
  • Memory pressure on the host machine ("my computer is freaking out")
  • Agent completion events flood the parent session, bloating the transcript

This makes high-fan-out orchestration unusable for real work — the tool becomes the bottleneck at exactly the scale where it should shine.

Likely causes

  1. Agent completion event flooding — Each agent completion sends a <codewhale:runtime_event> with a full summary into the parent transcript. 30+ completions = massive transcript growth
  2. Unbounded context growth — No mechanism to summarize or prune completed agent entries from the parent context
  3. Render thrashing — The TUI re-renders the full transcript on every event, and 30 simultaneous completions trigger 30 re-renders
  4. Worktree filesystem pressure — 40+ git worktrees each with their own build artifacts consume disk and inode resources

Scope

This issue covers the performance/degradation path:

  1. Throttle event ingestion — Batch agent completion events into a single render cycle instead of re-rendering per event
  2. Compress agent results in transcript — Store only verdict + key stats in the parent transcript; full agent output goes to artifact files
  3. Context budget auto-compaction — Trigger compaction when context pressure exceeds a threshold driven by agent fan-out
  4. Worktree lifecycle — Auto-delete worktrees after agent completion (or after configurable TTL)
  5. Render debouncing — Coalesce rapid TUI redraws during high-event periods

Non-goals

  • Not reducing agent concurrency. The goal is to handle high fan-out, not avoid it.
  • Not removing agent event data — just not rendering it all in the live transcript.

Acceptance

  • 30+ concurrent agents should not cause visible typing latency
  • Parent context should not grow unboundedly from agent completion events
  • Terminal rendering remains responsive during agent storm
  • Worktree disk usage is bounded (auto-cleanup)
  • Tests: benchmark transcript growth with N simulated agent completions; measure render latency

Evidence

Observed live on 2026-07-03 running CodeWhale 0.8.67 with 41 sub-agents. Terminal became laggy, memory pressure was high, several agents cancelled themselves due to resource contention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or requestperformanceRuntime/render performancetuiTerminal UI behavior, rendering, or interactionv0.8.68Targeting v0.8.68whaleflowWhaleFlow branch/leaf workflow runtime and workflow mode

    Projects

    Status
    Backlog

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions