Skip to content

[BUG] Synchronous Unix command loading blocks UI during completion #164

@jlguo

Description

@jlguo

Issue: Synchronous Unix command loading blocks UI during completion

Problem Description

When users trigger command completion (e.g., typing / or @), the system scans all PATH directories synchronously, causing UI freezing/hanging. This results in delayed or unresponsive command suggestions, especially on systems with many PATH entries or slow filesystems.

Current Behavior

  • Command completion triggers synchronous scanning of all PATH directories using readdirSync and statSync
  • UI becomes unresponsive during scanning
  • Users must wait for full PATH scanning to complete before seeing command suggestions
  • No immediate fallback commands are provided

Expected Behavior

  • Command completion should be responsive and non-blocking
  • Users should see immediate basic command suggestions while full list loads in background
  • UI should remain responsive during command loading

Root Cause

The loadSystemCommands function in src/ui/hooks/useUnifiedCompletion.ts (lines 118-175) uses blocking synchronous file operations:

  • readdirSync and statSync for scanning PATH directories
  • No event loop yielding during batch processing
  • No immediate fallback command provision

Impact

  • User Experience: Poor with laggy/unresponsive command completion
  • Performance: UI freezes during PATH scanning
  • Responsiveness: Slower startup/initialization of completion features

Files Affected

  • src/ui/hooks/useUnifiedCompletion.ts (lines 118-175 - loadSystemCommands function)

Reproduction Steps

  1. Open the CLI application
  2. Type / to trigger command completion
  3. Observe UI freezing/hanging while system scans PATH directories
  4. Notice delayed appearance of command suggestions

Environment

  • OS: Any (more noticeable on systems with many PATH entries)
  • Application: CLI with command completion feature
  • Affected Version: Current main branch

Priority

Medium-High - Affects core user interaction with command completion

Suggested Solution

Convert synchronous file operations to asynchronous with:

  1. Immediate provision of minimal fallback commands
  2. Async fs/promises operations (readdir, stat)
  3. Batch processing with event loop yielding
  4. Better error handling for individual file/directory failures

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions