Spaces:
Sleeping
Sleeping
databoysu commited on
Commit ·
33ef871
1
Parent(s): 1dfb089
local test
Browse filesFiles changed (14)
- .dockerignoreAdded+32
- .gitignore+9-3
- .hfignoreAdded+35
- CLAUDE.md+119-312
- __pycache__/__init__.cpython-312.pyc
- __pycache__/client.cpython-312.pyc
- __pycache__/context.cpython-312.pyc
- __pycache__/environment.cpython-312.pyc
- __pycache__/models.cpython-312.pyc
- __pycache__/sandbox.cpython-312.pyc
- __pycache__/tasks.cpython-312.pyc
- inference.py+4-4
- models.py+42-29
- server/__pycache__/__init__.cpython-312.pyc
1234567891011121314151617181920212223242526272829303132# Local dev / VCS.git.gitignore.hfignore
# Python__pycache__/*.pyc*.pyo.venv/.pytest_cache/.mypy_cache/*.egg-info/
# Node / toolingnode_modules/
# Secrets / local config.env.env.*
# Outputsoutputs/*.log
.agent/.agents/.github/
CLAUDE.mdpackage.jsonpackage-lock.json121234566789101112.venv.agents.venv/.agents/.envuv.lockclaude.md__pycache__/__pycache__/_pycache_/node_modules/package.jsonpackage-lock.json.github/.agent/1234567891011121314151617181920212223242526272829303132333435# Python/cache__pycache__/*.pyc*.pyo*.pyd
# Virtual envs / local tooling.venv/.agents/node_modules/.agent/
# Local secrets/config.env.env.*
# VCS and editor noise.git/.gitignore.DS_Store.idea/.vscode/CLAUDE.md
# Build / generated artifacts*.egg-info/dist/build/.pytest_cache/.mypy_cache/
# Local outputs/logsoutputs/*.log.github/1123345567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971986720020120289101112131415162041718206192020820921021121222324252627282930312133233215343536373839402174142219220221222434422445464748495051226525322854555657585960616223023123223323423563642376566676869239707124172737475762432442452462472482497778251252798081828384254858625625725887882602612622632642658990919226726826993942719596273979827599100101102277103104279105106107108109281110111283284285286287112113114115116117118119120289121122291123124293125126127128295129130297298131132133300134135302303304305306136137308138139140141142143310311144145313314315316317318319320321146147148149150323151152325153154155156157327328329330331332333158159335336337338339340341342343344345346347348349350351352353354355356160161162163# CLAUDE.md — TraceFix-RL# CLAUDE.md - TraceFix-RL (RL_ENV_FINAL)
Codebase knowledge for AI assistants. Read before making changes.Current, code-backed notes for assistants working in this repository.Last updated: 2026-04-08
**Phase status:**- Phase 1 — REPLACE_LINES action space ✅- Phase 1B — Hackathon compliance (clamper + inference.py) ✅- Phase 2 — Mini-Git (UNDO_EDIT + RESET_TO_ORIGINAL) ✅- Phase 3 — Curriculum learning + static task registry ✅- Phase 4 — Constrained decoding + Chain-of-Thought + "Reasoning Model" support ✅
---
## File Map
```models.py ← Pydantic v1 schema (action + observation spaces)tasks.py ← Static task registry (16 hardcoded curated tasks)sandbox.py ← Isolated multiprocessing executorenvironment.py ← RL state machine (reset/step/reward/clamping/curriculum)context.py ← ±10-line localized view around last editserver.py ← FastAPI WebSocket + HTTP serverinference.py ← Hackathon baseline agent (OpenAI client)openenv.yaml ← OpenEnv metadata (validate-submission.sh)Dockerfile ← 2-stage HuggingFace Spaces build (production)requirements.txt
── Offline tools (NOT in Docker image) ────────────────────────────────────mutation_engine.py ← Bug injection operators — run locally to generate tasksdataset_generator.py← Validate + build task dicts from base solutions```
**Critical:** `mutation_engine.py` and `dataset_generator.py` are **not copied into the Docker image**. They are local data-science tools only. `tasks.py` must not import them.
---
## `models.py`
- **Pydantic v1** (`pydantic==1.10.17`). Never upgrade — `.dict()`, `.parse_raw()`, `.json()`, `@validator` are v1 APIs used everywhere.- `ActionType`: exactly **6** strings — `"VIEW_CODE"`, `"RUN_TESTS"`, `"REPLACE_LINES"`, `"UNDO_EDIT"`, `"RESET_TO_ORIGINAL"`, `"SUBMIT"`.- `CodeAction(extra="forbid")` — any extra JSON key raises `ValidationError`.
### CodeAction fields
| Field | Type | Required for ||---|---|---|| `thought` | `Optional[str]` | Always (Chain-of-thought scratchpad) || `action_type` | `ActionType` | always || `start_line` | `Optional[int]` (ge=1) | `REPLACE_LINES` || `end_line` | `Optional[int]` (ge=1) | `REPLACE_LINES` || `new_code_block` | `Optional[str]` | `REPLACE_LINES` |
No extra fields for `UNDO_EDIT` or `RESET_TO_ORIGINAL`.
### CodeObservation key fields
| Field | Notes ||---|---|| `code_lines: List[str]` | Complete current source (authoritative) || `localized_context: str` | ±10 lines around last edit; empty until first REPLACE_LINES || `last_execution_output: str` | Tail of stdout+stderr from last RUN_TESTS/SUBMIT || `syntax_error: bool` | `ast.parse()` check, updated every step || `test_results: List[TestResult]` | Per-test pass/fail + error_message || `step_count / steps_remaining` | Progress vs MAX_STEPS=50 || `reward_last_step: float` | Per-step RL signal || `done: bool` | Episode ended || `info: dict` | `episode_id`, `task_name`, `task_difficulty` |
---
## `tasks.py` — Static Registry
**This file is a dumb registry.** It contains only hardcoded dicts — no imports from `mutation_engine` or `dataset_generator`. Zero cold-start cost; fully deterministic for evaluators.
To add new tasks: run `mutation_engine.py` + `dataset_generator.py` locally, curate the best outputs, paste them in as hardcoded dicts.
### Exported symbols
| Symbol | Type | Description ||---|---|---|| `TASKS_BY_DIFFICULTY` | `Dict[str, List[Dict]]` | Tasks grouped by difficulty tier || `ALL_TASKS` | `List[Dict]` | Flat list of all tasks (for random sampling) |
**Current registry size:** `easy=4`, `medium=6`, `hard=6` → 16 tasks total.
### Task dict schema
```python{ "name": str, # e.g. "binary_search_off_by_one" "description": str, "code": List[str], # buggy version, lines without trailing \n "solution": List[str], # correct version "tests": List[Callable],# accept (namespace_dict), raise AssertionError "difficulty": str, # "easy" | "medium" | "hard" "bug_type": str, # e.g. "wrong_operator" or "logic_inversion"}```
### Task catalogue
| Name | Bug | Difficulty ||---|---|---|| `sum_even_wrong_condition` | `!= 0` instead of `== 0` | easy || `sum_even_missing_accumulator` | `-=` instead of `+=` | easy || `reverse_string_wrong_step` | `[::-2]` instead of `[::-1]` | easy || `reverse_string_returns_original` | `[::1]` instead of `[::-1]` | easy || `binary_search_off_by_one` | `right = len(arr)` instead of `len(arr)-1` | medium || `binary_search_wrong_mid` | `left + right` instead of `(left + right) // 2` | medium || `flatten_missing_recursion` | `append` instead of `extend(flatten(item))` | medium || `flatten_inverted_branch` | `not isinstance` inverts the recursive branch | medium || `word_count_no_lower` | missing `text = text.lower()` | medium || `word_count_no_punct_strip` | missing punctuation stripping | medium || `lru_cache_wrong_eviction` | `pop(-1)` instead of `pop(0)` — evicts MRU | hard || `lru_cache_no_promotion` | `get()` doesn't move key to most-recently-used | hard || `valid_parentheses_wrong_mapping` | all three bracket mappings are wrong | hard || `valid_parentheses_no_empty_check` | missing `not stack or` guard before `pop()` | hard || `merge_intervals_strict_overlap` | `<` instead of `<=` — touching intervals not merged | hard || `merge_intervals_missing_sort` | missing `intervals.sort()` | hard |
---
## `environment.py`
### Interface```pythonobs, system_prompt = env.reset()obs, reward, done, info = env.step(action: CodeAction)```
### Reward constants```pythonR_STEP_COST = -0.01 # every step (RL signal only)R_RUN_TESTS = +0.10R_PER_NEW_PASS = +0.05 # per newly passing testR_INVALID_LINE = -0.02R_SYNTAX_ERROR = -0.10 # inside _act_run_tests on syntax failureR_UNDO_RESET = -0.10 # UNDO_EDIT and RESET_TO_ORIGINALMAX_STEPS = 50```
### Episode state (ALL reset in `reset()`)
- **System Prompt**: Enforces SOP (Standard Operating Procedure: ORIENT → DIAGNOSE → FIX → VERIFY → REPEAT → SUBMIT) and strictly forbids consecutive `VIEW_CODE` calls.
| Field | Description ||---|---|| `_code_lines` | Working copy of buggy code || `_task` | Current task dict || `_step_count` | Steps this episode || `_prev_pass_count` | Test passes at last RUN_TESTS || `_last_test_results` | From last RUN_TESTS/SUBMIT || `_last_output` | Text output for observation || `_last_edited_line` | 1-indexed anchor for context.py || `_episode_id` | 8-char UUID prefix || `_done` | Episode finished || `_cumulative_reward` | Sum of all step rewards || `_accumulated_step_costs` | `count × 0.01` — used by hackathon clamper || `_original_code` | Deep copy of episode-start code; never mutated || `_edit_history` | Stack of `List[str]` snapshots; one pushed before each REPLACE_LINES |
`training_step: int = 0` — **not reset by `reset()`**. Persists across episodes. Set externally by trainer.
### `_sample_task()` — Evaluation-safe curriculum sampler
Priority order:
1. **`task_override=dict`** → return it directly (eval/test pinning)2. **`training_step == 0`** → random pick from `ALL_TASKS` ← **judge-safe default** - The Meta evaluator calls `reset()` without setting `training_step`, so this must not crash or bias to one bucket3. **`training_step > 0`** → curriculum bucketing: - `< 1000` → easy - `1000 – 4999` → medium - `>= 5000` → hard - Falls back to any non-empty bucket if the target is empty
### Action handlers
| Method | Delta reward | Key behavior ||---|---|---|| `_act_view_code()` | 0.0 | Sets `_last_output` with numbered source || `_act_run_tests()` | `R_RUN_TESTS` ± syntax ± new passes | Updates `_prev_pass_count` || `_act_replace_lines(s, e, block)` | 0.0 or `R_INVALID_LINE` | Snapshots before mutating; slice assign; anchor = end of new block; blocks deletion of >5 lines (`R_DESTRUCTIVE_PENALTY`) || `_act_undo_edit()` | `R_UNDO_RESET` (-0.10) | Pops `_edit_history`; sets `_last_edited_line = None` || `_act_reset_to_original()` | `R_UNDO_RESET` (-0.10) | Restores `_original_code`; clears `_edit_history`; sets `_last_edited_line = None` || `_act_submit()` | clamped [0.0, 1.0] | Hackathon score formula |
**Action Penalties**:- **Anti-Loop**: `step()` applies an escalating `-0.05 * n` penalty if the agent chooses the exact same `action_type` repeatedly.- **Escape Hatch Rule**: The prompt explicitly warns against manual space-fixing on syntax/indent errors, directing the agent to use `UNDO_EDIT` or `RESET_TO_ORIGINAL`.
### Hackathon Reward Clamper (`_act_submit` & Timeout)
```pythonproportion = passes / total # 0.0 on syntax errorraw_score = proportion - self._accumulated_step_costsfinal_score = max(0.0, min(1.0, raw_score))```## Project Status Snapshot
- **Deterministic Evaluation**: Floor ≥0.0 and <=1.0 guaranteed.- **Trigger**: Runs on `SUBMIT` **or** when hitting `MAX_STEPS` timeout. Never trusts the LLM to call `SUBMIT`.- Stored in `info["final_score"]` when `done=True`.- Repo: `code_reasoner_rl_env`- Branch: `master`- Working tree: dirty - Modified: `.gitignore`, `inference.py`, `models.py`, `__pycache__/models.cpython-312.pyc` - Untracked: `.hfignore`- Last recorded pre-validation command in terminal: - `./pre-val.sh https://sus-human-tracefix-rl.hf.space .` - Exit code: `1`
---This file describes the current implementation in `RL_ENV_FINAL` only.
## `context.py`## High-Level Architecture
`get_localized_context(code_lines, anchor_line, window=10) -> str`- Returns `""` if `anchor_line is None` or `code_lines` is empty.- Uses `len(code_lines)` dynamically — handles REPLACE_LINES growth/shrink correctly.- Hard cap: `MAX_CONTEXT_CHARS = 2_000`.- `environment.py`: core gym-style state machine (`TraceFixRLGym`)- `server/tracefix_rl_environment.py`: OpenEnv adapter (`Environment` interface)- `server/app.py`: FastAPI app creation and uvicorn entrypoint- `models.py`: action/observation schemas (`CodeAction`, `CodeObservation`, `TestResult`)- `sandbox.py`: isolated code execution + test running + timeout handling- `tasks.py`: static task registry (easy/medium/hard)- `context.py`: localized context windowing around last edit- `client.py`: typed OpenEnv client (`TraceFixRLEnv` / `MyEnv`)- `inference.py`: baseline agent runner with OpenAI-compatible API- `openenv.yaml`: OpenEnv runtime metadata (`app: server.app:app`, `port: 7860`)
---## Runtime and Entry Points
## `sandbox.py`- Local server via project script: - `uv run --project . server`- Container command in `Dockerfile`: - `uvicorn server.app:app --host 0.0.0.0 --port 7860`- OpenEnv spec points to: - `server.app:app`
`run_code_with_tests(source: str, callables, timeout=5) -> (output_str, List[TestResult], had_syntax_error)`## Environment Behavior (`environment.py`)
- **Always a 3-tuple.** Never access as an object (no `.all_pass`, no `.test_results`).- `source` must be a `str` — call `"\n".join(code_lines)` before passing.- Isolation: `multiprocessing.Process`, SIGTERM → SIGKILL on timeout.- Output tail-truncated to `MAX_OUTPUT_CHARS = 1_000`.Action space:
---- `VIEW_CODE`- `RUN_TESTS`- `REPLACE_LINES`- `UNDO_EDIT`- `RESET_TO_ORIGINAL`- `SUBMIT`
## `server.py`Reward constants currently defined:
FastAPI WebSocket layer. Port: `os.environ.get("PORT", 7860)`.- `R_STEP_COST = -0.01`- `R_RUN_TESTS = +0.10`- `R_PER_NEW_PASS = +0.05`- `R_SYNTAX_ERROR = -0.10`- `R_INVALID_LINE = -0.02`- `R_DESTRUCTIVE_PENALTY = -0.20`- `R_UNDO_RESET = -0.10`- `MAX_STEPS = 50`
| Endpoint | Notes ||---|---|| `GET /health` | Liveness probe || `GET /info` | Env metadata + `CodeAction.schema()` || `POST /reset` | Stateless, new env per request || `WS /ws` | Primary RL channel — auto-resets on `done=True`. Append `?difficulty=easy|medium|hard` to set tier. |Episode internals include:
---- code snapshotting (`_original_code`, `_edit_history`)- anti-loop penalty for repeated identical `action_type`- contextual anchor (`_last_edited_line`) for localized context- cumulative step-cost tracking (`_accumulated_step_costs`)
## `inference.py`Submit scoring model:
Config from `os.getenv`:- `proportion = passing_tests / total_tests` (or `0` on syntax error)- `raw_score = proportion - _accumulated_step_costs`- `final_score = clamp(raw_score, 0.0, 1.0)`- same clamp model used on max-step timeout auto-evaluation
| Variable | Default | Notes ||---|---|---|| `API_BASE_URL` | `https://api.openai.com/v1` | OpenEnv compatible proxy URL || `MODEL_NAME` | `gpt-4o` | Robust fallback model if missing || `HF_TOKEN` | `""` | Optional HuggingFace Token || `ENV_WS_URL` | `ws://localhost:7860/ws` | Connecting environment URL || `DEBUG_LOG` | `0` | Set to `1` to print raw LLM output |Task sampling policy:
**CLI Flags:**- `python inference.py --easy` (or `--medium`, `--hard`) appends `?difficulty=...` parameter to the WS URL to override `training_step` bucketing.- `training_step == 0`: random from `ALL_TASKS`- `< 1000`: easy- `< 5000`: medium- `>= 5000`: hard- fallback to first non-empty bucket
### Decoding & Fallbacks## Schema Notes (`models.py`)
- **Structured Output**: Uses `json_schema` protocol with strict `CodeAction` forcing `thought` generation before `action_type`.- **Reasoning Models**: Directly parses `.model_dump()["reasoning_content"]` if `content` is empty (e.g. DeepSeek-R1 / Nemotron in LM Studio).- **Mask-Free Parser**: Invalid JSON explicitly returns `PARSE_ERROR` to the server (preventing silent `VIEW_CODE` loops), forcing LLM self-correction.Important: current code uses Pydantic v2-style validation APIs.
**Exact stdout log format (regex-parsed by validation judge):**```[START] task=<task_name> env=TraceFixRL model=<model_name>[STEP] step=<n> action=<action_type> reward=<r.rr> done=<true|false> error=<msg|null>[END] success=<true|false> steps=<n> score=<s.sss> rewards=<r1,r2,...,rn>```- `CodeAction` uses `@model_validator(mode="before")`- Non-`REPLACE_LINES` actions force `start_line`, `end_line`, `new_code_block` to `None`- `REPLACE_LINES` enforces required fields and 1-indexed positive range constraints
- `reward` → `:.2f`; `done` → lowercase; `error` → `"null"` on success.- `score` → `:.3f` — pulled from `info["final_score"]` (the clamped [0,1] value).- `rewards` → comma-separated, no spaces.This is not compatible with Pydantic v1-only assumptions.
---## Sandbox Notes (`sandbox.py`)
## `openenv.yaml``run_code_with_tests(...)` returns a strict 3-tuple:
Consumed by `openenv validate` step in `validate-submission.sh`.- `output_str`- `List[TestResult>`- `had_syntax_error: bool`
Key fields: `reward_range: [0.0, 1.0]`, `inference_script: inference.py`, `websocket_path: /ws`, `port: 7860`.Execution safeguards:
---- subprocess isolation via `multiprocessing.Process`- timeout terminate/kill path- tail truncation (`MAX_OUTPUT_CHARS = 1000`)- restricted builtins to block risky operations
## `Dockerfile`## Tasks Registry (`tasks.py`)
Two-stage build. Runtime COPY (all with `--chown=appuser:appuser`):```models.py environment.py sandbox.py tasks.pyserver.py context.py inference.py```- Static hardcoded registry grouped by difficulty- Exports: - `TASKS_BY_DIFFICULTY` - `ALL_TASKS`- Expected total currently: 16 tasks - easy: 4 - medium: 6 - hard: 6
**`mutation_engine.py` and `dataset_generator.py` are NOT copied.** They are offline tools.## OpenEnv Adapter and Client
---`server/tracefix_rl_environment.py`:
## Offline Tools (local only)- Maps optional reset difficulty to `training_step` hints- Writes `system_prompt` into observation metadata- Sets observation reward/done from gym step output
### `mutation_engine.py``client.py`:
`MutationEngine(seed).mutate(code_lines, difficulty, max_attempts=10)`→ `(List[str], {"bug_type": str, "num_bugs": int})` or `(None, None)`- Sends actions using `model_dump(exclude_none=True)`- Parses OpenEnv payloads into typed `CodeObservation`
Operator sets:## Inference Runner (`inference.py`)
| Difficulty | Operators ||---|---|| easy | `_var_name_error`, `_wrong_operator` || medium | easy + `_off_by_one`, `_logic_inversion`, `_index_error` || hard | medium + `_mutable_default`, `_remove_return`, `_wrong_function_call` |Key defaults:
### `dataset_generator.py`- `API_BASE_URL = https://router.huggingface.co/v1`- `MODEL_NAME = Qwen/Qwen2.5-72B-Instruct`- `MAX_STEPS = 50`- `SUCCESS_SCORE_THRESHOLD = 0.99`- `THINKING_TOKEN_LIMIT = 512`
`validate_task(original, mutated, tests)` — original must pass all tests; mutated must fail ≥ 1.`generate_task(base_task, mutator)` — calls mutate + validate; returns task dict or `None`.Behavior:
**Workflow to add new tasks:**```bashpython -c "from mutation_engine import MutationEnginefrom dataset_generator import generate_task# define base_task with solution + tests# run generate_task, inspect output, paste into tasks.py"```- Logs in strict sequence: `[START]`, repeated `[STEP]`, then `[END]`- Uses JSON extraction fallback path from model text- Falls back to `RUN_TESTS` on parse or validation failure- Supports `--easy`, `--medium`, `--hard`, `--debug`
---## Drift and Risk Notes
## Dependencies1. `requirements.txt` currently pins `pydantic==1.10.17`, but code in `models.py` uses v2 APIs (`model_validator`).2. `pyproject.toml` is the active dependency source for `uv sync`; `requirements.txt` appears stale relative to runtime assumptions.3. `environment.py` defines `R_SUBMIT_ALL_PASS` and `R_SUBMIT_FAIL`, but submit currently uses clamped proportion-minus-step-cost scoring instead of those constants.4. `server/tracefix_rl_environment.py` advertises concurrent sessions support, while `create_app(..., max_concurrent_envs=1)` constrains server-level concurrency.
```fastapi==0.111.0uvicorn[standard]==0.30.1pydantic==1.10.17 ← v1 ONLYwebsockets==12.0openai>=1.30.0 ← inference.py only```## Practical Checklist Before Validation
IDE lint warnings for these packages are expected false-positives — they live in Docker, not system Python.
---
## Invariants
1. **Pydantic v1 only.** Never upgrade.2. **1-indexed lines in public API**; 0-indexed in `_code_lines`.3. `reset()` wipes every mutable field including `_accumulated_step_costs`, `_original_code`, `_edit_history`. `training_step` is NOT reset.4. Reward delta model — handlers return delta; `R_STEP_COST` applied once per step before routing.5. REPLACE_LINES anchor = `min(start + len(new_lines) - 1, file_length)`.6. SUBMIT reward clamped `[0.0, 1.0]` — this is the grader score. Floor guaranteed ≥ 0.0.7. `_act_run_tests()` updates `_prev_pass_count`; `_act_submit()` does not.8. Task `code` strings have no trailing `\n`; `_source()` joins with `\n`.9. `context.py` is already fully dynamic — no changes needed for REPLACE_LINES growth/shrink.10. Output truncation is **tail-based** (end of traceback = actionable info).11. **Mini-Git snapshot timing**: snapshot pushed **before** slice assignment. Rejected edits (OOB, inverted range) produce no snapshot.12. **Context desync invariant**: Both rollback handlers set `_last_edited_line = None`. Without this, `context.py` anchors to a ghost line after revert.13. **`_original_code` is immutable**: set once in `reset()`, only read in `_act_reset_to_original()`.14. **`sandbox.run_code_with_tests` returns a 3-tuple**: `(output_str, List[TestResult], had_syntax_error)`. Never treat as object.15. **`tasks.py` must not import `mutation_engine` or `dataset_generator`**: those are offline tools not in the Docker image.16. **`training_step == 0` → random from ALL_TASKS**: the judge calls `reset()` with default `training_step=0`, so this path must work correctly and not bias to one difficulty bucket.1. Confirm dependency source of truth (`pyproject.toml` vs `requirements.txt`) and align Pydantic version expectations.2. Re-run pre-validation and capture the first failing check/output.3. Remove tracked cache artifacts from version control if unintended (for example `__pycache__/*.pyc`).4. Keep stdout format in `inference.py` unchanged, as validator parsing depends on it.35 unmodified lines363738394041423940414243444535 unmodified lines from models import CodeAction
API_BASE_URL = os.getenv("API_BASE_URL", "https://router.huggingface.co/v1")MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-72B-Instruct")HF_TOKEN = os.getenv("HF_TOKEN", "")LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME", "")API_BASE_URL = os.getenv("API_BASE_URL", "http://localhost:1234/v1")MODEL_NAME = os.getenv("MODEL_NAME", "nvidia/nemotron-3-nano-4b")HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("API_KEY") or "lm-studio"LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME")
ENV_BASE_URL = os.getenv("ENV_BASE_URL", "http://localhost:7860")TASK_NAME = os.getenv("TASK_NAME", "tracefix_rl")4 unmodified lines567889101121 unmodified lines33343536363738394041424344454647383940414243444546495051525354555647484950515253545556575859606162636465666768695870716072736274756476777867686970717980818283848586874 unmodified linesfrom typing import Any, Dict, List, Literal, Optional
from openenv.core.env_server.types import Action, Observationfrom pydantic import BaseModel, Field, field_validator, model_validatorfrom pydantic import BaseModel, Field, model_validator
ActionType = Literal[21 unmodified lines end_line: Optional[int] = Field(default=None) new_code_block: Optional[str] = Field(default=None)
@field_validator("start_line", "end_line", mode="before") @model_validator(mode="before") @classmethod def _coerce_optional_int(cls, value: Any) -> Optional[int]: if value is None: return None if isinstance(value, str): raw = value.strip() if raw == "": return None try: return int(raw) except ValueError: def validate_and_normalize(cls, data: Any) -> Any: if not isinstance(data, dict): return data
action_type = data.get("action_type")
def _coerce_optional_int(value: Any) -> Optional[int]: if value is None: return None if isinstance(value, int): return value return None
@model_validator(mode="after") def validate_replace_fields(self) -> "CodeAction": if self.action_type == "REPLACE_LINES": if self.start_line is None: if isinstance(value, int): return value if isinstance(value, str): raw = value.strip() if raw == "": return None try: return int(raw) except ValueError: return None return None
data = dict(data) data["start_line"] = _coerce_optional_int(data.get("start_line")) data["end_line"] = _coerce_optional_int(data.get("end_line"))
if action_type == "REPLACE_LINES": start_line = data.get("start_line") end_line = data.get("end_line") new_code_block = data.get("new_code_block")
if start_line is None: raise ValueError("REPLACE_LINES requires start_line.") if self.end_line is None: if end_line is None: raise ValueError("REPLACE_LINES requires end_line.") if self.new_code_block is None: if new_code_block is None: raise ValueError("REPLACE_LINES requires new_code_block.") if self.start_line < 1 or self.end_line < 1: if start_line < 1 or end_line < 1: raise ValueError("REPLACE_LINES requires start_line and end_line >= 1.") if self.start_line > self.end_line: if start_line > end_line: raise ValueError("REPLACE_LINES requires start_line <= end_line.") else: # Ignore extra form fields for non-edit actions (web UI often sends defaults). self.start_line = None self.end_line = None self.new_code_block = None return self # Web UI often sends default line fields for non-edit actions. data["start_line"] = None data["end_line"] = None data["new_code_block"] = None
return data
class TestResult(BaseModel):.dockerignoreAdded+32
.gitignore+9-3
.hfignoreAdded+35
CLAUDE.md+119-312
__pycache__/__init__.cpython-312.pyc
__pycache__/client.cpython-312.pyc
__pycache__/context.cpython-312.pyc
__pycache__/environment.cpython-312.pyc
__pycache__/models.cpython-312.pyc
__pycache__/sandbox.cpython-312.pyc
__pycache__/tasks.cpython-312.pyc
inference.py+4-4
models.py+42-29
server/__pycache__/__init__.cpython-312.pyc