fix(ai/mcp-stdio): make createChildProcess synchronous to prevent spawn race condition#5852
Conversation
…ild process creation timing issue
|
@timjuenemann Is this PR related to I followed the documentation only to find that If so, it would be great if the Vercel team can prioritize this issue as I would imagine this to be a big blocker for what I would think to be a critical/popular use case. Tagging @iteratetograceness @lgrammel to raise awareness to this issue since I think it's quite important. |
|
Yes, this PR fixes exactly that issue! |
|
@timjuenemann thank you for catching this race condition! Also, I'm not sure why the |
| ); | ||
|
|
||
| expect(childProcess.pid).toBeDefined(); | ||
| await new Promise<void>((resolve) => { |
There was a problem hiding this comment.
Not sure this is a necessary assertion; we should be able to just keep: expect(childProcess.pid).toBeDefined()
There was a problem hiding this comment.
Yes you're right!
packages/ai/.changeset/README.md
Outdated
| @@ -0,0 +1,8 @@ | |||
| # Changesets | |||
packages/ai/.changeset/config.json
Outdated
| @@ -0,0 +1,11 @@ | |||
| { | |||
There was a problem hiding this comment.
also remove pls
| 'ai': patch | ||
| --- | ||
|
|
||
| Fix issue where StdioMCPTransport never resolves cause of child process creation timing issue |
There was a problem hiding this comment.
| Fix issue where StdioMCPTransport never resolves cause of child process creation timing issue | |
| fix (ai/mcp-stdio): make `createChildProcess` synchronous to prevent spawn race condition |
| @@ -117,12 +117,12 @@ describe('StdioMCPTransport', () => { | |||
| }); | |||
|
|
|||
| it('should handle child_process import errors', async () => { | |||
There was a problem hiding this comment.
non-blocking: should handle child_process import errors is a legacy test (from before we moved stdio transport files out of the ai/core folder)! we can remove
createChildProcess synchronous to prevent spawn race condition
|
Thanks for the review @iteratetograceness :) let me know if there is anything else. |
…pawn race condition (#5852) Co-authored-by: Grace Yun <74513600+iteratetograceness@users.noreply.github.com>
…ining2 * origin/v5: (25 commits) chore(providers/langchain): extract to separate package (#5928) Version Packages (canary) (#5898) fix (docs): fix typo (#5914) (#5919) docs: update chat-with-pdf page to include updated provider information (#5895) (#5917) docs: Added documentation for function call parsing middleware (#5900) refactoring: extract SharedV2Headers (#5912) feat (providers/openai): add support for reasoning summaries (#5906) (#5909) fix (docs): fix OpenRouter code examples (#5876) (#5893) fix(providers/xai): return actual usage when streaming instead of NaN (#5873) (#5891) fix (docs): fix valibotSchema import (#5865) (#5889) fix (providers/fal): improve model compatibility (#5855) (#5892) chore: extract spec types (#5901) chore: remove logprobs (#5896) Version Packages (canary) (#5872) chore (ci): unify jobs & remove unnecessary example builds (#5894) feat (ai): allow using provider default temperature by specifying null (#5890) fix(ai/mcp-stdio): make `createChildProcess` synchronous to prevent spawn race condition (#5852) (#5888) feat (providers/google): add thinking config to provider options (#5842) (#5887) fix (examples): avoid mixed message types in `use-chat-streamdata-multistep` (#5824) (#5886) chore: restructure language model supported urls (#5882) ...
Background
I ran into an issue where StdioMCPTransport never resolved. This happened cause the spawn event was sent before the listener was added.
Summary
I made the
createChildProcesssynchronous, so the listeners won't miss out on events.Tasks
pnpm prettier-fixto fix any formatting issues -> For some reason it fixed thousands of filesFuture Work
–