I just bought a 1996 Mazda B4000 4x4 4.0 ohv, runs good but had cel p0401. The previous owner blocked the egr valve off with a metal plate where the gasket should be. I removed the plate and installed a new gasket, started the truck and it idled really rough or stalled. I also noticed the pipe that goes from the egr valve to the upper intake manifold did not have the correct o-ring on it causing a vacuum leak. My question is, why would it run fine with the egr blocked off, when there is a vacuum leak at the intake manifold? Does that mean the egr valve is bad and the vacuum leak is not the problem? I'm just trying to pinpoint the problem. My plan right now is to replace the upper intake gaskets, egr valve, dpfe sensor, and the egr vacuum solenoid. But, I would rather find the problem part and just replace that. I hate throwing parts at it until its fixed, but I'm stuck.

I just bought a 1996 Mazda B4000 4x4 4.0 ohv, runs good but had cel p0401. The previous owner blocked the egr valve off with a metal plate where the gasket should be. I removed the plate and installed a new gasket, started the truck and it idled really rough or stalled. I also noticed the pipe that goes from the egr valve to the upper intake manifold did not have the correct o-ring on it causing a vacuum leak. My question is, why would it run fine with the egr blocked off, when there is a vacuum leak at the intake manifold? Does that mean the egr valve is bad and the vacuum leak is not the problem? I'm just trying to pinpoint the problem. My plan right now is to replace the upper intake gaskets, egr valve, dpfe sensor, and the egr vacuum solenoid. But, I would rather find the problem part and just replace that. I hate throwing parts at it until its fixed, but I'm stuck.

I think you have two different issues and your trying to connect the two, Stop!!!..Ok! you fixed one ,the vacuum leak..
I believe the original owner made work for you by blocking off the EGR pipe and caused carbon to build up in the pipe coming from the exhaust.
P0401 code is which is insufficient EGR (exhaust gas recirculation) flow. Remove the EGR and start the engine, you should have really good exhaust pressure coming out, if not you'll have to find a way to clean it out. Also the pipe going to the intake can't blocked with carbon ether. After the cleaning you can check the EGR valve with the engine at idol using a hand vacuum pump open it, the engine will almost stall if you good flow.