mathewboswell.com — safe-llm-assisted-patch-automation-workflow.md
guest@mathewboswell:~$ cat safe-llm-assisted-patch-automation-workflow.md

Building a Safe LLM-Assisted Patch Automation Workflow

2025-01-28 · # security # automation # llms # devops

Patch automation is not new. Dependabot and Renovate have opened dependency pull requests for years. What LLMs add is help with the parts those tools don't handle well: reading release notes, adjusting code for small breaking changes, and explaining the change to reviewers.

That help is valuable. It also introduces a new kind of risk: a system that writes code changes based on text it has read. The workflow around it needs to assume the model will sometimes be wrong.

Principle: the model proposes, the pipeline disposes

Everything below follows from one rule. The LLM can propose changes. It doesn't merge them, deploy them, or bypass checks. Execution belongs to a deterministic pipeline with defined gates.

Stage 1: Trigger

A patch workflow starts from a trusted signal: a scanner finding, a security advisory matched against your SBOM, or a dependency bot's update.

The trigger should include the vulnerability ID, affected component, current version, and candidate fixed version from authoritative data. The model shouldn't be choosing the target version from memory.

Stage 2: Branch and change

The automation creates a branch and applies the version bump using the ecosystem's normal tooling, such as the package manager or image build. Lockfiles update the standard way.

If the build or tests fail, the LLM can help. Give it the failing output, the relevant release notes, and the affected source files. Ask for a minimal diff to restore compatibility. Keep the scope tight: changes outside the files involved in the failure should be rejected.

Stage 3: Pull request

Every change goes through a pull request. The LLM drafts the description:

  • What vulnerability is addressed and why it matters here
  • What changed, including any code modifications beyond the version bump
  • Notable items from the changelog
  • Risk assessment and suggested rollback

Reviewers should be able to understand the change without opening five other tabs.

Stage 4: Automated checks

The PR runs the same checks as any other change, plus a few specific to security patches:

  • Build and full test suite
  • SCA scan confirming the vulnerability is resolved and no new ones are introduced
  • SAST on modified code
  • Container image scan if an image is rebuilt
  • Policy checks, such as allowed licenses, approved registries, and signed artifacts

A patch that resolves one CVE and introduces another isn't a fix.

Stage 5: Approval gates

Not every patch needs the same scrutiny. Define tiers in policy:

  • Auto-merge eligible: patch-level version bumps, no code changes, all checks green, non-critical service
  • Single reviewer: minor-version bumps or small LLM-authored code adjustments
  • Owner and security review: major-version upgrades, changes to authentication or cryptography code, critical services

The tier should be calculated from the diff and service metadata, not chosen by the model.

Stage 6: Progressive rollout

Merging isn't the finish line. Deploy the way you deploy anything risky:

  • Release to a canary or a small percentage of traffic first
  • Watch error rates, latency, and saturation against a baseline
  • Expand in stages if health checks pass
  • Halt automatically if they don't

For infrastructure and endpoints, the equivalent is rings: a pilot group, then broader groups, with time to observe between them.

Stage 7: Rollback

Design rollback before the first automated deploy. It might be reverting the commit and redeploying, shifting traffic back to the previous version, or restoring a prior image tag.

Test it. A rollback path that has never been exercised is a hypothesis.

Stage 8: Verify and record

After rollout, confirm the fix in the running environment with a rescan or runtime inventory check. Then close the finding and record:

  • The triggering evidence
  • The model's proposed changes and the final diff
  • Check results and approvers
  • Deployment and verification outcomes

That audit trail makes it possible to answer, months later, why a change happened and who agreed to it.

Security of the workflow itself

The automation has access to source code and CI. Protect it accordingly.

  • Use least-privilege tokens: create branches and PRs, not push to main.
  • Treat advisory text, changelogs, and repository content as untrusted input that can't alter policy.
  • Pin the actions and tools the workflow uses.
  • Alert on unusual behavior, such as PRs touching unexpected files.

Start small

Begin with direct dependencies in a few well-tested repositories, with auto-merge disabled. Measure merge rate, time to remediation, and failed deploys. Enable auto-merge for the lowest tier only once the data supports it.

guest@mathewboswell:~$ cd /posts
guest@mathewboswell:/posts/safe-llm-assisted-patch-automation-workflow2026 — System 1.0