We spoke about this in another topic, and I generally think you're on the right track, at least where error-detection is concerned, although I think the nitty-gritty of predictive coding is making a few too many leaps in logic for me. I know it works well for comp sci people and AI researchers, but just because an algorithm successfully mirrors human behavior does not mean that humans are using that algorithm.
I think a simpler, and more elegant, predictive explanation is that the at time t, the brain tries to predict what kind of sensory input it's going to get at time t+1, which is similar to the predictive coding theory you've outlined, but it removes the extra layer of the brain trying to predict how it's going to respond at t+1.
They may actually be the same thing (each 'layer' predicting what's coming down the pipe from the layer below it), but I think it makes more intuitive sense this way and removes the need for the self-referential stuff, which can be confusing.
The interesting question for me is: where does this error detection occur? There's evidence that the cingulate cortex is activated in error-detection task paradigms (and as a bonus, is suppressed by psychedelics) and is overactive in OCD patients (who I hypothesize have over-active error-detection circuits), or if this is a more decentralized process.
I'm inclined to think that it's more localized.
Blessings
~ND