SpecFix โ Speculative Sandbox Framework Using State-Graph Rollback Checkpoints for Automated Code Repair
Autonomous AI Bug Repair with a 0% Production Regression Guarantee. Every proposed patch is executed inside an isolated speculative sandbox and verified against test suites before committing. Failed patches trigger automatic Git rollbacks and feed detailed error diagnostics back into subsequent AI retry attempts.
๐ Executive Overview
Software engineering teams spend 30โ50% of their time on manual bug triage and repair. While modern Large Language Models (LLMs) can generate code fixes, applying AI-generated patches directly to software repositories introduces significant risk: hallucinated code, broken syntax, or unexpected side-effects can corrupt production codebases.
SpecFix eliminates this risk by introducing a Speculative Sandbox Framework:
- Speculative Execution: No AI patch is ever committed directly. Every fix is treated as an unverified speculation.
- Git Rollback Checkpoints: Before applying a patch, SpecFix tags a rollback checkpoint (
git tag). If verification fails, the repository is instantly reset (git reset --hard&git clean -fdx). - Automated Verification: Patches are tested in an isolated sandbox running the target project's automated test suite (
pytest). - Self-Correction Retry Loop: Test failure outputs (
stderr) are captured and injected into retry prompts, enabling AI models to self-correct patch alignment or syntax errors on subsequent attempts. - State-Graph Audit DAG: Every attemptโsuccessful or failedโis stored as a node in a SQLite-backed Directed Acyclic Graph (DAG), providing full operational auditability.
- Tiered Model Routing: Simple bugs are routed to lightweight Tier 1 SLMs (e.g., NVIDIA Qwen 2.5 Coder 32B), while complex multi-file bugs escalate to Tier 2 Cloud LLMs (e.g., Google Gemini 2.5 Flash), optimizing latency and API compute cost.
๐๏ธ System Architecture
SYSTEM PIPELINE ARCHITECTURE
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ Bug Report & โโโโโโถโ Intake Gateway โโโโโโถโ YAGNI Discipline โโโโโโถโ Complexity โ
โ Target Repo โ โ [intake.py] โ โ Gate [yagni.py] โ โ Analyzer โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ [complexity.py] โ
โโโโโโโโโโฌโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ State Graph โโโโโโโ Verifier โโโโโโโ Sandbox Execution โโโโโโโโโโโโโโโโดโโโโโโโโโโโ
โ Audit DAG โ โ (pytest) โ โ Timeout Protection โ โ
โ [state_graph.py] โ [verifier.py] โ โ [sandbox.py] โ โผ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโฌโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ โฒ โ Tiered LLM Routerโ
โ (Verification Fail) โ (Apply Patch) โ [router.py] โ
โผ โ โโโโโโโโโโฌโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโ โ
โ Checkpoint Rollback & Retry Loop โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ [checkpoint.py] โ (Tier 1: NVIDIA Qwen /
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Tier 2: Google Gemini)
โจ Key Features
- ๐ก๏ธ Zero-Commit Guarantee: Zero broken or unverified code reaches production branches.
- ๐ Automatic Rollback & Recovery: Clean Git reset mechanics restore pristine repository state on test failure.
- ๐ฏ YAGNI Prompt Discipline: Constrains LLMs to produce minimal, surgical unified diffs without unnecessary refactoring.
- ๐ฉน Robust Diff Normalization: Intelligently handles bare diff hunks, missing line counts, and hunk header formatting variations.
- ๐ง Deterministic Complexity Analyzer: Scores bugs based on stack depth, file counts, and concurrency keywords to determine routing tier.
- โก Tiered LLM Routing:
- Tier 1 (Local / Hosted SLM): NVIDIA Qwen 2.5 Coder 32B Instruct via NVIDIA API.
- Tier 2 (Cloud LLM): Google Gemini 2.5 Flash API.
- Offline Mock Fallback: Automatic fallback to deterministic
MockModelProviderwhen API keys are not set.
- ๐ SQLite State-Graph Audit DAG: Comprehensive attempt tracing with parent-child retry relationships, exit codes, stderr feedback, and generated diffs.
- ๐ป React + TypeScript Web Dashboard: Modern dark-mode web application featuring an Interactive Repair Workbench, Benchmark Evaluation Matrix, and State-Graph DAG Visualizer.
โก Quick Start
Prerequisites
- Python: 3.11 or higher
- Git: Installed and accessible in environment PATH
- Node.js: v18+ (Required only for running the Web Dashboard UI)
1. Installation
Install SpecFix from PyPI / local package wheel:
pip install specfix
For development or contributing:
# Clone repository
git clone https://github.com/your-username/SpecFix.git
cd SpecFix
# Create & activate virtual environment
python -m venv .venv
.\.venv\Scripts\activate # Windows PowerShell
# source .venv/bin/activate # Linux / macOS
# Install package in editable mode with dev dependencies
pip install -e ".[dev]"
2. Verify Installation
Run the automated unit test suite to confirm everything is set up correctly (no API keys required):
pytest
๐๏ธ Model Provider Configuration
SpecFix supports real AI model repair using Tier 1 (NVIDIA Qwen) and Tier 2 (Google Gemini) providers. Configure environment variables to enable real LLM execution:
Windows PowerShell
# Tier 1 Provider (NVIDIA Qwen API)
$env:NVIDIA_API_KEY="nvapi-your-key-here"
$env:NVIDIA_MODEL="nvidia/qwen-2.5-coder-32b-instruct" # Optional default
$env:NVIDIA_BASE_URL="https://integrate.api.nvidia.com/v1" # Optional default
# Tier 2 Provider (Google Gemini API)
$env:GEMINI_API_KEY="AIzaSy-your-key-here"
$env:GEMINI_MODEL="gemini-2.5-flash" # Optional default
Linux / macOS Bash
# Tier 1 Provider (NVIDIA Qwen API)
export NVIDIA_API_KEY="nvapi-your-key-here"
export NVIDIA_MODEL="nvidia/qwen-2.5-coder-32b-instruct"
# Tier 2 Provider (Google Gemini API)
export GEMINI_API_KEY="AIzaSy-your-key-here"
export GEMINI_MODEL="gemini-2.5-flash"
๐ก Note: If API keys are omitted, SpecFix automatically falls back to
MockModelProviderso tests and local trial runs execute seamlessly offline.
๐ Running SpecFix
1. User Interactive Repair Workflow (specfix repair)
Navigate to any target Python project repository and launch the interactive repair wizard:
cd C:\Projects\MyProject
specfix repair
Or pass the problem description via CLI arguments non-interactively:
specfix repair --problem "divide() crashes on zero divisor. Fix divide() in calculator.py so zero divisor raises ValueError('Cannot divide by zero')"
Optional CLI flags:
--repo PATH: Path to target repository directory (default: current working directory.).--problem TEXT: Non-interactive natural language problem description.--db PATH: Path to custom SQLite audit database (default:specfix.db).--retries N: Maximum repair retry attempts (default:3).
2. Developer Benchmark Workflow (specfix run)
To evaluate automated repair against a JSON bug report:
specfix run --bug path/to/bug_report.json --repo path/to/clean_target_repo
2. Web Dashboard & API Server
SpecFix includes a full-featured React + TypeScript dark-mode Web Dashboard backed by a lightweight Python REST server.
Step 1: Launch Python REST API Backend
python server.py
(Runs REST API server on http://127.0.0.1:8000)
Step 2: Launch React Frontend (Development Mode)
In a separate terminal:
cd dashboard
npm install
npm run dev
(Launches interactive Web Dashboard UI at http://localhost:3000)
Web Dashboard Features:
- ๐ ๏ธ Automated Repair Workbench: Trigger repairs live on sample bug reports and view generated diffs & verification output.
- ๐ Benchmark Evaluation Matrix: View empirical test benchmark performance across bug categories.
- ๐ณ State-Graph Audit DAG: Visualize attempt nodes, parent-child retry links, execution metrics, and error logs.
๐งช Empirical Evaluation Benchmark
SpecFix includes an empirical evaluation harness covering 4 representative bug categories:
| Benchmark Bug Category | Class | Primary Provider | Success Rate | Attempt Recovery |
|---|---|---|---|---|
| Arithmetic / Logic | SIMPLE | Tier 1 (NVIDIA Qwen) | 100% (PASS) | Attempt 1/2 |
| Boundary / Off-by-One | SIMPLE | Tier 1 (NVIDIA Qwen) | 100% (PASS) | Attempt 1/2 |
| Data / Collection Logic | SIMPLE | Tier 1 (NVIDIA Qwen) | 100% (PASS) | Attempt 1/2 |
| Error-Handling Exception | SIMPLE | Tier 1 (NVIDIA Qwen) | 100% (PASS) | Attempt 2/2 (Recovered via Error-Feedback Retry) |
To run the evaluation suite locally:
python -m tests.evaluation.run_evaluation
๐ Project Structure
SpecFix/
โโโ pyproject.toml # Package configuration, dependencies & CLI entrypoint
โโโ server.py # Python REST API server for Web Dashboard
โโโ README.md # Project documentation
โโโ PROJECT_PLAN.md # Architectural specification & engineering plan
โโโ GUIDE_DEMO_GUIDE.md # Guide presentation & live demonstration script
โโโ dashboard/ # React + TypeScript + Vite + Tailwind CSS Web Dashboard
โ โโโ src/ # UI Components, Workbench, DAG visualizer, Benchmark Matrix
โ โโโ package.json # Node dependencies
โ โโโ vite.config.ts # Vite build & dev server config
โโโ src/
โ โโโ specfix/
โ โโโ __init__.py # Package initialization
โ โโโ __main__.py # CLI entry point & main repair pipeline orchestrator
โ โโโ intake.py # Bug report parsing & Git repo state validation
โ โโโ yagni.py # YAGNI prompt discipline & unified diff validator/normalizer
โ โโโ complexity.py # Deterministic heuristic complexity analyzer
โ โโโ router.py # Two-tier model router (Tier 1 vs Tier 2)
โ โโโ checkpoint.py # Git rollback tag creation, reset & commit manager
โ โโโ sandbox.py # Isolated patch execution & timeout protection
โ โโโ verifier.py # VerificationResult dataclass & test runner output parser
โ โโโ state_graph.py # SQLite-backed attempt DAG audit database
โ โโโ config.py # Typed configuration thresholds & system defaults
โ โโโ llm/
โ โโโ base.py # Abstract ModelProvider interface, diff parser & repair helpers
โ โโโ mock.py # Deterministic mock provider for offline testing
โ โโโ nvidia_qwen.py # NVIDIA Qwen API Provider (Tier 1 SLM)
โ โโโ gemini.py # Google Gemini API Provider (Tier 2 LLM)
โโโ tests/ # Comprehensive Pytest test suite (230+ unit & integration tests)
โ โโโ test_checkpoint.py # Git checkpoint creation & rollback tests
โ โโโ test_complexity.py # Complexity analyzer scoring tests
โ โโโ test_intake.py # Bug intake validation tests
โ โโโ test_integration.py # Full pipeline integration tests
โ โโโ test_router.py # Model router tier assignment tests
โ โโโ test_sandbox.py # Sandbox execution & timeout tests
โ โโโ test_state_graph.py # SQLite DAG state graph tests
โ โโโ test_yagni.py # YAGNI prompt enforcement tests
โ โโโ evaluation/ # Empirical benchmark suite runner & fixtures
โโโ scripts/
โโโ setup_eval_targets.py # Benchmark repository fixture setup utility
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file specfix-0.1.1.tar.gz.
File metadata
- Download URL: specfix-0.1.1.tar.gz
- Upload date:
- Size: 74.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f94dd98ac00f4fafc015996e6d475284917f5f3ec70ef6d1c44f485127fa5be
|
|
| MD5 |
a4eb91130b59172e4ed99f5d7184b6bc
|
|
| BLAKE2b-256 |
8513c63f3f63ac6c74ad4727d91fbfa9b4592be598a26c223852c55145ad9fac
|
File details
Details for the file specfix-0.1.1-py3-none-any.whl.
File metadata
- Download URL: specfix-0.1.1-py3-none-any.whl
- Upload date:
- Size: 48.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05bfd89997384490b58d1bf5871f78736b26967d3dcde8137f52959dd759b0d9
|
|
| MD5 |
e1618a0d8d38305b3bfc062d97550411
|
|
| BLAKE2b-256 |
3c1a9d35c0b08b36962cfa9c14696f9cc21dcd521584a0699c458a929dfc8d9b
|