I Googled -Captain Naylor Mexican War- and this result is a scanned book about the events of the Mexican War. Click on the link and you at page 484. Scroll back to page 261 and a discription of the same incident, "...party of guerillas had succeeded in breaking open the mule yard..." Read earlier pages for the major defeat suffer in two battles Aug 19-20, 1847.
Page 244 starts Chapter V and first date of diary is Aug 7th, 1847 Page 264 to 265 accounts Sperry's death. Seems he was in the hospital so it might have been a medical discharge, then recovered enough to join the mule party as a volunteer officer.