Skip to content

Fix Slash-Command UI Freeze on New Tasks (Bug#1081)#1107

Open
DevDesai444 wants to merge 1 commit intogeneralaction:mainfrom
DevDesai444:Bug-1081-DevDesai
Open

Fix Slash-Command UI Freeze on New Tasks (Bug#1081)#1107
DevDesai444 wants to merge 1 commit intogeneralaction:mainfrom
DevDesai444:Bug-1081-DevDesai

Conversation

@DevDesai444
Copy link
Contributor

Description

Fixes UI freezewhen typing / immediately after creating a new task (#1081).

Problem Identified

The first slash-command interaction on a fresh task could block the renderer thread due to a combination of startup-time hot paths:

  1. Large PTY output bursts were written synchronously into xterm in a single pass.
  2. Activity classification fanned out too aggressively (multiple per-provider/per-kind listeners), increasing work exactly when the terminal first became active.
  3. Activity classification processed full chunks, which is expensive for large buffered output.
  4. Terminal activity wrote to localStorage repeatedly, adding synchronous overhead during early typing.

This made the UI feel frozen/stuttery right when / was typed.

How This PR Solves It

1) Reduce main-thread blocking from terminal output

  • Added frame-sliced terminal write draining in TerminalSessionManager so big PTY bursts are processed incrementally instead of one heavy synchronous write.
  • Preserved scroll behavior and first-frame handling.
  • Added slow input-path telemetry logging (terminalSession:slowInputHandler) to surface future regressions.

2) Reduce activity-event overhead

  • Main process now emits a global PTY activity channel (pty:activity) and global PTY exit channel (pty:exit:global).
  • Renderer activityStore now prefers the global feed and only falls back to direct listeners when needed.

3) Bound classifier work per event

  • Added shared chunk sampling (sampleActivityChunk) and classify only sampled tail data in hot paths.
  • Applied this to activity classification paths used during startup/interactions.

4) Remove redundant synchronous storage writes

  • Debounced/deduped agent:locked writes so terminal activity does not repeatedly hit localStorage for identical values.

Why this addresses #1081

The freeze was not caused by React command palette rendering itself; it was caused by renderer contention during first terminal interaction/output.
This PR removes the biggest synchronous hotspots on that exact path, so slash command UI appears without the initial jank.

Validation

  • pnpm run type-check
  • pnpm run lint ✅ (existing repo warnings only)
  • pnpm run format
  • pnpm exec vitest run src/test/main/ptyIpc.test.ts
  • Manual flow validated: create task → immediately type / → no visible freeze/stutter.
Check.mp4

@vercel
Copy link

vercel bot commented Feb 25, 2026

@DevDesai444 is attempting to deploy a commit to the General Action Team on Vercel.

A member of the Team first needs to authorize it.

@DevDesai444 DevDesai444 marked this pull request as ready for review February 25, 2026 08:13
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 25, 2026

Greptile Summary

Resolves UI freeze when typing / immediately after creating a new task by optimizing four main-thread hotspots during first terminal interaction.

  • Frame-sliced terminal writes: Splits large PTY output into 16KB chunks processed via requestAnimationFrame instead of blocking synchronous writes
  • Global activity feed: Main process now emits consolidated pty:activity and pty:exit:global events; renderer uses shared listeners with ref-counted direct fallback
  • Bounded classification work: Activity classifier samples only the last 8KB of chunks instead of processing full buffers
  • Deduplicated localStorage writes: Terminal activity handler caches write tokens to prevent redundant identical writes

All optimizations preserve existing behavior (scroll position, first-frame handling, activity detection) while eliminating synchronous contention on the slash-command path. Tests pass and manual validation confirms no visible freeze.

Confidence Score: 4/5

  • Safe to merge with thorough testing of edge cases recommended
  • Well-architected performance fix with clear separation of concerns. The frame-sliced write queue and global activity feed are solid patterns. Score reflects complexity of terminal state management and potential edge cases around disposal timing and write queue draining during rapid attach/detach cycles.
  • Pay close attention to src/renderer/terminal/TerminalSessionManager.ts (write queue disposal) and src/renderer/lib/activityStore.ts (ref-counting logic)

Important Files Changed

Filename Overview
src/main/services/ptyIpc.ts Emits global PTY activity events with sampled chunks and broadcasts exit events
src/renderer/components/ChatInterface.tsx Adds deduplication to localStorage writes with token-based caching
src/renderer/lib/activityStore.ts Refactors to prefer global feed with ref-counted direct fallback subscriptions
src/renderer/terminal/TerminalSessionManager.ts Implements frame-sliced terminal writes and slow input handler logging

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User types '/' in fresh task] --> B[Terminal input handler]
    B --> C{Before PR}
    C -->|Large PTY burst| D[Synchronous xterm write]
    C -->|Activity events| E[Per-provider/per-kind listeners]
    C -->|Classification| F[Full chunk processing]
    C -->|localStorage| G[Repeated writes]
    D --> H[UI freeze/stutter]
    E --> H
    F --> H
    G --> H
    
    B --> I{After PR}
    I -->|Large PTY burst| J[Frame-sliced writes via queue]
    I -->|Activity events| K[Global feed + fallback]
    I -->|Classification| L[Sampled tail chunks]
    I -->|localStorage| M[Deduplicated writes]
    J --> N[Smooth UI]
    K --> N
    L --> N
    M --> N
    
    J --> O[requestAnimationFrame drain]
    O --> P[16KB slices]
    P --> Q[xterm callback chain]
    
    K --> R[Global pty:activity channel]
    R --> S[Shared listener]
    S --> T[Route by PTY ID]
Loading

Last reviewed commit: a3b3f4c

@arnestrickmann
Copy link
Contributor

Hi @DevDesai444,
Can you please change the pr title to be more descriptive?

Thank you for your interest in contributing and for opening this PR.

@DevDesai444 DevDesai444 changed the title Bug 1081 dev desai Fix Slash-Command UI Freeze on New Tasks (Bug#1081) Feb 27, 2026
@DevDesai444
Copy link
Contributor Author

@arnestrickmann, is there any change required in this PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants