I think your diagnosis is basically correct -- they like you, but got mixed signals during the interview, so they're essentially offering a "re-do" of one of the interviews.
It's not the usual process, but sometimes companies do it. Candidates sometimes come in nervous, or sleep-deprived, or sick, or they just perform awesome in some interviews and bomb one or two. There's a lot of inherent variance in the interview process and this is one way to make sure candidates who are close to the boundary get a fair chance.
I think cleaning up your Github code (comments, good method names, unit tests) is a good idea--it can only help show that you can produce clean code and you want the job.