Skip to content

November 22, 2026 · Agents

What Failed in Our Agent Harness and Fine-Tuning

We ran a coding agent on real Python issues with Gemma 4 31B, and most of what broke was in the harness, not the model.

Grainy print of misaligned concentric rings and a bent red beam of light
Published
Written by
Hanan Choudhary Hadayat
Topics
Agents

We recently built a coding agent on Gemma 4 31B. It reads a GitHub issue from a Python project such as FastAPI, Rich, Requests or httpx, edits the code, and hands over a patch. A grader then applies the project’s own tests in a fresh sandbox. In parallel we prepared a LoRA adapter for the same model.

We kept a log of everything that went wrong. Very little of it was the model being too weak. Most of it was plumbing: tool names, budgets, a config flag, a grader that read the wrong packages, and training data that did not look like what the model sees at run time. This post is that log, written as warnings.

Part 1: the harness

1. A misspelled tool name can end the whole task

The model called edit_syntax-gate and edit-syntax-gate with empty arguments. The real function was run_skill_script. The framework threw an unknown-tool exception, the exception escaped the dispatch loop, and the task stopped before the verifier ever ran. Our prompt had said “Run edit-syntax-gate”, which is the name of the skill, not the name of the function.

The fix was to put the exact registered function name and a literal, valid argument object in the prompt, and to let the script find the changed files on its own. In a small synthetic check the model used the tool correctly 3 of 3 times after the fix, against 0 of 3 before, and produced no invented names in 20 trials.

Check what happens when the model calls a tool that does not exist. If the answer is “the task crashes”, fix that path before you tune any prompt.

2. One config flag can delete a role

Our pipeline had a coder, a read-only analyzer that the coder could call, and a verifier. The analyzer was mounted with skip_summarization: true. In the agent framework we used, that flag makes the tool’s reply the caller’s final answer. So the coder made one call, asked the analyzer a question, and its turn ended with the analyzer’s report. The verifier then had to write the fix from scratch.

This happened in 61 of 70 runs. Those runs resolved 28 percent of tasks. The 9 runs where the coder kept control resolved 56 percent. Nobody had chosen this behavior. It came from one line in a YAML file.

After we set the flag to false, the coder kept control in 70 of 70 runs and the build resolved 34 of 70 tasks, against 27 of 70 for the old build in the same run. That is 13 wins and 6 losses on the tasks where they differed. It looks good, but a sign test gives p = 0.17, so we do not count it as proven.

Read your traces as state machines. Count how often each role actually acts. Do not assume the roles in your diagram are the roles that run.

3. A shared budget moves the failure, it does not remove it

All three roles shared one budget of 50 model calls. The analyzer used a median of 16 calls before the verifier started, and up to 48. Verifiers that found the right fix late got a “budget exceeded” error on the edit itself. Every one of the 29 runs that shipped no source change failed, and none of the 17 runs that hit the 50-call cap resolved.

When we gave the coder its turn back, the coder spent the budget instead. Runs that hit the cap went from 11 to 21 out of 70, and empty patches went from 5 to 18. Plan per-role budgets from the start, and log where every call goes.

4. Prompt rules are suggestions, tools are rules

We tried to fix behavior with prompt lines: “return after 8 tool calls”, “make your first edit by call 14”, “write a failing test first”. The model ignored them. The analyzer still made 18 and 33 calls in the first two runs after we added the 8-call rule. A larger build with more prompt rules solved 3 of 8 tasks against 4 of 8 for the simpler one.

Removing a tool did change behavior. But removing the submit tool from the coder backfired, because calling a tool that is not there crashes the task, see point 1. If a rule matters, enforce it in code: in the tool, in the dispatcher or in the runner.

5. Dead tools cost calls and attention

Our code search tool returned zero results on 62 of 62 calls, because the embedding index was not available in that environment. The prompt told the analyzer to use it first. A verification script failed 10 of 13 times because it resolved --workspace . against its own folder instead of the repository. Loading a skill’s instructions costs one model call, and the model often loaded skills it never ran.

Audit each tool: how often it is called, how often it errors, and whether the agent acts on the result. Remove the ones that never help.

6. Make cheap checks mandatory

The syntax check worked every time it ran, but it was optional. In one run the agent shipped a file with a syntax error that the check would have caught. Only 5 of 23 runs that edited code ran a syntax check after their last edit. An edit made after a check also makes that check stale. Run the cheap deterministic checks automatically after every edit, not when the model remembers.

7. The agent will make a mess of the repository

Things we found in shipped patches:

  • A correct edit undone by the agent’s own git checkout <file>.
  • A branch switch in the middle of a task.
  • New conftest.py and pytest.ini files at the repository root.
  • Scratch files in 20 of 35 patches, including a 109 KB .bak file.
  • A file named repro.py followed by a backtick, from a malformed argument.
  • Edits to test files that the official tests also patch, which collide when the grader applies them.

Our file tools did not expand $TMPDIR, so a literal $TMPDIR/reproduce_issue.py path failed. The harness also captured every untracked file into the patch. The fix that worked was a cleanup step right before submit, which restores test files from git, removes new scratch files and keeps the source edits.

8. Stop after submit

