Fit, not format
Code& data
Physics of Coding Agents · Part 1

Fit, not format.重在契合,不在格式。

A coding agent changes code by telling its harness where an edit goes: it points at line numbers, or it quotes the code. That choice decides what the agent loop pays, and which errors anyone ever sees. 编程智能体改代码时,要告诉 harness 改在哪里:要么指行号,要么把原文引出来。这个选择决定了 agent 循环要付出多少代价,也决定了哪些错误能被看见。

Langlin Wan1, Zhixuan Liang2, Guangyuan Wang3,4, Shilong Liu2,5,*

1Carnegie Mellon University  2Princeton University  3McGill University  4Mila – Quebec AI Institute  5Columbia University  *corresponding通讯作者

cart.py — change line 15修改第 15 行
11def total(items: list[Item]) -> float:
12 """Sum the cart before tax."""
13 s = 0.0
14 for x in items:
15 s += x.price
16 return s
 
results.logone harness · only the edit interface varies同一个 harness · 只改变编辑接口
# S-Code harness · 6 models · 3 benchmarks · 4,700+ runs# S-Code harness · 6 个模型 · 3 个基准 · 4,700+ 次运行
acceptaccepted, large refactors大文件重构 · 首次编辑被接受point 99% vs quote 58%
outcometasks solved, same runs同一批运行 · 任务解出94.4% vs 94.4% ← identical← 完全相同
silentlarge line-range edits that break the file把文件写坏的大范围行号编辑1 in 5 · no error raised· 没有任何报错
verifiedbroken first edits vs. line ranges写坏的首次编辑(对比行号范围)−92% MiMo  −63% luna
verifiedtasks per output token vs. search/replace每输出 token 解出任务数(对比搜索替换)1.77× luna  1.43× MiMo
Overview: data shapes fluency, the model sends edit calls, the harness checks them; one edit three ways.
Fit, not format. Training data makes a model fluent in pointing at code and in quoting it, to degrees that differ between models. Fit has a model side (how many attempts it needs) and a system side (what each attempt costs, and whether a wrong edit is caught). Click to enlarge.
重在契合,不在格式。训练数据让模型学会两种指代代码的方式:指行号和引原文,但各家模型掌握的程度不同。契合有模型侧(需要尝试几次)和系统侧(每次尝试花多少、写错了能不能被发现)两面。点击图片放大。
01 · The puzzle01 · 一个谜题

Same tasks solved, very different first tries

解出的任务一样多,第一次尝试却天差地别

On large-file refactors, GPT-5.6-luna's first edit is accepted in 99% of runs when it points at the lines to change, and in 58% when it quotes them. Both ways solve 94.4% of the tasks.

在大文件重构上,GPT-5.6-luna 指行号时首次编辑的接受率是 99%,引原文时只有 58%。可两种写法解出的任务都是 94.4%。

We put six models through three code-editing benchmarks, more than 4,700 runs, in one harness where only the edit interface changes. The same pattern shows up everywhere: the first action swings widely between interfaces, and the final outcome barely moves.

我们在同一个 harness 里只改变编辑接口,让六个模型跑了三个代码编辑基准,共 4,700 多次运行。到处都是同一个规律:第一步动作随接口大起大落,最终结果却几乎不动。

Each row: one model on one benchmark每一行:一个模型在一个基准上
search/replace patch line range spread across interfaces三种接口的差距

Switch to task solved and the three interfaces fall into line. Paper Table 1, first run.

切到“任务解出”,三种接口几乎挤到了一起。数据来自论文表 1(第一轮)。

So where did the difference go?

那么,差距去哪儿了?

02 · Result 102 · 结果一

Success hides misfit; cost reveals it

成功率掩盖失配,成本把它暴露出来

An agent stops when the model decides it is done, not when an edit fails. A rejected edit comes back as an error the model can act on: it rereads the file, retypes the edit, and tries again. The loop absorbs the failure, and bills for every lap.

agent 什么时候停下,是模型自己判断任务完成了,而不是某次编辑失败了。被拒绝的编辑会以报错的形式回到模型手里:它重读文件、重打编辑、再试一次。循环把失败吸收掉了,但每转一圈都要付费。

On matched tasks, a run whose first targeted edit is rejected costs 1.2–1.8 times as much as one whose first edit goes through. On the refactors, GPT-5.6-luna solves 1.64 times as many tasks per output token with line ranges as with search/replace: its first line-range call is about half as long, and it rarely has to retry.

在配对的同一批任务上,首次编辑被拒的运行,花费是首次编辑一次通过的 1.2–1.8 倍。在大文件重构上,GPT-5.6-luna 用行号范围时,每个输出 token 解出的任务数是搜索替换的 1.64 倍:它第一次调用的长度只有约一半,也很少需要重试。

