Skip to content

LAB 18 / Tools & environments

SWE-GymStart your first Harness RL training run with 1,577 lines of code!

Train Qwen3.5-4B on 240 SWE-Gym tasks with Rondo-RL, using patch test results as GRPO rewards. Compare the base model and two training checkpoints on 15 evaluation tasks.

View code ↗

SWE-Gym + Rondo-RL: your first Harness RL training run with 1,577 lines of code

Code and resources for reproducing the run

I'd wanted to build a lightweight framework for training an agent inside its harness for a while. After looking at NVIDIA's Polar, I wrote Rondo-RL with PyTRIO. For this run I plugged Qwen3.5-4B into Codex, gave it a real GitHub issue and a repository with runnable tests, and let it work on a fix. The test result for its patch supplied the reward for GRPO training.

Codex is the harness here. It maintains the conversation, calls tools and sends their output back to the model. Qwen decides which file to read next or which line to edit, and Codex carries out the action in Docker. Rondo records each model call, scores the final patch with tests and turns the attempt into training data. PyTRIO handles sampling, backpropagation and LoRA weight updates. The next time Codex starts, it uses the freshly updated weights.

In music, a rondo keeps returning to its main theme. That's how I wanted the model to train. It runs a rollout in the environment through its harness, learns from the reward and returns to the environment with an updated policy to try again.

Overview of the training loop

Rondo-RL's core is 1,577 lines of code, roughly 1% of the size of verl or AReaL. That makes it easy to read and extend, including with AI assistance if you want to adapt it for your own experiments. Supported harnesses include Codex, Claude Code, pi, OpenCode and DeepSeek Harness. For this run I used Codex with Qwen3.5-4B and a 256K context window.

01 The training tasks ​

The training tasks come from SWE-Gym. The SkyRL dataset we used contains 293 bug-fixing tasks from Python repositories. We skipped MONAI's 53 tasks because of its large Docker image and used all 240 tasks from the remaining ten repositories. Each task includes the original issue and a Docker image with the repository checked out at the revision where the issue occurred, under /testbed. The model can read the source, edit files and run tests. When it finishes, we collect the patch from its working directory. Dataset · Task preparation script

Take getmoto__moto-7023. A user called deregister_resource on a resource that didn't exist. They expected an EntityNotFoundException and got a KeyError from a Python dictionary. I looked through one Codex trace for this task. It took 16 model calls. The final git diff added just two lines. Original moto issue

moto issue #7021 reports a KeyError when deregistering an unknown ARN. The Codex patch adds two lines and removes none, checking that the resource exists before the original del statement. Rondo runs the patch in a clean container. All nine tests pass and the patch earns a reward of 1.

We drew the test set from the dataset's validation split. It originally contained 23 tasks from repositories that were absent from the training set. We ran the reference patches through the scoring pipeline first. Eight tasks had issues with their container environments and even their reference patches failed to score 1, so we dropped them. The remaining 15 came from four projects, astroid, marshmallow, pydicom and sqlfluff.

02 Training results ​

This GRPO run lasted 60 steps. I evaluated the step-30 and step-60 Qwen3.5-4B checkpoints on the same 15 tasks, with 16 attempts per task. I reused the base model's earlier results on these tasks and included a hy4-flash run through OpenRouter for reference. avg@16 measures the fraction of all 240 attempts that passed. pass@16 measures the fraction of the 15 tasks solved at least once.

Modelavg@16 · passing attemptspass@16 · tasks solved at least once
Qwen3.5-4B · Base13.8% (33/240)40.0% (6/15)
Qwen3.5-4B · step 3025.0% (60/240)60.0% (9/15)
Qwen3.5-4B · step 6031.7% (76/240)60.0% (9/15)
hy4-flash (OpenRouter)89.2% (214/240)100% (15/15)

The three Qwen results alongside hy4-flash. The middle blue bar rises from 25.0% at step 30 to 31.7% at step 60. Both checkpoints score 60.0% on pass@16.

