I've never run into this issue until today. I was migrating from Apollo GraphQL to OpenAPI generator, both come from SPM. I removed every dependency to Apollo and added OpenAPI generator, runtime and urlsession packages. And now Xcode throws Internal inconsistency error every second time I try to build the project.
While writing this post, I remembered I had this issue last year or so. I solved it by re-adding the files Xcode was barking at. I'm going to try it now, maybe it will solve the issue I now have.