CODA: Generalizing to Open and Unseen Domains with Compaction and Disambiguation