MSBA-361 · Lesson 4 of 12 · 18 min
Copilot Autofix
▶ Video coming soon A video version of this lesson is on the way.
The commerce group's 1,180 open alerts had produced a predictable reaction. Developers agreed that the alerts mattered, agreed that they could not stop feature work to fix them, and wanted to know whether anything could help. Seraphine's answer for the fourth session was Copilot Autofix, and her first slide was a warning about expectations rather than a demonstration: Autofix suggests fixes; it does not take responsibility for them.
What Copilot Autofix does
Copilot Autofix is a feature of code scanning that uses a large language model to suggest a code change that fixes an alert. It combines the alert's details, including the rule, the location and the data flow path, with the surrounding code, and produces a suggested patch with an explanation of what the change does and why it should resolve the problem.
Autofix appears in two places. In a pull request, when code scanning finds a new alert in the change, Autofix can generate a suggestion that appears alongside the alert annotation, and the author can commit it directly or edit it first. On an existing alert on the default branch, the alert page offers a button to generate a fix, and the suggestion can be turned into a pull request.
Two details shape how organizations use it. First, Autofix is enabled by default for repositories that use CodeQL, under either default or advanced setup, unless an administrator turns it off. Second, administrators can disable it at enterprise, organization or repository level, and a setting made higher up stops lower levels from re-enabling it.
| Question | Answer |
|---|---|
| Which repositories can use it? | Public repositories on GitHub.com, and private or internal repositories with a GitHub Code Security (or Advanced Security) license |
| Does each developer need a Copilot license? | No; Autofix for code scanning is part of Code Security, not a Copilot seat feature |
| Does generating a suggestion consume AI credits? | No, according to GitHub's current documentation; agentic autofix, below, does |
| Which tools' alerts does it fix? | CodeQL alerts, and since late 2024 alerts from some partner tools |
| Where is it switched off? | Code security settings at enterprise, organization or repository level |
What a suggestion looks like
Seraphine generated a fix live for one of the commerce group's SQL injection alerts in a reporting service. Autofix proposed replacing a query built by joining strings with a parameterized query, adjusting the call so the value was passed as a parameter, and explaining that this kept user input out of the SQL text. It changed four lines in one file.
- const sql = `SELECT sku, qty FROM stock WHERE store_id = ${storeId} AND sku LIKE '${prefix}%'`;
- return db.query(sql);
+ const sql = "SELECT sku, qty FROM stock WHERE store_id = ? AND sku LIKE ?";
+ return db.query(sql, [storeId, `${prefix}%`]);It looked right, and it was close to right. Teodric pointed out that the reporting service's database library expected named parameters rather than question marks in this module, because of a wrapper his team had written. The suggestion would have failed at run time. He edited it, ran the tests, and committed. Seraphine said that was the whole lesson: the suggestion saved most of the work, and a developer who knew the code finished it.
Using Autofix responsibly
GitHub's own guidance on responsible use of Autofix makes several points, and Skerry adopted them as rules.
| Risk | Why it happens | What to do |
|---|---|---|
| The fix is incorrect | The model can misunderstand the code or the library | Review every suggestion as you would a colleague's pull request |
| The fix changes behavior | Making code safe can reject inputs that used to be accepted | Run the tests and check edge cases |
| The fix is partial | A suggestion may address one path but not others | Let code scanning run again and confirm the alert closes |
| The fix adds a dependency | Some suggestions use a library for escaping or validation | Check the dependency is approved and passes dependency review |
| The fix touches other files | Suggestions can edit more than the alert's file | Read the whole diff, not just the highlighted line |
The most important rule was that Autofix does not change the review process. A pull request containing an Autofix suggestion still needs its usual reviews and checks. In repositories governed by the Confidential code ruleset from MSBA-291, that meant two approvals and passing builds, whether or not a model had written some of the code.
Freya also asked teams not to use the explanation as a substitute for understanding. The explanation is useful for a reviewer, but the developer accepting the change should be able to say in their own words why it fixes the problem.
Agentic autofix
In July 2026 GitHub released a preview of agentic autofix, and it became generally available on October 15, 2026. Where Copilot Autofix suggests a single change for one alert, agentic autofix works more like a developer handed a task. It explores the relevant files, proposes a fix, runs CodeQL again to check that the alert is resolved, and opens a draft pull request with a summary, its reasoning and the validation it performed. Reviewers can ask for further changes by commenting on the pull request.
| Copilot Autofix | Agentic autofix | |
|---|---|---|
| How you start it | Generate a fix on an alert, or automatically in a pull request | Assign the alert to Copilot |
| What it produces | One suggested change for one alert | A draft pull request, which can cover up to 25 alerts selected together |
| Validation | You let code scanning run after committing | It reruns CodeQL itself before opening the pull request |
| Which alerts | Pull request alerts and existing alerts | Alerts on the default branch only |
| Cost | No AI credits for suggestions | AI credits from the Code Security budget plus Actions minutes |
| Availability | Public repositories and Code Security licenses | Code Security or Advanced Security customers on Enterprise Cloud, including data residency |
| Enablement | On by default with CodeQL | Enterprise policy, then organization or repository setting, plus a Copilot billing method |
When agentic autofix is enabled, the alert page's option to generate a single fix is replaced by an option to assign the alert to Copilot. Usage appears in enterprise billing under the Advanced Security product, and enterprises can set budgets for Code Security AI credits so that a burst of assignments does not produce a surprise bill.
Skerry's enterprise owners turned on the agentic autofix policy on November 12, 2026, but enabled it only in skerry-sandbox as a pilot. Lorcan Adeyemi-Brooke, the finance partner, set a monthly budget for the AI credits. The pilot's first test was a batch of 25 medium-severity alerts of one rule in a sandbox copy of an internal tool. Copilot opened one draft pull request that fixed 22 of them, explained why it had not changed the other three (they were in code that built SQL from constants only), and listed the CodeQL run it had used to check its work. Reviewers still requested two changes before approving.
Autofix in pull requests
The most valuable use of Autofix, Seraphine argued, was not the backlog but new code. When a developer opens a pull request that introduces an alert, a suggested fix in the same pull request is the cheapest possible remediation: the developer is already in the code, the context is fresh, and the fix lands before the problem ever reaches the default branch.
Skerry's data showed this. In the first three weeks of November, pull requests in in-scope repositories introduced 640 new CodeQL alerts. Autofix produced a suggestion for most of them. About half of all the new alerts were fixed in the same pull request by committing a suggestion, often edited; another quarter were fixed by hand; the rest were either dismissed with a reason or merged to be handled later, which the merge ruleset in lesson 11 was about to restrict.
When to turn Autofix off
There are reasons an organization might disable Autofix for some repositories. Some teams work under contracts or regulations that restrict sending code to AI services, even within GitHub. Some repositories contain code where any change needs a formal review by a separate group, so suggestions in pull requests create noise without saving time. Skerry kept Autofix on everywhere except for the 18 store terminal firmware repositories, where the payment terminal certification process required every change to be traced to an approved design document. For those, suggestions were still useful as hints, so the firmware lead, Anselm Okonkwo-Fairley, asked for Autofix to stay on in a sandbox fork where engineers could look at suggestions without them appearing in the certified repositories' pull requests.
Worked problem
Reviewing a suggestion
Autofix suggests fixing a path traversal alert by adding a check that rejects file names containing two dots, and changes one line. The alert is in an export job that writes files named after store codes. Is the suggestion enough?
Show solution
- Check what values are legitimate: store codes are letters and digits only.
- Notice that rejecting two dots does not stop absolute paths or other separators.
- Prefer an allow list that accepts only the legitimate pattern, and resolve the final path and confirm it is inside the export directory.
- Edit the suggestion accordingly, run tests and let code scanning confirm.
Answer: Not on its own. Replace the deny check with an allow list for store codes and confirm the resolved path stays in the export directory, then let code scanning confirm the alert closes.
Where Autofix struggles
Autofix works best on alerts with a well-known fix pattern in a single file: an unparameterized query, missing output encoding, an unsafe file path. It works less well in three situations, and developers at Skerry learned to recognize them quickly.
| Situation | What happens | What to do |
|---|---|---|
| The fix belongs in another file or a shared helper | The suggestion fixes the symptom locally | Use the suggestion as a hint and make the change where the shared cause is |
| The fix needs a new dependency | The suggestion may add one | Check the dependency through dependency review and the team's approved list |
| The alert is a false positive | Autofix may still propose a change | Dismiss with a reason instead of merging an unnecessary change |
| Large or unusual code | No suggestion, or a partial one | Fix by hand; not every alert gets a suggestion |
The first situation was the most common. In the commerce code, Autofix often suggested parameterizing a query directly, when the team's standard was to call the shared query helper. Teodric's habit was to accept the idea of the suggestion and rewrite it to use the helper. The commerce team later added repository instructions for Copilot that described the helper, as lesson 11 explains.
What the November numbers showed
Seraphine looked at November's 640 new alerts in pull requests to see whether Autofix was helping or merely producing changes. About half were fixed by committing an Autofix suggestion, often after editing it; about a quarter were fixed by hand; and the rest were dismissed with a reason or left for later. In a sample of 40 Autofix commits, she found three that fixed the alert but not a second path with the same problem nearby, which CodeQL then reported as a new alert on the next analysis. Her conclusion for the champions was simple: Autofix speeds up the common case, and the reviewer's job is to look for the uncommon one.
Common mistakes
MistakeCommitting Autofix suggestions without review or tests.
InsteadTreat suggestions like any colleague's code: read the whole diff, run tests and keep normal reviews.
MistakeAssuming a Copilot license is needed for every developer.
InsteadAutofix for code scanning comes with Code Security or public repositories.
MistakeTurning on agentic autofix everywhere without a budget.
InsteadPilot it, and set a budget for Code Security AI credits.
MistakeUsing Autofix only on the old backlog.
InsteadIts biggest value is fixing new alerts in the pull request that introduced them.
Summary and key terms
- Copilot Autofix uses an AI model and the alert's details to suggest a fix with an explanation.
- It appears in pull requests and on existing alerts, and is on by default for CodeQL repositories.
- It is available for public repositories and with Code Security, without a Copilot license per developer.
- Suggestions can be wrong, partial or change behavior, so review and testing remain essential.
- Agentic autofix, generally available since October 15, 2026, opens validated draft pull requests for up to 25 default-branch alerts at a time.
- Agentic autofix needs an enterprise policy and a Copilot billing method, and consumes AI credits and Actions minutes.
- Fixing alerts in the pull request that introduced them is the cheapest remediation of all.
- Copilot Autofix
- A code scanning feature that suggests code changes to fix alerts, with an explanation.
- Agentic autofix
- A feature that assigns default-branch alerts to Copilot, which explores the code, validates a fix with CodeQL and opens a draft pull request.
- Suggested fix
- A proposed patch that a developer can commit, edit or reject.
- AI credits
- The usage unit billed for agentic autofix and other metered AI features.
- Responsible use
- GitHub's guidance on the limits of AI-generated fixes and the review they need.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Where does Copilot Autofix show suggestions?
Show answer
In pull requests for newly introduced alerts, and on existing alerts through the option to generate a fix.
What three things must be in place to use agentic autofix?
Show answer
The enterprise policy, the organization or repository setting, and a Copilot billing method.
Why is a pull request the best place to fix a new alert?
Show answer
The developer is already in the code, and the problem never reaches the default branch.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.