HKUDS/DeepTutor · error · LearningStoreError

Invalid mastery interaction transition

Error message

Invalid mastery interaction transition: {current_status.value} -> {interaction.status.value}

What it means

State-machine guard in put_interaction: the stored interaction's status cannot legally transition to the incoming status (e.g. answered → awaiting). The interaction lifecycle only permits defined transitions between mastery interaction states.

Solutions

  1. Check the current interaction status before mutating and use an allowed transition
  2. Reload the interaction from storage instead of applying changes to a stale copy
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at deeptutor/learning/storage.py:190 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/f796b431e0431eec. Report an issue: GitHub.

Appendix: source

Thrown at deeptutor/learning/storage.py:190

            (self.progress.book_id, *_ACTIVE_INTERACTION_STATES),
        ).fetchone()
        return self._interaction_from_row(row)

    def put_interaction(self, interaction: MasteryInteraction) -> None:
        if interaction.path_id != self.progress.book_id:
            raise ValueError("interaction path_id does not match transaction path")
        existing = self._conn.execute(
            "SELECT path_id, status FROM mastery_interactions WHERE interaction_id = ?",
            (interaction.interaction_id,),
        ).fetchone()
        if existing is not None and str(existing["path_id"]) != interaction.path_id:
            raise ValueError(
                f"interaction_id {interaction.interaction_id!r} already belongs to another path"
            )
        if existing is not None:
            current_status = InteractionStatus(existing["status"])
            if interaction.status not in _ALLOWED_INTERACTION_TRANSITIONS[current_status]:
                raise LearningStoreError(
                    f"Invalid mastery interaction transition: "
                    f"{current_status.value} -> {interaction.status.value}"
                )
        now = time.time()
        interaction.updated_at = now
        self._conn.execute(
            """
            INSERT INTO mastery_interactions (
                interaction_id, path_id, status, question_json, session_id,
                turn_id, user_answer, result_json, created_at, updated_at
            ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
            ON CONFLICT(interaction_id) DO UPDATE SET
                status = excluded.status,
                question_json = excluded.question_json,
                session_id = excluded.session_id,
                turn_id = excluded.turn_id,
                user_answer = excluded.user_answer,
                result_json = excluded.result_json,

View on GitHub (pinned to 3e82f13042)