Record it twice and compare the recordings. IF different then this will confirm the correlation hypothesis. Typically when a 500 occurs, barring a malformed request, it is simply out of context with the state of the application from the prior request, an unexpected page has been returned.
You may cross check for the unexpected page by following standard test practices, for each and every step there is an expected result. Use web_reg_find() or web_reg_save_param() to check for values from each submitted page request which indicates that the expected page has been returned. If the expected page has not been returned then break the flow of the business process script, clean up and then either return to the business flow or move to the next iteration. ( return(1); will cause the system to iterate immediately without respecting the iteration pacing )