Out of 240 attempts each, the base model produced 33 successful fixes and the final checkpoint produced 76. That's 43 more successful attempts and a gain of 17.9 percentage points in avg@16. In the first 30 steps, the number of tasks solved at least once rose from six to nine. At step 60 the model still solved those same nine tasks, but it passed 16 more attempts across them. In the left panel, the blue avg@16 bar gets taller and the pass@16 bar stays put.

These 60 steps cost 1,822.69 yuan on PyTRIO. The red box in the screenshot shows the bill for this run. Input prefill accounted for 2,667.95M tokens, sampling for 28.12M and training for 66.63M, giving 2,762.70M tokens in total (about 2.76 billion). Of the prefill tokens, 2,378.09M were cache hits, an 89.14% hit rate across input tokens. Codex sends the conversation history with each turn, so much of the prefix can be reused.

PyTRIO usage bill. The red box at the bottom marks the service session and charge for the 60-step run.

If you're learning GRPO with Agentic RL Lab, I'd start by changing steps in examples/swegym_grpo/config.yaml from 60 to 10. You still get four new tasks per step and 16 attempts per task. After ten steps, you'll have 640 attempts across 40 tasks to examine.

An H20-NVLink 96 GB GPU listed at 10.50 yuan per hour in AutoDL's Beijing Zone A.

I estimate Polar RL would take about 40 hours to run 60 steps on eight H20s with these training parameters. At AutoDL's listed rate of 10.50 yuan per GPU-hour, that's 84 yuan an hour for eight cards, or about 3,360 yuan for the run. The catch is actually finding eight H20s to rent at that price.

In the left SwanLab plot, rollout/failed counts how many of each step's 64 sessions ended abnormally. Most of those sessions hit the 50-turn limit. Their patches still went through the tests. The smoothed count generally hovered in the thirties and forties, averaging 37.3 sessions per step over the first 30 steps and 32.4 over the last 30. The right plot shows rollout/reward_mean. A patch can score either 0 or 1 here, so the mean is also the fraction of successful fixes at that step. The tasks change at every step and the individual scores fluctuate, but the smoothed curve is fairly steady. Mean reward rose from 0.573 in the first half to 0.644 in the second.

The 60-step run in SwanLab. The left panel counts sessions that ended abnormally at each step. The right panel shows mean reward per step.

Full training run on SwanLab

I went through the training traces and found 157 tasks with a mix of successful and unsuccessful fixes across the 16 attempts. GRPO subtracts the task's mean reward from each attempt's reward. Successful fixes get positive advantages and unsuccessful ones get negative advantages. If all 16 attempts pass or all 16 fail, the differences are all zero and the task provides no update signal. On the test set, pydicom-1256 went from 4/16 successful fixes at step 30 to 10/16 at step 60. That change goes in the same direction as the modest rise in training reward over the second half.

In the PyTRIO Playground I gave the base model and the final step-60 weights (rondo-step-000059-sampler) the same little question. How many rs are there in strawberry? Both answered three. Both spelled the word out letter by letter and marked all three occurrences. The trained model's reasoning seemed a little more concise, too 🤔

The same question in the PyTRIO Playground, with the base model on the left and the step-60 weights on the right. Both count three r's in strawberry. The page shows 860 and 688 tokens respectively.

After training, I plugged the 4B model into my own Codex setup. The weights were already on PyTRIO. I opened the step-60 sampler, copied the Base URL and Model ID from the OpenAI section, then added my PyTRIO API key.

OpenAI-compatible API settings for the step-60 sampler on the PyTRIO weights page.

I sent it “你好哦~” (“Hey there!”). It replied in three seconds, which felt pretty quick.

The conversation in Codex. The status bar at the bottom shows rondo-step-000059-sampler.

03 · Quick start ​

