Microsoft Patents an AI Coding Engine That Patches Its Own Mistakes Mid-Write
Most AI coding tools either produce a working answer or fail outright. Microsoft's new patent describes a system that dissects its own broken attempts, keeps the parts that work, and surgically rewrites only what doesn't.
What Microsoft's self-correcting code writer actually does
Ever asked an AI assistant to write a complex piece of code and watched it confidently hand you something that simply doesn't run? That failure is usually total: the AI tries again from scratch, making the same kinds of mistakes.
Microsoft's patent describes a different approach. When the AI's first attempt at a program fails a test, the system doesn't throw everything away. Instead it identifies which parts of the failed attempt were correct, holds onto those, and asks the AI to write only the missing or broken section. It then stitches the saved piece and the new piece back together.
The system can repeat this loop many times, each pass getting closer to a program that actually passes all the requirements. Think of it like a surgeon removing only the diseased tissue instead of replacing the entire organ. The result, in theory, is an AI coder that wastes less effort and reaches a working answer faster.
generating an original candidate program based on an original specification; generating original candidate program results based on executing the original candidate program; based on the original candidate program results, determining that the original candidate program does not satisfy the original specification …
Translation: The system writes an initial piece of code, runs it, and checks if it fails to meet the requirements.
How the engine splits, salvages, and stitches programs back together
The patent describes a compositional program synthesis engine that sits on top of a large language model (an LLM, like the AI behind Copilot or ChatGPT). Its job is to turn a written specification (a description of what a program should do) into working code through a structured cycle of generate, test, repair.
Here is how the loop works:
- The LLM generates a first-pass candidate program from the specification.
- The engine runs that program against the requirements to see if it passes.
- If it fails, the engine extracts a segment of the original program (either the beginning, the end, or a distinct logical branch) that it judges to be correct.
- It asks the LLM to write only the missing or incorrect piece, called a subprogram.
- The engine combines the saved segment and the new subprogram using a composition operator (either sequential, meaning one runs after the other, or conditional, meaning an if-then-else branch) to form a new candidate program.
- The cycle repeats until the full program satisfies the specification.
The three decomposition strategies the engine supports are refining the suffix (fixing what comes at the end), refining the prefix (fixing what comes at the start), and splitting the program into separate cases with an if-then-else structure. Each strategy is a different way to decide what to save and what to rewrite, letting the engine pick the approach most likely to succeed for a given failure.
… addressing errors by systematically breaking down tasks, salvaging correct parts, and synthesizing subprograms that are integrated using composition operators until a program satisfies the given specification …
Translation: When errors happen, it keeps the parts that work, fixes the broken pieces, and glues them back together.
What this means for AI coding tools you might already use
For anyone using an AI coding assistant today, the experience of getting a broken answer and having to nudge the AI repeatedly is familiar. This patent is aimed squarely at that problem. By keeping the correct parts of a failed attempt rather than starting over, the system could cut the number of AI calls needed and, in practice, make the tool feel far less frustrating.
Microsoft's run of AI coding-tool filings points toward deeper integration of this kind of repair logic into products like GitHub Copilot. If this approach makes it into a shipping product, the change for you as a user would be less obvious rewriting of the same broken output and more reliable first-to-second-attempt improvement when the AI gets something wrong.
Microsoft's 23rd filing we've tracked since May in AI models working in teams follows earlier applications covering shared memory across models and teams that recruit missing agents.
The engine described here is pure software, a control layer that sits on top of an existing AI model with no new hardware required. A team that already has the underlying AI infrastructure in place has a plausible path to a working version without building anything from the ground up.
The harder question is reliability. Saving the correct parts of a broken program and fixing only what is broken, without accidentally damaging what already worked, is difficult to get right consistently at scale.
If it does work, users would never see this system by name. They would simply notice that the AI stopped making the same mistake twice.
There are more where this came from
We read every patent application Big Tech publishes and send you the ones worth knowing. Plain English, free, every week.
The drawings
11 drawing sheets from US 2026/0259708 A1 · click any drawing to enlarge
Want this weekly breakdown for a company we don't cover? Patentlyze Pro →