Repository navigation
fix(files): count untracked lines without blocking the server (#1584) - #1609
Merged
Merged
Conversation
/api/git/status read every untracked file with lstatSync/readFileSync in one synchronous pass. With 46k untracked files on Windows that held the server's event loop, and every chat stream and request with it, for 12 s. Untracked files are now read with async fs, 8 at a time, in 64 KiB chunks up to the size lstat reported, and the status entries are mapped in turns of 1000. Counts and response shape are unchanged: one line per newline byte plus an unterminated last line; empty, NUL-holding, over 256 KiB and non-regular files count 0. No cache, no shared scan: every request still reads afresh (#1322, #1350). Co-Authored-By: Claude Opus 5.5 <[email protected]>
pi-web status, stop, open and update list a record only when its URL answers within 2 s. A server whose event loop a long request held took the connection but answered nothing in time, so status printed "No pi-web server is running." and stop did nothing. A closed port refuses at once, so a probe that times out now counts as a running server; a refused or failed connection still does not. The pid was already found alive and ours before the probe. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…1584) A fetch timeout also comes from a slow refusal (Windows retries a refused loopback connect for about 2 s), an address that drops packets or a stuck name lookup. Counting those as running could let `stop` kill a recycled pid's process tree. After a timeout, connect to the same address: only an accepted connection means a busy server. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a time (#1584) The explorer aborts a replaced status request, and the route passes the request's signal, so a long scan whose answer nobody waits for stops instead of piling up behind each tool-end refresh. Four reads at a time match libuv's default thread pool; more only queued ahead of the server's other fs work. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 12, 2026
Hwwwww-dev
pushed a commit
to Hwwwww-dev/pi-web
that referenced
this pull request
Nov 19, 2026
…1584) (agegr#1609) * fix(files): count untracked lines without blocking the server (agegr#1584) /api/git/status read every untracked file with lstatSync/readFileSync in one synchronous pass. With 46k untracked files on Windows that held the server's event loop, and every chat stream and request with it, for 12 s. Untracked files are now read with async fs, 8 at a time, in 64 KiB chunks up to the size lstat reported, and the status entries are mapped in turns of 1000. Counts and response shape are unchanged: one line per newline byte plus an unterminated last line; empty, NUL-holding, over 256 KiB and non-regular files count 0. No cache, no shared scan: every request still reads afresh (agegr#1322, agegr#1350). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(cli): count a busy server as running in status and stop (agegr#1584) pi-web status, stop, open and update list a record only when its URL answers within 2 s. A server whose event loop a long request held took the connection but answered nothing in time, so status printed "No pi-web server is running." and stop did nothing. A closed port refuses at once, so a probe that times out now counts as a running server; a refused or failed connection still does not. The pid was already found alive and ours before the probe. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(cli): a timed-out probe counts only when a TCP connection opens (agegr#1584) A fetch timeout also comes from a slow refusal (Windows retries a refused loopback connect for about 2 s), an address that drops packets or a stuck name lookup. Counting those as running could let `stop` kill a recycled pid's process tree. After a timeout, connect to the same address: only an accepted connection means a busy server. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(files): stop a git status scan its request left, read 4 files at a time (agegr#1584) The explorer aborts a replaced status request, and the route passes the request's signal, so a long scan whose answer nobody waits for stops instead of piling up behind each tool-end refresh. Four reads at a time match libuv's default thread pool; more only queued ahead of the server's other fs work. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 2e8d3b1)
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 24, 2026
…1584) (agegr#1609) * fix(files): count untracked lines without blocking the server (agegr#1584) /api/git/status read every untracked file with lstatSync/readFileSync in one synchronous pass. With 46k untracked files on Windows that held the server's event loop, and every chat stream and request with it, for 12 s. Untracked files are now read with async fs, 8 at a time, in 64 KiB chunks up to the size lstat reported, and the status entries are mapped in turns of 1000. Counts and response shape are unchanged: one line per newline byte plus an unterminated last line; empty, NUL-holding, over 256 KiB and non-regular files count 0. No cache, no shared scan: every request still reads afresh (agegr#1322, agegr#1350). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(cli): count a busy server as running in status and stop (agegr#1584) pi-web status, stop, open and update list a record only when its URL answers within 2 s. A server whose event loop a long request held took the connection but answered nothing in time, so status printed "No pi-web server is running." and stop did nothing. A closed port refuses at once, so a probe that times out now counts as a running server; a refused or failed connection still does not. The pid was already found alive and ours before the probe. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(cli): a timed-out probe counts only when a TCP connection opens (agegr#1584) A fetch timeout also comes from a slow refusal (Windows retries a refused loopback connect for about 2 s), an address that drops packets or a stuck name lookup. Counting those as running could let `stop` kill a recycled pid's process tree. After a timeout, connect to the same address: only an accepted connection means a busy server. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(files): stop a git status scan its request left, read 4 files at a time (agegr#1584) The explorer aborts a replaced status request, and the route passes the request's signal, so a long scan whose answer nobody waits for stops instead of piling up behind each tool-end refresh. Four reads at a time match libuv's default thread pool; more only queued ahead of the server's other fs work. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Fixes #1584.
Git status.
getGitStatus()read every untracked file synchronously (lstatSync+readFileSync), so 46k untracked files on Windows held the server's event loop, and every chat stream with it, for 12 s.\n, plus one for an unterminated last line; empty, NUL anywhere, over 256 KiB or not a regular file count 0. No cache, no worker, no setting (perf(git): cache the status listing and share one scan between requests #1322 / perf(git): count an untracked file's lines once while it is unchanged #1350 stand).request.signal, so a scan nobody waits for stops instead of piling up behind each tool-end refresh.additions; worst event-loop block 8.7 s → 25 ms; total time longer (8.8 → 14.2 s at concurrency 8, the price of not blocking). Not measured on Windows.pi-web status/stop.isServerAnswering()read a 2 s fetch timeout as "no server", so both lied during a stall. Now a timed-out probe counts as running only when a plain TCP connection to the same address then opens. A timeout alone isn't enough: Windows retries a refused loopback connect for ~2 s, and an unreachable address or stuck lookup times out too, which would letstopact on a recycled pid.Tests:
lib/git-changes.test.mjs(exact counts across edge cases, no sync fs on repo files, an aborted request stops the scan),lib/pi-web-cli-commands.test.mjs(busy socket counts; closed port and timeout-without-connect don't).🤖 Generated with Claude Code