I put the configuration for this run in examples/swegym_grpo/. The defaults cover 240 tasks in 60 steps. On an x86_64 Linux machine with glibc, install uv, Docker, Node.js 22, and npm. Check that your user can run docker ps. Codex and the patch tests run on this machine. PyTRIO handles model sampling and weight updates. If you're new to PyTRIO, the Lab's setup guide walks you through registering an account. SWE-Gym training example · Agentic RL Lab setup guide

bash
git clone https://github.com/KMnO4-zx/Rondo-RL.git
cd Rondo-RL
uv sync --frozen
uv run trio login
uv run swanlab login  # 用默认的在线模式记录训练曲线
PYTHONPATH=src uv run python -m rondo.harness  # 下载各个 harness 以供训练使用

Next, run prepare.py to prepare the training tasks. It skips the 53 MONAI tasks, writes the remaining 240 to examples/swegym_grpo/tasks.jsonl, and pulls only the images missing from your machine.

bash
docker login  # 可选,使用自己的 Docker Hub 账号拉镜像
uv run --with "swegym @ git+https://github.com/SWE-Gym/SWE-Bench-Package.git@16dd480cce9b27bf111a362d280881c6def5d2a7" \
  python examples/swegym_grpo/prepare.py

To see how the base model fixes bugs, try a single round. With tasks_per_step: 4 in the config, Rondo picks four random training tasks. Passing --sessions 4 gives Codex four independent attempts per task, for 16 attempts in all. This round only generates and scores patches. Section 10 covers how to run the 15 evaluation tasks.

bash
PYTHONPATH=src uv run python -m rondo.rollout examples/swegym_grpo/config.yaml --sessions 4

To train the model, run the following command from the repository root. Rondo starts the gateway and takes four new tasks per step. It runs 16 sessions per task, with up to 32 sessions running concurrently. My 60-step run took 20 hours and 16 minutes.

bash
PYTHONPATH=src uv run python -m rondo.train examples/swegym_grpo/config.yaml

Rondo saves a checkpoint every six steps and records the weight locations in runs/<run timestamp>/checkpoints.jsonl. To see what changed in an attempt, open the step-*/ directory under the same run. It holds the patches, test output, and per-turn logs. The YAML sets the sampling temperature (1.0), the maximum length of a single response (8,192 tokens), and the learning rate (4e-5). For local-only logging, set swanlab.mode to offline and skip the SwanLab login. Example configuration

Let's follow one bug fix from the first file read through the weight update.

04 · How four tasks turn into 64 rollouts ​

Each of four tasks gets 16 independent sessions. Every Codex container sends its model requests through the same Rondo gateway.

Rondo shuffles the 240 tasks once. Each training step takes the next four in order, so one pass takes exactly 60 steps. Each task gets 16 independent Codex sessions, or 4 × 16 = 64 rollouts per step, with at most 32 running on the server at once. Each of the 16 attempts at a given task has its own container and working directory. Even if the first Codex session has already fixed the bug, the second still sees the original file when it opens it.

With all these Codex sessions requesting the model at once, how does the backend know which turns belong to the same attempt? Rondo starts a shared gateway, pytrio_shim, and points the Codex instance in every container at it. The host uses its trio login credentials to access PyTRIO. Inside each container, Codex uses its own session ID as its RONDO_API_KEY. Every model request carries the same ID from the first file read to submission. The gateway samples through PyTRIO and records that turn's input tokens, response tokens, and response logprobs under the session ID. The tools run in each session's own container, and the next request carries their output back. Codex launch configuration · Gateway implementation

05 · What does the gateway record on the first file read? ​

The first model request for the moto task. Memory holds the token IDs and logprobs for training, while the trace log records counts and tool calls.

Back to that KeyError. On the first turn, the model sees the issue, the tool definitions, and the context supplied by Codex, totaling 8,185 input tokens. It generates 102 response tokens, including a tool call asking Codex to run cat moto/lakeformation/models.py. Once the command output comes back into the conversation, the model asks to read moto/lakeformation/exceptions.py on its second turn, looking for the exception the repository already defines.

