Repository navigation
Conversation
fs/promises watch() attaches nothing until the first next(), so a directory or file created between the root check (or the initial scan) and the start of iteration reported no event, and development servers never rebuilt for it. Amp-Thread-ID: https://ampcode.com/threads/T-01a21265-4774-72b1-8fc2-b4f4874e1fef Co-authored-by: Amp <amp@ampcode.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Thank you for following the naming conventions! 🙏 |
commit: |
This was referenced Nov 25, 2026
This branch was successfully deployed
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.
The definitions watcher could miss a directory created after the dev server started, so nothing rebuilt and new tools stayed invisible until a restart. This is what made
sees a definitions directory that did not exist yetflaky (failed run on #422, passing on rerun; it had also failed once on Windows). The cause:watch()fromnode:fs/promisesreturns an async generator, and the OS watch is only attached on the firstnext(). The watcher readwatchableRoot()(or ran its initial scan) and only then started iterating, so anything created in between produced no event.mkdir -p server/mcp/toolscreates each level milliseconds apart while the watcher follows it down one level per event, so it regularly lands in that gap. The watcher now requestsnext()first and checks or scans afterwards. Each round gets its ownAbortController, so leaving an ancestor closes its watch and settles the pending request.To try the PR build in a Nitro app, install it and add a definitions folder while
nitro devruns:To run the watcher tests from this branch:
Before and after
The race depends on scheduling, so both sides get the same one-line fault injection in a throwaway worktree: one extra event-loop turn between reading the root and attaching the watch.
Before (
9a2a836, #422):After (
947973a):The same injection with a 200 ms delay also fails before and passes after. Without injection, the watcher tests passed 12 of 12 runs locally with four busy-loop processes competing for CPU.
There is no deterministic regression test: the gap can't be forced through the public API, so the existing test stays the guard. The bug is also on
main(0.x); this PR only fixes the v1 stack. Windows is covered only by this PR's CI run.ELI5
The dev server watches a folder so it notices when you add a new tool file. It used to look at the folder first and only then start listening, so a folder created in that split second went unnoticed. Now it starts listening first and looks second.