Result 1结果一 Success hides misfit; cost reveals it. The agent loop turns failed edits into retries, so interfaces differ in what a task costs, not in whether it is solved. Compare them by first-action acceptance and tasks solved per output token, not by success alone. 成功率掩盖失配,成本把它暴露出来。agent 循环把失败的编辑变成重试,所以不同接口的差别体现在任务花了多少,而不是能不能解出来。比较接口时,要看首次动作的接受率和每个输出 token 解出的任务数,不能只看成功率。
03 · Result 203 · 结果二

Quoting is checkable; pointing is cheap and silent

引原文可以核对;指行号便宜,却不出声

Every edit call carries an address (where), evidence of the target (what is there now), and the new text. Search/replace and patch quote the target, so the harness can refuse an edit that does not match the file. A line range carries no evidence at all; the harness can only check that the numbers are in range. Evidence works like a checksum on the address, and omitting it removes its cost, not the need for it.

每次编辑调用都包含三部分:地址(改哪里)、目标的证据(那里现在是什么),以及新内容。搜索替换和补丁会引出原文,所以文件对不上时 harness 可以拒绝这次编辑。行号范围不带任何证据,harness 只能检查行号有没有越界。证据就像地址的校验和:省掉它,省掉的只是成本,需要它的场合并不会因此消失。

Quoting costs output and fails visibly: doubling the quoted text raises the odds of a no-match by about a quarter. Pointing saves that output, but on large edits the two failure modes split apart.

引原文要花输出,失败时看得见:引用的原文长一倍,对不上的几率就增加约四分之一。指行号省下了这部分输出,但在大编辑上,两类失败彻底分道扬镳。

Out of 100 large first edits (≥ 200 token-equivalents)每 100 个大编辑(≥ 200 个 token 当量)中
search/replace
12 rejected · 2 broken12 个被拒 · 2 个写坏
patch
9 rejected · 3 broken9 个被拒 · 3 个写坏
line range
1 rejected · 20 broken1 个被拒 · 20 个写坏
rejected: the agent sees an error被拒:agent 看得到报错 applied, but the file no longer parses: silent已应用但文件无法解析:无声无息

Paper Figure 6 and Appendix B, rounded. Edits that land on the wrong lines but still parse are not counted at all.

数据来自论文图 6 和附录 B(取整)。改错了位置但仍能解析的编辑,根本没被算进来。

Of the broken first line-range edits, 62% would parse if one boundary moved by a single line. A pointer is cheap, and when it misses, it misses by one. In one RefactorBench run, GPT-5.6-luna adds a parameter in four files with a single call. In celery/apps/multi.py it replaces lines 44–51, but its new text ends one line early and drops a closing parenthesis. The call is accepted, the file no longer parses, and the model is never told.

写坏的首次行号编辑里,62% 只要把一端挪动一行就能解析。行号便宜,可一旦指偏,往往就偏一行。在一次 RefactorBench 运行中,GPT-5.6-luna 用一次调用在四个文件里加了一个参数。在 celery/apps/multi.py 里它替换了第 44–51 行,但新内容少写了一行,丢了一个右括号。调用被接受了,文件已经无法解析,模型却从头到尾不知道。

Result 2结果二 Evidence makes errors visible. Quoting pays output for edits the harness can check; pointing saves output but fails silently, mostly with a boundary one line off. 证据让错误变得可见。引原文用输出换来可核对的编辑;指行号省下输出,却会无声地失败,而且大多只是边界偏了一行。
04 · Result 304 · 结果三

Which form wins depends on the model

哪种写法更好,取决于模型

Models learn both ways of referring to code from their training data. Compilers and tracebacks print file:line; diffs quote the lines around a change. Post-training then adds the format of each developer's own harness. So fluency, how reliably a model writes a form, ends up different for every model.

模型从训练数据里学会了两种指代代码的方式:编译器和 traceback 打印 file:line,diff 则引用改动前后的原文。后训练又加上了各家开发者自己 harness 的格式。于是流利度,也就是模型写某种形式的可靠程度,每个模型都不一样。

First edit accepted, by model and interface · outlined = that model's best首次编辑接受率(按模型 × 接口)· 加框为该模型的最佳
search/replacepatchline range

Small print in each cell: share of tasks solved, which barely moves. Claude Sonnet 5 has no patch arm.

每格下方的小字是任务解出率,几乎不变。Claude Sonnet 5 没有补丁这一组。

Line ranges fit GPT-5.6-luna and DeepSeek-V4-Flash, search/replace fits GLM-5.3 and MiMo-v2.5-Pro, and patch fits Qwen3.8-Flash. The model × interface interaction is overwhelming (p < 10−40), and it holds even between search/replace and line ranges, two interfaces that differ only in whether they point or quote.

