My pet idea is that the working nanomachines do not self-reproduce. After all, that's a different problem and complicates the machine that overtly just needs to do its primary function.
Having separate factories gives a place for auditing and a choke point for production and tuning parameters. It may well be completely different in how its set up, with larger assembly mechanism and specialized structures.
Consider, cleaning up an oil spill for example. Maybe that's not something that will need doing in that future, but it's an easy to understand example of a particular class of problem. Maybe you'll be mining land fills for elements or cleaning groundwater.
You start with a shipment of pumpkin-sized deployment bouys, which were produced in a factory and contain any essential substances, bootstrapping, and master software. Toss those into the ocean around the area affected.
Those first grow leaves and rootlets for power and locally sourced materials, and then produce fruiting bodies. The number of fruits is strictly limited and they have serial numbers. The fruits produce the deployment pods, again a fixed number of them, and the deployment pods migrate from the staging area (power, accessibility, extra input material) to the target area (the underground material, or undersea sludge) where the nanomachines are released to do the target job.
The doing-the-job is a totally different task than building the nanobots. They operate in different environments.
The "pumpkins" are a control point and they are on human scale and are few in number, so you could go out and pick them all up again if you needed to do that manually. They can be addressed and told to change things as you see how the taskmis progressing, and what problems arise.
If left unchecked, even if running amok, the total effect is limited. That is, it will fail safe. It requires human action to keep it going by adding fresh pumpkins.
Note that there might not be just one kind of nanomachine or one set of firmware for any model. The centrallized separate factories can produce the right mixture with no need to get them to self-regulate their population interactions.
Note that life is meta-evolved to evolve. Copying has errors and things are set up to allow such errors to be useful. Our nanobots would be produced with rigid QA and firmware has hash checksums of the whole thing. It will not mutate, and if mistakes do happen the mechanisms are designed to be fragile in the face of random changes, quite opposite of Life. And erronious components won't feed back into a reproduction cycle because it is not a closed loop but a one-way deployment of successive products.