Replying to myself... Tim was right (of course). Using the $SESSION global variable only works when the student is answering the question. It no longer works when reviewing the attempt.
I will definitely have to find another solution... maybe with some help from the Moodle question type gurus.
