This has already been discussed on email-devel but didn't come to a conclusion. I don't want to linger on it, but I would like the problem to get assigned a bug number, so it has a chance of being addressed in the future. A summary of the problem: suppose buffer A has a buffer-local value of 'process-environment' containing an extra directory in the PATH, and that a given 'program' is only available on that directory. Then 'M-x compile RET program RET' will not find 'program', because the *compilation* buffer will not "inherit" the PATH from A. For the reasons why one would want/need such a setup, see https://lists.gnu.org/archive/html/emacs-devel/2021-08/msg01380.html and other messages in that thread. Finally, I attach my proposed patch.