Skip to content

fix(interactive): read input files asynchronously in processRequests - #531

Open
Utkarsh Patwa (utkarshpatwa393-sys) wants to merge 2 commits into
microsoft:mainfrom
utkarshpatwa393-sys:fix/interactive-non-blocking-read-530
Open

Utkarsh Patwa (utkarshpatwa393-sys) wants to merge 2 commits into
microsoft:mainfrom
utkarshpatwa393-sys:fix/interactive-non-blocking-read-530

Conversation

@utkarshpatwa393-sys

Copy link
Copy Markdown

Summary

Fixes #530 by reading the input file asynchronously in processRequests using fs.promises.readFile instead of the synchronous fs.readFileSync.

Context & Motivation

processRequests is an async function, but when given an inputFileName, it previously called fs.readFileSync(inputFileName). This blocked the Node.js event loop before the first await, preventing scheduled timers, I/O events, and concurrent tasks from executing during file reads.

Replacing this with await fs.promises.readFile(inputFileName, "utf-8") ensures processRequests yields execution and allows concurrent event loop tasks to progress without blocking.

Changes

  • typescript/src/interactive/interactive.ts: Replaced synchronous fs.readFileSync(inputFileName).toString() with await fs.promises.readFile(inputFileName, "utf-8").
  • typescript/test/interactive.test.ts: Added unit test reads input files asynchronously without blocking the event loop to verify that concurrent timers fire during file reading.

Validation

  • npm run build-all: Clean build of library and all workspace examples.
  • npm test: 373 tests passed, 0 failed (65 test suites).
  • git diff --check: Passed with zero whitespace issues.

Use fs.promises.readFile instead of synchronous fs.readFileSync so that
the Node.js event loop is not blocked during file input reading, allowing
concurrent timers, sockets, and promises to progress.

Fixes microsoft#530

Signed-off-by: Utkarsh patwa <utkarshpatwa393@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 15, 2026 16:53
@utkarshpatwa393-sys

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The regression test relies on a zero-delay timer firing before an asynchronous file read completes, so it can fail even when the implementation correctly yields.

1 open issue
What changed in this PR

Addresses #530 by making file input in TypeChat’s processRequests asynchronous, allowing other event-loop work to progress while files are read.

Changes:

  • Replaces synchronous file loading with await fs.promises.readFile, preserving UTF-8 decoding and line processing.
  • Adds a regression test intended to verify non-blocking file input and request delivery.
File Description
typescript/​test/​interactive.test.ts Adds a timer-based asynchronous file-reading test.
typescript/​src/​interactive/​interactive.ts Reads input files asynchronously before processing their lines.

Review effort: Balanced

Comment thread typescript/test/interactive.test.ts Resolved
Signed-off-by: Utkarsh patwa <utkarshpatwa393@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 15:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are blocking the asynchronous file-input change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

processRequests blocks the event loop while reading its input file

2 participants