Zero2Scale

Why the same bugs come back, even from experienced programmers

21 min read


The article on the map of software bugs opened with this line:

if user.role == "admin" or "editor":

Ask a programmer with five years of Python what bool("editor") returns, and they will say True straight away. Ask whether or or == binds tighter, and they will get that right too. Yet lines like this still show up in code written by people who answer both questions correctly.

Apple's goto fail bug from the same article is the same story. Nearly every C programmer knows that an if without braces controls only the next statement. Still, a duplicated goto fail; line shipped in the TLS certificate check of iOS and macOS.

If bugs came from not knowing, experience would fix them. Most recurring bugs come from somewhere else. They come from how attention, memory, and learning work in people, and from how a team splits knowledge between its members. This article goes through those mechanisms one at a time and shows which groups on the map each one explains. Once the mechanisms are clear, it is easy to see why "we'll be more careful next time" doesn't work, and what works instead.

Experience fixes only some kinds of error

James Reason, a psychologist who studied accidents in industry, aviation, and medicine, classified human error in the book Human Error (1990). The classification builds on Jens Rasmussen's model, which splits human performance into three levels: acting from habit (skill), following rules (rule), and reasoning from knowledge (knowledge). Reason's main question is whether a person planned wrong, or planned right and then acted wrong.

Kind What happens Example in code Does experience help?
Slip The intention is right, the action is wrong, because attention drifted Typing <= instead of <, or copying a block and editing only part of it No
Lapse The intention is right, but a step is forgotten Forgetting defer resp.Body.Close(), or forgetting to check an error No
Rule-based mistake A rule that used to be right is applied where it no longer is err == sql.ErrNoRows after the error has been wrapped Somewhat, but experience also creates rules that expire
Knowledge-based mistake A new situation, reasoned out from scratch, and reasoned wrong Not knowing that a non-empty string is truthy A lot

Experience moves work from the bottom rows to the top. What once needed thought becomes a rule. A rule used often enough becomes a habit that runs without thought. So knowledge-based mistakes drop sharply as people gain experience.

Slips and lapses, though, happen in work that has become fluent and automatic, which is exactly the work experience creates. As for mistakes, Reason points out that they are much harder to detect than slips, because a person following a wrong plan doesn't feel that anything is wrong.

That is the short answer to the question in the title. The bugs left in an experienced programmer's code mostly sit in the top three rows. The rest of this article shows how they happen, and why being more careful doesn't stop them.

The more fluent you are, the less you look

A slip happens when the hands are doing something familiar while attention is somewhere else. In code, the clearest research on this is the last line effect.

Andrey Karpov of the PVS-Studio team noticed that in short blocks of code written by copying the first line and editing each copy, the bug is usually in the last line. Karpov later worked with researchers at TU Delft and a psychologist on a study published in 2017 (Beller et al.). Across 219 open source projects they found 263 faulty blocks of this kind, and confirmed that the last line is much more likely to be wrong than the lines before it. It looks something like this:

func (a Vec3) Equal(b Vec3) bool {
	return a.X == b.X &&
		a.Y == b.Y &&
		a.Z == b.Y // should be b.Z
}

The researchers interviewed the people who wrote such code and explained the effect as an action slip. The task is repetitive and dull, so near the end, attention has already moved on to the next task. Every block whose origin they could trace had been added in an unusually large commit. The author knew perfectly well that the third line should say b.Z. Knowledge wasn't missing. Attention was, for that one second.

Here is another pattern every Go programmer has seen:

func load(path string) error {
	data, err := os.ReadFile(path)
	if err != nil {
		return nil // should be return err, or the caller thinks it worked
	}
	return parse(data)
}

if err != nil { return ... } is a block Go programmers type dozens of times a day. The hands type it on their own, and nil is the word that follows return more than any other in the language. The pattern is common enough that a linter, nilerr, exists just to catch it.

Lapses are similar. Someone who knows that resp.Body must always be closed can still forget when interrupted halfway. They get pulled into a meeting right after typing http.Get, come back, carry on with the logic of the task, and skip the step that was still pending.

For both slips and lapses, knowledge doesn't help, because the author already knows the right answer. Care runs out: when you are tired, when you are in a hurry, when the commit is large. What helps is a check that doesn't depend on anyone's attention.

People read meaning, compilers read tokens

If the author slipped, why don't they see it when they read the code back? There are three reasons.

