r/coolgithubprojects • u/joyboyy937 • 18m ago
How I stopped local coding models (Qwen3 / Qwen2.5-Coder) from hallucinating bad fixes — without giving the LLM shell access.
A couple of days ago I shared my air-gapped Windows debugger (**TraceZero**) on Reddit and got two brutally honest critiques from local-LLM devs:
- *"A small local model on its own hallucinates broken syntax."*
- *"I'm scared to trust a local model not to nuke my files if it has terminal access."*
Both were 100% right. Here is the exact 3-layer guardrail architecture I built around local Ollama (`127.0.0.1:11434`) to fix both problems:
* **Layer 1: `<2ms` Python AST Static Pre-Scanner:** Before touching the LLM, an AST pass flags mutable defaults, loop mutations, and race conditions deterministically and slices only the `±35` lines around the bug so the model stays laser-focused.
* **Layer 2: Silent Execution-Verified Reflexion (`compile()` + `sys.settrace`):** Every candidate patch is compiled and executed inside an isolated, step-guarded in-memory namespace (`50,000` step cap to catch infinite loops). If the model outputs a `SyntaxError` or runtime crash, it gets rejected and re-prompted automatically up to 3 times before you ever see the diff.
* **Layer 3: Zero Shell Access + Human-in-the-Loop Diffs:** The LLM has **zero** `subprocess`, PowerShell, or file-deletion tools—it is strictly text-in / diff-out. Nothing touches your disk until you inspect the live red/green unified diff and click **Apply** (with automatic `.tracezero/backups/` snapshots).
It works with **any** local Ollama model via `tracezero.json` (`qwen3-coder`, `qwen3:8b`, `deepseek-coder-v2`, or `qwen2.5-coder:1.5b` out of the box for 8 GB CPU-only laptops), runs in **Windows Airplane Mode** (`0 KB` egress, logged to `.tracezero/audit.log`), and has a **Free Forever Lite** tier (`3` AI fixes/day + unlimited AST scans forever).
Repo, `AUDIT_SPEC.md` & `0/67` VirusTotal scan: https://github.com/joyboyy937-rgb/tracezero-desktop
Happy to share the AST rules or sandbox edge cases if anyone is building local coding tools!