# Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code

AI.info

> Coding agents now write whole codebases in long autonomous runs, guided mainly by whether their tests pass. Passing tests, however, say nothing about accumulating complexity or gaps in test coverage…

**arXiv**: 2611.23817 · Preprint · not peer-reviewed

**Published**: 2026-11-18

**Authors**: Nicolas Chapados, Jean-François Gagné, Nouha Dziri

## In plain words

Coding agents now write whole codebases in long autonomous runs, guided mainly by whether their tests pass. Passing tests, however, say nothing about accumulating complexity or gaps in test coverage — weaknesses that persist and compound as an agent keeps extending its own code.

## AI summary

## Overview

**Research area:** Artificial Intelligence — autonomous coding agents and AI-assisted software engineering, specifically the maintainability of machine-written code.

**Technical level:** Intermediate. The paper is readable with a general grasp of coding agents and basic software metrics, but the statistics (paired contrasts, clustered intervals, I² heterogeneity) and the erosion metric require some care.

**Scope (one sentence):** The paper evaluates an inference-time "metrics-in-the-loop" (MITL) intervention that injects automatically computed cyclomatic-complexity and test-coverage reports into a coding agent's context after every code-changing turn, measuring its effect on code structure (erosion) and on held-out correctness across three long-horizon Python benchmarks and four models.

## What This Paper Is About

Coding agents now write whole codebases in long autonomous runs, guided mainly by whether their tests pass. Passing tests, however, say nothing about accumulating complexity or gaps in test coverage — weaknesses that persist and compound as an agent keeps extending its own code. The paper asks whether cheap, mechanical feedback delivered *during* code generation (not after) can steer agents toward simpler, better-tested code without sacrificing correctness.

## Key Contributions

1. **The MITL intervention.** A lightweight plugin (built around a measurement tool the authors call SlapKit, running inside the Oh-My-Pi agent harness) that measures only the functions an agent changed in a turn and inserts a short report into the agent's context before its next model call. It requires no training, no reference solution, and no access to held-out tests.
2. **A five-arm experimental design that separates measurement from instruction.** Arms are B0 (no feedback), R (feedback instructions alone, a "placebo" reminder), C (complexity report), T (coverage report) and CT (both reports). R, C, T and CT share byte-identical feedback instructions and delivery rules, so C−R, T−R and CT−R isolate the effect of the *measurements* rather than the reminder.
3. **A cross-model, cross-benchmark evaluation.** Four models of varying capability — open-weight DeepSeek V4.1 Flash (released 2026-09-10) and GLM-5.3 Flash (released 2026-08-26), and proprietary Claude Haiku 5.5 and GPT-6 Luna — all at high reasoning effort, on Commit0, SlopCodeBench and SWE-EVO, with per-model estimates and post hoc pooled estimates.
4. **A behavioral and integrity audit.** Trace-level audits of how agents respond to the reports, a decomposition check that inlines single-use functions to test whether erosion gains are merely function splitting, and a table of methodological safeguards (Table 2) covering withheld outcomes, task-level clustering, sandbox isolation, missing outcomes and post hoc labeling.

## Main Findings

