scores = [0]
state_length = len(task_states)

if state_length > 0 and task_states[-1]['child_history'] and len(task_states[-1]['child_history']) > 0:
scores += [task_states[-1]['child_history'][i].get('score', 1) for i in xrange(len(task_states[-1]['child_history']))]
max_score = max(scores)

return valid, state_length, max_score, idx

This is better in covering edge cases and more closely reflects how score is actually calculated.