One detail is easy to miss when reading the logs. In the gateway's Session.requests, the response_tokens field holds a sequence of 102 token IDs. The adjacent logprobs field also has 102 entries, each giving the log probability of the corresponding response token when it was generated. In the *.trace.jsonl file on disk, response_tokens holds just the count, 102. The same line records the original response text, tool name, arguments, and sampling time. That's the file I open when I want to retrace what the model did. At the end of the session, the sequence of IDs goes to trajectory.build along with the records from the other 15 turns. How per-turn traces are written

06 · Once the file is in context, which tokens contribute to training? ​

Two file-read requests are joined at their shared prefix. The logprob and advantage are aligned with the next target token.

The second request includes the original task, the model's tool call asking to read the file, and the file contents that came back. If the start of the second prompt matches “first prompt + first response” token ID for token ID, Rondo keeps one copy of that history and appends the tool output and the newly generated second response. That way, the action that first requested models.py counts once. Comparing token IDs matters because retokenizing the same text can produce a different sequence.

Each trainable chain becomes a Datum, one training example for PyTRIO. The code uses tokens[:-1] as inputs and tokens[1:] as targets, offset by one position. The logprob and advantage at each position line up with the target token the model is asked to predict there.

  • At A₁ → O₀, the target O₀ comes from the file returned by the tool. It stays in the sequence as context for later tokens. The logprob and advantage at this position are both set to zero.
  • At O₁ → A₂, the target A₂ is a response token the model generated after reading the file. Rondo keeps the sampling logprob of A₂ and assigns it the advantage for this attempt. The values −0.5 and +0.75 in the figure are illustrative. How training examples are built

07 · Can turns still be joined after context compaction? ​

Context compaction and subagents can both change the prefix between adjacent requests. One session can split into several training sequences.

If Codex condenses a dozen or so earlier turns into a summary, the next turn starts differently. Rondo compares the tokens in adjacent requests. If the prefixes no longer match, it starts a new chain with the full prompt after compaction. The responses already sampled stay in the old chain. The summary serves as input to the new chain. Only the response generated after the model reads that summary receives training weight.

The right side of the figure shows another case. Suppose a parent agent makes a request, a subagent uses the same session ID to inspect a file, and then the parent makes another request. If the prefixes differ at both handoffs, Rondo produces three chains. The session ID tells Rondo which requests belong to the same repair attempt. The token prefix determines whether two adjacent turns can be joined. All three chains share the final score for that repair. I used multi_agent = false in this Codex run. The right half of the figure illustrates how the framework handles subagent requests.

08 · The patch earned one point. How does that reach all 16 turns? ​

Rondo tests a patch in a clean container, then uses scores from attempts on the same task to compute group-relative advantages.

The two lines left by the moto trajectory are in deregister_resource(). Before deleting the resource, the patch checks whether the ARN exists.

diff
+        if resource_arn not in self.resources:
+            raise EntityNotFound()
         del self.resources[resource_arn]

Codex ran tests inside its own container. For scoring, Rondo starts a clean container from the same image, applies the patch, and runs the task's test script. The scoring container receives only the repository diff, and its own test results determine the score. This task lists one previously failing test that must now pass (FAIL_TO_PASS), plus eight tests that already passed and must continue to pass (PASS_TO_PASS). Every listed test must appear in the output with a status of PASSED or XFAIL to earn one point. A single missing or failing test gives a score of zero. The two-line patch earned one point. Patch scoring implementation

GRPO compares each attempt with the other attempts on the same task. To keep the arithmetic simple, the figure shows four attempts. Their scores are 1, 0, 0, 0, with a mean of 0.25. Rondo computes advantage = reward for this attempt − mean reward for this task. The successful attempt gets +0.75, and the other three each get −0.25. Every model-generated response token in a session shares that value, even if the session splits into two chains. The score gives feedback on the entire patch. It can't tell us how much credit the fifth file read deserves on its own.

