Skip to content

poll_sessions uses blocking std::fs I/O inside tokio::spawn — holds the worker thread during session file scans #316

@ooloth

Description

@ooloth

Current state

poll_sessions is called from inside tokio::spawn in the TUI's stream_interval tick, but it performs blocking filesystem I/O (std::fs::read_dir and std::fs::read_to_string) synchronously on the tokio worker thread. Hub's Rust conventions require using tokio::fs rather than std::fs equivalents inside async contexts. The scan visits every file in the sessions directory for every in-progress task on every tick, holding the worker thread for the full duration of the scan.

Ideal state

  • poll_sessions uses tokio::fs::read_dir and tokio::fs::read_to_string (making read_session_snapshot async), or the call site in main.rs wraps poll_sessions in tokio::task::spawn_blocking
  • The tokio worker thread is never held while reading session files from disk

Starting points

  • workflows/src/agent_session.rs lines 174–199 — read_session_snapshot contains the blocking std::fs::read_dir (line 178) and std::fs::read_to_string (line 195)
  • ui/tui/src/main.rs line 295 — the tokio::spawn call site that invokes poll_sessions

QA plan

  1. Open workflows/src/agent_session.rs — confirm read_session_snapshot is not async fn and uses std::fs::read_dir at line 178 and std::fs::read_to_string at line 195
  2. Open ui/tui/src/main.rs line 295 — confirm poll_sessions is called inside tokio::spawn(async move { ... }) without spawn_blocking
  3. After the fix: confirm either read_session_snapshot uses tokio::fs equivalents and poll_sessions is async fn, or the call site in main.rs wraps the call in tokio::task::spawn_blocking
  4. Run just check — expect no warnings or errors
  5. Run just test — expect all tests to pass

Done when

poll_sessions does not hold the tokio worker thread while reading session files from disk.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions