Skip to content

Blocking Synchronous I/O on the Main Thread Causes UI Stutter #28395

Description

@Daksh7785

Performance: Replace blocking filesystem operations in shell.execute with asynchronous APIs

Category: Performance
Priority: High

Affected Components

  • packages/core/src/tools/shell.ts
  • packages/cli (React Ink UI)

Summary

The shell tool performs synchronous filesystem operations (fs.mkdtempSync) on the main Node.js event loop immediately before spawning shell processes. Since the CLI UI is rendered using React Ink on the same event loop, these synchronous operations can briefly block rendering, resulting in input latency, dropped frames, and less responsive streaming output.

Current Behavior

The temporary directory used for shell execution is created synchronously:

tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gemini-shell-'));

Although this operation is typically fast, it can become noticeably slower on busy systems, network-mounted filesystems (e.g. WSL/NFS), or under heavy concurrent tool execution.

Expected Behavior

Filesystem operations in the shell execution path should be non-blocking so the React Ink UI remains responsive during tool execution and streaming.

Steps to Reproduce

  1. Run multiple shell tool invocations in quick succession.
  2. While commands are executing, type into the CLI input.
  3. Observe occasional input lag or UI stuttering.

Impact

  • Reduced UI responsiveness during shell execution.
  • Increased input latency while the agent is running commands.
  • Brief interruptions in streamed terminal output.

Suggested Solution

Replace synchronous filesystem operations in the shell execution path with their asynchronous equivalents.

A minimal implementation would:

  • Replace fs.mkdtempSync(...) with await fsPromises.mkdtemp(...).
  • Audit the same execution path for other *Sync filesystem calls and replace them where appropriate.

Since execute() is already asynchronous, this change should integrate naturally without affecting behavior.

Testing

  • Verify all existing shell execution tests continue to pass.
  • Add or update performance tests to ensure concurrent shell executions do not introduce unnecessary event loop blocking.
  • Manually verify the CLI remains responsive while multiple shell commands are executing.

Acceptance Criteria

  • No synchronous filesystem operations remain in shell.execute.
  • Existing functionality is preserved.
  • CLI responsiveness is maintained during concurrent shell executions.
  • All related tests pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreIssues related to User Interface, OS Support, Core Functionalityeffort/medium2-3 days: UI state, async flow, cross-component refactorskind/bugpriority/p2Important but can be addressed in a future release.status/bot-triaged

    Type

    Fields

    No fields configured for Bug.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions