Repository navigation
Conversation
its-gabo
force-pushed
the
gs_fix_course_progress_consistency
branch
from
December 4, 2026 14:54
d2119c2 to
0eebab2
Compare
its-gabo
marked this pull request as ready for review
December 4, 2026 14:56
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Makes learner progress easier to maintain and makes "completed" mean the same thing on every screen. First the test coverage was raised, then the 1,282-line
StudentLessonProgressServicewas split into focused services and repositories. The new coverage exposed two bugs, fixed here. Course completion is now one stored fact that every screen reads, and recounting learners after content is removed runs in the background.Test coverage (written against the old code first): 33 new end-to-end tests in
src/studentLessonProgress/__tests__, plus 12 unit tests. Previously, reopening a lesson, recounting after a lesson was deleted, chapter completion and its events, and completing a course after its content changed had little or no coverage. New coverage:Bug fixes:
UserChapterFinishedEventagain each time. Each repeat wrote another activity-log entry and could send the learner another "chapter finished" email. It is now published only when the chapter is newly finished.completed_as_freemiumcolumn stays because certificates still read it.===or>=inconsistently. Others read the completion date. They disagreed as soon as an author added or removed a chapter, and nothing recounted learners when chapters were removed or a course copy was synced.Completion rule:
CourseCompletionServiceis the only code that writes it.Background recount: removing a lesson or chapter, or a course-copy sync that removes chapters, used to recount every affected learner synchronously. For lesson deletion that happened inside the admin's HTTP request, so a large course could time out the request or run past the outbox's 5-minute claim.
course-progress-recountBullMQ job per event, keyed by the event ID.Refactor:
studentLessonProgress.service.ts(1,282 → 491 lines) is now a facade with the same public methods, so none of its ~12 callers change. Behind it:LessonProgressAccessService: the access check (previews, drafts, tracking rules, learning-mode enrollment) that was copied into three methods, plus resolving the acting user.CourseCompletionService: chapter recount and course completion, including repetition, certificates and statistics.CourseProgressRecountServiceandCourseProgressRecountWorker: the background recount.LessonProgressRepository,LessonProgressAccessRepositoryandCourseProgressRepositoryhold the data access, one query or write per method. Services make no direct database calls.match(...).exhaustive(), shared contracts live instudentLessonProgress.type.ts, and the controller's response type is inschemas/.Contracts:
isCompletedandprogressPercentage. Both come from one set of SQL helpers insrc/courses/utils/course-progress-sql.ts. The schema and web client were regenerated through the existing scripts. The web app reads these fields instead of comparing chapter counts;isCourseAttemptCompletedcovers repeats in progress.CourseProgressRecountRequestedEvent { courseId, chapterId | null }with a TypeBox payload schema.course-progress-recount.Notes:
api-schema.jsonalso picks up anonboarding-statusparameter difference that was already out of date onstaging.certificate-issuing.e2e-spec.ts› "returns the learner's active certificate instead of issuing another" fails intermittently with a Postgres deadlock. It fails on unmodifiedstagingtoo (one in three runs), so it is not caused by this change.Business Value
Learners and HR see one completion status and one progress figure on every screen, and adding content to a finished course no longer quietly un-finishes it or contradicts an issued certificate. Learners stop receiving duplicate "chapter finished" notifications, and activity logs stop recording the same chapter completion several times. Removing content from large courses no longer risks timing out the admin's request or stalling progress updates, and learners who have finished everything that remains are recognised automatically. Learner progress now follows the same structure as the rest of the backend and is covered by end-to-end tests, which makes future progress and completion work cheaper and safer.
PR flow video
Recorded at
0eebab20cc8b.video.mp4