M
Mastra3w ago
april

`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:
Error: Failed to load provider registry with dynamic loading. Make sure provider-registry.json is generated by running: npm run generate:providers

Tried paths:
[...]/packages/mastra/node_modules/@mastra/core/dist/provider-registry.json: Unexpected non-whitespace character after JSON at position 77837 (line 2483 column 2)
[...]
at loadRegistry (file://[...]/packages/mastra/node_modules/@mastra/core/dist/chunk-II37LKES.js:2234:9)
at _GatewayRegistry.getProviders (file://[...]/packages/mastra/node_modules/@mastra/core/dist/chunk-II37LKES.js:2459:18)
at Object.ownKeys (file://[...]/packages/mastra/node_modules/@mastra/core/dist/chunk-II37LKES.js:2249:32)
at Function.entries (<anonymous>)
at getStaticProvidersByGateway (file://[...]/packages/mastra/node_modules/@mastra/core/dist/chunk-II37LKES.js:2497:36)
[...]]
Error: Failed to load provider registry with dynamic loading. Make sure provider-registry.json is generated by running: npm run generate:providers

Tried paths:
[...]/packages/mastra/node_modules/@mastra/core/dist/provider-registry.json: Unexpected non-whitespace character after JSON at position 77837 (line 2483 column 2)
[...]
at loadRegistry (file://[...]/packages/mastra/node_modules/@mastra/core/dist/chunk-II37LKES.js:2234:9)
at _GatewayRegistry.getProviders (file://[...]/packages/mastra/node_modules/@mastra/core/dist/chunk-II37LKES.js:2459:18)
at Object.ownKeys (file://[...]/packages/mastra/node_modules/@mastra/core/dist/chunk-II37LKES.js:2249:32)
at Function.entries (<anonymous>)
at getStaticProvidersByGateway (file://[...]/packages/mastra/node_modules/@mastra/core/dist/chunk-II37LKES.js:2497:36)
[...]]
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
april
aprilOP2w ago
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:
// ... rest of JSON ...
"openai/o4-mini"
]
},
"version": "1.0.0"
}mini" // malformed from this line
]
},
"version": "1.0.0"
}

// ... rest of JSON ...
"openai/o4-mini"
]
},
"version": "1.0.0"
}mini" // malformed from this line
]
},
"version": "1.0.0"
}

- 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.
Mastra Triager
📝 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!
Abhi Aiyer
Abhi Aiyer2w ago
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?
Daniel Lew
Daniel Lew2w ago
@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 out
Daniel Lew
Daniel Lew2w ago
GitHub
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...
april
aprilOP2w ago
Sure! Not sure exactly what you need, here is the package-lock.json: https://gist.github.com/akortman/11c0a0ccd1b300d81acb39fae15e485b
Gist
Mastra project lockfile for bug #10434
Mastra project lockfile for bug #10434. GitHub Gist: instantly share code, notes, and snippets.
april
aprilOP2w ago
@mastra-core is at 0.24.1 for me @Daniel Lew This fixes it, thank you!
Abhi Aiyer
Abhi Aiyer2w ago
Great to hear we'll release it in 0.x versions tmrw
meDanHumphrey
meDanHumphrey2w ago
I've just got the same problem.... awaiting the 0.x release when possible @Daniel Lew
Daniel Lew
Daniel Lew2w ago
0.x is relased now @meDanHumphrey ! Let me know if it fixes it for you
meDanHumphrey
meDanHumphrey2w ago
@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:
meDanHumphrey
meDanHumphrey2w ago
No description
meDanHumphrey
meDanHumphrey2w ago
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?
Daniel Lew
Daniel Lew2w ago
hmm I can't reproduce this @meDanHumphrey , can you try deleting your node_modules and installing again?
meDanHumphrey
meDanHumphrey2w ago
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
Daniel Lew
Daniel Lew2w ago
is it possible to share a reproduction of it?
meDanHumphrey
meDanHumphrey2w ago
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.
Daniel Lew
Daniel Lew2w ago
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
meDanHumphrey
meDanHumphrey2w ago
When was this introduced - I really need to downgrade
Daniel Lew
Daniel Lew2w ago
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
meDanHumphrey
meDanHumphrey2w ago
I'm happy to screen share and work through giving you what you need, I just can't share the project
Daniel Lew
Daniel Lew2w ago
I think @mastra/core@^0.18.0 might be the version before it was released
Daniel Lew
Daniel Lew2w ago
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...
Daniel Lew
Daniel Lew2w ago
Did it just start happening when you upgraded? And if so, what did you upgrade from
meDanHumphrey
meDanHumphrey2w ago
That's weird - I've successfully used a more recent version.
meDanHumphrey
meDanHumphrey2w ago
If I use 24.1 - I get a corrupted file when I run npm run dev
No description
meDanHumphrey
meDanHumphrey2w ago
If I use the updated package that you've just published, I get the missing file error shared above
Daniel Lew
Daniel Lew2w ago
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?
meDanHumphrey
meDanHumphrey2w ago
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
Daniel Lew
Daniel Lew2w ago
can you paste the whole error?
meDanHumphrey
meDanHumphrey2w ago
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)
shARP
shARP2w ago
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
No description
Daniel Lew
Daniel Lew2w ago
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
meDanHumphrey
meDanHumphrey2w ago
@Daniel Lew Thank You - that's resolved it!!
Daniel Lew
Daniel Lew2w ago
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!
meDanHumphrey
meDanHumphrey2w ago
Awesome, thanks again for your help 🙂
Nik
Nik2w ago
hey @shARP what node version are you on?
shARP
shARP2w ago
node 22
Daniel Lew
Daniel Lew2w ago
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" },
shARP
shARP2w ago
i'm actually at the 22.14.0 version with the engines set to
"engines": {
"node": "^22.14.0",
"engines": {
"node": "^22.14.0",
the error was gone when i downgraded to @latest, so i think this is just an issue on the v1.0
Daniel Lew
Daniel Lew2w ago
Yeah, 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.0
shARP
shARP2w ago
maybe that's happening because my tsconfig is set to compile to cjs? cause i see this is coming from this plugin right here
No description
shARP
shARP2w ago
i'm using yarn btw if you think this is just some symlink with version issue, i can maybe try deleting my node_modules
Abhi Aiyer
Abhi Aiyer2w ago
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

Did you find this page helpful?