Skip to content

Conversation

@Agarwalchetan
Copy link

Fix blocking busy-wait in typing handler using FIFO async queue

Acceptance Criteria fulfillment

  • Removed synchronous busy-wait loop that could block the JavaScript event loop
  • Implemented a FIFO async queue using Promise chaining to process typing events sequentially
  • Preserved existing typing indicator behavior and event ordering
  • Ensured robustness by preventing queue breakage if a typing callback throws
  • Kept production logs clean by removing unsafe console.error calls
  • Added unit tests validating sequential execution and final typing state

Fixes #1113


Overview

This PR removes a critical performance bug where a synchronous while loop was used to lock the thread while handling typing events.
Because JavaScript is single-threaded, this could block the event loop and cause the host application or browser to freeze when multiple typing events occurred in quick succession.


Changes

File:
packages/api/src/EmbeddedChatApi.ts

Fix:

  • Replaced while (typingHandlerLock) {} with a FIFO async queue implemented via Promise chaining (this.typingChain)

Robustness:

  • Added a try / catch block inside the queue consumer to ensure the queue remains functional even if a typing callback throws
  • Removed unsafe console.error calls to avoid noisy production logs while preserving internal state consistency

Tests:

  • Added unit tests verifying sequential processing of typing events and correctness of intermediate and final typing states

Video / Screenshots

N/A (internal logic change; no UI modifications)


PR Test Details

  • Unit tests added for the typing handler logic
  • Manual verification performed by simulating rapid typing events
  • No public API changes

This change replaces a blocking lock with an async FIFO queue to prevent UI freezes while preserving typing event ordering.

@CLAassistant
Copy link

CLAassistant commented Jan 26, 2026

CLA assistant check
All committers have signed the CLA.

@Agarwalchetan Agarwalchetan force-pushed the fix/busy-wait-typing-handler branch from d41f58f to 2998706 Compare January 26, 2026 17:02
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.

Bug: Blocking busy-wait loop in typing handler can freeze the browser

2 participants