license: gpl-3.0
tags:
- python
- governance
- ast
- deterministic
- code-governance
pretty_name: CodeTruth Agent V2 Evaluation
CodeTruth Agent V2
Deterministic Pre-Modification Governance Layer for Python Code Changes
Overview
CodeTruth Agent V2 is an open-source deterministic governance layer that analyzes candidate Python function pairs using semantic similarity and behavioral analysis, and produces SAFE, REVIEW, or BLOCK governance decisions before repository modification is attempted.
No LLM in the decision path. Fully deterministic. Fully reproducible.
The Problem
AI coding agents generate and apply code changes autonomously. They do not pause to check whether a function that looks similar actually does something completely different.
rollback() and get_rollback() have a semantic score of 0.95.
One performs database recovery. The other reads a boolean flag.
An autonomous agent cannot detect this distinction from names or embeddings alone.
V2 catches it through behavioral analysis — before the patch reaches the repository.
How It Works
Repository Scan
→ Candidate Selection
→ Semantic Analysis (sentence-transformers/all-MiniLM-L6-v2)
→ Behavioral Analysis (AST-based, 10 operation categories)
→ Multi-Signal Fusion
→ Governance Decision: SAFE / REVIEW / BLOCK / FREEZE_PATCH
→ Human Approval
→ Safe Application
Governance Decisions
| Decision | Meaning |
|---|---|
| SAFE | Low risk — AUTO_APPLY recommended |
| REVIEW | Medium/High risk — human approval required |
| BLOCK | Critical risk — individual approval required |
| FREEZE_PATCH | Opposing behavior detected — mandatory human review |
V2 recommends governance actions. It does not modify files autonomously.
Evaluation Results
Evaluated on 8 open-source Python repositories:
| Repository | Files | Gov Findings | Gov BLOCKs | Pairs | Pipeline BLOCKs | Opposing | Errors |
|---|---|---|---|---|---|---|---|
| Flask Tutorial | 9 | 2 | 0 | 4 | 0 | 0 | 0 |
| Click | 60 | 3 | 1 | 25 | 3 | 0 | 0 |
| HTTPX | 60 | 0 | 0 | 25 | 3 | 0 | 0 |
| Flask (Full) | 83 | 4 | 2 | 25 | 8 | 0 | 0 |
| DRF | 154 | 2 | 1 | 50 | 24 | 0 | 0 |
| Rich | 213 | 14 | 4 | 37 | 9 | 0 | 0 |
| Django | 2,917 | 68 | 16 | 100 | 55 | 0 | 0 |
| Transformers | 4,426 | 296 | 76 | 1,000 | 464 | 4 | 0 |
| Total | 7,862 | 386 | 99 | 1,241 | 563 | 4 | 0 |
Zero pipeline errors across 1,241 function-pair analyses.
Precision Audit
14-pair BLOCK precision audit:
| Category | Count | Proportion |
|---|---|---|
| Governance-significant (GENUINE) | 6 | 60% |
| Family-pattern noise (NOISE_FAMILY) | 3 | 30% |
| Embedding limitation (NOISE_EMBEDDING) | 1 | 10% |
All 4 opposing-behavior detections confirmed GENUINE.
Star Example — Opposing Behavior Detection
update_version_in_file vs update_version_in_examples
Semantic score: 0.70 — names look related
Tags A: FILE_READ, FILE_WRITE, STATE_MUTATION
Tags B: DELETE_OPERATION
Action: FREEZE_PATCH (CRITICAL)
One function rewrites files. The other deletes content. Semantic similarity alone would not catch this. V2 catches it through behavioral opposition detection.
Dataset Contents
This dataset contains the full evaluation reports from the 8-repository evaluation:
tutorial_report.json— Flask Tutorial evaluationclick_report.json— Click evaluationhttpx_report.json— HTTPX evaluationflask_report.json— Flask (Full) evaluationdrf_report.json— Django REST Framework evaluationrich_report.json— Rich evaluationdjango_report.json— Django evaluationtransformers_report.json— Hugging Face Transformers evaluation
All reports include full decision pipeline results, governance findings, and opposing-behavior detections for independent verification.
Reproduce the Evaluation
import json
import random
with open('transformers_report.json') as f:
data = json.load(f)
# Reproduce Group B precision audit sample
blocks = [r for r in data['decision_pipeline_results']
if r['fusion_decision'] == 'BLOCK']
random.seed(20260603)
group_b = random.sample(blocks, 5)
# Get all opposing detections
group_c = [r for r in data['decision_pipeline_results']
if r['fusion_opposing_detected']]
# Returns exactly 4 pairs
Known Limitations
- Single-reviewer audit — 14 pairs, wide confidence interval
- Python-only — AST parser is Python-specific
- V1 25-file sampling cap — V1-driven extraction did not activate in evaluation
- NOISE_FAMILY 30% — token-overlap on naming families generates combinatorial noise
- No patch generation — V2 decides only, does not generate patches (V3 scope)
- No interactive HITL UI — programmatic API only (V3 scope)
Citation
@software{codetruth_v2_2026,
author = {Saud, Zeeshan},
title = {CodeTruth Agent V2: A Deterministic Pre-Modification Governance Layer for Python Code Changes},
year = {2026},
doi = {10.5281/zenodo.20569647},
url = {https://doi.org/10.5281/zenodo.20569647}
}
Links
- GitHub: https://github.com/Zeeshan78699/CodeTruthAgent
- Zenodo DOI: https://doi.org/10.5281/zenodo.20569647
Author
Zeeshan Saud — Independent Researcher, UAE zeeshansaud786@gmail.com
License
GPLv3 — see LICENSE