kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

A quiz answer is lost if the learner leaves the question without pressing Next, Previous or Submit

Open Rishika-dev opened this issue 1 week ago • 2 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Target branch: develop

Observed behavior

In a quiz, the answer currently on screen is only saved when the learner moves to another question (Next / Previous) or opens the Submit dialog. If the learner leaves the quiz any other way, the answer they selected is silently discarded — even though the footer already counts it as answered.

Here a learner answers question 1 of a class quiz ("4 + 4" → "8"), the footer shows "1 of 2 questions answered", they leave with the app-bar ✕, and when they come back the answer is gone and the footer reads "0 of 2 questions answered":

https://github.com/user-attachments/assets/aa44f55c-be2a-4417-9ac4-5b1450e3c310

No AttemptLog is saved for that question, so the coach report also shows it unanswered.

Ways to leave that drop the answer: the app-bar ✕, browser Back, the course side panel, being signed out for inactivity, closing the tab, or the Android app being backgrounded/killed.

Cause

In ExamPage (kolibri/plugins/learn/frontend/views/ExamPage/index.vue), saveAnswer is called only from goToQuestion (Next/Previous), toggleModal (open Submit) and finishExam. There is no beforeRouteLeave or unmount hook that saves. The composable's unmount flush (stopTrackingProgress → updateContentSession({ immediate: true, force: true }), registered via onBeforeUnmount in composables/useProgressTracking.js) only sends interactions already queued in unsaved_interactions — and the on-screen answer is queued inside saveAnswer, which never ran. So on leave nothing calls checkAnswer() to capture it, and it's lost.

Meanwhile questionsAnswered (same file) counts currentQuestionAnswered, so the footer reports the question as answered before anything is persisted.

The same shape (answer saved only on navigate/submit, with no save-on-leave) is in the other quiz renderers:

  • views/QuizRenderer/index.vue
  • views/courses/QuizRenderer/index.vue
  • views/courses/PrePostTestRenderer/index.vue

This is a regression. Commit 30b15906c1 (PR #13602, first released in v0.18.2) deliberately deferred saving until after the learner navigates to another question or submits — replacing the earlier @interaction-driven save. That reintroduced #3913 ("Save answer when users click on the back to exam list"), which #3912 had fixed in 2018.

As an additional consequence (reasoned from the code, not separately reproduced): if a coach ends a quiz while learners are mid-question, those on-screen answers can never be recorded — closing marks the MasteryLogs complete (kolibri/core/exams/viewsets/exam.py), and a later save would be refused.

Expected behavior

An answer the learner has entered is saved when they leave the question, by any route — as it was before v0.18.2. Returning to the quiz shows the answer still selected, and the coach report reflects it.

User-facing consequences

  • A learner loses answers they believe they submitted (the footer told them the question was answered).
  • The coach report and class averages are missing those answers.
  • It's most damaging on the graded class-quiz path, and also affects practice quizzes, course quizzes and course pre/post tests.

Steps to reproduce

  1. As a coach, create a class quiz with at least two questions and start it.
  2. Sign in as a learner and open the quiz.
  3. Answer question 1 (select an option). The footer shows "1 of 2 questions answered".
  4. Instead of pressing Next, leave the quiz — e.g. the app-bar ✕.
  5. Re-open the quiz. Question 1 is unanswered ("0 of 2 questions answered"), and no attempt was saved.

Possible fix

I'd be glad to work on this once the approach is agreed. Save the on-screen answer on leave:

  • Add a beforeRouteLeave guard that calls saveAnswer() in ExamPage, and an equivalent unmount/leave save in the three renderers above.
  • The save should be sent immediately (immediate: true) so a changed answer that already has an id still flushes before the component (and its progress tracker) tears down.
  • Add a best-effort pagehide flush for tab close and app backgrounding.

With a minimal version of this (a beforeRouteLeave in ExamPage that calls saveAnswer()) applied locally, the answer now survives leaving via the ✕ — the footer reads "1 of 2 questions answered" on return, and the attempt is saved:

https://github.com/user-attachments/assets/502b865e-c3c2-46bb-b4e2-1398e490ffff

Context

  • Kolibri develop (the files involved are unchanged between 07e85c89ef and 758605b764), dev server
  • macOS 26, Chromium
  • Related: #3912 / #3913 (the 2018 fix and the bug it fixed), PR #13602 (the regression)

AI usage

I used an AI coding assistant to look for data-loss bugs in the quiz save path. It traced that saveAnswer has no save-on-leave hook and that the unmount flush doesn't carry the on-screen answer, and it identified the regressing commit. I reproduced the loss in a running quiz, confirmed no attempt was saved in the database, checked the minimal fix, and recorded the videos.

Rishika-dev avatar Nov 27 '26 13:11 Rishika-dev

🔍 Thanks for opening this issue! @rtibblesbot will check it against the code and comment with its findings.

What happens next:

  • The community-issue-review label stays on until the review comment is posted.
  • The comment identifies the files, lines, or commits examined so you can follow the reasoning and respond if you disagree.
  • If the check confirms the issue, @rtibblesbot may also correct the title and description. GitHub preserves the edit history, so the original text remains available.
  • @rtibblesbot's comments are LLM-generated, so please evaluate them critically.

A maintainer decides what happens next. This check does not close the issue.

learning-equality-bot avatar Nov 27 '26 13:11 learning-equality-bot

Verdict: claim holds Evidence: kolibri/plugins/learn/frontend/views/ExamPage/index.vue:645-704 on develop at 758605b764; commit 30b15906c1 (PR #13602, first tagged in v0.18.2)

  • saveAnswer is called only from goToQuestion, toggleModal and finishExam (ExamPage/index.vue:683,696,701).
  • interactionHandler only sets currentQuestionAnswered (:639-644); questionsAnswered counts it before anything is saved (:510-512).
  • No beforeRouteLeave, beforeDestroy or unmount hook in ExamPage, QuizRenderer, courses/QuizRenderer or courses/PrePostTestRenderer.
  • stopTrackingProgress on unmount (composables/useProgressTracking.js:632-650) flushes only unsaved_interactions, which saveAnswer fills.
  • 30b15906c1 replaced @interaction="saveAnswer" (debounced save) with @interaction="interactionHandler".
  • Closing a quiz sets MasteryLog.complete (kolibri/core/exams/viewsets/exam.py:677-679), and progress_tracking.py:567-571 then rejects updates with "Cannot update a finished coach assigned quiz".
  • None of the issues listed here or found by search reports this. #16026 is about a save that is still in flight, and #16073 is about order questions counting as answered when opened.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 27 '26 14:11 rtibblesbot