Repository navigation
fix(interactive): read input files asynchronously in processRequests - #531
Open
Utkarsh Patwa (utkarshpatwa393-sys) wants to merge 2 commits into
Conversation
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>
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
🟡 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
Signed-off-by: Utkarsh patwa <utkarshpatwa393@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #530 by reading the input file asynchronously in
processRequestsusingfs.promises.readFileinstead of the synchronousfs.readFileSync.Context & Motivation
processRequestsis an async function, but when given aninputFileName, it previously calledfs.readFileSync(inputFileName). This blocked the Node.js event loop before the firstawait, preventing scheduled timers, I/O events, and concurrent tasks from executing during file reads.Replacing this with
await fs.promises.readFile(inputFileName, "utf-8")ensuresprocessRequestsyields execution and allows concurrent event loop tasks to progress without blocking.Changes
typescript/src/interactive/interactive.ts: Replaced synchronousfs.readFileSync(inputFileName).toString()withawait fs.promises.readFile(inputFileName, "utf-8").typescript/test/interactive.test.ts: Added unit testreads input files asynchronously without blocking the event loopto 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.