Inspiration

We’ve all been there: you push what should be a straightforward feature on a Friday afternoon, close your laptop, and ten minutes later your phone buzzes with a bright red GitHub Actions failure.

When you dig into the runner logs, nine times out of ten it isn't an architectural disaster. It's a missing import, an outdated mock fixture, a subtle typing mismatch, or a silly syntax typo. Fixing it takes all of two minutes, but context-switching, downloading megabytes of raw terminal logs, finding the culprit line, and pushing a new branch takes twenty.

We asked ourselves a simple question: why are engineers manually babysitting deterministic CI failures that a smart agent could diagnose and patch before anyone even opens the repository? That question sparked AutoPatch.


What it does

AutoPatch works like an autonomous on-call engineer dedicated strictly to your CI/CD pipelines.

  1. Catches Failures Instantly: The moment a GitHub Actions workflow or check-run fails, AutoPatch receives a webhook event.
  2. Isolates the Signal from the Noise: It downloads the raw runner output, strips away thousands of lines of environment setup boilerplate and ANSI color codes, and isolates the exact fatal error trace.
  3. Performs Root Cause Analysis: Using Google Gemini, it determines the failure category (unit test crash, missing dependency, syntax bug, lint violation) and pinpoints the suspect files in the repository.
  4. Synthesizes Surgical Patches: It pulls the affected source files via the GitHub API and generates clean, minimal code diffs that fix the bug without touching unrelated logic.
  5. Opens a Ready-to-Merge PR: It branches off the broken commit, applies the fix, and opens a GitHub Pull Request complete with an executive summary, confidence score, and clear diff explanation for the team to review.
  6. Live Incident Dashboard: Developers can track pipeline health, inspect live RCA diagnostics, review diff histories, and configure automated remediation rules through a clean web dashboard.

How we built it

We built AutoPatch with a microservices-inspired architecture designed for serverless reliability on Google Cloud Platform:

  • Backend & API: Built with Python and FastAPI, handling webhook ingestion, GitHub App authentication, and job orchestration.
  • AI Core: Powered by the Google GenAI SDK (Gemini). We structured root cause diagnostics and patch synthesis with strict Pydantic schemas to enforce structured outputs.
  • GCP Infrastructure:
    • Google Cloud Run: Hosts our containerized FastAPI backend with auto-scaling to handle sudden spikes in CI webhook traffic.
    • Google Cloud Tasks: Offloads heavy diagnostic and patching jobs into asynchronous background queues, keeping webhook response times well under GitHub's 10-second timeout threshold.
    • Google Cloud Firestore (Native Mode): Stores incident logs, repository states, and user preferences with composite indexing for real-time querying.
    • Google Cloud Storage (GCS): Archives heavy raw terminal log dumps for auditing.
  • Frontend: A responsive single-page application built with React, TypeScript, and Tailwind CSS, providing real-time visibility into active incidents and generated patches.

Challenges we ran into

  • Wrangling Giant, Messy CI Logs: CI logs are notoriously noisy. A single failing test suite can generate 15,000 lines of terminal output loaded with npm install steps and ANSI color escapes. Passing that raw dump to an LLM wastes tokens and confuses the model. We had to write dedicated log extractors and regex parsers to cleanly isolate the stack trace and fatal frames before prompting.
  • LLM Code Formatting Quirks: When an LLM outputs raw code patches inside structured JSON, unescaped double quotes, raw backslashes, and multiline strings often break standard json.loads(). To solve this, we engineered a multi-pass repair engine in our agent that combines regex fence stripping, slice extraction, and ast.literal_eval fallbacks so the pipeline never crashes on malformed JSON.
  • GitHub Webhook Timeouts: GitHub drops webhook deliveries if the server doesn't respond within 10 seconds. Deep log analysis and code generation can take 15 to 25 seconds. We decoupled the architecture so the primary endpoint immediately returns 202 Accepted and offloads the workload to Google Cloud Tasks.

Accomplishments that we're proud of

  • True Zero-Touch Remediation: Seeing a broken unit test in a sample repo trigger our webhook, produce a targeted 3-line patch, and open a functional GitHub PR within 25 seconds without touching a single key.
  • High-Precision Diffs: The agent reliably writes surgical, minimal patches rather than hallucinating new dependencies or rewriting whole files.
  • Resilient Production Pipeline: Building an end-to-end cloud-native system on GCP that gracefully handles scale-to-zero, async task execution, and automated fallback parsing.

What we learned

  • Context Filtering Trumps Prompt Complexity: Feeding a model 40 lines of carefully isolated stack trace produces vastly better code fixes than feeding it 4,000 lines of raw terminal logs with a complex prompt.
  • Developer Trust is Everything: Developers don't want AI blindly pushing commits to main. Creating descriptive, human-readable draft PRs with clear explanations makes automated remediation safe and practical for real engineering teams.
  • Cloud Tasks & Cloud Run Synergy: Using Cloud Tasks alongside Cloud Run allowed us to build an enterprise-ready async worker system without maintaining dedicated background worker servers.

What's next for AutoPatch

  • Ephemeral Sandbox Pre-Validation: Spinning up temporary Docker containers to run tests against the generated patch locally before ever opening the GitHub PR, guaranteeing that the fix actually passes CI.
  • Multi-Platform Support: Expanding integrations beyond GitHub Actions to support GitLab CI, Bitbucket Pipelines, and CircleCI.
  • Monorepo & Multi-File Dependency Graphing: Incorporating AST-based dependency graph lookups so the agent can trace broken imports across large monorepos (Nx / Turborepo).
  • Slack & Discord Bot Integrations: Allowing engineering teams to approve, test, and merge AutoPatch fixes directly from their team chat channels with a single button click.

Built With

Share this project:

Updates

Submission history