As a developer, there are few things more anxiety-inducing than the Slack notification sound at 3:00 AM: "Production is down."
You groggily open your laptop, pull up the server logs, trace the exception through 5 different files, fix a missing try/catch block, push the hotfix, and try to go back to sleep.
I got tired of this. As an engineer obsessed with automation, I decided to build something that solves the problem for me. Enter AutoFixer-Agent.
What is AutoFixer?
AutoFixer is an autonomous AI agent (built with Python) that watches your production server logs in real-time. When it detects a crash or an exception, it doesn't just alert you β it investigates the stack trace, finds the exact bug in your codebase, generates a contextual fix using LLMs, and automatically opens a Pull Request on GitHub.
You wake up to a PR waiting for review, not a broken production environment. β
How it Works Under the Hood π οΈ
The architecture is surprisingly simple but immensely powerful:
-
The Log Watcher: A background Python daemon constantly tails your
error.log. - The Brain (LLM Orchestration): When an exception is thrown, the agent captures the stack trace and uses the Google Gemini API to analyze the root cause. It maps the error back to the specific line of code in the repository.
- The Fixer: The agent generates a drop-in replacement block of code.
-
The GitHub Bot: Using GitHub Actions and the GitHub CLI, the agent branches off
main, applies the fix locally, runs sanity checks, and pushes a new Pull Request with a detailed explanation of the bug.
The "Aha!" Moment π‘
The hardest part wasn't generating the code β LLMs are great at that now. The hardest part was building the context window.
If a generic KeyError happens, the LLM needs to know what dictionary it came from. A naked stack trace is not enough.
python
# Bad prompt (hallucination-prone):
"Fix this error: KeyError: 'user_id'"
# Good prompt (context-aware):
"Fix this error: KeyError: 'user_id'
Surrounding code (lines 45-95 of auth/handler.py):
...
def process_request(payload):
user = payload['user_id'] # <-- line 52
..."
To solve this, AutoFixer dynamically pulls in the surrounding **50 lines of code** from the file mentioned in the stack trace before sending the prompt to the AI. This gives the model enough context to write a *safe*, production-ready fix rather than a hallucinated one.
## Why This Matters
We are moving from **"AI as a pair programmer"** (GitHub Copilot) to **"AI as a DevOps team member."**
Tools like AutoFixer prove that we can delegate tedious, high-stress tasks β like 3 AM hotfixes β to autonomous systems that handle the boring parts while we sleep.
## Try it Out!
I've open-sourced the entire project! You can clone it, simulate a crash in your local logs, and watch it generate a GitHub PR in real time.
π **GitHub:** [turfin-logic/autofixer-agent](https://github.com/turfin-logic/autofixer-agent)
If you're into automation, DevSecOps, or AI agents β drop a β on the repo or contribute. Let's automate the boring (and stressful) stuff together. πͺ
Top comments (0)