
An error that said “locked” cost a median of 18 turns; one that said “don’t retry” cost 4
Two wordings of the same tool error: one kept three models retrying, the other stopped them all.
On the agent compass Stage 3 of 4 · Run the toolsMeasured result
18 → 4 median turns
A tool that always failed with “the file is locked” cost three of four models a median of 18 to 20 turns. The same failure, worded to say retrying couldn’t help and what to do instead, cost every model four or five turns.
- Task
- the
durationbug fix with anedit_filethat failed on every call, under two wordings of its error - Models
anthropic/claude-haiku-5.5,openai/gpt-5.6-luna,z-ai/glm-5.3-flash,deepseek/deepseek-v4.1-flash- Runs
- three per model and wording, with a 20-turn limit
- Date
- October 2026
Measured with the companion code
When a tool call fails, the harness, the program around the model, returns the error text to the model in a tool message, and whatever the model does next is a reaction to that text. That makes the wording of every tool error part of how the agent behaves. The measurements below put a number on how much. They report medians: of each model’s three runs, the middle one, with one run lower and one higher (median).
What was tested
The task is a bug fix: a small Go package, duration, whose tests fail because its unit table maps 'm' to time.Second.
A single line needs to change.
For these recorded runs, edit_file was swapped for a version that returns the same error on every call: the file is locked.
The other tools behaved normally.
Four models each attempted the task three times in October 2026, with 20 turns allowed.
A second set of runs was identical except for the error text, which became the project is read-only: edits are not possible in this session, so don't retry; report the fix instead.
The result
With “the file is locked” (medians of three runs):
| Model | Turns | Edit attempts | Hit the turn limit | Cost |
|---|---|---|---|---|
anthropic/claude-haiku-5.5 |
5 | 2 | 0 of 3 | $0.0013 |
openai/gpt-5.6-luna |
18 | 12 | 1 of 3 | $0.0036 |
z-ai/glm-5.3-flash |
18 | 10 | 0 of 3 | $0.0048 |
deepseek/deepseek-v4.1-flash |
20 | 14 | 3 of 3 | $0.0061 |
anthropic/claude-haiku-5.5, the default model in the companion code, made two edit attempts and then gave its answer: the cause, the one-line fix, and the fact that it couldn’t apply the fix.
The other three spent most of their 20 turns retrying in different forms: rephrasing the edit, rereading the file, and rerunning the tests in case something had changed.
They also went looking for a way past the lock:
- In every one of their nine runs, they tried an edit to
duration_test.go, usually one that changed nothing, to find out whether the lock covered onlyduration.go. openai/gpt-5.6-lunatried paths like../project/duration.goandsubdir/../duration.go, which are the escapesos.Root(a Go type that confines file access to one directory) exists to refuse.- In one run,
z-ai/glm-5.3-flashwrote a new file,fix_units.go, with aninitfunction that rewrote the unit table when the package loaded. That would have made the tests pass while the locked file stayed untouched. deepseek/deepseek-v4.1-flashnever stopped on its own; the turn limit ended all three of its runs.
Under the read-only wording, every run of every model tried the edit once and then reported the fix, finishing in four or five turns. For the three models that had kept retrying, the cost fell to between a fifth and a third of what it had been.
Why the wording matters
A model has nothing to go on except the text of the error. Locks usually get released, so “the file is locked” reads as a temporary problem, and both retrying and searching for an unlocked route are sensible responses to it. The message never says that another attempt is useless, or what a good result looks like when the edit can’t be made.
The read-only wording settles both. It says the situation will last for the whole session, tells the model not to retry, and gives it something useful to do instead.
What it can’t show
Three runs per model is a small sample. Still, the gap between a median of 18 turns and a median of 4 is much wider than the run-to-run variation recorded elsewhere in these guides. The experiment covers one task, one tool, and two wordings, and a different kind of failure might call for different advice. The default model also gave up after two attempts under the first wording, so the benefit of a better message depends on which model reads it.
The side results matter as much as the headline.
When a model can’t finish the obvious way, it tests the edges of what it has been given: a different file, a different spelling of the same path, a new file that changes behavior when the package loads.
Nothing in those runs asked a model to get around the lock; the only task was the bug fix.
That behavior is why the companion code confines its file tools with os.Root, and why the crash catalog’s grader fails any run that deletes or skips a test.
What to do with it
Write tool errors for the model that will read them:
- Say whether another attempt can succeed. “Temporary, retry in a moment” and “permanent for this session” call for different next steps, and when you leave it out, the model has to guess.
- Name the better move. “Report the fix”, “list the files to find the right path”, “send JSON like
{"path": "a.go"}”. - Be specific about what was wrong with the call. The errors in the companion code give the field, the value that arrived, and the value expected:
bad arguments: "path": got an array, want a string; send JSON like {"path": "a.go"}. - Keep the wording the same from run to run. Fixed wording keeps recorded runs replayable and shows the model the same text every time. The deep detail on how the companion code does that is just below.
encoding/json/v2 changes its error text between processes on purpose, so the companion code builds its messages from the error’s fields with errors.AsType and never from err.Error().
The decoder behind those messages lives in ch04/agent/tools.go:
// argError says why arguments didn't decode, in the same words every
// time. json/v2 deliberately varies the wording of its errors between
// runs, and this text goes to the model and into saved runs.
func argError(err error) string {
if _, ok := errors.AsType[*jsontext.SyntacticError](err); ok {
return err.Error() // syntax errors read the same every time
}
se, ok := errors.AsType[*json.SemanticError](err)
if !ok || se.GoType == nil {
return "the JSON doesn't fit the arguments"
}
where := "the arguments"
if p := strings.TrimPrefix(string(se.JSONPointer), "/"); p != "" {
where = strconv.Quote(p)
}
if errors.Is(se.Err, json.ErrUnknownName) {
return "unknown field " + where
}
return fmt.Sprintf("%s: got %s, want %s", where,
kindOf(se.JSONKind), goKind(se.GoType.Kind()))
}
Good errors save turns, but a turn limit is still required: it was the only thing that stopped deepseek/deepseek-v4.1-flash.
Try it
The recorded runs behind the table are in the repository’s evidence directory, and go run ./evidence, with no key set, prints the table again from them, as fix-locked and fix-locked-clear among the other tables. The code in ch04 also has a hand-written replay in which the model makes three bad calls and recovers from each error.
From the code directory of a clone:
$ go run ./ch04 -replay recover
To test wording yourself with an API key, change edit_file in ch04/agent/tools.go to return an error you write on every call, then run go run ./ch04 once for each of two models, setting OPENROUTER_MODEL to each in turn.
Each run costs well under a cent.
func argError(err error) string
argError says why arguments didn't decode, in the same words every time.
argError says why arguments didn't decode, in the same words every time. func argError(err error) string. In ch04/agent/tools.go, line 59.
type error interface {
Error() string
}
The error built-in interface type is the conventional interface for representing an error condition, with the nil value representing no error.
The error built-in interface type is the conventional interface for representing an error condition, with the nil value representing no error. type error interface { Error() string }. Documented at pkg.go.dev, builtin.error.
type string string
string is the set of all strings of 8-bit bytes, conventionally but not necessarily representing UTF-8-encoded text.
string is the set of all strings of 8-bit bytes, conventionally but not necessarily representing UTF-8-encoded text. type string string. Documented at pkg.go.dev, builtin.string.
package errors ("errors")
Package errors implements functions to manipulate errors.
Package errors implements functions to manipulate errors. package errors ("errors"). Documented at pkg.go.dev, errors.
func AsType[E error](err error) (E, bool)
AsType finds the first error in err's tree that matches the type E, and if one is found, returns that error value and true.
AsType finds the first error in err's tree that matches the type E, and if one is found, returns that error value and true. func AsType[E error](err error) (E, bool). Documented at pkg.go.dev, errors.AsType.
package jsontext ("encoding/json/jsontext")
Package jsontext implements syntactic processing of JSON as specified in RFC 4627, RFC 7159, RFC 7493, RFC 8259, and RFC 8785.
Package jsontext implements syntactic processing of JSON as specified in RFC 4627, RFC 7159, RFC 7493, RFC 8259, and RFC 8785. package jsontext ("encoding/json/jsontext"). Documented at pkg.go.dev, encoding/json/jsontext.
type SyntacticError struct {
requireKeyedLiterals
nonComparable
// ByteOffset indicates that an error occurred at or after this byte offset.
ByteOffset int64
// JSONPointer indicates that an error occurred within this JSON value
// as indicated using the JSON Pointer notation (see RFC 6901).
JSONPointer Pointer
// ...
}
SyntacticError is a description of an error that occurred when encoding or decoding JSON according to the grammar.
encoding/json/jsontext.SyntacticError
SyntacticError is a description of an error that occurred when encoding or decoding JSON according to the grammar. type SyntacticError struct { requireKeyedLiterals nonComparable // ByteOffset indicates that an error occurred at or after this byte offset. ByteOffset int64 // JSONPointer indicates that an error occurred within this JSON value // as indicated using the JSON Pointer notation (see RFC 6901). JSONPointer Pointer // ... }. Documented at pkg.go.dev, encoding/json/jsontext.SyntacticError.
func (error).Error() string
func (error).Error() string.
var se *json.SemanticError
var se *json.SemanticError. In ch04/agent/tools.go, line 63.
package json ("encoding/json/v2")
Package json implements semantic processing of JSON as specified in RFC 8259.
Package json implements semantic processing of JSON as specified in RFC 8259. package json ("encoding/json/v2"). Documented at pkg.go.dev, encoding/json/v2.
type SemanticError struct {
requireKeyedLiterals
nonComparable
action string // either "marshal" or "unmarshal"
// ByteOffset indicates that an error occurred at or after this byte offset.
ByteOffset int64
// JSONPointer indicates that an error occurred within this JSON value
// as indicated using the JSON Pointer notation (see RFC 6901).
// ...
}
SemanticError describes an error determining the meaning of JSON data as Go data, or vice versa.
encoding/json/v2.SemanticError
SemanticError describes an error determining the meaning of JSON data as Go data, or vice versa. type SemanticError struct { requireKeyedLiterals nonComparable action string // either "marshal" or "unmarshal" // ByteOffset indicates that an error occurred at or after this byte offset. ByteOffset int64 // JSONPointer indicates that an error occurred within this JSON value // as indicated using the JSON Pointer notation (see RFC 6901). // ... }. Documented at pkg.go.dev, encoding/json/v2.SemanticError.
field GoType reflect.Type
GoType is the Go type that could not be handled.
encoding/json/v2.SemanticError.GoType
GoType is the Go type that could not be handled. field GoType reflect.Type. Documented at pkg.go.dev, encoding/json/v2.SemanticError.GoType.
var nil Type
nil is a predeclared identifier representing the zero value for a pointer, channel, func, interface, map, or slice type.
nil is a predeclared identifier representing the zero value for a pointer, channel, func, interface, map, or slice type. var nil Type. Documented at pkg.go.dev, builtin.nil.
package strings ("strings")
Package strings implements simple functions to manipulate UTF-8 encoded strings.
Package strings implements simple functions to manipulate UTF-8 encoded strings. package strings ("strings"). Documented at pkg.go.dev, strings.
func TrimPrefix(s, prefix string) string
TrimPrefix returns s without the provided leading prefix string.
TrimPrefix returns s without the provided leading prefix string. func TrimPrefix(s, prefix string) string. Documented at pkg.go.dev, strings.TrimPrefix.
field JSONPointer jsontext.Pointer
JSONPointer indicates that an error occurred within this JSON value as indicated using the JSON Pointer notation (see RFC 6901).
encoding/json/v2.SemanticError.JSONPointer
JSONPointer indicates that an error occurred within this JSON value as indicated using the JSON Pointer notation (see RFC 6901). field JSONPointer jsontext.Pointer. Documented at pkg.go.dev, encoding/json/v2.SemanticError.JSONPointer.
package strconv ("strconv")
Package strconv implements conversions to and from string representations of basic data types.
Package strconv implements conversions to and from string representations of basic data types. package strconv ("strconv"). Documented at pkg.go.dev, strconv.
func Quote(s string) string
Quote returns a double-quoted Go string literal representing s.
Quote returns a double-quoted Go string literal representing s. func Quote(s string) string. Documented at pkg.go.dev, strconv.Quote.
func Is(err, target error) bool
Is reports whether any error in err's tree matches target.
Is reports whether any error in err's tree matches target. func Is(err, target error) bool. Documented at pkg.go.dev, errors.Is.
field Err error
Err is the underlying error.
encoding/json/v2.SemanticError.Err
Err is the underlying error. field Err error. Documented at pkg.go.dev, encoding/json/v2.SemanticError.Err.
var ErrUnknownName = errors.New("unknown object member name")
ErrUnknownName indicates that a JSON object member could not be unmarshaled because the name is not known to the target Go struct.
encoding/json/v2.ErrUnknownName
ErrUnknownName indicates that a JSON object member could not be unmarshaled because the name is not known to the target Go struct. var ErrUnknownName = errors.New("unknown object member name"). Documented at pkg.go.dev, encoding/json/v2.ErrUnknownName.
package fmt ("fmt")
Package fmt implements formatted I/O with functions analogous to C's printf and scanf.
Package fmt implements formatted I/O with functions analogous to C's printf and scanf. package fmt ("fmt"). Documented at pkg.go.dev, fmt.
func Sprintf(format string, a ...any) string
Sprintf formats according to a format specifier and returns the resulting string.
Sprintf formats according to a format specifier and returns the resulting string. func Sprintf(format string, a ...any) string. Documented at pkg.go.dev, fmt.Sprintf.
func kindOf(k jsontext.Kind) string
kindOf names a kind of JSON value.
kindOf names a kind of JSON value. func kindOf(k jsontext.Kind) string. In ch04/agent/tools.go, line 81.
field JSONKind jsontext.Kind
JSONKind is the JSON kind that could not be handled.
encoding/json/v2.SemanticError.JSONKind
JSONKind is the JSON kind that could not be handled. field JSONKind jsontext.Kind. Documented at pkg.go.dev, encoding/json/v2.SemanticError.JSONKind.
func goKind(k reflect.Kind) string
goKind names what JSON a kind of Go value takes.
goKind names what JSON a kind of Go value takes. func goKind(k reflect.Kind) string. In ch04/agent/tools.go, line 100.
func (Type) Kind() Kind
Kind returns the specific kind of this type.
Kind returns the specific kind of this type. func (Type) Kind() Kind. Documented at pkg.go.dev, reflect.Type.Kind.

