TL;DR
Introductory computer science students often accept Generative AI (GenAI) code blindly because modern models easily solve basic programming tasks. To combat this passive overreliance, researchers built a pipeline that deliberately injects subtle, realistic bugs into correct AI-generated code. The study reveals that these "wrong on purpose" near-misses successfully shift student behavior from lazy prompting to active code review and localized debugging.
What Problem Does This Paper Address?
In professional software engineering, GenAI tools like GitHub Copilot are powerful assistants, but they frequently output subtle bugs, security vulnerabilities, or logic errors. Consequently, critical code review and verification have become essential developer skills.
However, in introductory computer science (CS1) courses, standard assignments are simple enough that GenAI models usually get them right on the first try. This creates a pedagogical dilemma: if the AI's code always works, students have zero incentive to read, trace, or verify it. This lack of critical engagement fosters an "illusion of competence," where students believe they understand code they haven't actually evaluated. The authors investigate how to design prompt-based programming workflows that explicitly teach code verification and debugging rather than just prompt engineering.
Methods
The authors extended Prompt Programming, an interactive web platform where students write natural language prompts to generate C code and test it against hidden unit tests.
The core innovation is a Bug Injection Pipeline that acts as a middleware layer between the AI's generation and the student's editor:
- The student submits a prompt, and the GenAI assistant (backed by GPT-4o-mini) generates a candidate solution.
- The pipeline intercepts the code and runs it against hidden tests.
- If the code fails naturally, it is passed to the student as a natural bug ($n$).
- If the code passes, a separate GenAI instance acting as a "bug injection expert" mutates the correct code to generate five buggy candidates. The pipeline validates these candidates and serves the first variant that compiles but fails the tests to the student as an injected bug ($i$).
Students must then decide whether to fix the bug by rewriting their prompt or by manually editing the code in a built-in editor.
Datasets
The system was deployed in an introductory C programming course at the University of Auckland during the second semester of 2025.
- Participants: 917 students who interacted with the platform across five lab tasks (focused on arrays, matrices, and binary addition).
- Data Collected: 2,636 complete student sessions encompassing 6,071 individual bug-fixing turns, alongside a post-task qualitative reflection questionnaire.
Key Insights and Ideas
- Bug Source Dictates Strategy: Students dynamically adapt their problem-solving strategy based on the nature of the failure. Natural bugs usually stem from fundamental task misunderstandings, prompting students to reframe their prompts. Injected bugs, being "near-misses," signal to the student that the code is almost correct, prompting them to roll up their sleeves and edit the code directly.
- Desirable Difficulty via Near-Misses: Injected bugs provide a bounded, manageable challenge. Because the bug is highly localized (e.g., changing an index or flipping a comparison operator), it triggers deeper cognitive processing without causing the unproductive struggle or frustration often associated with completely broken code.
- Breaking the Oracle Myth: By forcing students to confront an AI that is "wrong on purpose," the workflow successfully reframes GenAI from an infallible oracle into an unreliable collaborator that requires constant human oversight.
Key Results
- Prompting vs. Editing: When facing an injected bug on their first turn, students chose to edit the code directly 67.57% of the time, compared to only 45.42% for natural bugs. Conversely, they chose to reprompt 51.71% of the time for natural bugs, but only 31.46% for injected ones.
- Repair Effort: Code edits following injected bugs were significantly smaller and more targeted, featuring a median Levenshtein edit distance of just 4 characters, compared to 24 characters for natural bugs.
- Immediate Success: Students achieved an immediate fix on their first attempt 89.92% of the time for injected bugs, versus 51.16% for natural bugs, proving that near-miss injections are highly fixable, localized tasks.
- Student Reflections: 64% of students agreed that they understand self-written code better than AI-generated code. Qualitatively, students overwhelmingly reported that finding the deliberate bugs provided excellent practice for code tracing, reading comprehension, and debugging.
Limitations and Future Work
The study was conducted within a single introductory course using structured, short array and matrix problems in C, meaning the findings might not immediately generalize to open-ended projects or other programming paradigms. Additionally, the platform did not disclose to students whether a failure was natural or injected. The authors note that future work should explore how transparency regarding bug injection affects student trust. Finally, while student behavior shifted productively in-session, controlled A/B testing is still required to rigorously evaluate long-term learning gains and skills transfer to new, AI-free tasks.
Summary updated