Autonomous, Multi-Threaded, Agentic Remediation System for Software Repositories
Engineered for Deterministic Execution, Codebase Self-Healing, and Principled AI Orchestration.
📹 90s Live Demo → Watch AutoPatch AI autonomously detect, patch, and validate a bug inside a zero-trust Docker sandbox — end to end.
AutoPatch AI is an autonomous, event-driven, sandboxed code-remediation agent built for mission-critical software pipelines. Designed for zero-trust execution environments, it dynamically analyzes codebases, reproduces bugs in isolated state-machines, and mathematically synthesizes unified diffs using an iterative LangGraph loop — prioritizing deterministic patching, host isolation, and robust asynchronous telemetry.
The culmination of deep research in multi-agent orchestration, ephemeral system sandboxing, and real-time state telemetry.
While the LLM generation is the brain, the true achievement of this system is its underlying distributed and isolated architecture:
network_disabled=True) containers for code execution, completely neutralizing the risk of LLM-generated malicious payloads escaping to the host.queue.Queue structures for O(1) concurrent ingestion of real-time LangGraph state deltas, decoupling the heavy inference loop from the FastAPI server.asyncio.CancelledError, sets a threading.Event(), and instantly cascades a SIGKILL to the underlying Docker subprocesses, preventing zombie resource leaks.AutoPatch AI is evaluated against a custom Micro-SWE-bench harness—a curated set of isolated Python repositories containing logic bugs, edge-case failures, and algorithmic faults. The system is evaluated strictly on Test-Driven Resolution (hidden unit tests going from Red to Green) within a hard-capped 3-attempt loop.
| Metric | Result | Notes |
|---|---|---|
| Total Benchmark Cases | 5 | Curated repositories covering distinct logic faults. |
| Resolution Rate | 100% (5/5) | Evaluated via deterministic pytest exit codes (0). |
| Avg. Time to Resolution | ~42 seconds | From ingestion to final validated patch. |
| Avg. Attempts Required | 1.0 | First-shot success driven by high-fidelity Search/Replace prompting. |
To prevent malicious code execution or fork-bombing from hallucinated LLM outputs, the Docker execution engine strictly enforces OS-level resource quotas:
0 Bytes (Custom bridge network is programmatically severed prior to execution).256 MB per container (Prevents memory-leak crashes).128 PIDs (Neutralizes recursive fork-bomb payloads).120s (Inner-container Linux timeout prevents infinite while True loops).By abandoning naive "Unified Git Diffs" and moving to a Search/Replace Block Architecture (similar to Aider), token bloat was drastically reduced:
<400 lines via AST-based lexical retrieval scoring.<SEARCH> and <REPLACE> blocks.difflib to auto-correct spatial path hallucinations with a 100% success rate before passing paths to the Docker execution layer.AutoPatch AI's decision engine is not a simple monolithic prompt. It employs a sophisticated four-stage "Remediation Funnel" to distill raw issues into mathematically sound, fully validated unified diffs.
Stage 1: CONTEXT INGESTION (The "Radar")
index_repo node scans the target directory, ignoring binary artifacts and node_modules, to construct a highly dense, token-optimized context map of the active codebase.Stage 2: DETERMINISTIC REPRODUCTION (The "Crucible")
pytest, npm test) inside the Hardened Sandbox. It captures stdout, stderr, and exit codes.Stage 3: SYNTHESIS & UNIFIED DIFFING (The "Scalpel")
patcher.py utility aggressively extracts JSON blocks from raw LLM output using Regex fallbacks, and attempts to apply the patch via raw git apply or full-file substitution.Stage 4: RECURSIVE VALIDATION (The "Judge")
0, the graph resolves to SUCCESS. If non-zero, it routes back to Stage 3, injecting the new error logs into the prompt for a "self-healing" loop (capped at N retries to prevent infinite loops).| Feature | Description | Advantage |
|---|---|---|
| 🛡️ Zero-Trust Sandboxing | Spawns ephemeral Docker containers with severed network interfaces per job. | Guarantees absolute host protection against rogue LLM code execution. |
| 🕸️ LangGraph Orchestration | Utilizes Directed Acyclic Graphs (DAGs) for iterative prompt loops. | Enables autonomous self-healing; the model learns from its own test failures. |
| ⚡ Asynchronous SSE Telemetry | Server-Sent Events pushed via lock-free thread queues. | Millisecond-latency real-time frontend updates without blocking the LLM inference loop. |
| 🧵 Thread-Safe Cancellation | Traps client disconnects and triggers threading.Event cascades. | Kills deep LLM inference and Docker subprocesses instantly, guaranteeing zero zombie resources. |
| 🧩 Multi-Modal Patching | Supports "Search and Replace" blocks, surgical unified diffs, and full-file replacement. | Ensures patches apply successfully on any model size (even 1.5B parameters) by avoiding aggressive truncation. |
| 🧪 Aggressive Output Parsing | Custom JSON decoders with Regex fallback blocks. | Neutralizes "chatty" LLM models that append conversational text to structured JSON responses. |
AutoPatch AI employs a Controller-Executor model, isolating the heavy LangGraph inference engine from time-sensitive API routing via thread-safe queues. This prevents analysis bottlenecks from impacting API reaction speed and enhances stability.
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#1f2023', 'primaryTextColor': '#f0f0f0', 'lineColor': '#a0a0a0', 'secondaryColor': '#2a2a2e'}, 'themeCSS': '.mermaid svg { max-width: 800px; margin: 0 auto; }'}}%%
graph TD
subgraph UI_Layer["Input & Perception"]
A["React / Vite Dashboard"] <-->|REST API & SSE Stream| B["FastAPI Server"]
end
subgraph Orchestration["Execution Management (Main Thread)"]
B -->|Spawns Daemon| C["Job Manager (Singleton)"]
C --> D{"Job Queue & Event Bus"}
D -.->|Real-Time Yields| B
end
subgraph Execution_Engine["Decision Engine (LangGraph Daemon)"]
C --> E["State Machine Initialization"]
E --> F["Repository Indexing"]
F --> G["Bug Reproduction"]
G --> H["Patch Generation (LLM)"]
H --> I["Recursive Validation"]
I -->|Failure Loop| H
end
subgraph Sandbox["Zero-Trust Sandbox (Docker)"]
G --> J["Ephemeral Container"]
I --> J
J -.->|stdout/stderr| D
end
%% Connections
I -->|Success| K["Graceful Teardown"]
C --> K
%% Styling
style A fill:#0077c8,stroke:#fff
style B fill:#3f51b5,stroke:#fff
style C fill:#fdd835,stroke:#333,color:#333
style D fill:#673ab7,stroke:#fff
style E fill:#009688,stroke:#fff
style F fill:#00bcd4,stroke:#fff
style H fill:#fb8c00,stroke:#fff
style I fill:#e65100,stroke:#fff,stroke-width:2px,color:#fff
style J fill:#f44336,stroke:#fff
style K fill:#9c27b0,stroke:#fff
Job Manager (The Maestro): Central coordinator, manages state, and spins up daemon threads for non-blocking execution.FastAPI Server (Nerves): Handles inbound REST requests and streams out continuous SSE telemetry.LangGraph Orchestrator (Brain): Executes the Remediation Funnel (Index → Reproduce → Patch → Validate).Patcher (Hands): Applies surgical unified diffs or full-file replacements to the active codebase.Docker Sandbox (Crucible): The isolated arena where untrusted code is compiled and tested.Cleanup Routines (Janitor): Guaranteed finally blocks that reap containers and drop network bridges.sse-starlettedocker python library)threading, queue, asyncioPrerequisites:
Clone & Setup:
git clone https://github.com/YOUR_USERNAME/autopatch-ai.git
cd autopatch-ai/backend
# Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate
# Install Python dependencies
pip install -r requirements.txt
Environment Configuration:
.env.example to .env in the backend directory.OLLAMA_BASE_URL or OPENAI_API_KEY).Running AutoPatch AI (Backend):
# Ensure virtual environment is active
source venv/bin/activate
python main.py
Running AutoPatch AI (Frontend):
cd ../frontend
npm install
npm run dev
This software executes dynamically generated code.
While AutoPatch AI runs its tests inside heavily restricted, network-disabled Docker containers, it modifies files on the host filesystem via volume mounts. You should ONLY run AutoPatch AI on Git repositories where all changes are committed, allowing you to easily git reset --hard if the LLM hallucination corrupts files.
The developers assume NO RESPONSIBILITY for unintended system modifications or data loss.
11 commits
6 commits
Python
71.6%
JavaScript
24.3%
CSS
3.6%
Autonomous, Multi-Threaded, Agentic Remediation System for Software Repositories
Engineered for Deterministic Execution, Codebase Self-Healing, and Principled AI Orchestration.
📹 90s Live Demo → Watch AutoPatch AI autonomously detect, patch, and validate a bug inside a zero-trust Docker sandbox — end to end.
AutoPatch AI is an autonomous, event-driven, sandboxed code-remediation agent built for mission-critical software pipelines. Designed for zero-trust execution environments, it dynamically analyzes codebases, reproduces bugs in isolated state-machines, and mathematically synthesizes unified diffs using an iterative LangGraph loop — prioritizing deterministic patching, host isolation, and robust asynchronous telemetry.
The culmination of deep research in multi-agent orchestration, ephemeral system sandboxing, and real-time state telemetry.
While the LLM generation is the brain, the true achievement of this system is its underlying distributed and isolated architecture:
network_disabled=True) containers for code execution, completely neutralizing the risk of LLM-generated malicious payloads escaping to the host.queue.Queue structures for O(1) concurrent ingestion of real-time LangGraph state deltas, decoupling the heavy inference loop from the FastAPI server.asyncio.CancelledError, sets a threading.Event(), and instantly cascades a SIGKILL to the underlying Docker subprocesses, preventing zombie resource leaks.AutoPatch AI is evaluated against a custom Micro-SWE-bench harness—a curated set of isolated Python repositories containing logic bugs, edge-case failures, and algorithmic faults. The system is evaluated strictly on Test-Driven Resolution (hidden unit tests going from Red to Green) within a hard-capped 3-attempt loop.
| Metric | Result | Notes |
|---|---|---|
| Total Benchmark Cases | 5 | Curated repositories covering distinct logic faults. |
| Resolution Rate | 100% (5/5) | Evaluated via deterministic pytest exit codes (0). |
| Avg. Time to Resolution | ~42 seconds | From ingestion to final validated patch. |
| Avg. Attempts Required | 1.0 | First-shot success driven by high-fidelity Search/Replace prompting. |
To prevent malicious code execution or fork-bombing from hallucinated LLM outputs, the Docker execution engine strictly enforces OS-level resource quotas:
0 Bytes (Custom bridge network is programmatically severed prior to execution).256 MB per container (Prevents memory-leak crashes).128 PIDs (Neutralizes recursive fork-bomb payloads).120s (Inner-container Linux timeout prevents infinite while True loops).By abandoning naive "Unified Git Diffs" and moving to a Search/Replace Block Architecture (similar to Aider), token bloat was drastically reduced:
<400 lines via AST-based lexical retrieval scoring.<SEARCH> and <REPLACE> blocks.difflib to auto-correct spatial path hallucinations with a 100% success rate before passing paths to the Docker execution layer.AutoPatch AI's decision engine is not a simple monolithic prompt. It employs a sophisticated four-stage "Remediation Funnel" to distill raw issues into mathematically sound, fully validated unified diffs.
Stage 1: CONTEXT INGESTION (The "Radar")
index_repo node scans the target directory, ignoring binary artifacts and node_modules, to construct a highly dense, token-optimized context map of the active codebase.Stage 2: DETERMINISTIC REPRODUCTION (The "Crucible")
pytest, npm test) inside the Hardened Sandbox. It captures stdout, stderr, and exit codes.Stage 3: SYNTHESIS & UNIFIED DIFFING (The "Scalpel")
patcher.py utility aggressively extracts JSON blocks from raw LLM output using Regex fallbacks, and attempts to apply the patch via raw git apply or full-file substitution.Stage 4: RECURSIVE VALIDATION (The "Judge")
0, the graph resolves to SUCCESS. If non-zero, it routes back to Stage 3, injecting the new error logs into the prompt for a "self-healing" loop (capped at N retries to prevent infinite loops).| Feature | Description | Advantage |
|---|---|---|
| 🛡️ Zero-Trust Sandboxing | Spawns ephemeral Docker containers with severed network interfaces per job. | Guarantees absolute host protection against rogue LLM code execution. |
| 🕸️ LangGraph Orchestration | Utilizes Directed Acyclic Graphs (DAGs) for iterative prompt loops. | Enables autonomous self-healing; the model learns from its own test failures. |
| ⚡ Asynchronous SSE Telemetry | Server-Sent Events pushed via lock-free thread queues. | Millisecond-latency real-time frontend updates without blocking the LLM inference loop. |
| 🧵 Thread-Safe Cancellation | Traps client disconnects and triggers threading.Event cascades. | Kills deep LLM inference and Docker subprocesses instantly, guaranteeing zero zombie resources. |
| 🧩 Multi-Modal Patching | Supports "Search and Replace" blocks, surgical unified diffs, and full-file replacement. | Ensures patches apply successfully on any model size (even 1.5B parameters) by avoiding aggressive truncation. |
| 🧪 Aggressive Output Parsing | Custom JSON decoders with Regex fallback blocks. | Neutralizes "chatty" LLM models that append conversational text to structured JSON responses. |
AutoPatch AI employs a Controller-Executor model, isolating the heavy LangGraph inference engine from time-sensitive API routing via thread-safe queues. This prevents analysis bottlenecks from impacting API reaction speed and enhances stability.
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#1f2023', 'primaryTextColor': '#f0f0f0', 'lineColor': '#a0a0a0', 'secondaryColor': '#2a2a2e'}, 'themeCSS': '.mermaid svg { max-width: 800px; margin: 0 auto; }'}}%%
graph TD
subgraph UI_Layer["Input & Perception"]
A["React / Vite Dashboard"] <-->|REST API & SSE Stream| B["FastAPI Server"]
end
subgraph Orchestration["Execution Management (Main Thread)"]
B -->|Spawns Daemon| C["Job Manager (Singleton)"]
C --> D{"Job Queue & Event Bus"}
D -.->|Real-Time Yields| B
end
subgraph Execution_Engine["Decision Engine (LangGraph Daemon)"]
C --> E["State Machine Initialization"]
E --> F["Repository Indexing"]
F --> G["Bug Reproduction"]
G --> H["Patch Generation (LLM)"]
H --> I["Recursive Validation"]
I -->|Failure Loop| H
end
subgraph Sandbox["Zero-Trust Sandbox (Docker)"]
G --> J["Ephemeral Container"]
I --> J
J -.->|stdout/stderr| D
end
%% Connections
I -->|Success| K["Graceful Teardown"]
C --> K
%% Styling
style A fill:#0077c8,stroke:#fff
style B fill:#3f51b5,stroke:#fff
style C fill:#fdd835,stroke:#333,color:#333
style D fill:#673ab7,stroke:#fff
style E fill:#009688,stroke:#fff
style F fill:#00bcd4,stroke:#fff
style H fill:#fb8c00,stroke:#fff
style I fill:#e65100,stroke:#fff,stroke-width:2px,color:#fff
style J fill:#f44336,stroke:#fff
style K fill:#9c27b0,stroke:#fff
Job Manager (The Maestro): Central coordinator, manages state, and spins up daemon threads for non-blocking execution.FastAPI Server (Nerves): Handles inbound REST requests and streams out continuous SSE telemetry.LangGraph Orchestrator (Brain): Executes the Remediation Funnel (Index → Reproduce → Patch → Validate).Patcher (Hands): Applies surgical unified diffs or full-file replacements to the active codebase.Docker Sandbox (Crucible): The isolated arena where untrusted code is compiled and tested.Cleanup Routines (Janitor): Guaranteed finally blocks that reap containers and drop network bridges.sse-starlettedocker python library)threading, queue, asyncioPrerequisites:
Clone & Setup:
git clone https://github.com/YOUR_USERNAME/autopatch-ai.git
cd autopatch-ai/backend
# Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate
# Install Python dependencies
pip install -r requirements.txt
Environment Configuration:
.env.example to .env in the backend directory.OLLAMA_BASE_URL or OPENAI_API_KEY).Running AutoPatch AI (Backend):
# Ensure virtual environment is active
source venv/bin/activate
python main.py
Running AutoPatch AI (Frontend):
cd ../frontend
npm install
npm run dev
This software executes dynamically generated code.
While AutoPatch AI runs its tests inside heavily restricted, network-disabled Docker containers, it modifies files on the host filesystem via volume mounts. You should ONLY run AutoPatch AI on Git repositories where all changes are committed, allowing you to easily git reset --hard if the LLM hallucination corrupts files.
The developers assume NO RESPONSIBILITY for unintended system modifications or data loss.
11 commits
6 commits
Python
71.6%
JavaScript
24.3%
CSS
3.6%