Sam thought the gate was closed, and the dogs couldn't escape the backyard.
A comma is supposed to be used before a conjunction separating independent clauses. Technically "Sam thought the gate was closed" and "the dogs couldn't escape the backyard" are both independent clauses. However, if the clauses were separated into two sentences, the meaning would change. As the sentence is written, the second clause means Sam thought the gate was closed. If the second clause were to stand alone, it means the gate was actually closed.
Should a comma be used in this kind of situation where the clauses look independent but really can't be separated? It seems to me that despite appearances the second clause is really not independent, and no comma should be used.