Skip to content

Fix random problem selection by difficulty - #256

Open
Ericko00o wants to merge 2 commits into
sysprog21:mainfrom
Ericko00o:fix/random-problem-selection
Open

Ericko00o wants to merge 2 commits into
sysprog21:mainfrom
Ericko00o:fix/random-problem-selection

Conversation

@Ericko00o

@Ericko00o Ericko00o commented Oct 7, 2026 •

Copy link
Copy Markdown

Explicit random selection currently shares the spaced-review recommendation policy. When multiple problems are overdue, repeated clicks can cycle through those problems indefinitely, excluding unseen problems and selecting reviews outside the chosen difficulties.

Separate explicit random selection from automatic recommendations. Random draws uniformly sample the problems matching the selected difficulties and topic filter, excluding the current problem whenever an alternative exists. Initial recommendations retain overdue-review priority across the broader review pool. Random selections also display the problem's difficulty.

Add regression tests for unseen-problem eligibility, difficulty filtering, current-problem exclusion, single-problem and empty pools, and the distinction between filtered practice and broader review recommendations. Update the lobby's expected selection text and add browser coverage for random selection, page restoration, and difficulty changes.

Validation: node --test tests/browser/problem-picker.test.js tests/browser/lobby.test.js completed with 43 tests passing, no failures, and 112 browser tests skipped because Playwright Chromium was unavailable. The JavaScript syntax check and git diff --cached --check passed. The required ./scripts/test.sh gate has not been run, and browser interaction remains unverified locally.

Closes #210


Summary by cubic

Fixes #210 by separating explicit random selection from the spaced-review recommendation policy. Random draws now sample uniformly from the problems matching the selected difficulties and topic filter instead of cycling through overdue reviews, which previously left unseen problems unreachable.

  • Random draws exclude the current problem whenever an alternative exists and show the chosen difficulty.
  • Recommendations keep overdue-review priority across the broader review pool.
  • Adds regression tests for unseen-problem eligibility, difficulty filtering, exclusion, narrowed-practice pools, and empty-pool handling.

Written for commit ac3968c. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="web/app.js">

<violation number="1" location="web/app.js:1028">
P2: Topic-filter redraws in random mode can select the current problem again because `filterSelectionChanged()` clears `avoidedProblem` before `recommend()`. Preserve the current card as the exclusion on random-mode redraws.</violation>
</file>

Reply to a comment to ask cubic a question or push back. It learns from your replies.

Turn on auto-fix | Re-trigger cubic

Comment thread tests/browser/lobby.test.js Outdated
Comment thread web/app.js
undefined,
avoidedProblem,
cards,
pickerMode,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Topic-filter redraws in random mode can select the current problem again because filterSelectionChanged() clears avoidedProblem before recommend(). Preserve the current card as the exclusion on random-mode redraws.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At web/app.js, line 1028:

<comment>Topic-filter redraws in random mode can select the current problem again because `filterSelectionChanged()` clears `avoidedProblem` before `recommend()`. Preserve the current card as the exclusion on random-mode redraws.</comment>

<file context>
@@ -1021,6 +1025,7 @@ function recommend(note = "") {
     undefined,
     avoidedProblem,
     cards,
+    pickerMode,
   );
   // Nothing to offer is still an answer, and it has to go through `setProblem`
</file context>

@jserv jserv changed the title Fix #210 random problem selection at selected difficulties Fix random problem selection at selected difficulties Oct 7, 2026
Comment thread web/app.js
keptDraw = null;
roll = Math.random();
avoidedProblem = undefined;
pickerMode = "random";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A level change is not an explicit random draw, but this switches it to uniform selection anyway. With a passed Hard problem and unseen Hard ones, checking Hard and unchecking the current level can now offer the passed problem first. That undoes "a problem already passed is not what gets recommended next", and the description does not mention it. If the goal is only to stop reviews crossing the selected levels, keep "recommend" here and restrict the review pool to the selected difficulties instead.

Comment thread web/app.js
undefined,
avoidedProblem,
cards,
pickerMode,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pickerMode is set to "random" and never goes back to "recommend", so after one click every later recommend() draws uniformly: filterSelectionChanged(), sign-in, report deletion and every settle(). Concrete case: click Random and get X, finish X, press Back. The bfcache restore refetches reports that now record X as passed, yet roll, avoidedProblem and the pool are unchanged, so settle() offers X again (and silently drops the reason keptDraw is cleared there). Reset to "recommend" wherever avoidedProblem is reset to undefined, and in settle() whenever the reports differ from the ones the random draw was made from (track them the way keptDraw does).

Comment thread web/app.js
return;
}
setProblem(choice.picked);
// Editing begins: When randomly selecting questions, display the difficulty level next to the question title.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Editing begins:" reads like an editor marker. A comment here should say why random mode skips the review sentence, e.g. that a random draw is never a review and the level is named because it may differ from the suggested one.

Comment thread tests/browser/lobby.test.js Outdated
Comment on lines +1913 to +1915
await setLevel(page, "Hard", true);
await setLevel(page, "Medium", false);
assert.equal((await cardInfo(page, (await snapshot(page)).card)).level, "Hard");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difficulty half of this test only runs after the Random click has already set pickerMode = "random", so deleting the assignment in the level handler still passes. It also checks only the level, not that the note lacks Review due. Exercise the level change from a fresh lobby with overdue reviews, as a separate test, and assert both.

jserv

This comment was marked as duplicate.

@Ericko00o Ericko00o changed the title Fix random problem selection at selected difficulties Fix random problem selection by difficulty Oct 7, 2026
Random draws previously prioritized overdue reviews, preventing unseen
problems from being selected when due reviews were available. Select
uniformly from the chosen difficulty and topic pool so every eligible
problem has an equal chance, excluding the current problem when another
is available. Preserve review priority for initial recommendations and
show the drawn problem's difficulty so users can identify its level.

Refs sysprog21#210

Co-authored-by: Jim Huang <jserv.tw@gmail.com>
@Ericko00o
Ericko00o requested a review from jserv October 7, 2026 09:37

@jserv jserv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check CONTRIBUTING.md carefully and enforce the rules. In particular, the manner for writing git commit messages.

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.

Pick a random problem cycles only through overdue attempts while unseen problems remain

2 participants