- The paper shows that incorporating deliberate bug injection significantly alters student responses, with injected bugs resolved at a 90% success rate and natural bugs at 51%.
- The methodology employs a hybrid approach combining iterative natural language prompts, GenAI code generation, and targeted bug injection within a controlled CS1 classroom assignment for 917 students.
- The study highlights improved debugging practices and deeper code comprehension, suggesting that structured failure experiences foster professional-grade error verification skills.
Analysis of "When AI Is Wrong on Purpose: How Students Respond to Buggy GenAI Code"
Prompt-Based Programming Workflow and Bug Injection
The paper investigates prompt-centered pedagogical workflows for CS1 students interacting with GenAI code assistants. The core approach employs a web platform ("Prompt Programming") supporting iterative natural-language problem specification, AI code generation, execution against hidden unit tests, and direct user code editing. Critically, the study introduces a bug injection pipeline that intercepts correct GenAI outputs, replacing them with runnable near-miss variants containing targeted faults. This prevents students from only relying on prompt refinement, requiring them to actively inspect and repair generated code.

Figure 1: The prompt programming interface supporting iterative specification, GenAI response, bug injection, code editing, and validation.

Figure 2: Bug injection pipeline: correct code is mutated and validated against tests; failing variants are served as injected bugs.
This hybrid approach enables controlled experimentation with two distinct bug types: (1) natural bugs (incorrect code due to prompt-specification mismatch or model error) and (2) injected bugs (deliberately introduced local faults in otherwise correct code).
Study Design and Data Acquisition
The deployment comprised a graded classroom assignment for 917 students in an introductory C course across five diverse programming tasks (array, matrix, binary operations). Students were made aware of the possibility of buggy code, but were not told whether failures were due to AI mistakes or deliberate injection.

Figure 3: Data collection procedure: platform logs (interactions, code edits, executions) and post-activity reflection questionnaires.

Figure 4: Session structure and bug labeling schema, differentiating natural and injected bugs on a turn basis.
Session logs, cleaned and filtered, captured 2636 student-task sessions and 6071 bug-fixing turns (actions after buggy GenAI outputs). Supplementary reflection data was also collected post-activity, comprising Likert items and thematic open-ended responses.
Behavioral Differences Across Bug Types
Quantitative analysis reveals marked behavioral shifts contingent on bug source:
- When faced with natural bugs, students predominantly refine prompts (specification repair), while injected bugs elicit code edits (local implementation repair).
- Immediate resolution rates reflect the proximity to correctness: turns following injected bugs result in next-attempt success approximately 90% of the time, as opposed to 51% for natural bug turns.





Figure 5: Action breakdown: editing, prompting, and noop fractions for buggy turns by bug source.
Local repair strategies for injected bugs exhibit lower edit distances and fewer edit-and-run cycles, consistent with their design as minor, localized defects. Contrastingly, natural bugs often entail broader code revision or task reinterpretation.





Figure 6: Edit distances for bug fixes; injected bugs require smaller changes.
Prompt analyses indicate specification-centric strategies (function signature updates, edge cases, reframing) dominate responses to natural bugs, while guidance and restatement are more prevalent after injected bugs.
Student Perceptions and Reflections
Reflective data reinforce the observed behavioral dichotomies:
- Code understanding and debugging emerged as primary perceived learning benefits.
- Students acknowledge greater comprehension of self-authored code versus AI-generated code (64% agree/strongly agree).
- The activity heightened awareness of GenAI limitations, promoting a verification mindset and careful review behaviors.


Figure 7: Likert scale responses: perceived bug-fixing ease and comparative understanding of AI-generated vs. self-written code.
Thematic coding of open responses highlights additional benefits: improved specification practices, exposure to diverse bug types, strategic GenAI workflow management, and greater error-spotting acuity.
Implications for CS Education and GenAI Workflows
These findings underscore the necessity for structured failure experiences in prompt-based GenAI workflows, especially at introductory levels where correct code is frequently produced. Bug injection establishes code review and repair as a mandatory intervention, aligning educational practice with professional development workflows that demand rigorous code verification.
From a theoretical perspective, the observed metacognitive action selection suggests that students leverage bug source as a decision signal for repair locus (specification vs. artifact). This has direct implications for scaffolding and interface design: platforms should stratify bug diagnosis modalities and provide targeted cues or requirements (e.g., evidence of verification, brief fault hypothesis) before enabling next actions.
Future directions for GenAI in education should involve progressive transparency about bug sources, rigorous A/B experimentation to isolate effects, inclusion of richer feedback modalities, and generalized replications across languages and task types. Critically, prompt-based activities should move beyond prompt optimization toward holistic skills including diagnostic reasoning and actionable verification habits.
Conclusion
The paper robustly demonstrates that deliberate injection of bugs in prompt-based programming workflows significantly alters student repair and verification behavior, fostering a code review mindset and higher engagement with local debugging. Immediate success rates, repair effort metrics, and reflective feedback all indicate the pedagogical utility of structured near-miss failures for cultivating skills critical to GenAI-mediated software development. Future work should focus on optimal scaffolding strategies and longitudinal assessment of transfer effects to novel tasks and environments.