The actual configuration runs 16 attempts per task. If all 16 pass or all 16 fail, subtracting the mean gives zero advantage for every attempt, and Rondo skips the update for that group. Two limits also affect scoring differently in practice. If a session reaches 50 model calls, Rondo still scores the patch in the working directory. If the entire harness run times out at 40 minutes, the attempt gets zero.

09 · With sampling logprobs in hand, what does training still compute? ​

Two ways to score a response token. One reuses its sampling logprob and the other recomputes a proximal logprob. Both still need a training forward pass with the current policy.

Take A₂ from the figure in Section 06. Suppose its logprob at generation time was −0.5. PyTRIO's sample_async returns the response tokens along with their individual logprobs, so Rondo writes −0.5 straight into the Datum. Retrieving that old value costs zero additional no-gradient forward passes.

The right side of the figure shows an extra step used by some decoupled training configurations. The trainer freezes the policy as it stood before the update and runs the same prefix through it again to compute the logprob it assigns to the same A₂. The figure uses −0.4 as an example. This retains the sampling value and adds a value from the proximal policy, at the cost of one extra no-gradient forward pass. Bypass mode in verl and synchronous PPO in AReaL can also reuse the sampling value. Decoupled mode in verl and decoupled PPO in AReaL with proximal logprob recomputation enabled use the second approach. verl operating modes · AReaL PPO implementation

Both paths still require the training forward pass. Rondo calls forward_backward_async so the current policy scores the target tokens again. It calculates the probability ratio from the difference between the new and old logprobs, combines that ratio with the advantage to compute the importance_sampling loss, and backpropagates. Then optim_step_async updates the LoRA weights with Adam. At the start of the next step, Rondo hands the updated weights to the sampler, and Codex can pick up the next batch of issues. Training loop

10 · A closer look at the 15 evaluation tasks ​

Evaluation uses the rollout-only entry point, rondo.rollout. Prepare the data with prepare.py --split validation to produce tasks.validation.jsonl. Make a separate copy of tasks.py that reads this file, point tasks in the evaluation YAML at that Python script, and set tasks_per_step=15 and sessions_per_task=16. You can run the base model directly. For a trained model, pass the corresponding weights value from checkpoints.jsonl to --checkpoint. Training logs count from zero, so step-29 and step-59 are steps 30 and 60 in the figure. All three Qwen evaluations used Codex and the same patch scoring rules.

Passing attempts for each evaluation task. The right panel shows Qwen at base, step 30, and step 60. Orange diamonds mark hy4-flash.

Each row in the right panel is one task. Follow the hollow gray circle, light blue square, and dark blue dot to see how many Qwen attempts passed at base, step 30, and step 60. Comparing the base model with step 60, nine tasks moved right, six stayed put, and not one moved left. I'll take that! The biggest gain came on marshmallow-1343, which went from 3/16 to 13/16 to 15/16.

Over the last 30 steps, pydicom-1256 improved the most, from 4/16 to 10/16. One task did go backward in that stretch. On astroid-1333, Qwen dropped from 3/16 to 1/16. Both checkpoints fixed the issue at least once, so pass@16 alone hides that difference.

I also looked at the six tasks at the bottom of the figure. Even after 60 steps, all three Qwen markers sit on zero for each of them. On pydicom-901, for example, Qwen failed all 48 attempts across its three evaluations, while hy4-flash passed 16/16. On sqlfluff-2419, Qwen finished at 16/16 and hy4-flash managed 5/16.

11 · What's next ​

With this run, I finally got to train a model through a harness, something I'd wanted to do for a while. Next I want to add more examples to Rondo-RL and try it on more training tasks. I'd also like to run more low-cost experiments so students with little budget can take part in harness RL training.

I hope Rondo-RL can one day become a general-purpose framework for agentic RL training, like verl and AReaL.

Open code. Real experiments. Honest limitations.