Persistent state file and error recovery