Now after doing the foundry I am slightly confused as to the canon death of HK 47, was he with Malgus when he died or was he with Revan?
In terms of story, the Foundry flashpoint takes place before the False Emperor one. As such, HK-47 was originally with Revan in the Foundry, but is defeated by an imperial strike team (as in, people doing the flashpoint). Malgus recovers the droid along with the Foundry itself, restores him and re-activates him. He's then defeated a second time.