Building long-horizon SWE environments on Hugging Face: Frontier SWE × OpenEnv
By the-thing: we packaged and adapted 4 FrontierSWE tasks as OpenEnv-shaped services, pushed them to Hugging Face Spaces, and ran an offline RL-style training loop with public datasets, Trackio metrics, and a trainer Space.
TL;DR
- Four Dockerized environments (notebook compression, Postgres wire adapter on SQLite, dependent type checker, libexpat → x86-64 asm) with a shared Gym-style API and MCP tools for planning and submission.
- Custom harness adapter built on top of OpenEnv harness work (meta-pytorch/OpenEnv PR #389 and RFC005), then forked and extended in
rycerzes/OpenEnvonfeature/pi-harness-adapter. - Composite rubric: gates → L1 (tests /
reward.json/ regex ratios) → optional LLM layers → episode reward you can log and filter on for training. - Offline pipeline: trajectories on the Hub → hindsight scoring (SGLang) → HCAPO-style dataset → LoRA fine-tune on a GPU Space, with Trackio curves for loss, LR, and gradient norms.
Try it: frontier-swe-postgres · frontier-swe-notebook · frontier-swe-type-checker · frontier-swe-libexpat-to-x86asm · source on GitHub
Spaces & Model
All public artifacts from this project live under the rycerzes namespace on Hugging Face.
Environment Spaces
These are the four Dockerized task environments, each exposing the shared OpenEnv HTTP/WebSocket API and MCP tool surface. All are running and publicly accessible.
| Space | Full name (on Hub) | Task |
|---|---|---|
| frontier-swe-postgres | Frontier SWE — Postgres SQLite Wire Adapter | Implement a Postgres wire-protocol adapter backed by SQLite; scored by wire-compatibility tests |
| frontier-swe-notebook | Frontier SWE — Notebook Compression | Losslessly compress and round-trip Jupyter notebooks; scored via reward.json fields |
| frontier-swe-type-checker | Frontier SWE — Dependent Type Checker | Build a dependent type checker; scored by reward_json_score with anchored rubric |
| frontier-swe-libexpat-to-x86asm | Frontier SWE — libexpat to x86-64 Assembly | Translate libexpat parsing logic to hand-written x86-64 assembly; scored by assembly benchmarks |
Each Space is a self-contained Docker image. The agent connects via WebSocket, calls reset / step / state, and optionally invokes MCP tools (submit_plan, submit_subtask, get_status, advance) to earn a dense episode reward.
Metrics Space
| Space | Full name (on Hub) | Role |
|---|---|---|
| trackio | Trackio | Live training dashboard — streams loss, learning rate, gradient norm, epoch, and global step curves from the LoRA fine-tune run |
Datasets
| Dataset | Role |
|---|---|
rycerzes/fswe-pg-01-traj-q36-27b |
Raw trajectory logs per episode (result.json, sessions, logs, hindsight when present) collected with Qwen 3.6 27B on the Postgres task |
rycerzes/fswe-hcapo-pg-01-trajectories |
Step-level HCAPO training JSONL — per-step advantages, assistant masks, and step weights derived from the trajectories above |
Fine-tuned Model
| Model | Description |
|---|---|
rycerzes/fswe-hcapo-pg-01-qwen36-27b |
LoRA adapter fine-tuned on top of Qwen 3.6 27B using the HCAPO dataset from the Postgres task. Trained with weighted cross-entropy on assistant tokens only, chunked forward passes for memory efficiency, and Trackio reporting. This is the policy produced by the offline RL loop described in Section 3 and Section 4 below. |
1. Environment innovation - why this setup is hard (and worth it)
Classic coding benchmarks often score a single patch. Long-horizon software engineering is different: the agent has to plan, edit a real workspace, call tools, and submit work over many steps-closer to how people ship systems than to a one-shot fix.
What we built on top of that idea
We did not reinvent the underlying FrontierSWE task specs; we re-homed them inside a uniform environment contract:
That includes a custom harness adapter layer we built on top of meta-pytorch/OpenEnv PR #389 and RFC005, then maintained and updated in our fork: rycerzes/OpenEnv feature/pi-harness-adapter.
| Piece | What it does for the agent |
|---|---|
| HTTP control | reset / step / state / health - same shape every task, so harnesses and demos do not fork per domain. Maintaining the openenv specs |
| MCP tools | submit_plan, submit_subtask, get_status, advance - forces explicit decomposition and scored subtasks, not a single anonymous blob of edits. |
| Multi-layer rubric | Gates catch broken builds or missing artifacts early; L1 is task-native (wire compat tests, notebook round-trips, type-checker scores, assembly benchmarks); L2/L3 optionally add LLM code and plan review when grader env vars are set; episode reward blends plan quality, frozen subtask scores, completion, and tool usage. |
That combination is deliberately stressful in a good way: the agent must coordinate (plan → execute → advance), respect verifier reality (hidden tests, anti-cheat), and earn a dense scalar at the end of an episode that can run on the order of 45–90+ minutes per run-so the environment is challenging, creative in how it composes rubrics, and meaningful for measuring behavior beyond single-turn chat.
1a. Harness adapter lineage (RFC005 + pi)
This project does not treat the coding agent as just another external HTTP caller. Instead, the agent runs as a harness process inside the task container, and OpenEnv drives that process turn-by-turn.
The adapter path used here:
1. RFC005 (OpenEnv harness RFC) — Defines the harness architecture and contracts: typed harness config/events/actions, adapter lifecycle (start / stop / send_message), transport modes (stdio, Streamable HTTP, MCP), and multi-turn reset / step semantics via HarnessEnvironment.
2. OpenEnv PR #389 — Implements the RFC005 foundation and harness environment flow (including adapter abstractions and concrete adapter work) that this repo builds on: meta-pytorch/OpenEnv#389.
3. Fork + updates for pi — We forked and extended that line in rycerzes/OpenEnv feature/pi-harness-adapter to run pi robustly in long-horizon SWE episodes — for example: dedicated harness event loop ownership, larger subprocess output buffering, and container integration tests.
Why pi
We chose pi because the pi-mono/coding-agent loop is the most minimal agent loop we have seen in practice (only a small number of core files), which keeps the harness surface area easy to reason about. In our Frontier SWE runs, that simplicity has translated into practical wins:
- Token efficiency: best token economics among the harnesses we tested, including high prompt-cache hit rates and low tokens per session.
- Operational simplicity: the smallest control loop to integrate and debug.
- Reliability: fewer moving parts have produced the lowest harness-level bug rate in our sessions.
2. The problem, the box, and what the agent actually does
Problem. Training or evaluating agents on real long-horizon SWE needs a repeatable service: same ports, same instructions, same scoring, same tool surface-whether you run locally, in CI, or on the Hub.
Our box. frontier-swe-openenv is a small monorepo: tasks/<task-id>/ holds instructions and verifiers (what "correct" means operationally); frontier_swe_env/ holds the FastAPI server, shared rubrics, and TaskConfig (how to invoke those verifiers inside the image); spaces/ holds thin Space definitions synced from main after images build.
Agent behavior (easy to follow for a demo).
- Connect (WebSocket client or baseline script).
reset→ read observation / phase.- Loop: natural language or tool use →
step→ optional MCP calls to submit a plan, run L1+L2 on a subtask, advance when satisfied. - Episode ends with a terminal episode reward and subtask history you can log.
For a concrete walkthrough without writing your own client, the repo ships scripts/run_baseline.py: point it at http://localhost:8000 with a task container running, and you get a full reset → step episode over the wire-good for recordings and "here is one turn of the loop" explanations.
3. Observable training progress - rewards, curves
Long episodes make online RL on the live env impractical at scale, so we invested in offline learning: collect once, score offline, fine-tune, log everything.
Public artifacts (HF-native story)
| Artifact | Link | Role in the demo |
|---|---|---|
| Raw trajectories (pg-01, Qwen 3.6 27B) | rycerzes/fswe-pg-01-traj-q36-27b |
Shows what we logged per episode (result.json, sessions, logs, hindsight when present). |
| HCAPO training JSONL | rycerzes/fswe-hcapo-pg-01-trajectories |
Step-level advantages paired with messages for supervised fine-tuning. |
| Fine-tuned model | rycerzes/fswe-hcapo-pg-01-qwen36-27b |
LoRA adapter on Qwen 3.6 27B, the policy output of the offline RL loop. |
| Trackio dashboard | rycerzes/trackio |
Observable loss, epoch, learning rate, gradient norm, global step. |
On a 3 epoch / ~18 optimizer step reference run (Space-backed trainer), the root README documents what we see in Trackio: loss trending down on the order of ~25% over the plotted window (smoothed), epoch progressing toward ~2.7, LR warmup-then-decay, gradient norms staying in a moderate band-i.e. a sanity fine-tune where optimization looks stable, not a mystery box.
Before / after. The cleanest before/after we surface in tooling today is training loss and optimization metrics on the HCAPO dataset, plus episode-level rewards inside collected trajectories for analysis. A live A/B rollout score on the full Docker env after LoRA is the natural next chapter for the demo-and the pipeline is set up so you can regenerate trajectories with the adapted policy and compare distributions. For hackathon judging, the curves + public datasets + reproducible launch script are the evidence chain we stand behind right now.
4. Reward logic and training pipeline - coherent signal end to end
Episode reward (macro). The scalar (R) matches EpisodeRubric: weighted plan score, mean frozen subtask scores, completion, and tool density-clipped into [0, 1] for filtering (e.g. --min-reward 0.05 in the dataset builder).
L1 (micro, task-specific). Each task implements its own verifier output: regex ratio on test totals (Postgres), reward_json fields (notebook), or reward_json_score with anchors (type checker, libexpat). Same server code paths; different physics.
Training path (why it should move policy behavior).
collect_trajectories.py- rollouts intotrajectories/episode_NNN/.backfill_rewards.py- repair missingepisode_rewardwhen needed.compute_hindsight_scores.py- SGLang/generatewith bounded logprob windows (memory-safe), MCP-aware step → subtask mapping, hindsight (Q^H) and smoothing.build_hcapo_dataset.py- GRPO-style macro advantages + normalized hindsight micro advantages → JSONL with per-step weights.train_hcapo.py+launch_hf_space.sh- weighted CE on assistant tokens (chunked forward for large models), Trackio reporting → producesrycerzes/fswe-hcapo-pg-01-qwen36-27b.
Coherent design is means that environment reward defines which episodes matter; hindsight defines which tokens inside those episodes get gradient; the trainer respects assistant masks and step weights so the update is not "one scalar smeared across the whole transcript." Details and equations live in training/README.md
Where to go next
- Run a Space from the TL;DR links and narrate one subtask submission end to end.
- Open Trackio to the named run and zoom the loss / LR panel while you talk through the pipeline slide.
- Try the fine-tuned model at
rycerzes/fswe-hcapo-pg-01-qwen36-27band compare rollouts against the base Qwen 3.6 27B policy. - Clone the repo,
uv sync, and use./scripts/launch_hf_space.shwhen you want the full HF training path on your own account.
