Oh, man. I had two huge and phenomenally stupid bugs in substitution. This is code that is only called by, like, every other function ever. I completely mystifies me how in the world I was able to get through so many test cases with it so moronically broken.
And fixing this bug fixes five of the test cases I constructed specifically to trip it, but leaves the sixth still broken. Grr.