QTI associate and match questions that take a single pair lose the answer as soon as the learner makes it
❌ 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:
- The
pairswatcher writes a list of pairs,[["C1", "C4"]], to the response variable. - For a single cardinality variable,
QTIVariable.coerceValue(utils/qti/variables.jsL240–253) unwraps a one-element list, so the variable holds["C1", "C4"]. - The variable watcher (
AssociateInteraction.vueL208–217,MatchInteraction.vueL310–319) compares that value withpairs([["C1", "C4"]]). They differ, so it callshydrate(value). hydrate(composables/useAssociateSlots.jsL80–102,composables/useMatchRows.jsL210–242) expects a list of pairs. It skips"C1"and"C4"because they aren't arrays, and clears every slot. Thepairswatcher then writes[], which becomesnull.
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
- Have a QTI exercise with an associate or match item declared as
cardinality="single". I used Kolibri's ownassociate-interaction-1andmatch-example-1fixtures with the response declaration changed tocardinality="single", one correct pair,max-associations="1"and thematch_correcttemplate, added to a local QTI exercise. - Put the item in a quiz (or open the exercise) as a learner.
- Place both halves of a pair.
- Both slots empty again, and
checkAnswer()returnsRESPONSE: 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.
🔍 Thanks for opening this issue! @rtibblesbot will check it against the code and comment with its findings.
What happens next:
- The
community-issue-reviewlabel 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.
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
pairswatcher writes[["C1", "C4"]]to the response variable. - For a single cardinality variable,
coerceValueunwraps the one-element list, andcoercePair(utils/qti/values.js#L123-L134) keeps["C1", "C4"]. - The variable watcher's
isEqual(["C1", "C4"], [["C1", "C4"]])is false, so it callshydrate. - Both
hydratefunctions skip anything that is not a 2-element array. The rows are cleared, thepairswatcher writes[], andcoerceValue([])returnsnull. - Every associate and match declaration in the specs and
__fixtures__usescardinality="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.