Student runtime and grading
The attempt lifecycle, start/resume, lazy expiry, all-or-nothing auto-grading, teacher finalise, and the write-through to the gradebook.
The student routes live under cbt/student and need Feature.CBT and user type student.
Eligibility (CbtStudentAccessService.assertEligible): an active enrolment in the exam term's academic year, with a stream, a current subject row for the exam's subject, and an assignment of the exam to that stream. Otherwise This exam is not assigned to your stream (403). A missing term is Exam term not found; a missing student profile is Student profile not found.
Attempt lifecycle
Auto-grading runs when an attempt leaves in_progress. Only a teacher sets graded, and only graded reaches the gradebook.
Student routes
| Route | operationId | Does |
|---|---|---|
POST /cbt/student/examinations/:examinationId/attempts | startCbtAttempt | Returns the live in_progress attempt if one hasn't expired; otherwise starts a new one |
GET /cbt/student/attempts/:attemptId | getCbtAttempt | Attempt, saved answers and student-safe questions (no isCorrect, no accepted answers). MCQ options are shuffled with a seed of attemptId:questionId, so order is stable across refreshes |
PUT /cbt/student/attempts/:attemptId/answers/:questionId | saveCbtAnswer | Upserts on (attemptId, questionId); doesn't extend the clock |
POST /cbt/student/attempts/:attemptId/submit | submitCbtAttempt | Finalises as submitted (even if past expiresAt); a non-in_progress attempt is returned unchanged |
Time budget. durationMinutes if set; otherwise, for per_question timing, the sum of each question's timeLimitSeconds. expiresAt is startedAt plus the budget.
| Route | When | Message |
|---|---|---|
| Start | Exam missing | Examination not found |
Not published | Examination is not open | |
Outside the assignment's availableFrom to availableTo | Examination is not available right now | |
Every non-voided attempt counts against maxAttempts | No attempts remaining | |
| No duration and no per-question limits | Examination has no configured time budget | |
| Save | Question not on this exam | Question does not belong to this exam |
Not in_progress, or past expiresAt (it is expired first) | attempt is closed | |
| Any | Missing or someone else's attempt | Attempt not found, This attempt does not belong to you |
Expiry is lazy
No scheduler sweeps attempts. An attempt past expiresAt becomes expired only when getAttempt or saveAnswer next touches it, and it counts against maxAttempts either way. Walking away is not a free retry.
Finalising claims the row with UPDATE ... WHERE status = 'in_progress', so a racing call matches nothing and just reloads. The winner sets submitted or expired and submitted_at, stores unanswered questions as empty, auto-grades, writes autoScore, and publishes CBT_ATTEMPT_SUBMIT. The student's response leaves out autoScore and finalScore.
Auto-grading
Runs inside finalize (at submit or lazy expiry), all-or-nothing, full marks or zero, no partial credit:
| Type | Auto-graded? | Correct when |
|---|---|---|
mcq_single / mcq_multi | Yes | The selected ids, sorted, equal the correct option ids, sorted. An empty correct set is never correct |
short_text | Yes | One of acceptedAnswers matches. exact compares the raw text. trimmed trims both sides. case_insensitive trims and lowercases. An empty accepted list is never correct |
long_text / math | No, left ungraded (awardedMarks: null) | Teacher marks manually |
finalize upserts every objective answer with awardedMarks / isCorrect / autoGraded: true, sets the provisional autoScore (against maxAutoScore = Σ marks of objective questions), and parks the attempt in submitted or expired. It never sets graded.
Teacher grading
Staff routes are under cbt/examinations/:examinationId/attempts/:attemptId:
| Route | operationId | Does |
|---|---|---|
GET | getCbtAttemptForStaff | Answers with awardedMarks and isCorrect |
PUT .../grades | saveCbtGrades | Draft marks for long_text and math, each 0 to the question's marks; status unchanged |
POST .../finalise | finaliseCbtAttempt | Sets graded, finalScore (all awarded marks), gradedAt, gradedById. Can be repeated after a correction |
POST .../void, .../reopen | voidCbtAttempt, reopenCbtAttempt | Void needs submitted, expired or graded; reopen needs voided. See CBT operations |
Gradebook write-through
Only teacher finalise writes a score. AssessmentGradeSyncService.syncFromCbtAttempt returns early without gradedById, which a student submit never sets.
Pick the attempt. Only the student's latest graded attempt (highest attemptNumber) counts. A missing exam or totalMarks of 0 stops here.
Find the enrolment and assessment. The first active enrolment in the term's year whose stream takes the subject (not checked against the exam's stream assignment), and the assessment with sourceCbtExaminationId equal to the exam. No enrolment logs No active enrollment found for CBT score sync; no assessment stops silently.
Write the score. finalScore / totalMarks × maxScore, two decimals, upserted on (assessmentId, enrollmentId) with enteredBy = gradedById, then the subject-term grade is recomputed. Errors are logged as CBT grade sync failed and swallowed.
clearFromCbtAttempt (on void) soft-deletes that score and recomputes (CBT grade clear failed on error). Deleting an exam runs releaseExamLinks, which unlinks its assessments but keeps the scores already written.