--- 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: ```python 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) ```javascript // buggy function add(a, b { return a + b; } // fixed function add(a, b) { return a + b; } ``` --- ### ๐ŸŸก Task 2 โ€” Logic Bug (Medium) ```javascript // buggy function isEven(n) { return n % 2 === 1; } // fixed function isEven(n) { return n % 2 === 0; } ``` --- ### ๐Ÿ”ด Task 3 โ€” Performance Issue (Hard) ```javascript // 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 ```bash 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