Error: path '/nix/store/…' is not valid

What causes the error error: path '/nix/store/…' is not valid? I tried tracing through the code but it’s not obvious why a store path would be considered not valid. I’m getting this during a build. After a bunch of experimentation, I determined that the presence of a $out/.build/manifest.db sqlite3 database was the proximate cause, and deleting that file (it wasn’t actually necessary to keep) allowed the build to succeed. But I don’t know why that would cause a problem.