行号范围最适合 GPT-5.6-luna 和 DeepSeek-V4-Flash,搜索替换最适合 GLM-5.3 和 MiMo-v2.5-Pro,补丁最适合 Qwen3.8-Flash。模型与接口的交互效应极强(p < 10−40),即便只比较搜索替换和行号范围这两种只差在“引”还是“指”的接口,结论依然成立。

And left to choose, models do not reliably pick what they write best. Given one tool that accepts all three forms, GPT-5.6-luna picks the patch format its developer trains on more than twice as often as line ranges, although on its own its first patch is accepted in 23% of runs and its first line range in 99%.

而让模型自己选时,它们并不总会挑写得最好的那种。给一个同时接受三种形式的工具,GPT-5.6-luna 选补丁(它的开发者训练所用的格式)的次数是行号范围的两倍多,可单独使用时,它的首次补丁只有 23% 被接受,首次行号范围却有 99%。

GPT-5.6-luna · habit vs. fluencyGPT-5.6-luna · 习惯与流利度
What it reaches for first (one tool, three forms)首先伸手去拿的形式(一个工具、三种形式)
search/replace 49%
patch 35%
16%
How often its first edit is accepted with each form alone单独使用每种形式时,首次编辑的接受率
search/replace
93% patch
23% line range
99%

Even packaging matters: offering three named tools instead of one tool with three argument shapes raises GPT-5.6-luna's first-edit acceptance by 16 points, because it then picks line ranges more often and patches less often.

连包装方式都有影响:把“一个工具三种参数”换成“三个独立命名的工具”,GPT-5.6-luna 的首次编辑接受率提高了 16 个百分点,因为它会更多地选行号范围、更少地选补丁。

Result 3结果三 Fit, not format; habit is not fluency. Acceptance depends on the model and the interface together, and the form a model reaches for need not be the form it writes best. 重在契合,不在格式;习惯不等于流利。接受率取决于模型和接口的组合,模型习惯伸手去拿的形式,未必是它写得最好的形式。
05 · The fix05 · 我们的做法

Verified selection: point, then quote just the two ends

校验选区:先指行号,再只引首尾两行

Can one interface be cheap to write, checkable by the harness, and written well by every model? Verified selection asks only for the two forms every model is fluent in, the ones natural text teaches. It points with line numbers, as diagnostics and tracebacks do, and quotes only the first and last line of the span, as diffs do. The model states its intent; the harness does the bookkeeping.

有没有一种接口,写起来便宜、harness 能核对、每个模型都写得好?校验选区只要求每个模型都流利的两种形式,也就是自然文本教会它们的那两种:像编译诊断和 traceback 那样指行号,再像 diff 那样只引出选区的首行和尾行。模型只负责说清意图,记账的事交给 harness。

What the model has to write to move a 30-line block搬动一段 30 行的代码,模型要写多少
search/replace
quote it, then retype it先引出原文,再重打一遍≈ 60
line range
retype it once重打一遍≈ 30
verified + @@ref
ends + one marker line引首尾 + 一行标记1 + ends
quoted to find the target为定位而引用的原文 retyped code重打的代码 quoted boundary line引用的边界行 @@ref 121-150@@

Lines of output, schematic (paper §2.3 and Figure 2e): the harness copies the 30 lines it already showed the model; the model writes one.

按输出行数示意(论文 §2.3 与图 2e):这 30 行 harness 早就给模型看过,由 harness 复制;模型只写一行。

P1Point with numbers, verify with boundaries. The model gives start_line/end_line and quotes first_line/last_line; the edit is applied only if both quotes match.用行号指,用边界验。模型给出 start_line/end_line,再引出 first_line/last_line;两端都对上才会应用。
P2Absorb small offsets when the evidence agrees. If both quoted lines sit the same few lines away, the range moves; otherwise the edit is refused, with the true location.证据一致时,吸收小偏移。如果两端原文都偏了同样几行,选区整体挪过去;否则拒绝这次编辑,并告诉模型原文真正在哪。
P3Reference instead of retyping. A line @@ref A-B@@ copies already-read lines, so moving a block costs one line of output.引用而不重打。一行 @@ref A-B@@ 就能复制已读过的行,搬动一整块代码只需输出一行。
P4One snapshot, no drift. All ranges refer to the file as read, and edits apply bottom-up, so earlier edits never shift later line numbers.同一快照,不会漂移。所有行号都指向读到的那一版文件,编辑从下往上应用,前面的修改不会挪动后面的行号。
The four call syntaxes side by side (paper Figure 2)四种调用写法对照(论文图 2)
One edit in four interfaces

Every run in this study uses S-Code, an open-source terminal coding-agent harness, so only the edit interface varies. Compared with plain line ranges, the model sees two extra string fields, a note on @@ref in the schema, and one paragraph of instructions. ★ Star S-Code on GitHub.