First, the author is the worst possible proofreader of their own code. It is like looking for typos in an email you just wrote. Your brain already knows what each sentence is meant to say, so it reads the meaning and not the letters. Reading a.Z == b.Y, you see "compare the Z axis", which is what you meant.

Second, expertise changes how people read. In a classic study, Chase and Simon (1973) showed chess players a board for a few seconds and asked them to rebuild it from memory. Masters placed pieces from real games far more accurately than novices, because they saw groups of familiar patterns instead of single pieces. When the pieces were placed at random, the masters' advantage almost disappeared. McKeithen and colleagues (1981) ran the same kind of experiment with programmers and found the same direction. Experienced programmers recalled real code much better, but the advantage disappeared when the lines were shuffled.

So an experienced programmer reads if err != nil { return nil } as one chunk that means "pass the error up". Reading in chunks is fast, and it is why good programmers can read a lot of code in a day. But a chunk with one wrong word still gets recognized as the right chunk.

Third, people and compilers look at different things. goto fail is the clearest example:

if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
    goto fail;
    goto fail;

A person sees the indentation. Both goto fail; lines are indented the same, so both appear to sit under the if. The compiler ignores indentation. It sees an if that controls only the first line, so the second line runs every time. The code tells a person one story and tells the machine another.

Two years later, GCC 6 added the -Wmisleading-indentation warning, enabled by -Wall, which flags indentation that doesn't match the real block structure. The original proposal for the warning used goto fail as its example. Go removed the problem in the language design. An if always needs braces, and gofmt always indents code to match its structure. Both approaches make what a person sees match what the machine runs, without asking anyone to read more carefully.

Rules that used to be right

A rule-based mistake is the mistake of someone who knows a lot. Experience is a store of rules, each learned in one place at one time, and those rules expire without warning.

The first example is in Go itself. Before Go 1.13 (2019), comparing errors with == was correct and common:

post, err := repo.FindPost(ctx, slug)
if err == sql.ErrNoRows {
	return nil, ErrNotFound
}

Go 1.13 added %w to wrap errors and errors.Is to compare them. The day someone changes FindPost to return fmt.Errorf("find post %q: %w", slug, err), the condition above becomes false forever. The code still compiles, nothing warns, and a page that should return 404 returns 500. The longer someone wrote Go before 2019, the stronger the == habit. Linters like errorlint, which this project enables, exist to catch that habit.

The second example hits people who write several languages. Count the length of one string, "สวัสดี👋" ("hello" in Thai, plus a waving hand):

Language Code Result What it counts
Go len(s) 22 UTF-8 bytes
JavaScript s.length 8 UTF-16 code units
Python 3 len(s) 7 code points
What a person sees 5 grapheme clusters: ส วั ส ดี 👋

Someone who writes all three languages every day carries three sets of rules that look almost the same. Each set is right in its own language, and none of them matches what the user sees. Switch languages in the middle of the day and it is easy to reach for the wrong set.

The third example is close to home for Thai programmers. Thailand has no daylight saving time. It is UTC+7 all year. A programmer who has worked with data in Bangkok for ten years may never have seen a 23-hour day. Those ten years taught the rule "a day is 24 hours", which is true every day, until the system gets users in Europe.

loc, _ := time.LoadLocation("Europe/Berlin")
start := time.Date(2026, 3, 28, 9, 0, 0, 0, loc) // daily 9 a.m. meeting

start.Add(24 * time.Hour) // 2026-03-29 10:00 CEST, the meeting moved an hour
start.AddDate(0, 0, 1)    // 2026-03-29 09:00 CEST

An expired rule is more dangerous than not knowing. Someone who doesn't know stops to ask or opens the docs. Someone who already has a rule applies it with confidence.

No feedback, no experience

Daniel Kahneman and Gary Klein came from two schools that disagreed about how far expert intuition can be trusted. In a joint paper in 2009, they agreed that intuition can be accurate only under two conditions. The environment must be regular enough to have patterns worth learning, and the person must have the chance to practice with accurate, timely feedback. They also warned that feeling confident is not a sign that a judgment is right.

Programming gives very fast feedback for some things. Get a type wrong and the compiler complains within seconds. Get the logic of the main path wrong and a test fails within minutes. That is why experienced programmers rarely make those mistakes. But many groups on the map give feedback in ways that teach nothing.

