Skip to content

Fix random problem selection by difficulty - #256

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

Ericko00o wants to merge 11 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

Separates explicit random selection from the spaced-review recommendation policy so random draws sample uniformly from the problems matching the selected difficulties and topic filter, show the drawn problem's difficulty, and exclude the current problem whenever an alternative exists. Recommendations keep overdue-review priority across the broader review pool.

  • A random draw persists across page restores and history maintenance such as deleting reports or merging older account history, and across returning from an unfinished interview; explicit difficulty and duration choices are also restored when the lobby is rebuilt. Only a newly graded attempt at the drawn problem ends the draw and returns to recommendations.
  • A tab-local draw identity makes completion exact even under a backward clock adjustment, and blocked storage leaves navigation and report saving usable.
  • A difficulty change before history finishes loading no longer resets the picker to recommendations.
  • Adds regression tests for unseen-problem eligibility, difficulty filtering, exclusion, narrowed-practice pools, empty pools, topic resets, real Back navigation, and difficulty-change, history-change, page-restore, interview-navigation, draw-completion, and storage-failure behavior.

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

View guided diff

cubic-dev-ai[bot]

This comment was marked as resolved.

@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 Outdated
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 Outdated
Comment thread tests/browser/lobby.test.js Outdated
Comment thread tests/browser/lobby.test.js Outdated
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
@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.

@Ericko00o
Ericko00o force-pushed the fix/random-problem-selection branch from ac3968c to c06be4d Compare October 8, 2026 08:59
cubic-dev-ai[bot]

This comment was marked as resolved.

cubic-dev-ai[bot]

This comment was marked as resolved.

@Ericko00o
Ericko00o requested a review from jserv October 8, 2026 14:41
@jserv

jserv commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Before asking someone to review, you MUST resolve any regressions flagged by GitHub Actions.

Comment thread web/app.js Outdated
Comment thread web/app.js Outdated
Comment thread web/app.js Outdated
@Ericko00o
Ericko00o force-pushed the fix/random-problem-selection branch from 162d9ee to e299d69 Compare October 9, 2026 08:17
@Ericko00o
Ericko00o requested a review from jserv October 9, 2026 08:57
@jserv
jserv requested review from ColtenOuO and alanhc October 9, 2026 10:11
Comment thread web/app.js Outdated
Comment thread web/app.js
// Keep the exclusion with the roll so restoring the page repeats the same draw.
let avoidedProblem;
// Preserve the draw policy as well as its roll during history/page restores.
let pickerMode = "recommend";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A back/forward restore does not keep the draw: the pageshow handler clears problemTopic but leaves pickerMode, roll and avoidedProblem as they were. After Random under a topic filter, going to preflight and back re-runs the same roll over the unfiltered pool and selects a different problem. Either keeping the topic on restore, or resetting the draw there the way the topic-change handler does, would make the two agree.

cubic-dev-ai[bot]

This comment was marked as resolved.

cubic-dev-ai[bot]

This comment was marked as resolved.

Ericko00o and others added 4 commits October 10, 2026 16:25
Random draws previously prioritized overdue reviews, leaving unseen
problems unreachable while reviews were due. Draw uniformly from the
selected difficulty and topic pool so all eligible problems have an
equal chance, avoiding the current problem when alternatives exist.
Initial recommendations retain review priority, while random draws
show the selected problem's difficulty.
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>
The combined test entered random mode before changing difficulty, so
it could not detect a missing mode assignment in the level handler.
An independent fresh-lobby case checks the level and review note.
A cached lobby kept its random selection after the interview completed,
so refreshed reports could offer the same passed problem again. Retain
the draw while history is unchanged, but return to recommendations when
new reports replace the history it was drawn from.
Ericko00o and others added 6 commits October 10, 2026 16:25
A history refresh can arrive before a draw has been shown. Compare the
reports only when a snapshot exists so the pending selection survives
until the history is ready.

Co-authored-by: cubic-dev-ai[bot]
 <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Only explicit random draws should bypass scheduled reviews. Filter
redraws now return to recommendations, and new requests clear the
previous history snapshot. This preserves review priority and prevents
history refreshes from treating a new selection as an old draw. Tests
cover filters after random draws and changes during restored history.
The indentation gate rejects the long picker call in the regression
test. Apply the repository formatter so CI can finish its checks.
Deleting reports or merging older account history should not revoke a
random choice. End the draw only for a newly graded attempt at that
problem, and reset a topic-filtered draw when restoration clears its
topic so the restored selection follows the same filter policy.
A completed interview should end its own random draw even when the
system clock moves backward. Carry a tab-local draw identity into the
interview and consume its graded completion marker on return, so old
reports and older interviews cannot revoke a newer selection. Storage
failures leave navigation and report saving usable.
Returning from an unfinished interview must keep its random draw even
when the browser reloads the lobby or tab storage is blocked. Carry the
draw identity through navigation and graded reports so only that
interview's completion restores recommendations, while history changes
remain independent of the candidate's selection.
@Ericko00o
Ericko00o force-pushed the fix/random-problem-selection branch from 3752b2b to a6dbeba Compare October 10, 2026 08:32
Returning from an interview can reconstruct the lobby and discard
explicit difficulty and duration choices. Restore these choices before
applying suggestions so clearing a topic filter retains the candidate's
preferences and later difficulty changes respect a manual duration.
@Ericko00o
Ericko00o requested a review from ColtenOuO October 10, 2026 08:56

@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.

Fold similar commits and refine git commit messages per CONTRIBUTING.md.

@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.

Rebase latest main branch and resolve conflicts.

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

3 participants