Spaces:
Runtime error
Download README.md from DeepParmar/code-review: direct link, hf CLI and curl.
- Browser
- Download file 11.3 kB
-
https://huggingface.co/spaces/DeepParmar/code-review/resolve/main/README.md
- Command line
-
hf download hf://spaces/DeepParmar/code-review/README.md
-
curl -L -o README.md https://huggingface.co/spaces/DeepParmar/code-review/resolve/main/README.md
title: Code Review OpenEnv
emoji: π
colorFrom: indigo
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
Code Review OpenEnv
A deterministic, OpenEnv-style benchmark environment for evaluating AI code review agents. The agent receives buggy Python pull requests, leaves structured review comments, and is graded on precision, recall, and semantic understanding against ground-truth bugs.
Live Space: https://deepparmar-code-review.hf.space
Environment Description & Motivation
Traditional code review benchmarks measure LLMs on a binary metric: Did the model flag the correct line? As frontier models approach ceiling performance on these shallow evaluations, we need environments that test deeper capabilities.
This environment simulates real-world code review β a task that software engineers perform daily. An AI agent must:
- Read buggy Python code (pull request diffs)
- Identify security vulnerabilities, logic bugs, and performance issues
- Explain why something is broken (not just where)
- Avoid false positives and deliberately planted traps
Action Space
| Operation | Parameters | Description |
|---|---|---|
add_comment |
line_number, severity, category, message, confidence |
Flag a bug with explanation + Telemetry calibration tracking |
approve |
summary |
Approve the PR (risky if bugs remain) |
request_changes |
summary |
Request changes with summary |
done |
(none) | Finish review, trigger final grading |
inspect_file |
filename |
View a specific file (hard task) |
inspect_lines |
filename, start_line, end_line |
View specific lines |
Severity: critical | major | minor | nit
Category: bug | security | performance | style
Observation Space
| Field | Type | Description |
|---|---|---|
task_id |
str |
easy, medium, or hard |
pr_title / pr_description |
str |
Pull request metadata |
full_file |
str |
Complete file under review |
code_diff |
str |
Unified diff |
existing_comments |
list |
Agent's prior comments |
step_number / max_steps |
int |
Step progress |
available_files |
list |
Files available for inspection (hard task) |
Tasks (3 Difficulty Tiers)
| Task | Domain | Real Bugs | Files | Traps | Semantic Check |
|---|---|---|---|---|---|
| easy | List processing | 3 | 1 | β | β |
| medium | Web API handler | 4 | 1 | β | β |
| hard | Async crypto service | 6 | 3 | 1 red herring + 2 adversarial comments | β explanation_tiers |
Task Details
- Easy: Off-by-one IndexError, null safety check, assignment-in-conditional syntax bug
- Medium: SQL injection, XSS, IDOR, hardcoded API secret
- Hard: Unsafe YAML deserialization (RCE), ECB cipher mode, async generator leak, race condition on shared dict, hardcoded secret key fallback, sync I/O blocking event loop β plus a red herring
try-except: passin a retry loop
Reward Function
| Condition | Reward |
|---|---|
| Correct bug match (Β±5 lines, severity+category) | +0.15 to +0.30 |
| Severity / category match bonus | +0.05 |
| Semantic keyword miss (hard task) | β0.10 |
| Confidence Calibration (if confidence > 80%) | +0.05 (correct) or β0.10 (wrong) |
| Duplicate comment | β0.05 |
| False positive | β0.10 |
| Red herring flagged | β0.20 |
done action |
Final weighted F1 grader score |
| Efficiency bonus (fast + high score) | +0.10 |
Grader: Weighted F1 with strict 1-to-1 bug-to-comment matching.
Severity weights: critical=3, major=2, minor=1, nit=0.5.
False positives are weighted by their assigned severity to penalize spamming.
All scores deterministic and reproducible.
Baseline Scores (Latest Results)
Includes Telemetric Confidence Scoring.
π HUGGING FACE NATIVE SERVERLESS (Final Production Phase)
Native inference parsing successfully verified directly over https://router.huggingface.co/v1. DeepSeek-V3 completely dominated the native test group, surgically identifying every web vulnerability in the medium test environment to achieve a mathematically perfect 0.999 limit ceiling.
| Native Model Identifier | Environment | Easy F1 | Medium F1 | Hard F1 | Avg F1 | Avg Conf. |
|---|---|---|---|---|---|---|
deepseek-ai/DeepSeek-V3 |
β¨ HuggingFace | 0.667 | 0.999 | 0.564 | 0.743 | 97% |
Qwen/Qwen2.5-72B-Instruct |
β¨ HuggingFace | 0.200 | 0.588 | 0.286 | 0.358 | 95% |
meta-llama/Meta-Llama-3-8B-Instruct |
β¨ HuggingFace | 0.429 | 0.001 | 0.001 | 0.144 | 96% |
meta-llama/Llama-3.3-70B-Instruct |
β Rate Limited | - | - | - | - | - |
mistralai/Mixtral-8x7B-Instruct-v0.1 |
β Model Unsupported | - | - | - | - | - |
π POST-SUBMISSION OPENROUTER BENCHMARKS
Final stress test verification leveraging OpenRouter API failover.
| Native Model Identifier | Environment | Easy F1 | Medium F1 | Hard F1 | Avg F1 | Avg Conf. |
|---|---|---|---|---|---|---|
deepseek-ai/DeepSeek-V3 |
π OpenRouter | 0.750 | 0.667 | 0.720 | 0.712 | 92% |
openai/gpt-4o-mini |
π OpenRouter | 0.833 | 0.667 | 0.581 | 0.694 | 90% |
meta-llama/llama-3.3-70b-instruct |
π OpenRouter | 0.500 | 0.833 | 0.545 | 0.626 | 94% |
qwen/qwen-2.5-72b-instruct |
π OpenRouter | 0.800 | 0.556 | 0.500 | 0.619 | 97% |
mistralai/mistral-small-3.1-24b |
π OpenRouter | 0.001 | 0.001 | 0.999 | 0.334 | 10% |
π§ Performance Analysis: Why Models Succeed or Fail
Our deterministic grading environment reveals deep behaviors not captured by standard multiple-choice benchmarks:
- π₯ DeepSeek-V3 (The Winner): Dominated because of superior confidence calibration and semantic reasoning. Unlike other models, DeepSeek doesn't just guess. When faced with the adversarial "Red Herring" (
try...except: passinside a backoff loop), its confidence drops, allowing it to bypass the trap entirely. It correctly uses multi-step logic to deduce why code is conceptually flawed rather than just syntactically incorrect. - π₯ Qwen-2.5-72B: Highly capable at identifying localized syntax and logic errors in the Easy and Medium environments. However, it suffered in the Hard task, demonstrating limitations in long-context, cross-file reasoning. It often failed to correctly track how keys generated in
config_loader.pywere insecurely consumed incrypto_service.py. - π₯ Llama-3.3-70B (The Overconfident Guesser): Suffered mathematically due to overconfidence syndrome. The environment heavily penalizes false positives submitted with
>80%confidence. Llama consistently flagged totally secure, verified code blocks as "Critical Vulnerabilities" with95%confidence, causing its F1 score to crash dynamically. It could not differentiate real bugs from the adversarial comment injections. - π Smaller/Local Models (Mixtral, Meta-Llama-8B, Gemma): Generally failed either due to JSON parsing collapse (outputting conversational text or reasoning tags instead of strict operation schemas) or by reaching maximum timeout limits when scanning larger codeblocks.
See FINDINGS_PAPER.md for full analysis.
Setup & Usage
Prerequisites
pip install -r code-review-env/requirements.txt
Run Server
cd code-review-env
uvicorn server:app --host 0.0.0.0 --port 7860
Docker
cd code-review-env
docker build -t code-review-env .
docker run -p 7860:7860 code-review-env
Run Inference
The inference script reads these environment variables:
API_BASE_URLβ The API endpoint for the LLM (default:https://router.huggingface.co/v1)MODEL_NAMEβ The model identifier (default:Qwen/Qwen2.5-72B-Instruct)HF_TOKENβ Your Hugging Face / API key (required)ENV_BASE_URLβ Environment server URL (default:http://127.0.0.1:7860)
# LLM mode (requires API key)
API_BASE_URL=https://router.huggingface.co/v1 \
MODEL_NAME=Qwen/Qwen2.5-72B-Instruct \
HF_TOKEN=<your-token> \
python inference.py
# Benchmark mode (deterministic, no LLM needed)
REVIEW_STRATEGY=benchmark TASK_IDS=easy,medium,hard \
python inference.py
Run Tests
python -m pytest code-review-env/tests -v
Project Structure
code-reviewer-v2/
βββ server.py # Root FastAPI entrypoint (delegates to impl)
βββ inference.py # Root inference shim (delegates to impl)
βββ openenv.yaml # OpenEnv specification manifest
βββ Dockerfile # Container build definition
βββ pyproject.toml # Project config + pytest settings
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ FINDINGS_PAPER.md # Academic findings paper
βββ ARCHITECTURE_BLUEPRINT.md # Technical architecture docs
βββ AUDIT_RESULTS.md # Full audit & compliance results
βββ REQUIREMENTS_CHECKLIST.md # OpenEnv requirements checklist
βββ updatess.txt # Benchmark progression & change log
βββ lgos-complate.txt # Benchmark log (Run 1 β 5 models)
βββ logs-2m.txt # Benchmark log (Run 2 β 6 models)
βββ logs-3.txt # Benchmark log (Run 3 β 6 models, latest)
βββ code-review-env/
β βββ server.py # FastAPI server with /reset, /step, /state, /health
β βββ inference.py # Full LLM inference engine + benchmark mode
β βββ openenv.yaml # OpenEnv spec (impl copy)
β βββ Dockerfile # Impl Dockerfile
β βββ requirements.txt # Impl dependencies
β βββ env/
β β βββ environment.py # Core environment engine
β β βββ reward_engine.py # Shaped reward computation
β β βββ state_manager.py # Episode state tracking
β β βββ models.py # Pydantic data schemas
β β βββ graders/
β β β βββ base_grader.py # Weighted F1 with semantic gates
β β β βββ grader_easy.py # Easy task grader
β β β βββ grader_medium.py # Medium task grader
β β β βββ grader_hard.py # Hard task grader (multi-file)
β β βββ tasks/
β β βββ task_easy.py # 3 runtime logic bugs
β β βββ task_medium.py # 4 security vulnerabilities
β β βββ task_hard.py # 6 bugs across 3 files + 1 red herring
β βββ tests/ # 70+ automated tests
βββ server/ # Alternate ASGI entrypoint
Validation
openenv validate
pytestβ 70 passedopenenv validateβ Passes- All live endpoints return HTTP 200
- Dockerfile builds and runs cleanly
- Inference completes in <20 minutes on vcpu=2, memory=8gb