It rarely happens. A 23-hour day comes once a year in countries with daylight saving. February 29 comes once every four years. A race condition may show up once in ten thousand requests. Microsoft's Zune 30 music player went on sale in late 2006, and its clock driver worked every day for two years, until December 31, 2008, the 366th day of the first leap year after launch. On that day, the loop that converted a day count into a year never exited. No earlier day had told anyone the code was wrong.

The path almost never runs. Yuan and colleagues (2014) analyzed 198 user-reported failures in Cassandra, HBase, HDFS, Hadoop MapReduce, and Redis. In 58% of the catastrophic failures, simple testing of the error-handling code would have caught the fault. A checker they built with only three rules would have prevented more than 30%. Error-handling code is code that almost never runs. A programmer with twenty years of experience has run the normal path millions of times, and may never have run the "disk filled up during the write" path at all. Experience builds up only on the paths that run.

The effect is far from the cause. A string from c.Params() that wasn't copied doesn't crash anything. It becomes wrong data in some other request, minutes later. A connection leaked one at a time brings the process down three days later. The person who sees the effect is usually not the person who wrote the cause, and even when it is the same person, connecting the two is hard. So no lesson forms.

Nobody on the team triggers it. Development data has 50 rows, so the N+1 query is fast enough. Production has five million. Honest users never send ../../etc/passwd as a file name. Feedback on security bugs comes from attackers, and it often comes only once.

For some groups, this turns experience upside down. Ten years of writing time-handling code without a problem doesn't mean the code was right. It may only mean the feedback hasn't arrived yet.

Right in each piece, wrong when combined

Experience lives in one person's head. Some bugs live between people.

At Knight Capital in August 2012, no step looked dangerous to the person doing it. The reused flag belonged to a function that had been out of use for years, and the deploy was done by hand, one server at a time. But the eighth server still had the old code, and the old code gave the same flag a different meaning. The result was a loss of about 440 million dollars in 45 minutes.

The Mars Climate Orbiter is the same. JPL's preliminary finding was that the cause was an error in a transfer of information between the spacecraft team in Colorado and the navigation team in California, which nobody caught and corrected in time. Each team was expert in its own work. Neither owned the boundary between them. The CrowdStrike incident in 2024 is the same thing in another form. The template for the content update expected 21 input fields, and the sensor code supplied only 20.

Code review has the same limit. A reviewer sees a diff, not the system. Bacchelli and Bird (2013) studied code review at Microsoft and found that finding defects was the top reason people gave for doing it, but comments about actual defects were a small share of all review comments, and reviewers spent most of their time understanding the context of the change. A diff that changes what one flag means looks harmless if the reader doesn't know that another server is still running the old version.

Nobody has experience with the boundary between team A and team B as it exists this week, because that boundary changes every time either side changes.

The wrong way is the easiest way

A language and its libraries decide the defaults once. Every programmer has to resist those defaults every time.

  • http.Get(url) followed by using resp compiles and works in tests. Closing the body is something you have to remember.
  • A number with a decimal point in Go is a float64, so that is where your hands go first. Storing money as int64 minor units takes intent.
  • s[:10] is the shortest way to truncate a string, and it can cut a Thai character in half.
  • time.Now() can be called from anywhere. Taking the time as a parameter takes design.

Put a number on it. Suppose an experienced programmer gets it right 99% of the time, and the codebase has 500 places that must close a resource. The chance that all 500 are right is 0.99 to the power of 500, about 0.7%. Put the other way, there is about a 99% chance that at least one is wrong. That is one person. A team of ten, plus agents that edit hundreds of files a day, keeps raising the number of times someone has to get it right.

So a recurring bug is a statistical property of the codebase, not a flaw in one person. Being right 99% of the time is very good for a person. It is not enough for a pattern that has to be repeated five hundred times.

A signal that is always on gets ignored

Diane Vaughan studied the decision to launch the space shuttle Challenger in 1986 and named the pattern normalization of deviance. Engineers had seen erosion on the O-rings after several earlier flights. Each time, nothing serious happened, and a sign of danger slowly became an accepted part of normal operation.

Software teams see this every day: a test that fails now and then and gets retried until it passes, a build with two hundred lines of warnings, an alert that fires at 3 a.m. every night. Each time the signal fires and nothing happens, the team learns that it means nothing. The day it fires because of a real bug, nobody looks.

Here, experience really does make things worse. The people who have been on the team longest are the ones who have learned, most often, that these warnings can be ignored.

