Skip to main content

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:

  1. Speculative Execution: No AI patch is ever committed directly. Every fix is treated as an unverified speculation.
  2. 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).
  3. Automated Verification: Patches are tested in an isolated sandbox running the target project's automated test suite (pytest).
  4. 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.
  5. 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.
  6. 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 MockModelProvider when 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 MockModelProvider so 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

specfix-0.1.1.tar.gz (74.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

specfix-0.1.1-py3-none-any.whl (48.3 kB view details)

Uploaded Python 3

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

Hashes for specfix-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0f94dd98ac00f4fafc015996e6d475284917f5f3ec70ef6d1c44f485127fa5be
MD5 a4eb91130b59172e4ed99f5d7184b6bc
BLAKE2b-256 8513c63f3f63ac6c74ad4727d91fbfa9b4592be598a26c223852c55145ad9fac

See more details on using hashes here.

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

Hashes for specfix-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 05bfd89997384490b58d1bf5871f78736b26967d3dcde8137f52959dd759b0d9
MD5 e1618a0d8d38305b3bfc062d97550411
BLAKE2b-256 3c1a9d35c0b08b36962cfa9c14696f9cc21dcd521584a0699c458a929dfc8d9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page