AI Coding Assistants in Practice: Repairing an Unfinished UEFI Graphics Application

    Can an AI coding assistant rescue a broken project generated by another model? This case study follows the repair of a UEFI Tetris game, from code review and runtime debugging to rendering and input improvements. It highlights pointer lifetime issues, an incorrect graphics protocol GUID, and a practical workflow built around incremental changes and real execution feedback.

    1. Background: Can AI Fix Another AI’s Unfinished Code?

    As large language models become more capable at programming, developers are increasingly asking AI assistants to build entire projects. But another use case deserves attention: can an AI assistant take over an unfinished codebase and make it work?

    I had a suitable test case: a Tetris game written for the UEFI environment by another AI assistant. After nearly six hours of work, that assistant had not even established a working build environment.

    The code was not worthless, however. It consisted of seven source files, used a modular design, and had a clear directory structure. It looked like a reasonable project—it simply did not run.

    Throwing it away would waste the existing work, while manually reviewing every line would take time. So I tried a different approach: give another model the job of reviewing and repairing the first model’s code.

    This article walks through that experiment, the debugging process, and the lessons learned.

    2. Experiment Design and Workflow

    I divided the work into two rounds:

    • Round 1: Make it run. The application needed to compile, load, enter its main game loop, and render a visible interface.
    • Round 2: Refine and optimize. Once it worked, the focus shifted to code organization, rendering efficiency, and input responsiveness.

    Both rounds followed the same AI-assisted debugging loop:

    1. Provide code and clear instructions
    2. → AI analyzes the code and lists issues
    3. → AI makes changes
    4. → Test the application
    5. → Report actual results to the AI
    6. → Iterate

    The essential requirement was honest feedback from real execution. The assistant could not see my screen. Serial logs, error messages, and descriptions of observed behavior were its main sources of evidence.

    3. Round 1: From Broken Code to a Running Game

    Step 1: Review Before Editing

    I copied the original source code into the new environment without changing it. My first instruction was simple:

    Review this code and identify issues that could prevent it from running. Do not make changes yet.

    Starting with a review helped avoid a cycle of isolated fixes made without understanding the overall application. It offered three benefits:

    1. I could assess whether the assistant understood the code.
    2. Its issue list became a troubleshooting roadmap.
    3. It reduced the risk of an immediate architectural rewrite that might break usable components.

    Within a few minutes, the assistant produced a structured list covering the entry point, main loop, game logic, rendering module, and input handling. It ranked the issues by severity and said the application should run after the fixes.

    I then asked it to implement the changes. That prediction still needed runtime verification.

    Step 2: Diagnose an Immediate Exit After Graphics Setup

    The code compiled, and the application loaded. The screen displayed:

    1. Starting Game Loop

    Then the application exited.

    I asked the assistant to add diagnostic output along the critical execution path and used serial logs to track its progress. The logs showed that execution stopped unexpectedly after calls involving GOP—the Graphics Output Protocol, UEFI’s standard graphics output protocol.

    The assistant traced the problem to the lifetime of the display mode information. The code retrieved mode information before calling SetMode and retained an info pointer. After the mode change, the retained pointer was no longer valid in this execution path. Subsequent graphics access relied on stale information and caused the failure.

    The fix was to retrieve the current framebuffer and mode information after SetMode. The revised code also used AllocatePool to keep a separately allocated copy of the mode information rather than retaining a pointer into protocol-managed storage.

    After that change, the application no longer exited immediately.

    The broader lesson was about pointer lifetime and memory ownership. In UEFI development, callers should not assume that memory exposed through a protocol remains valid indefinitely or belongs to them. The assistant’s ability to connect the failure to that lifetime issue showed a useful understanding of firmware programming conventions.

    Step 3: Fix the Graphics Protocol GUID

    The application now stayed running, but nothing appeared on the screen. I reported that result to the assistant.

    This time, its investigation focused on protocol lookup. It identified an incorrect GUID used for GOP.

    UEFI code relies on GUIDs to identify protocols. Using the wrong GUID in a LocateProtocol call can prevent the application from finding the intended graphics protocol. If code obtains an unrelated interface and treats it as GOP, its assumptions about the interface layout will also be wrong.

    The repair was to use the correct GOP protocol GUID definition.

    This kind of mistake is easy to miss during a build: a GUID is a 16-byte value, and an incorrect value can still compile successfully. The failure only becomes visible at runtime, as a failed protocol lookup or unexpected behavior.

    With that correction, Round 1 was complete. The Tetris game rendered in the UEFI environment, ran its main loop, and responded to keyboard input.

    A project that had remained unusable after nearly six hours of work was now running after another AI assistant took over the repair process.

    4. Round 2: Refinement and Optimization

    A running application was the baseline, not the endpoint. In the second round, I asked the assistant to preserve existing functionality while making targeted improvements.

    Code Organization

    The assistant consolidated duplicate logic and clarified dependencies between modules. The goal was to make the responsibilities of the entry point, game logic, and rendering layer easier to follow.

    Rendering Efficiency

    The rendering changes reduced full-screen redraws and introduced updates limited to dirty regions.

    In this application, rendering depended on CPU-driven framebuffer writes rather than GPU acceleration. Reducing the amount of framebuffer data written therefore mattered for smoothness.

    Error Handling and Diagnostics

    The assistant added consistent checks of protocol-call return values using EFI_STATUS. Failures produced serial diagnostic output instead of leaving the application to exit without useful evidence.

    This made subsequent failures easier to investigate and reduced the chance of another unexplained termination.

    Input Handling

    The input changes added key debouncing and a simple key buffer. These adjustments made the controls feel more responsive and consistent.

    The main observation from this round was that AI worked well on incremental improvements with explicit goals. When I specified what to optimize and required existing behavior to remain intact, the changes were generally usable.

    Vague instructions were riskier. They tended to encourage broad refactoring, increasing the scope of changes and making regressions harder to isolate.

    5. Lessons for Using AI to Rescue an Unfinished Project

    1. Start With a Review and a Prioritized Issue List

    Ask the assistant to review the entire codebase before editing it. Have it produce a structured list of problems, then address them in priority order.

    This is more effective than simply asking it to “fix everything.” It also gives you an opportunity to check its understanding before accepting changes.

    2. Feed Back Actual Runtime Results

    An AI assistant cannot observe the execution environment directly. Serial logs, compiler warnings, error messages, and precise descriptions of symptoms are its debugging evidence.

    The more specific the feedback, the more focused the next investigation can be. When necessary, explicitly ask the assistant to add diagnostic output so that an opaque failure becomes observable.

    3. Separate Functional Repairs From Optimization

    Make it work first; improve it second.

    The first round should address blocking issues. Structural cleanup, performance work, and usability improvements belong in a later round.

    Mixing these categories makes it harder to determine which change caused a new problem.

    4. Inspect Problems the Compiler Cannot Catch

    Pointer lifetime, GUID values, protocol versions, and memory ownership are recurring low-level development traps.

    They can also mislead an AI assistant because the code may look plausible and compile cleanly. Human review is particularly valuable at these boundaries.

    5. Treat Unfinished Code as Useful Context

    A broken project can still contain valuable module boundaries, naming conventions, and structural decisions. That context may make repair less costly than starting from scratch.

    Having one model review and repair another model’s output is a practical form of multi-model collaboration: one may be better at generating an initial implementation, while another may be better at examining and correcting it.

    The useful outcome is not that AI-generated code becomes automatically trustworthy. It is that existing work can be recovered through a disciplined review-and-test process.

    6. Conclusion

    This experiment gave me a more practical view of AI coding assistants in low-level development. An assistant can take over an unfinished project, review it, diagnose failures, implement fixes, and make targeted improvements.

    But that process still depends on a developer who understands the domain well enough to evaluate its reasoning and translate observed failures into useful evidence.

    AI does not remove the need for UEFI expertise. It can, however, help a developer apply that expertise more efficiently.

    If you have a structured but nonfunctional project, the same workflow is worth trying: review first, repair blocking issues, test each change, report real results, and optimize only after the application works.