Which mechanism drives each group on the map

Every group mixes several mechanisms. This table lists only the strongest ones.

Group What makes it come back
1. Logic and arithmetic Slips while copying and pasting, and seeing what you meant to write
2. Null, state, and data Lapses, and effects far from their cause
3. Error handling Paths that almost never run
4. Resources and memory Lapses, the wrong way being the easiest, and effects that arrive late
5. Concurrency Rare events, and pieces that are right alone but wrong combined
6. Security Honest users never trigger it
7. Interfaces and contracts Pieces right alone, and rules that expire when the other side changes
8. Text, encoding, and locale Rules carried over from other languages, and tests written only in English
9. Time and dates Rare events, and local rules (Thailand has no daylight saving)
10. Performance Development data too small to show it
11. Configuration, build, and deployment Pieces right alone, and deploys too infrequent to build habits
12. Requirements and design Knowledge split between the people who build and the people who use, and rules from past projects used to fill gaps in the requirements

Group 12 is worth a closer look. Experienced programmers tend to fill gaps in a requirement with whatever was right on their last project, without asking. That is another rule-based mistake. A newcomer with no rules in their head is more likely to ask.

Why "we'll be more careful" doesn't work

After a bug, most teams write down a lesson that sounds like this: "everyone needs to be more careful about this", "add it to the review checklist", "add a line to AGENTS.md". All of these add knowledge. None of the mechanisms above comes from a lack of knowledge. The person who wrote a.Z == b.Y already knew it should be b.Z.

Care is also a limited resource. Every new thing people are asked to watch for takes attention away from something else. A checklist that grows after every bug ends up as one more signal that is always on.

What works is moving the check out of people's memory and attention and into structure that runs by itself every time.

Mechanism Why experience doesn't help What works
Slips and lapses They happen in fluent work Tools that check every time: the compiler, linters, and Opengrep rules
Seeing what you meant The author knows what they meant to write A formatter that makes layout match structure, warnings like -Wmisleading-indentation, and review by someone else
Expired rules Nothing says the rule changed Keep the current rule in a linter, like errorlint, instead of in people's heads
No feedback The event never happens during development Create the feedback: tests that pass the time in as a parameter and try daylight saving changes and February 29, deliberately injected errors, go test -race, fuzzing, and production-sized data
Right in each piece The knowledge is split across heads A shared schema, contract tests, and canary deploys
The wrong way is easiest The default has to be resisted every time Change the default: a type for money, now as a parameter, and wrappers that make the right way the easy way
A signal that is always on The team learns to ignore it Keep warnings at zero, fix or delete rules that misfire, and fix flaky tests instead of retrying them

The rule "core must not call time.Now()" in this project's AGENTS.md handles several mechanisms at once. It changes the easy path, because core code has to take now as a parameter. It creates feedback, because a test can pass in any date, including February 29. And it doesn't depend on anyone's memory, because the architecture test and the Opengrep rule core-reads-clock fail the build every time someone forgets.

Agents hit the same mechanisms

The Opengrep article said that agents make mistakes in patterns. The mechanisms in this article explain why. An agent doesn't get tired and doesn't get pulled into meetings, but the other mechanisms are all still there, and some are stronger.

  • A model's experience is the code it learned from. That code includes plenty of Go from before 2019 that compares errors with ==, and plenty from before Go 1.22 that writes v := v inside loops. Expired rules come with the model from the start.
  • An agent never sees production. It never sees a 23-hour day or a table with five million rows. Its only feedback is the compiler and the tests it runs during the task.
  • An agent sees only the files in its context, which is narrower than what a single human reviewer sees.
  • A model tends to write the pattern most common in the code it learned from, and the most common pattern is usually the easiest one.

So the fixes are the same as for people, and they work faster, because an agent gets the tool's message within seconds of editing a file and can fix it right away.

What a recurring bug tells you

A recurring bug doesn't tell you the author is bad at the job. It tells you that preventing that kind of bug still depends on people's attention and memory, which run out, slip, and learn the wrong lessons.

So the question after each bug should change from "who made the mistake?" to "which mechanism produced this bug, and what would stop it from happening again without relying on anyone to remember?"

The next articles take the map one group at a time. Each one comes back to that question: which mechanisms make the group recur, and which type systems, tools, Opengrep rules, and tests can take that load off people's memory.

References