`mastra dev` generating malformed provider-registry.json on every execution
Hi! I’ve got an error that has started happening consistently on my machine but not on any of my coworkers, and I’m looking for some guidance from someone who works with the Mastra source - I think it’s likely an easy fix for someone familiar with the codebase. I'm not sure if I can provide any reproduction given how my coworkers don't have this issue with the same codebase.
- Mastra's auto-generated
provider-registry.json becomes malformed on my machine every time for unknown reasons
- This could be bypassed if I could turn off dynamic loading but there does not appear to be a way to do that without me editing the code directly.
- Relevant code: packages/core/src/llm/model/provider-registry.ts
- This means mastra dev doesn't work on my machine at all without some very awkward workarounds.
I'm still investigating why the JSON file is malformed on my machine, but I could do with some
advice on this.
When I run mastra dev but not with build + start:
GitHub
mastra/packages/core/src/llm/model/provider-registry.ts at c00f6140...
The TypeScript AI agent framework. ⚡ Assistants, RAG, observability. Supports any LLM: GPT-4, Claude, Gemini, Llama. - mastra-ai/mastra
44 Replies
My own investigation
- It's in Mastra's new model provider registry feature.
- (I think?) This feature auto-loads models in dev mode but not in production mode, which explains this behaviour somewhat.
- We don't actually use this feature at this time.
- The file
[...]/packages/mastra/node_modules/@mastra/core/dist/provider-registry.json:
- This file exists
- This file is malformed JSON. My guess - two different sources write to this file, one
overwriting the other, leaving a malformed part at the very end that looks like this:
- I don't know why this is happening on my machine so far.
- This file regenerates itself every time mastra dev is executed, so I can't even bypass this
by fixing the JSON.
And some more (discord message limits make this a bit hard so this might be harder to read than I'd like)
- The error occurs in function loadRegistry (originally in src/llm/model/provider-registry.ts it seems)
- loadRegistry will fall back on a default if it's argument useDynamicLoading is false, so if I could ensure that was the case it would likely be a good workaround
- loadRegistry is called by _GatewayRegistry.getProviders
- The _GatewayRegistry singleton has the following logic:
this.useDynamicLoading = options.useDynamicLoading ?? isDev2
- Commenting out this line fixes the issue(since useDynamicLoading will be false)
- When I run this, options.useDynamicLoading is undefined, isDev2 is true
- const isDev2 = process.env.MASTRA_DEV === "true" || process.env.MASTRA_DEV === "1";
- in my case MASTRA_DEV=true, even though I've attempted to set it to false in my
environment to no effect.
I should also add that mastra has worked without issue on my machine for months, and no change preceded this issue, it just started happening while I was running some tests.📝 Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10434
🔍 If you're experiencing an error, please provide a minimal reproducible example whenever possible to help us resolve it quickly.
🙏 Thank you for helping us improve Mastra!
Hi @april such a strange issue. We'll look into why this is happening and see if we can resolve it!
Can you provide me all your package versions?
@april I created a potential fix if you want to try it out! Here's a PR snapshot version for it
@mastra/core@0.0.0-fix-issue-10434-concurrent-write-corruption-20251124213939, you'll have to install all your mastra packages with that version. This is a 1.0-beta version, so let me know if your versions were for 0.x and i'll make another snapshot that you can try outGitHub
fix(core): use atomic writes to prevent provider-registry.json corr...
Fixes #10434
When mastra dev runs, multiple processes can write to provider-registry.json concurrently (auto-refresh, syncGateways, syncGlobalCacheToLocal). This causes file corruption where the en...
Sure! Not sure exactly what you need, here is the
package-lock.json: https://gist.github.com/akortman/11c0a0ccd1b300d81acb39fae15e485bGist
Mastra project lockfile for bug #10434
Mastra project lockfile for bug #10434. GitHub Gist: instantly share code, notes, and snippets.
@mastra-core is at 0.24.1 for me
@Daniel Lew This fixes it, thank you!Great to hear we'll release it in 0.x versions tmrw
I've just got the same problem.... awaiting the 0.x release when possible @Daniel Lew
0.x is relased now @meDanHumphrey ! Let me know if it fixes it for you
@Daniel Lew Thanks , however, I've updated to 18.6 and the 24.6 packages and now get a different error. The provider-registry.json file isn't found. All I've done is installed the updates and run
npm run dev and get the following:
What I don't understand is why this started happening - I don't think there were any updates on our end. Is this an introduced bug - can I revert to a previous version to get dev running again?
hmm I can't reproduce this @meDanHumphrey , can you try deleting your node_modules and installing again?
Already tried that
Do you know when this was introduced, I need to try to downgrade the mastra packages so I can continue working while waiting for a fix
is it possible to share a reproduction of it?
We have a big project - I don't mind connecting with you and/or sharing relevant details to debug, but I can't share the project with you.
hmm just trying to think of ways of debugging this because I've tried a few different things and I don't run into this error
When was this introduced - I really need to downgrade
the provider-registry.json was introduced a while back as part of the model router feature, let me see if i cna find the version
I'm happy to screen share and work through giving you what you need, I just can't share the project
I think @mastra/core@^0.18.0 might be the version before it was released
this is the version it was released on https://github.com/mastra-ai/mastra/releases/tag/%40mastra%2Fcore%400.19.1
GitHub
Release 2025-10-01 · mastra-ai/mastra
Mastra Release - 2025-10-01
We are excited to announce the release of our new model router and model fallbacks! You can now choose any model provider and model without the need to install or import...
Did it just start happening when you upgraded? And if so, what did you upgrade from
That's weird - I've successfully used a more recent version.
If I use 24.1 - I get a corrupted file when I run
npm run dev
If I use the updated package that you've just published, I get the missing file error shared above
Yeah, that's what the latest fix was supposed to address. And it looked like it fixed the issue for the other person, just not sure yet why it introduced a separate issue for you
ohh, did you delete your
.mastra folder as well as the node_modules after you updated?No, I hadn't done that previously, but it didn't fix the issue:
Error: Failed to load provider registry with dynamic loading. Make sure provider-registry.json is generated by running: npm run generate:providers
can you paste the whole error?
Error: Failed to load provider registry with dynamic loading. Make sure provider-registry.json is generated by running: npm run generate:providers
Tried paths:
/Users/dan/projects/planit-amplify-workflows/node_modules/@mastra/core/dist/provider-registry.json: Unexpected non-whitespace character after JSON at position 92914 (line 2927 column 2)
/Users/dan/projects/planit-amplify-workflows/node_modules/@mastra/core/src/llm/model/provider-registry.json: ENOENT: no such file or directory, open '/Users/dan/projects/planit-amplify-workflows/node_modules/@mastra/core/src/llm/model/provider-registry.json'
/Users/dan/projects/planit-amplify-workflows/packages/mastra/.mastra/output/packages/core/src/llm/model/provider-registry.json: ENOENT: no such file or directory, open '/Users/dan/projects/planit-amplify-workflows/packages/mastra/.mastra/output/packages/core/src/llm/model/provider-registry.json'
/Users/dan/projects/planit-amplify-workflows/packages/mastra/.mastra/output/src/llm/model/provider-registry.json: ENOENT: no such file or directory, open '/Users/dan/projects/planit-amplify-
workflows/packages/mastra/.mastra/output/src/llm/model/provider-registry.json'
at loadRegistry (file:///Users/dan/projects/planit-amplify-workflows/node_modules/@mastra/core/dist/chunk-INOOZ2A2.js:2879:9)
at _GatewayRegistry.getProviders (file:///Users/dan/projects/planit-amplify-workflows/node_modules/@mastra/core/dist/chunk-INOOZ2A2.js:3126:18)
at Object.ownKeys (file:///Users/dan/projects/planit-amplify-workflows/node_modules/@mastra/core/dist/chunk-INOOZ2A2.js:2894:32)
at Function.entries (<anonymous>)
at getStaticProvidersByGateway (file:///Users/dan/projects/planit-amplify-workflows/node_modules/@mastra/core/dist/chunk-VXHOOZSK.js:180:36)
at file:///Users/dan/projects/planit-amplify-workflows/node_modules/@mastra/core/dist/chunk-VXHOOZSK.js:182:67
at ModuleJob.run (node:internal/modules/esm/module_job:343:25)
at async onImport.tracePromise.proto (node:internal/modules/esm/loader:647:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
do any of you think my error here might be related? i'm just trying to run the playground (no agents, just an empty mastra instance) — i'm in the
@beta version for all packages
ohh hmm, @meDanHumphrey I wonder if it's some cache issue with the
mastra global cache. That it had cached the malformed provider-registry.json file in ~/.cache/mastra
@shARP I don't think that's related@Daniel Lew Thank You - that's resolved it!!
Awesome! Glad to hear it. I'm going to put out a PR to make sure that if the global cache file gets corrupted for whatever reason that it won't copy it into the project and it'll regenerate it 😁
thanks for finding this issue!
Awesome, thanks again for your help 🙂
hey @shARP what node version are you on?
node 22
What exact version? We're seeing this issue on older versions, but ones that satisfy the node version constraint in the package json work, so anything above
"engines": {
"node": ">=22.13.0"
},
i'm actually at the
22.14.0 version
with the engines set to
the error was gone when i downgraded to @latest, so i think this is just an issue on the v1.0Yeah, it seems to be resolving to a deprecated 1.0.3 version of @mastra/server instead of the beta version of it. But we can only reproduce it only with
npm and only on a node version less than 22.14.0maybe that's happening because my tsconfig is set to compile to cjs? cause i see this is coming from this plugin right here

i'm using yarn btw
if you think this is just some symlink with version issue, i can maybe try deleting my node_modules
Let’s try it? Or there’s some npm registry issue cause the packages being resolved are marked deprecated in npm. Not sure why they get resolved like that