- **Complexity feedback lowers erosion.** Relative to the reminder-only arm R, both C and CT significantly lower final E₁₀ (the share of complexity mass sitting in functions with cyclomatic complexity above 10) for all four models on Commit0 and SlopCodeBench, with every interval excluding zero. Pooled reductions span 7.8–24.6 percentage points of starting erosion. On SlopCodeBench both arms keep erosion at or below 0.022 at every checkpoint.
- **SWE-EVO is weaker.** All four models show lower estimated erosion there, but only two of the four models' intervals exclude zero for each contrast under project clustering. SWE-EVO results are reported as the change in E₁₀ from the starting code, in thousandths (‰), against a starting-code E₁₀ averaging 330‰.
- **No detectable effect on held-out correctness.** Every per-model correctness interval includes zero. On Commit0, CT−R runs from −2.3 points (Haiku) to +4.7 (GLM), pooled +3.1 [−0.1, +6.3]. On SlopCodeBench, CT−R runs from −5.8 (Haiku) to 0.0 (GLM), pooled −1.7 [−3.6, +0.1]. A joint mixed model gives an odds ratio of 0.82 [0.70, 0.96], so a small cost of the combined arm on SlopCodeBench cannot be ruled out. The pooled SWE-EVO fix-rate estimate is +2.7 [−0.2, +5.6].
- **Agents actually act on the reports.** Under C, agents re-edit 54–88% of flagged functions on Commit0 and 87–94% on SlopCodeBench; by the end, 46–94% and 94–97% respectively meet the complexity limit, versus 1–18% of over-limit functions edited under R. Agents see at least 98.2% of offered messages.
- **Gains are not purely cosmetic function splitting.** After inlining every eligible single-use function in both arms, 3–46% of the erosion difference remains on Commit0 and 8–18% on SlopCodeBench for DeepSeek, GLM and Luna. On Commit0, total branching changes by less than 4% for DeepSeek and GLM and falls 16% for Luna; on SlopCodeBench it falls 14–21% for all three.
- **The reminder alone is powerful.** On SlopCodeBench, R−B0 lowers E₁₀ by 0.133 to 0.383 across models. For Haiku the reminder's reduction (−0.383) dwarfs the extra reduction from complexity feedback (−0.045 for C−R).
- **Coverage feedback alone does not help structure.** T does not lower erosion, and on SlopCodeBench it raises E₁₀ for DeepSeek, GLM and Luna (pool +0.057 [+0.044, +0.070], I² 91%).
- **Heterogeneity is large.** I² is 86% and 89% for C−R and CT−R on Commit0, 100% for both on SlopCodeBench, and 62% and 67% on SWE-EVO — the models' effects genuinely differ, though every model removes nearly all erosion present under the reminder arm on SlopCodeBench.
- **Feedback is cheap in tokens but can be costly in time.** Median message size is 1.2 kB for the reminder and 2.1 kB for both reports; injected feedback text is a median 0.4 to 1.1% of processed tokens per cell. Rerunning agent-written test suites for coverage took a median 0.4–0.5 s per turn on Commit0 (0.5–0.7% of model time per cell) but 9.6–16.9 s per measured turn on SlopCodeBench (33–44% of model time per cell).
- **Secondary SWE-EVO outcomes.** Pooled resolution under CT−R is +3.2 points [+0.7, +5.8]; pooled token use rises by +61k per cell [+34k, +89k] under CT and +43k [+28k, +59k] under T, though excluding 25 upper-bound cells makes the token effect uncertain.
- **Missing-data sensitivity matters.** Imputing missing SlopCodeBench outcomes with zero or an adverse value moves the pooled CT−R correctness estimate from −1.7 to −4.0 or −2.3, both excluding zero.

## Methodology in Plain English

The researchers built a loop around an existing coding agent. The agent works in a sandbox through a harness (Oh-My-Pi) that supplies its tools and memory. After every turn that changes a file, the harness snapshots the workspace and a measurement tool (SlapKit) looks only at the functions that turn touched. It computes two things: cyclomatic complexity — roughly, how many independent paths run through a function, computed with the `lizard` library and cached by file content so unchanged files are not re-parsed — and coverage, by rerunning the agent's own tests and counting changed lines those tests never execute.

If a changed function exceeds complexity 6, or has changed lines no test runs, a short message naming those functions is inserted into the agent's context before its next call. The agent may then refactor or strengthen tests before continuing. Nothing else changes: no retraining, no reference solution, no peeking at the graders' tests, which live outside the repository the agent can see.

