guglxni/oxidizer-rust-env
Oxidizer — Rust Build Fixer RL Environment
An OpenEnv-compatible reinforcement learning environment where an AI agent fixes broken Rust projects by editing Cargo.toml and src/main.rs until cargo check succeeds.
Motivation
Fixing Rust compilation errors is a real-world software engineering task that developers face daily. Unlike toy environments, this models a genuine developer workflow: read compiler diagnostics, identify root causes (missing dependencies, wrong feature flags, syntax errors), apply targeted fixes, and verify the build. The environment is designed following AIDLC principles with adaptive difficulty, quality gates, and structured audit logging.
Tasks (5 levels, Easy to Expert)
Difficulty Progression
- Easy/Medium: Single error type, single file edit fixes it
- Hard/Medium-Hard: Multiple errors but can be fixed in 1-2 targeted edits
- Expert: Errors span both files — agent must plan a multi-step repair strategy
Action Space
class Action(BaseModel):
file_to_edit: Literal["Cargo.toml", "src/main.rs"] # which file to overwrite
new_content: str # complete new file content (max 128 KB)The agent edits one file per step by submitting the complete new content. This models the real-world pattern of editing a file and running cargo check to see if the fix worked.
Observation Space
class Observation(BaseModel):
compiler_output: str # stdout+stderr from cargo check (ANSI stripped)
cargo_toml_content: str # current Cargo.toml
main_rs_content: str # current src/main.rsThe agent sees the full compiler diagnostics including error codes (E0432, E0277, etc.) and the current file contents, enabling it to reason about what to change.
Reward Function (Partial Progress)
The reward provides gradient signal over the full trajectory — not just binary pass/fail:
Example trajectory on Task 4 (Expert):
reset → 5 errors (serde derive, serde_json missing, syntax)
step 1 → fix Cargo.toml (add derive + serde_json) → 1 error remaining → reward 0.72
step 2 → fix main.rs (add semicolon) → 0 errors → reward 1.00, done=trueAPI Endpoints
Setup & Usage
Local (Python)
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python3 -m uvicorn env:app --port 7860
# Test it:
curl -X POST http://localhost:7860/reset -H "Content-Type: application/json" -d '{"task_id": 0}'Docker
docker build -t oxidizer .
docker run -p 7860:7860 oxidizerInference (baseline agent)
export HF_TOKEN="your-token"
export API_BASE_URL="https://router.huggingface.co/v1"
export MODEL_NAME="Qwen/Qwen2.5-72B-Instruct"
python3 inference.py --task 0 # single task
python3 inference.py # all 5 tasksEnvironment Variables
Security (OWASP Top 10:2025)
- A01: Optional API_KEY auth middleware
- A02: Swagger UI disabled in production
- A03:
extra="forbid"on all request models;new_contentmax 128KB - A04: Credentials from env vars only, never logged
- A05:
file_to_editis a PydanticLiteral— no injection possible - A09: Structured logging; opaque error IDs in HTTP 500s
- A10: Internal details never exposed to clients
- ASI04: Compiler output sanitised before LLM prompt embedding
AIDLC Workflow Integration
This environment follows AWS AIDLC principles:
- Adaptive difficulty: 5 tasks from Easy to Expert, each requiring different strategies
- Quality gates: Partial reward at each step; warning detection as a final quality check
- Structured audit logging: AIDLC-compliant
[START]/[STEP]/[END]stdout format - Content validation: Agent edits are validated (max length, null bytes, Pydantic typing) before application
