Skip to content

Batch agent events and prioritize input in TUI event loop #500

@bug-ops

Description

@bug-ops

Parent: #499

Problem

tui_loop() in crates/zeph-tui/src/lib.rs processes one event per tokio::select! iteration, then draws a full frame. During fast streaming or parallel tool execution, agent events dominate the select and keyboard events queue up, causing perceived freeze.

Additionally, tokio::select! gives no priority to input events over agent events, so under load user keypresses can be starved.

Fix

  1. Use biased tokio::select! with input events checked first
  2. After waking on an agent event, drain all pending agent events via try_recv() before drawing
  3. This batches multiple chunks into a single frame, reducing draw calls and prioritizing user input

Files

  • crates/zeph-tui/src/lib.rs (tui_loop function)
  • crates/zeph-tui/src/app.rs (may need a drain_agent_events method)

Acceptance Criteria

  • Input events are processed with priority over agent events
  • Multiple agent events between frames are batched into one draw call
  • No regression in streaming display quality

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