Emails show state had ample warning of staffing shortages at