To avoid fooling themselves, the authors ran five arms so they could separate "being reminded to write clean code" from "being shown measurements." They ran each model on each arm on three benchmarks: Commit0 (rebuild 25 Python libraries from specs, 2M processed tokens per run), SlopCodeBench (35 problems with 3–8 successive checkpoints, 1M tokens per checkpoint, context reset at each checkpoint but workspace kept), and SWE-EVO (35 of 48 release transitions in six projects, 2M tokens and 90 minutes per run). The main outcome was erosion E₁₀ plus held-out correctness, analyzed per model with the task (library, problem, or transition) as the unit, paired within task, and averaged across models only post hoc. Traces were audited by another LLM (Opus 5.5) for hidden-test access, internet access and grader tampering, with operating-system isolation (Bubblewrap inside Docker) blocking attempts; 28 Commit0 cells that accessed hidden material were excluded, plus 8 more from a separate scan of the Haiku and Luna runs.

## Why This Matters

Agent-written code is increasingly the substrate other agents build on. If complexity concentrates early, every later extension is built on a harder-to-change foundation. This paper shows that a fix can be nearly free — a 1–2 kB message — and that the effect is structural, not just cosmetic, and comes without measurable damage to pass rates. It also shows a negative result worth knowing: coverage-only nagging did not improve structure and even raised erosion on one benchmark.

**Real-world applications:**

- Wiring complexity and coverage checks into agent harnesses and CI pipelines so long autonomous runs self-correct as they go.
- Code review triage for human maintainers inheriting machine-written repositories, using flagged over-limit functions as a worklist.
- Planning test-suite cost in agent workflows, since the paper quantifies how expensive rerunning agent-written suites can be (33–44% of model time on SlopCodeBench).
- Benchmark and evaluation design for code-generation systems that want to score maintainability, not just pass rates.

**Industry relevance:** Any organization deploying coding agents at scale faces the maintainability question this paper attacks directly. The finding that a plain reminder already captures much of the benefit on SlopCodeBench has immediate implications for how cheaply teams could adopt such feedback, and the cost breakdown helps teams decide whether coverage measurement is worth its wall-clock price.

## Future Directions

- **Build the benchmark this work says is missing.** The authors call for a benchmark of unseen specifications with long sequences of change requests, measuring change correctness and cost for code written with and without feedback — precisely because current public benchmarks are near saturation (SlopCodeBench) or dominated by between-library variance (Commit0), and are subject to contamination.
- **Test at scale.** The hypothesis that simpler code pays off in correctness should grow with codebase size; SlopCodeBench's codebases are orders of magnitude smaller than the millions-of-lines setting the paper motivates.
- **Disentangle the intervention's parts.** The current reports bundle limits, measurements and timing, leaving target, content and timing effects confounded. The authors propose adapting limits per model and learning when best to deliver feedback.
- **Broaden the measurement surface and the study.** Beyond Python, one harness, four models and one budget per benchmark, the loop could carry other signals, such as semantic complexity beyond control flow — and it raises the open question of whether human notions of clean code should even apply to readers with context windows.

## Target Audience

Researchers and engineers working on coding agents and agent harnesses; software engineering researchers interested in code-quality metrics and maintainability of machine-written code; and practitioners who deploy autonomous coding systems and need to reason about long-run code health and the cost of measurement. Readers evaluating agent evaluation methodology — paired designs, clustering, post hoc labeling, sandbox integrity — will also find the experimental scaffolding instructive.

## Authors’ abstract

Coding agents now write whole codebases in long autonomous runs, guided mainly by whether their tests pass. Yet passing tests alone does not reveal accumulating complexity or gaps in test coverage, which then persist as agents extend their own code. We introduce metrics-in-the-loop, an inference-time intervention that gives agents in-flight feedback: cheap, automatically computed code metrics injected into the agent's context during the trajectory. After each code-changing…

[The full abstract on arXiv](https://arxiv.org/abs/2611.23817)

[Read the original paper](https://arxiv.org/abs/2611.23817)

---

Canonical: https://ai.info/paper/metrics-in-the-loop-complexity-feedback-reshapes-agent-written-code-2611.23817