本研究的所有运行都基于开源的终端编程 agent harness S-Code,因此只有编辑接口这一个变量。相比普通的行号范围,模型看到的改动只有两个字符串字段、schema 里一条关于 @@ref 的说明,以及一段使用说明。★ 去 GitHub 给 S-Code 点个 Star。

06 · Result 406 · 结果四

Cheap like a pointer, checked like a quote

像指行号一样便宜,像引原文一样可核对

On the large-file refactors, over two runs, verified selection removes most of the silent breakage that bare line ranges let through.

在大文件重构上,两轮实验合计,校验选区消除了裸行号范围放过的大部分无声破坏。

Broken first edits on the refactors, two runs pooled大文件重构中写坏的首次编辑(两轮合计)
MiMo-v2.5-Pro
71
GPT-5.6-luna
19
Tasks solved per output token, relative to search/replace (two runs pooled)每输出 token 解出的任务数,相对搜索替换(两轮合计)
GPT-5.6-luna · line range
1.64× GPT-5.6-luna · verified
1.77× MiMo-v2.5-Pro · line range
1.14× MiMo-v2.5-Pro · verified
1.43×

Bars run from 0 to 2×. For MiMo-v2.5-Pro, bare line ranges are not significantly more efficient than search/replace, while verified selection is; compared with bare line ranges, it also raises task success (p = .002).

条形刻度从 0 到 2×。对 MiMo-v2.5-Pro,裸行号范围的效率并不显著高于搜索替换,校验选区则显著更高;与裸行号范围相比,它还提高了任务成功率(p = .002)。

11 → 2broken first edits on Microsoft's multi-file RefactorBench, where one call often changes several files.微软的多文件 RefactorBench 上写坏的首次编辑数;那里一次调用常常要改好几个文件。
16%of first edits on the refactors give line numbers that contradict their own quotes; a third of them would have parsed, invisible to any parse check.的大文件重构首次编辑,行号和它自己引的原文对不上;其中三分之一按裸行号也能解析,任何语法检查都发现不了。
78 vs 70of 80 Claude Sonnet 5 runs edit in place on the first try with verified selection vs. the string replacement it was trained on.在 80 次运行中,Claude Sonnet 5 第一次就原地改好的次数:校验选区对比它被训练使用的字符串替换。
The full ablation (paper Figure 8)完整消融实验(论文图 8)
Ablation: boundary check, alignment, @@ref
Result 4结果四 Pointing checked at its boundaries keeps most of the efficiency of pointing and removes most of its silent errors, on large files and on edits that span files. 在边界处加以核对的指行号,保住了指行号的大部分效率,又消除了它的大部分无声错误。在大文件和跨文件编辑上都成立。
07 · Takeaways07 · 启示

What this means for harness builders

这对做 harness 的人意味着什么

Measure the loop, not only the outcome. An interface defect rarely shows up as a failed task. It shows up as tokens spent getting there. Report first-action acceptance and tasks solved per output token alongside success, within each model.

衡量整个循环,而不只是结果。接口的缺陷很少表现为任务失败,而是表现为为了做成任务多花的 token。除了成功率,还要在同一模型内报告首次动作接受率和每输出 token 解出的任务数。

Ask the model only for its intent. A model's output is the most expensive and least exact part of an edit. Ask for a pointer and the least evidence that makes it checkable, and let the harness number, check, align and copy. Those steps are exact and nearly free for a harness; output tokens are decoded one at a time, while what is already in context sits in the KV cache.

只向模型要它的意图。模型的输出是一次编辑里最贵、也最不精确的部分。只向它要一个指针,再加上让这个指针可被核对的最少证据;编号、核对、对齐、复制都交给 harness。这些步骤对 harness 来说精确又几乎免费;输出 token 却要一个一个地解码,而已经在上下文里的内容只需从 KV 缓存里读出来。

The lesson for edit interfaces is fit, not format.

编辑接口的教训就是:重在契合,不在格式。

The 90-second version90 秒看完
Cite引用
@article{wan2026fitnotformat,
  title   = {Physics of Coding Agents: Part 1,
             Fit, Not Format at the Edit Interface},
  author  = {Wan, Langlin and Liang, Zhixuan and
             Wang, Guangyuan and Liu, Shilong},
  journal = {Preprints},
  year    = {2026},
  doi     = {10.20944/preprints202610.1889.v1},
  url     = {https://www.preprints.org/manuscript/202610.1889}
}

If this was useful, a star helps.

如果对你有帮助,欢迎点个 Star。

The paper repository holds the harness changes, task lists, run logs and every analysis script. S-Code is the open-source harness every run used.

论文仓库包含 harness 改动、任务列表、运行日志和所有分析脚本。S-Code 是所有实验运行所用的开源 harness。