🌐 US-Proxy
id="body-softwares" class="foundation-grid action-show controller-softwares engine-home">

PyRootTrace

Inspiration

This theme is interesting because it is very common to see students struggling in python or to code. While learning to code it happens many times that you know the logic and wrote a code for it but you don't know the error in it. It helps to clarify the misunderstandings that get built while learning and to make the student realise about it.

What it does

The main idea is that a wrong answer doesn't reveal why a student made a mistake. A student might be doing something wrong again and again without realising. Instead of giving students the direct solution, more questions should be given on the same misconception, to help students build up the understanding for a long term.

The approach

  1. Structural and runtime trace extraction: When a student's code fails, our backend uses python's built in ast (Abstract Syntax Tree) module to compute how different a student's code structure is from a correct code (compute structural edit distance), against a reference AST. And it uses sys.settrace inside a containerized sandbox to record step-by-step variable states up to the point of divergence.

  2. Misconception Classification: Approach is to use Qwen2.5-Coder-7B-Instruct model finetuned via QLoRA on curated python error logs from public RunBugRun and CSEDM CodeWorkout datasets. The classifier maps the failure into one of the 5 misconceptions:

    • M1 — Premature Loop Return: Putting return inside an if/else block on the first iteration of a for loop instead of checking all elements first.
    • M2 — In-Place Mutation & Reference Aliasing: Modifying a list while iterating over it, or assuming list_b = list_a creates an independent copy.
    • M3 — Off-by-One & range() Exclusivity: Forgetting that range(start, stop) and slice [a:b] exclude the stop index.
    • M4 — In-Place Return vs. NoneType Confusion: Assigning x = my_list.sort() or x = my_list.append(y) assuming in-place methods return a new list, or using print() instead of return.
    • M5 — Accumulator & State Reset Neglect: Defining an accumulator variable inside a loop (resetting it every iteration) or forgetting to reset state between function calls.
  3. Next problem Generation: Then Qwen2.5-Coder-7B-Instruct generates a targeted follow-up coding problem in a new context with two executable scripts: a canonical solution and a buggy solution that explicitly encodes the detected misconception.

  4. Test-Based problem validation: A pytest runner executes both scripts against generated test cases. A problem is given to the student if the canonical solution passes all the tests and the buggy solution fails on targeted edge-case input.

Challenges we ran into

  1. Observational equivalence. Different bugs can produce identical wrong outputs, so judging only the static code or the final answer isn't enough. This is why we ground diagnosis in runtime variable traces instead.
  2. Unverified generation. LLM-generated problems often have hallucinated test cases or fail to test the intended bug at all. Building a gate that mathematically proves a problem isolates the misconception was one of our hardest design problems.
  3. Messy, unlabelled data. RunBugRun and CSEDM weren't built around our five misconception categories, so mapping real student errors onto them took careful curation.
  4. Safe execution. Running untrusted student code and generated scripts required a properly containerized sandbox.
  5. Scope control. Misconception tracking and learning-gain studies were tempting, but we prioritised a reliable minimum viable system first.

Accomplishments that we're proud of

  1. A diagnosis pipeline that uses dynamic execution traces rather than guessing from static code text.
  2. A verification gate that guarantees every practice problem fails on the exact misconception it targets, which is something plain LLM prompting can't promise.
  3. A tutor that withholds the answer and builds understanding instead.
  4. A design that goes beyond "more practice questions" and moves toward measurable reduction in repeated errors.
  5. A clear evaluation plan: precision, recall and macro-F1 for detection, pass rate of generated problems versus a plain-LLM baseline, and before/after transfer tests.

What we learned

  1. A wrong answer tells you very little. The path the code took (variable states step by step) tells you much more.
  2. LLMs are good at writing problems but unreliable at checking them, so generation needs executable verification.
  3. Good tutoring means asking more targeted questions rather than handing over solutions.
  4. Modelling misconceptions as latent states that persist across sessions is more useful than tracking general skill mastery.
  5. Prioritising a reliable minimum viable system before adding advanced features keeps a prototype honest and evaluable.

What's next for PyRootTrace

  1. Complete M-BKT tracking so the tutor remembers which misconceptions each student still holds, and keeps targeting them until the bug probability drops below 15%.
  2. Run the empirical study. Compare against Baseline A (random practice on the same topic) and Baseline B (an LLM without verification) using transfer tests, and publish error-decay curves.
  3. Expand beyond five misconceptions to cover more Python concepts such as scope, mutable default arguments, and recursion.
  4. Support more languages such as Java and C++, since the same trace-and-verify approach applies.
  5. Teacher dashboards that show which misconceptions are most common across a class.
  6. Better explanations that walk students through their own variable trace, so they can see exactly where their mental model and the program diverged.

Built With

Share this project:

Updates

Submission history