The first battle at Ai was a disaster because of Achan's sin. In Joshua 8 God proves his faithfulness, goodness and justice to his people, through the reassurance of his victory-giving presence.