AMD21/codefixerenv
CodeFixerEnv ๐ง
An OpenEnv reinforcement learning environment for Python code-debugging tasks.
Built for the Meta ร PyTorch ร Hugging Face OpenEnv Hackathon โ Round 1.
What is CodeFixerEnv?
CodeFixerEnv is a reinforcement learning environment that teaches an AI agent how to debug Python code. The agent receives a buggy function, reads a description of what the function should do, and submits corrected code. The environment runs the code against a deterministic test suite, grades the submission on multiple weighted criteria, and returns a dense reward signal that guides the agent toward a correct and efficient solution.
Architecture
codefixer-final/
โโโ env/
โ โโโ models.py โ Pydantic: Observation, Action, Reward, StepResult
โ โโโ environment.py โ CodeFixerEnv class (reset / step / state)
โโโ tasks/
โ โโโ tasks.py โ 3 tasks + deterministic graders
โโโ tests/
โ โโโ test_env.py โ 20 unit tests
โโโ server.py โ FastAPI REST server (port 7860)
โโโ inference.py โ Baseline agent using OpenAI client
โโโ openenv.yaml โ OpenEnv spec metadata
โโโ Dockerfile
โโโ requirements.txtObservation Space
Action Space
Reward Space
Dense rewards โ meaningful signal every step, not just at the end.
fix action:
reward = grader_score โ previous_best (improvement delta)
+0.20 efficiency bonus if solved in โค 2 steps
โ0.05 if no improvement (redundancy penalty)
explain: โ0.05
give_up: โ0.10Tasks
๐ข Easy โ sum_range(n)
Fix an off-by-one error. range(n) โ range(1, n+1). Grading: syntax 20% + correctness 70% + no hardcoding 10%
๐ก Medium โ flatten(lst)
Fix two bugs in a nested list flattener. Grading: syntax 15% + correctness 75% + isinstance usage 10%
๐ด Hard โ longest_unique(s)
Rewrite O(nยฒ) brute-force as O(n) sliding window. Grading: syntax 10% + correctness 70% + linear complexity 20%
API Endpoints
Setup
pip install -r requirements.txt
python server.py
# Server at http://localhost:7860Docker
docker build -t codefixerenv .
docker run -p 7860:7860 codefixerenvRunning the Baseline Agent
export API_BASE_URL=http://localhost:7860
export MODEL_NAME=Qwen/Qwen2.5-72B-Instruct
export HF_TOKEN=hf_...
python inference.pyRunning Tests
python -m pytest tests/test_env.py -v
# Expected: 20 passed