Skip to content

Persist learner answers for in-progress quiz attempts #1211

Open

Description

@KanishJebaMathewM

Context

The Learn backend now supports learner-safe quiz question retrieval through PR #1206 and persistent learner quiz attempts through PR #1209.

The next small step in the GSoC 2027 Offline-First Learning roadmap is to persist individual answers while a learner is working through an in-progress attempt. This issue depends on PR #1209 being merged into main, because that change introduces the persistent quiz_attempts table and the attempt lifecycle status used by this work.

Proposed changes

  • Add a D1 migration and schema documentation for persistent learner answers.
  • Associate each answer with one quiz attempt and one question.
  • Add an authenticated API endpoint to save or update an answer.
  • Validate that the attempt exists and that its question belongs to the attempt's quiz.
  • Derive the learner identity exclusively from the authenticated server-side session.
  • Allow only the owner of the attempt to save answers.
  • Allow answer updates without duplicate records by using an idempotent upsert keyed by attempt and question.
  • Permit changes only while the attempt status is in_progress.
  • Validate answer payloads against the existing quiz question types and their stored options/constraints.
  • Add focused automated tests for persistence, updates and authorization.

Reuse the authentication and learner authorization patterns established in PR #1206 and the existing quiz question schema in learn/schema.sql and learn/migrations/0015_quizzes.sql.

The existing question model uses question_type with multiple_choice as the default and stores selectable options in options_json. The implementation should preserve existing question semantics, reject unsupported or malformed answer payloads, and avoid exposing any answer-key fields.

Acceptance criteria

  • The migration and schema documentation define persistent learner answers.
  • Authenticated learners can save an answer for their own in-progress attempt.
  • Unauthenticated requests return 401.
  • Attempts owned by another learner are rejected with 403.
  • Missing attempts and questions are handled with appropriate errors.
  • A question must belong to the quiz associated with the attempt.
  • Answers cannot be changed after the attempt leaves in_progress.
  • Re-saving an answer updates the existing record rather than creating a duplicate.
  • The learner identity is taken from the authenticated session; client-supplied user IDs are ignored or rejected.
  • Client-supplied scores, correctness flags, answer keys and grading data are not accepted or returned.
  • Correct answers and grading information are never exposed.
  • Existing quiz retrieval and attempt creation behavior remains unaffected.
  • Focused automated tests pass.

Testing expectations

Add focused tests covering at least:

  • Successful answer creation.
  • Updating an existing answer idempotently.
  • Unauthenticated requests.
  • Attempts belonging to another learner.
  • Attempts that are no longer in_progress.
  • Invalid or nonexistent attempt IDs.
  • Questions that do not belong to the attempt's quiz.
  • Valid and invalid payloads for the supported question types.
  • Server-derived learner association and database persistence.
  • No exposure or acceptance of correct answers, scores or correctness flags.

Run the relevant quiz test suite and validate the migration and diff formatting.

Scope boundaries

This issue covers answer persistence for in-progress quiz attempts only.

Explicitly out of scope:

  • Quiz submission.
  • Automatic or manual grading.
  • Results and feedback.
  • Attempt history UI.
  • Frontend quiz-taking interface.
  • IndexedDB.
  • Offline synchronization.
  • Answer deletion or attempt lifecycle transitions beyond enforcing in_progress writes.

Dependencies

  • Must be implemented after PR #1209 is merged into main.
  • Follow learner authentication and authorization patterns from PR #1206.

Relevant files

  • learn/src/worker.py
  • learn/schema.sql
  • learn/migrations/
  • learn/tests/test_quizzes.py

Activity

  1. added
    good first issue
    2026-11
    on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    2026-11good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions