Spaces:
Sleeping
title: AI Code Review OpenEnv
emoji: ๐ค
colorFrom: blue
colorTo: purple
sdk: docker
app_file: inference.py
pinned: false
๐ AI Code Review โ OpenEnv RL Environment
Train and evaluate AI agents on real-world code review using structured RL environments.
A real-world reinforcement learning environment where AI agents learn structured code review: identify bugs โ reason about them โ fix them correctly.
Built for the Meta ร Hugging Face ร OpenEnv ร Scaler Hackathon 2026 (Round 1 Submission).
๐ Why This Matters
Most AI coding tools are built for generation, not review. But in real-world software engineering, that's the wrong priority:
- Code review is the last line of defence against production bugs
- Bugs often slip through because reviewers miss the why, not the what
- Understanding why code is wrong matters more than just patching it
๐ This environment turns code review into a measurable, learnable RL problem โ with structure, reward signal, and reproducibility built in from the ground up.
๐ง What Makes This Environment Strong
| Property | Detail |
|---|---|
| โ Real-world task | Code review, not a toy problem |
| โ Two-phase reasoning | Agent must identify before it can fix |
| โ Deterministic grading | No LLM judge, no randomness |
| โ Reward shaping | Partial progress is rewarded at every step |
| โ Reproducible evaluation | Same input always produces same score |
| โ Spec compliant | Fully compatible with OpenEnv + hackathon requirements |
๐๏ธ Environment Design
Implements the full OpenEnv interface โ three methods, no more:
obs = env.reset() # Start a new episode
result = env.step(action) # Execute one action โ {observation, reward, done, info}
metadata = env.state # Inspect episode state
๐ฅ Observation Space
| Field | Description |
|---|---|
code |
Buggy JavaScript code to review |
task |
Task description + current phase |
history |
Log of all prior steps this episode |
task_id |
Task number (1, 2, or 3) |
language |
javascript |
difficulty |
easy / medium / hard |
category |
syntax / logic / performance |
๐ฎ Action Space
| Field | Values |
|---|---|
action_type |
"identify" or "fix" |
content |
Free-text explanation or code |
๐ Episode Flow
identify โ fix โ identify โ fix โ identify โ fix
task 1 task 2 task 3
One episode covers all 3 tasks in order.
๐งช Tasks
๐ข Task 1 โ Syntax Error (Easy)
// buggy
function add(a, b {
return a + b;
}
// fixed
function add(a, b) {
return a + b;
}
๐ก Task 2 โ Logic Bug (Medium)
// buggy
function isEven(n) {
return n % 2 === 1;
}
// fixed
function isEven(n) {
return n % 2 === 0;
}
๐ด Task 3 โ Performance Issue (Hard)
// buggy
for (let i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
// fixed
arr.forEach(item => {
console.log(item);
});
๐ฏ Reward System
โ Deterministic & Reproducible
No randomness. Same input โ same score.
๐งฉ Identify Reward
score = matched_keywords / total_keywords
๐ ๏ธ Fix Reward
| Condition | Score |
|---|---|
| Exact match | 1.0 |
| Whitespace-normalised | 0.9 |
| โฅ 80% token overlap | 0.6 |
| โฅ 50% token overlap | 0.3 |
| Below 50% | 0.0 |
๐ Identify Bonus
+0.1 bonus if identify โฅ 0.4 (final reward clamped to 1.0)
โ ๏ธ Edge Case Handling
| Situation | Effect |
|---|---|
| Skipped identify phase | fix score ร 0.5 |
Unknown action_type |
0.0 |
| Repeated identify | 0.0 |
๐ Max Reward Per Episode
| Scope | Max Reward |
|---|---|
| Per step | 1.0 |
| Per task | ~2.0 |
| Full episode | ~6.0 |
๐ค Inference Pipeline
1. Read HF_TOKEN, API_BASE_URL, MODEL_NAME
2. Initialise OpenAI client + environment
3. Reset environment
4. Identify โ Fix for each task
5. Log results in required format
๐งพ Log Format (Strict)
[START]
[STEP]
[STEP]
...
[END]
๐ Example Output
[START] task=code-review env=ai-code-review-env model=gpt-4.1-mini
[STEP] step=1 action=identify:task1 reward=0.71 done=false error=null
[STEP] step=2 action=fix:task1 reward=1.00 done=false error=null
[STEP] step=3 action=identify:task2 reward=0.60 done=false error=null
[STEP] step=4 action=fix:task2 reward=1.00 done=false error=null
[STEP] step=5 action=identify:task3 reward=0.45 done=false error=null
[STEP] step=6 action=fix:task3 reward=1.00 done=true error=null
[END] success=true steps=6 rewards=0.71,1.00,0.60,1.00,0.45,1.00
๐ Why This Stands Out
- Real-world problem (not synthetic)
- Deterministic evaluation (fair + reproducible)
- Reward shaping (better learning signal)
- Two-phase reasoning (prevents shortcutting)
โ๏ธ Setup
pip install -r requirements.txt
export HF_TOKEN=your_token
python inference.py
๐ Project Structure
code-review-env/
โโโ inference.py
โโโ openenv.yaml
โโโ Dockerfile
โโโ README.md
โโโ env/
๐ Evaluation Alignment
| Criteria | Covered |
|---|---|
| Real-world utility | โ |
| Task design | โ |
| Grader quality | โ |
| Environment design | โ |
| Spec compliance | โ |
๐ License
MIT License Built for Meta ร Hugging Face ร OpenEnv ร Scaler Hackathon 2026