After a successful submit, some runs called submit again with the same patch, once 37 times in a row. That burns time and turns. Tell the agent to answer with text after a successful submit, and make a second submit a no-op in code if you can.

9. Context compaction can drop the task

When the framework compacted the history, the summary sometimes replaced the original issue text. We found 7 coder requests that no longer contained the issue at all. Pinning the issue in the system prompt kept it in all 27 matching requests we checked, but it did not show a solve-rate gain on its own. Check what the model still sees after compaction, and treat the summarizer as code that can fail. One task failed repeatedly because the summarizer itself crashed.

Part 2: evaluation

10. Grade the reference patch and an empty patch before you trust any number

Our first local grader was wrong in three ways. The sandbox imported httpx 0.28.1 from the host instead of the project’s own source, so a correct reference patch failed. It had no /etc/hosts, so TLS tests failed on name resolution. And the network setup made timeout tests fail with “network unreachable” instead of timing out.

After the fixes, the reference patch passed 36 of 36 gradable tasks on two runs that agreed exactly. An empty patch still passed one task, because the host had an older Starlette that already did what the new tests checked. Run the known-good patch twice and the empty patch once on every task. Exclude any task where the empty patch passes or the reference fails.

11. Your noise is bigger than your gain

The same build, run twice, gave 7 wins and 7 losses against itself. Single tasks flipped between seeds. A simple estimate puts the noise on a 40-task set with one run per task at about 15.8 percentage points. On 129 tasks, a 5-point gain is not statistically detectable.

So run both builds in the same run, alternate which goes first, use at least two seeds, and compare paired wins and losses with a sign test. Only compare across runs as a secondary check.

12. Change one thing at a time

We once bundled five harness ideas into one build. It solved 22 of 70 tasks against 27 for the build it replaced, and we could not tell which idea hurt. Keep one commit per change, so a later run can test any single change.

Part 3: fine-tuning

13. Train on your own model in your own harness

At one point 75 percent of our planned training text came from another, larger model working in a different harness with different tools. That teaches the model someone else’s habits. Your own model’s successful runs inside your real harness are worth more per row. The rest of the data can fill in, but it should not dominate the mix.

14. Measure the real token length of your data

The public agent trajectories we planned to use rendered to a mean of 48,488 tokens per row. Our affordable training length was 16k tokens, and only 2 rows fell between 8k and 16k. GPU memory follows the full rendered context, not just the tokens you put the loss on. Our own harness compacts context at around 14,000 tokens, so its traces fit, and they match what the model sees at inference.

15. Your out-of-memory error may be the logits

Training failed at 4,096 tokens on an 80 GB A100. The failing allocation was exactly 4.00 GiB. Gemma 4 has a vocabulary of 262,144 tokens, and 4,096 times 262,144 times 4 bytes is 4.00 GiB: the full fp32 logits tensor in the loss. Chunked cross-entropy fixed that part.

If you chunk the loss yourself, copy the model’s logit post-processing exactly. Gemma 4 applies a final logit softcap of 30. We checked that the chunked loss matched the original loss to within 2.4e-7 before trusting it. After that fix, the backbone’s activations were the next limit: 8k still ran out of memory on 80 GB, and 16k needed a 141 GB H200.

16. Do not trust a learning rate from somewhere else

A recommended rate of 5e-4 was unstable for us, with a gradient norm of 76.6 and a loss spike to 2.34. A rate of 1e-4 was stable. Run a short probe with two or three rates before the real run. It costs a few dollars and saves the run.

17. Train in the exact format you serve

Three things nearly differed between training and serving for us. Traces from one serving route recorded no thinking text, while we planned to serve with thinking on. Rendering a conversation through the chat template again can reorder tool arguments, so the tokens you train on may not be the tokens the model produced. And the serving model was a quantized checkpoint, while training used a dequantized copy.

Record the exact tokens the model produced through a proxy. Then load the trained adapter in the real serving stack on the real checkpoint and check that outputs change. Ours changed on 6 of 6 prompts.

18. Keep the test set out of the training data

Freeze the split with a fixed seed before you generate any data. Check every training mix against the held-out task IDs. Ours showed 0 of 40 leaks. When you keep several successful runs per task, remove duplicates by the patch they produce, not by the trajectory text. Two different paths to the same patch teach the same thing.

19. Check the environment before you blame the model

Our first batch of runs solved 1 of 10 tasks. Part of that was missing test dependencies in the sandbox. Installing them raised it to 3 of 10. Two more tasks failed only because of a Pygments version, and the reference patches failed on them too.

Part 4: infrastructure

20. Long jobs die in boring ways

  • A training watcher mistook a local wait timeout for a training failure and stopped the GPU at step 7 of 818.
  • A rollout runner died silently when the agent process that started it exited. Start long jobs detached, for example with setsid nohup, and resume from disk.
  • An API authentication error in the middle of a run made one batch of results worthless. We dropped that batch and ran it again instead of mixing it in.

Treat every number from a run that had an error as suspect until you know which tasks it touched.

What we do now

Our research estimate put the harness effect at about 9 percentage points and an affordable adapter at about 3. So we fix the harness first, and we only fine-tune once the harness is frozen and the grader passes its preflight. Before any change goes in, we run it paired against the current build on the same tasks, and we read the traces of every task that flipped.

All field notesWrite to us