Skip to content

Fix adaptive difficulty and trial handling bugs - #37

Open
CMonnin wants to merge 1 commit into
mainfrom
logic-fixes
Open

CMonnin wants to merge 1 commit into
mainfrom
logic-fixes

Conversation

@CMonnin

@CMonnin CMonnin commented Oct 27, 2026

Copy link
Copy Markdown
Member

Summary

Fixes to the adaptive loop and trial handling in pictureNamingTask.ts, plus stricter settings validation.

 loop_function
-  if lastResult.result === "Correct"        # translated label
+  if lastResult.resultAsNumber === "1"
     streak++
   if streak === advancementSchedule
-    if streak <= numberOfLevels             # always true → level runs past max
+    if currentDifficultyLevel < numberOfLevels
       level++
 getRandomElementWithSeed(pool)
+  if pool is empty: throw                   # previously spun / indexed undefined
 showImg / welcome
-  on_start:  add(click, new closure)
-  on_finish: remove(click, other new closure)   # no-op, listener leaked
+  ...clickAsKeyPress(jsPsych)                   # shared handler reference
 logging.on_load
   if shouldRepeatTrial
     finishTrial(...)
+    return                                      # was touching removed DOM
-  <input onclick="...'${t("correct")}'...">     # translated text inside JS string
+  <input data-result-as-number="1" data-color="green">  + addEventListener

$Settings: language is now en | fr, initialDifficulty <= numberOfLevels, regressionSchedule >= 0, downloadOnFinish: "false" no longer coerces to true.

Evidence

  • Before: with advancementSchedule: 2, numberOfLevels: 9, enough consecutive correct answers push the level to 10 → empty pool → hang/crash.
    After: level stays at 9; an empty pool throws no stimuli available for the requested difficulty/language.
  • tsc and vite build pass. Not exercised in a browser — please click through a session (Correct/Incorrect buttons, repeat path, keyboard vs click advance) before merging.

Merge Danger

Door: two-way

Blast Radius: task-flow

Touches the logging screen and the difficulty progression, so a regression would show up as wrong levels or a stuck logging page. Configs that previously parsed with initialDifficulty > numberOfLevels or an unknown language will now fail at startup.

🤖 Generated with Claude Code

- Cap difficulty on the current level, not the streak counter
- Fail clearly when no stimuli match instead of looping forever
- Remove click-as-keypress listeners using the same reference
- Return after finishTrial on repeated trials
- Replace inline onclick handlers with listeners wired in on_load
- Score on resultAsNumber rather than the translated label
- Tighten settings schema (language enum, initialDifficulty <= numberOfLevels,
  non-negative regressionSchedule, string booleans)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant