Skip to content

The codebase is a big ball of mud

Maintaining 1 of 3 in Maintaining Aspects: effective action (meta-systematic) · epistemology (relating formal and informal) · contingencies (messes to manage)

Reasoning from the intended design fails once the code has lost its properties. The corrected path observes first, then reasserts one property at a time behind tests.

Meta-rational here follows David Chapman: insights come frominvestigating the relationship between a system of technical rationality and its context(Meta-rationality: An introduction). The pages call that stepping outside the procedure to ask whether it fits the situation.

  • Nobody can say what a change will affect without trying it.
  • Simple fixes take days and break unrelated areas.
  • Tests pass and production still surprises.
  • A rewrite has been planned for years.
  • How the system really works is known to two people.

Will Larson describes one of the smartest engineers he ever worked with, who could not finish projects. Every task exposed a related problem, then a surrounding one, until the original change had become insurmountable. Years later, extending large systems himself, Larson recognized the experience. The systems appeared to have properties, such as all writes going through one log, but each property had caveats: a performance shortcut here, an exception two products made to hit a launch date there. Persistent violations void an abstraction, and once enough have accumulated no properties remain, so any abstract model of the system’s behavior is wrong in ways you cannot predict.

Brian Foote and Joseph Yoder named this kind of system in 1997 and called it the de facto standard architecture: haphazardly structured, sprawling, held together with expedient repairs, with information shared promiscuously among distant parts. Big balls of mud endure because they work, and because the forces that produce them are real: deadlines, changing requirements, code meant to be thrown away and kept, and the sound judgment that a quick entry into the market can be worth more than an architecture built on unproven guesses.

A rational approach to modifying code starts from a model of the design and reasons forward: if the system has these properties, this change will have these effects. In a big ball of mud the properties do not hold, and Larson’s observation is that a more nuanced model does not help; you refine it and it is still wrong. Nelson Elhage reaches the same conclusion from the infrastructure side. Such systems work, where they work, through specific interactions between distant parts rather than through any comprehensible core logic, so reading the source cannot answer the questions you need answered.

What works instead is empirical reasoning. Replace assertions about properties with observed behavior. Ask the running system questions through logs, metrics, traces, and instrumentation. Document what it does rather than what it was intended to do. Mental models still serve for forming hypotheses, but every hypothesis has to be checked against the system before it is relied on. In the terms of Chapman’s table, the formal description and the informal reality have drifted apart, and the work is to relate them again rather than trust either alone.

The second move is to stop treating the mud as one problem. Kevin Simler describes a codebase as an organism that decays whenever anything around it changes and stays healthy only through many small interventions. Matt Belcher lists the signs that those interventions have stopped: changes that break unrelated areas, slowing delivery, a domain model that no longer fits the business, and large refactorings, which are what you get when small ones were skipped for too long. A system a business depends on cannot be taken down for an overhaul, and after a big-bang change nobody can tell which of many modifications caused the new failure. The way back is the one Larson describes: pick one property to reassert, observe the behavior around it, run a pilot, migrate into it, and repeat. Each step makes the next easier. Geoffrey Litt’s reading of Stewart Brand adds that buildings which survive are the ones whose layers can change at different rates, and that code left rough enough for its inhabitants to alter may outlast code designed to be admired. Pairing Larson’s method with particular skills, below, is an inference from these readings; none of the authors writes about agent skills.

Most changes to a large old system are not this situation. If the area you are touching has kept its properties, the tests around it are trusted, and the change is local, reason from the design: read the module, make the change, run the suite, ship. The characterization-test and property-reassertion method is expensive, and applying it to a well-behaved corner of a system is waste. The signal that you are in the mud rather than in old code is the third item on the list above. Until tests have passed and production has surprised at least once in the area you are changing, a small change with a test is the right tool, and the assumption that the code does what it says is the right default.

1 Request lands a change is requested in code nobody understands 2 Trust the design a model of the intended design is assumed 3 Check assumptions skipped the model feels right 4 Easy local change the easy local change replaces the design fix 5 Fix it later skipped the rewrite never comes 6 Ship it the existing tests still pass 7 Elsewhere breaks a distant part depended on the old behavior another patch adds another exception
How the situation goes wrong when handled purely rationallyHow to read
How to read this chart
1 Normal step a step the process takes as intended 2 Break point where the process loses contact with the situation 3 Skipped step a step the process never takes 4 Skill inserted click a pill to read about the skill grilling: Interviews you round by round until nothing about a plan is left silently assumed.grilling GLOSSARY.md: The project glossary: the domain vocabulary every skill reads and writes.GLOSSARY.md A red loop: the same process restarts B teal loop: a misfit noticed sends work back
  • A red outline marks a break point, where the process stops looking at the situation.
  • A dashed, faded card is a step the process skips.
  • A teal pill names a skill inserted at that step; click it for the description.
  • A red dashed loop shows the same process restarting; a teal dashed loop shows a misfit noticed and sent back to an earlier step.
  • A lettered badge marks where each loop starts.

The developer builds a model of what the code was meant to do and does not check it against the running system. The change made is the locally easy one rather than the design change the request needs, and the proper fix is deferred to a rewrite that never arrives. The existing tests pass, because they encode the same stale model. Then a distant part of the system, which depended on the old behavior through a caveat nobody knew about, breaks, and the patch that fixes it adds one more exception to the pile.

1 Request lands in a codebase nobody fully understands 2 Observe first what it does, not what it was meant to do research: Sends a background agent to primary sources and writes cited findings to a file.research diagnosing-bugs: A diagnosis loop for hard bugs: reproduce, hypothesise, instrument, isolate.diagnosing-bugs 3 Rebuild the words name what the mud conflated domain-modeling: Challenges overloaded terms and writes the glossary and decision records.domain-modeling 4 Pick one property a seam where it can be made true again codebase-design: Vocabulary for deep modules and where seams belong.codebase-design 5 Guard with tests characterization tests at the seam tdd: The red-green-refactor loop with rules for tests worth keeping.tdd 6 Small steps keep it working the whole time implement: Implements a spec or tickets test-first at agreed seams.implement code-review: Reviews a diff for standards and spec conformance in parallel sub-agents.code-review 7 Record and repeat ADR for the property, tickets for the rest to-tickets: Breaks a spec into tracer-bullet tickets with blocking edges.to-tickets A surprise: back to observation, not to the model B next property
The same path with skills inserted at the break pointsHow to read

The request lands in the same mud. Observation comes first, the vocabulary the mud has blurred is rebuilt before anything is designed, and the change is scoped to one property that can be made true at one seam and guarded with tests before the code moves. When the system surprises during the small steps, the work returns to observation rather than to the model, because a surprise in a system without properties is information about the system. Once a property is recorded, the next one is picked, which is Larson’s migration, each a little easier than the last.

A request lands: cancellations after fulfillment has started must stop the goods from shipping. The developer reads the cancel handler, sees that it sets a status and emits an event, and concludes that fulfillment must be listening. She adds a check, the tests pass, and the change ships. Three weeks later the warehouse reports that a batch of canceled orders went out anyway. A second cancel path, added for a partner integration years ago, never emitted the event. The patch is a second check in the second handler, and a note that a third path might exist.

Same request, corrected path. Before touching the handler she asks for a record, from logs and traces, of what happens on cancellation after fulfillment. The research turns up both paths and a nightly job that re-reads status, and the word cancel turns out to name three things, which the glossary now says. She picks one property, that every cancellation reaches fulfillment through one seam, pins the current behavior with characterization tests, migrates the partner path behind the seam, and files the nightly job as the next ticket.

Skill When to invoke it here What it changes Example
research Before touching code, when the question is what the system does. A background agent reads logs, metrics, and the code paths that run in production, and writes down observed behavior with citations. /research what actually happens when an order is canceled after fulfillment starts; cite log lines and code paths
codebase-design and improve-codebase-architecture When choosing which property to reassert first and where. Typed command for the scan. Supplies the vocabulary of seams and a ranked scan of deepening opportunities, so the first migration is the one with the most leverage rather than the one nearest to hand. /improve-codebase-architecture
tdd Before the change, at the chosen seam. Characterization tests pin observed behavior, so each step of the migration is rejected at once if it changes anything it should not. /tdd characterization tests for the cancellation path as it behaves today
Skill When to invoke it here What it changes Example
diagnosing-bugs When an observation contradicts the model, even if nothing is formally broken. Applies its loop of reproduce, hypothesize, instrument, and isolate to a property rather than a defect, which reads Larson’s and Elhage’s method into the skill by inference. /diagnosing-bugs why some writes bypass the event log; treat it as a bug in the invariant
domain-modeling Once observation shows one term covering several behaviors. Names the distinctions the code has been blurring in GLOSSARY.md and records the property you intend to reassert as an ADR. /domain-modeling the codebase uses "order" for three different lifecycle objects; separate them
implement and code-review For the migration itself. Typed command for implement. Small steps with typechecks and tests on each, reviewed against the ADR that states the property rather than against the original request. /code-review against main: does this hold the invariant recorded in ADR-0004?
to-tickets At the end of each migration. Typed command. Turns the exceptions you found but did not fix into tickets with blocking edges, so the next property is queued rather than forgotten. /to-tickets from the remaining caveats found while reasserting the event-log invariant

The commonest misreading hears observation over modeling as permission to stop designing. Teams patch by experiment, adding logging and special cases until something works, which is how the mud was made. The method here is empirical about the present and deliberate about the future: each observation ends in a property that is written down and reasserted. A second misreading picks the property nearest to hand rather than the one with leverage, which produces a year of tidy migrations that leave the system no more predictable.

Overdone, it shows as characterization tests with no ADR behind them, or as small changes each justified as reassertion when nobody can say which invariant now holds that did not before.

This is too slow to be practical. A business that depends on the system needs the cancellation bug fixed this week, not a research task, a glossary, a seam, and a migration plan. The only organizations with time for the incremental route are the ones whose mud is not yet bad enough to hurt. And Foote and Yoder themselves say that mud endures because it works, so perhaps the right answer is to patch and accept it.

Patching is not excluded. The failure path is what happens when patching is the only tool, and the cost is paid later, at random. The corrected path also fixes this week’s bug, through a change guarded with tests at one seam, and spends the extra effort on a record of what was learned. Foote and Yoder recommend mud as a starting point and describe piecemeal growth and reconstruction as the ways out; they do not recommend staying.

Where this comes from: The framing of large codebases as things to be treated as nebulous rather than formal comes from the first section of Chapman’s readings post, on working with the nebulosity of software itself, which introduces Foote and Yoder, Simler, Belcher, and Elhage together and connects them to the epistemology row of his table. The examples are Will Larson’s engineer who could not finish projects and the caveat-ridden invariants Larson later met himself, with Foote and Yoder supplying the name and the forces behind it.