kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

QTI associate and match questions that take a single pair lose the answer as soon as the learner makes it

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

QTI associate and match questions whose response is declared with cardinality="single" can't be answered. As soon as the learner completes the pair, both slots empty again. The question is still counted as answered, and an empty response (RESPONSE: null, score 0) is saved.

Here a learner pairs France with Paris in an associate question, then matches Capulet to Romeo and Juliet in a match question. Both use cardinality="single":

https://github.com/user-attachments/assets/6ab61806-2824-4d07-87c9-53bc0dfb7d8f

The saved attempt for the associate question is {"responses": {"RESPONSE": null}, "outcomes": {"SCORE": 0}}.

cardinality="single" with base-type="pair" / "directedPair" is valid QTI 3.0 for these interactions, for example a question with max-associations="1". All of Kolibri's associate and match fixtures use cardinality="multiple", which is why existing tests don't catch this.

Cause

AssociateInteraction.vue and MatchInteraction.vue keep their slots and the response variable in sync with two watchers. Writing a completed pair goes like this:

  1. The pairs watcher writes a list of pairs, [["C1", "C4"]], to the response variable.
  2. For a single cardinality variable, QTIVariable.coerceValue (utils/qti/variables.js L240–253) unwraps a one-element list, so the variable holds ["C1", "C4"].
  3. The variable watcher (AssociateInteraction.vue L208–217, MatchInteraction.vue L310–319) compares that value with pairs ([["C1", "C4"]]). They differ, so it calls hydrate(value).
  4. hydrate (composables/useAssociateSlots.js L80–102, composables/useMatchRows.js L210–242) expects a list of pairs. It skips "C1" and "C4" because they aren't arrays, and clears every slot. The pairs watcher then writes [], which becomes null.

Expected behavior

A single cardinality pair response works like a multiple one. The completed pair stays in place, the response holds ["C1", "C4"], and the item is scored against it.

User-facing consequences

  • Learners can't answer these questions at all. Whatever they do, the attempt is saved empty and scored 0.
  • The quiz footer and submit dialog count the question as answered although nothing was recorded, so the learner gets no warning.
  • Coaches see every learner as having got the question wrong.

Steps to reproduce

  1. Have a QTI exercise with an associate or match item declared as cardinality="single". I used Kolibri's own associate-interaction-1 and match-example-1 fixtures with the response declaration changed to cardinality="single", one correct pair, max-associations="1" and the match_correct template, added to a local QTI exercise.
  2. Put the item in a quiz (or open the exercise) as a learner.
  3. Place both halves of a pair.
  4. Both slots empty again, and checkAnswer() returns RESPONSE: null.

A Jest check with renderAssessmentItem shows the same: after placing France and Paris, checkAnswer().answerState.responses.RESPONSE is null instead of ["C1", "C4"].

Possible fix

I'd be glad to work on this once the approach is agreed. In both components, the variable watcher could treat a single cardinality value as a one-pair list before comparing and hydrating:

const list = variable.value?.cardinality === CARDINALITY.SINGLE && value ? [value] : value;
if (isEqual(list, pairs.value)) {
  return;
}
hydrate(list);

With that change applied locally, the pairs stay in place and both questions record their answers. The existing associate and match specs still pass, plus new tests for the single cardinality case:

https://github.com/user-attachments/assets/2c71d7cd-19a4-4ada-b285-5ab0df387d66

Context

  • Kolibri develop (the QTI viewer interaction files are unchanged between 07e85c89ef and 758605b764), dev server
  • macOS 26, Chromium

AI usage

I used an AI coding assistant to look for bugs in the QTI interactions. It found this one and traced it through the response variable and the sync watchers. It also wrote the Jest check and drafted this issue. I reproduced it in a local quiz, checked the saved attempt, and recorded the videos.

Rishika-dev avatar Nov 27 '26 12: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 12:11 learning-equality-bot

Verdict: claim holds Evidence: kolibri/plugins/qti_viewer/frontend/ on develop at 758605b764: utils/qti/variables.js#L240-L253, components/interactions/AssociateInteraction.vue#L208-L224, components/interactions/MatchInteraction.vue#L310-L326, composables/useAssociateSlots.js#L80-L102, composables/useMatchRows.js#L210-L242

The code runs the loop the issue's Cause section describes:

  • The pairs watcher writes [["C1", "C4"]] to the response variable.
  • For a single cardinality variable, coerceValue unwraps the one-element list, and coercePair (utils/qti/values.js#L123-L134) keeps ["C1", "C4"].
  • The variable watcher's isEqual(["C1", "C4"], [["C1", "C4"]]) is false, so it calls hydrate.
  • Both hydrate functions skip anything that is not a 2-element array. The rows are cleared, the pairs watcher writes [], and coerceValue([]) returns null.
  • Every associate and match declaration in the specs and __fixtures__ uses cardinality="multiple".
  • The issue's line references match develop.
  • I found no other open issue, and none closed in the last 30 days, that reports this. #16073 is about the order interaction.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 27 '26 12:11 rtibblesbot