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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: gpl-3.0
|
| 3 |
+
tags:
|
| 4 |
+
- python
|
| 5 |
+
- governance
|
| 6 |
+
- ast
|
| 7 |
+
- deterministic
|
| 8 |
+
- code-governance
|
| 9 |
+
pretty_name: CodeTruth Agent V2 Evaluation
|
| 10 |
---
|
| 11 |
+
|
| 12 |
+
# CodeTruth Agent V2
|
| 13 |
+
|
| 14 |
+
## Deterministic Pre-Modification Governance Layer for Python Code Changes
|
| 15 |
+
|
| 16 |
+
[](https://doi.org/10.5281/zenodo.20569647)
|
| 17 |
+
[](https://github.com/Zeeshan78699/CodeTruthAgent/blob/main/LICENSE)
|
| 18 |
+
[](https://github.com/Zeeshan78699/CodeTruthAgent)
|
| 19 |
+
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
## Overview
|
| 23 |
+
|
| 24 |
+
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.
|
| 25 |
+
|
| 26 |
+
**No LLM in the decision path. Fully deterministic. Fully reproducible.**
|
| 27 |
+
|
| 28 |
+
---
|
| 29 |
+
|
| 30 |
+
## The Problem
|
| 31 |
+
|
| 32 |
+
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.
|
| 33 |
+
|
| 34 |
+
`rollback()` and `get_rollback()` have a semantic score of 0.95.
|
| 35 |
+
One performs database recovery. The other reads a boolean flag.
|
| 36 |
+
An autonomous agent cannot detect this distinction from names or embeddings alone.
|
| 37 |
+
|
| 38 |
+
V2 catches it through behavioral analysis — before the patch reaches the repository.
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
## How It Works
|
| 43 |
+
|
| 44 |
+
```
|
| 45 |
+
Repository Scan
|
| 46 |
+
→ Candidate Selection
|
| 47 |
+
→ Semantic Analysis (sentence-transformers/all-MiniLM-L6-v2)
|
| 48 |
+
→ Behavioral Analysis (AST-based, 10 operation categories)
|
| 49 |
+
→ Multi-Signal Fusion
|
| 50 |
+
→ Governance Decision: SAFE / REVIEW / BLOCK / FREEZE_PATCH
|
| 51 |
+
→ Human Approval
|
| 52 |
+
→ Safe Application
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## Governance Decisions
|
| 58 |
+
|
| 59 |
+
| Decision | Meaning |
|
| 60 |
+
|----------|---------|
|
| 61 |
+
| SAFE | Low risk — AUTO_APPLY recommended |
|
| 62 |
+
| REVIEW | Medium/High risk — human approval required |
|
| 63 |
+
| BLOCK | Critical risk — individual approval required |
|
| 64 |
+
| FREEZE_PATCH | Opposing behavior detected — mandatory human review |
|
| 65 |
+
|
| 66 |
+
**V2 recommends governance actions. It does not modify files autonomously.**
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
## Evaluation Results
|
| 71 |
+
|
| 72 |
+
Evaluated on 8 open-source Python repositories:
|
| 73 |
+
|
| 74 |
+
| Repository | Files | Gov Findings | Gov BLOCKs | Pairs | Pipeline BLOCKs | Opposing | Errors |
|
| 75 |
+
|------------|-------|-------------|-----------|-------|----------------|---------|--------|
|
| 76 |
+
| Flask Tutorial | 9 | 2 | 0 | 4 | 0 | 0 | 0 |
|
| 77 |
+
| Click | 60 | 3 | 1 | 25 | 3 | 0 | 0 |
|
| 78 |
+
| HTTPX | 60 | 0 | 0 | 25 | 3 | 0 | 0 |
|
| 79 |
+
| Flask (Full) | 83 | 4 | 2 | 25 | 8 | 0 | 0 |
|
| 80 |
+
| DRF | 154 | 2 | 1 | 50 | 24 | 0 | 0 |
|
| 81 |
+
| Rich | 213 | 14 | 4 | 37 | 9 | 0 | 0 |
|
| 82 |
+
| Django | 2,917 | 68 | 16 | 100 | 55 | 0 | 0 |
|
| 83 |
+
| Transformers | 4,426 | 296 | 76 | 1,000 | 464 | 4 | 0 |
|
| 84 |
+
| **Total** | **7,862** | **386** | **99** | **1,241** | **563** | **4** | **0** |
|
| 85 |
+
|
| 86 |
+
**Zero pipeline errors across 1,241 function-pair analyses.**
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## Precision Audit
|
| 91 |
+
|
| 92 |
+
14-pair BLOCK precision audit:
|
| 93 |
+
|
| 94 |
+
| Category | Count | Proportion |
|
| 95 |
+
|----------|-------|-----------|
|
| 96 |
+
| Governance-significant (GENUINE) | 6 | 60% |
|
| 97 |
+
| Family-pattern noise (NOISE_FAMILY) | 3 | 30% |
|
| 98 |
+
| Embedding limitation (NOISE_EMBEDDING) | 1 | 10% |
|
| 99 |
+
|
| 100 |
+
All 4 opposing-behavior detections confirmed GENUINE.
|
| 101 |
+
|
| 102 |
+
---
|
| 103 |
+
|
| 104 |
+
## Star Example — Opposing Behavior Detection
|
| 105 |
+
|
| 106 |
+
```
|
| 107 |
+
update_version_in_file vs update_version_in_examples
|
| 108 |
+
Semantic score: 0.70 — names look related
|
| 109 |
+
Tags A: FILE_READ, FILE_WRITE, STATE_MUTATION
|
| 110 |
+
Tags B: DELETE_OPERATION
|
| 111 |
+
Action: FREEZE_PATCH (CRITICAL)
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
One function rewrites files. The other deletes content.
|
| 115 |
+
Semantic similarity alone would not catch this.
|
| 116 |
+
V2 catches it through behavioral opposition detection.
|
| 117 |
+
|
| 118 |
+
---
|
| 119 |
+
|
| 120 |
+
## Dataset Contents
|
| 121 |
+
|
| 122 |
+
This dataset contains the full evaluation reports from the 8-repository evaluation:
|
| 123 |
+
|
| 124 |
+
- `tutorial_report.json` — Flask Tutorial evaluation
|
| 125 |
+
- `click_report.json` — Click evaluation
|
| 126 |
+
- `httpx_report.json` — HTTPX evaluation
|
| 127 |
+
- `flask_report.json` — Flask (Full) evaluation
|
| 128 |
+
- `drf_report.json` — Django REST Framework evaluation
|
| 129 |
+
- `rich_report.json` — Rich evaluation
|
| 130 |
+
- `django_report.json` — Django evaluation
|
| 131 |
+
- `transformers_report.json` — Hugging Face Transformers evaluation
|
| 132 |
+
|
| 133 |
+
All reports include full decision pipeline results, governance findings, and opposing-behavior detections for independent verification.
|
| 134 |
+
|
| 135 |
+
---
|
| 136 |
+
|
| 137 |
+
## Reproduce the Evaluation
|
| 138 |
+
|
| 139 |
+
```python
|
| 140 |
+
import json
|
| 141 |
+
import random
|
| 142 |
+
|
| 143 |
+
with open('transformers_report.json') as f:
|
| 144 |
+
data = json.load(f)
|
| 145 |
+
|
| 146 |
+
# Reproduce Group B precision audit sample
|
| 147 |
+
blocks = [r for r in data['decision_pipeline_results']
|
| 148 |
+
if r['fusion_decision'] == 'BLOCK']
|
| 149 |
+
random.seed(20260603)
|
| 150 |
+
group_b = random.sample(blocks, 5)
|
| 151 |
+
|
| 152 |
+
# Get all opposing detections
|
| 153 |
+
group_c = [r for r in data['decision_pipeline_results']
|
| 154 |
+
if r['fusion_opposing_detected']]
|
| 155 |
+
# Returns exactly 4 pairs
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
---
|
| 159 |
+
|
| 160 |
+
## Known Limitations
|
| 161 |
+
|
| 162 |
+
- **Single-reviewer audit** — 14 pairs, wide confidence interval
|
| 163 |
+
- **Python-only** — AST parser is Python-specific
|
| 164 |
+
- **V1 25-file sampling cap** — V1-driven extraction did not activate in evaluation
|
| 165 |
+
- **NOISE_FAMILY 30%** — token-overlap on naming families generates combinatorial noise
|
| 166 |
+
- **No patch generation** — V2 decides only, does not generate patches (V3 scope)
|
| 167 |
+
- **No interactive HITL UI** — programmatic API only (V3 scope)
|
| 168 |
+
|
| 169 |
+
---
|
| 170 |
+
|
| 171 |
+
## Citation
|
| 172 |
+
|
| 173 |
+
```bibtex
|
| 174 |
+
@software{codetruth_v2_2026,
|
| 175 |
+
author = {Saud, Zeeshan},
|
| 176 |
+
title = {CodeTruth Agent V2: A Deterministic Pre-Modification Governance Layer for Python Code Changes},
|
| 177 |
+
year = {2026},
|
| 178 |
+
doi = {10.5281/zenodo.20569647},
|
| 179 |
+
url = {https://doi.org/10.5281/zenodo.20569647}
|
| 180 |
+
}
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
---
|
| 184 |
+
|
| 185 |
+
## Links
|
| 186 |
+
|
| 187 |
+
- **GitHub:** https://github.com/Zeeshan78699/CodeTruthAgent
|
| 188 |
+
- **Zenodo DOI:** https://doi.org/10.5281/zenodo.20569647
|
| 189 |
+
|
| 190 |
+
---
|
| 191 |
+
|
| 192 |
+
## Author
|
| 193 |
+
|
| 194 |
+
**Zeeshan Saud** — Independent Researcher, UAE
|
| 195 |
+
zeeshansaud786@gmail.com
|
| 196 |
+
|
| 197 |
+
---
|
| 198 |
+
|
| 199 |
+
## License
|
| 200 |
+
|
| 201 |
+
GPLv3 — see [LICENSE](https://github.com/Zeeshan78699/CodeTruthAgent/blob/main/LICENSE)
|