The ticket sat for two days. The release build failed in the test environment, and it failed the same way every time. The steps were written down. The logs and the screenshots were attached.
Whoever picked it up did what every team does. Pull the code, build it locally, drop that binary in place of the one that failed. Run it again. The failure is gone. The ticket is closed, and the note says “cannot reproduce locally.”
Nobody thought the afternoon was strange. What had just happened, though, was a complete controlled comparison: two binaries, one source tree, one fails and one does not. The result was sitting on the desk. The bug is not in the code. It is in the difference between the two binaries. That is the most informative conclusion the whole investigation produced, and it was thrown away together with the binary that failed.
The person standing there is not thinking about any of this. The only sentence in their head is the one everyone in that spot has had: nothing changed, so why does a local rebuild stop it from reproducing? I later started calling this a swap-and-heal. This piece is the answer, and the answer is three things.
First: the code can stay the same while the program changes. A compiler makes thousands of small decisions for you — where a variable lives, how the instructions are ordered, which checks survive. Change the compiler version, or change a switch, and those decisions all change with it. Not one character of the source moved, and what you built is already a different program.
Second: the symptom going away is not the bug going away. After you swap the binary, all you know is that you cannot see the problem in the new one. Whether the bug is still in the old one is a question you can answer only by laying the two binaries next to each other. Treat “I can’t see it” as “it isn’t there,” and it comes back somewhere else.
Third: evidence does not survive being handled. More of the things you do while investigating destroy evidence than you think. Swapping the binary, rebuilding, rebooting, upgrading — any of them can throw away the one thing that mattered, such as the binary that actually failed. Order matters. Secure the scene first, compare second, and only then start changing things.
1. Compilation is not translation: same code, different program
Most people picture compilation as translation. Source goes in, the program comes out, and building it in another directory still gives you “that program.” It doesn’t. While compiling, the compiler decides a great many things: whether to inline a function, whether a * b + c is two operations or one instruction, whether a variable lives in a register or on the stack, which of two same-named functions from two libraries wins, whether an assertion stays. Same source, a different batch of decisions, and the program that comes out is different.
The compiler making those decisions has a version, it has its own habits, and it has bugs. One sentence has to be put down first, because the rest of this piece keeps coming back to it:
What a given piece of source means is decided by the compiler version.
Read a swap-and-heal with that in mind and it says something else entirely:
The failure shows up in binary A and not in binary B, so the cause — at least part of it — lives in the difference between A and B.
That cuts the suspect list roughly in half. Most teams throw the cut away on the spot. Once the binary is replaced, there is nothing left to recheck, because A is gone. Heap Corruption Forensics makes the same point about crashes: the crash site is not the scene, and once the scene has been walked over, the truth does not come back. A swap is the same event. This time the person walking over the scene is the one debugging it.
The next section sorts “how the symptom disappeared” into four kinds. Each one comes with source you can paste and commands you can run. The section after that is what to do when it happens to you.
2. How the symptom disappeared: four kinds
“It went away after a rebuild” is more than one kind of bug. The way to tell them apart is to stop staring at what the bug is, and look at how the symptom went away. Different ways of disappearing are different problems.
| How it went away | Kind | What actually changed |
|---|---|---|
| A local Debug build fixed it | State | What uninitialized memory contains |
| The local build is slower, and that fixed it | Timing | How wide the race window is |
| Changing one compiler flag fixed it | Compiler decisions | Different decisions about the same source |
| Nothing changed; a clean rebuild in another directory fixed it | Build identity | The history of how the binary was produced |
Each kind below has full source and the commands to run it. The boundary first: every program here is a small one written to show a mechanism. None of them is the postmortem of a real incident. Every line of output was measured on my machines, and none of it was cleaned up. The machines:
- Windows 11 (10.0.26300), MSVC 19.51.36260 x64, Intel i7-8550U;
- WSL2 Ubuntu 24.04.1, gcc 13.3.0, kernel 6.18.33.2;
- .NET SDK 11.0.100 (Roslyn).
The cl commands below need an x64 Native Tools command prompt, or a shell where you have already run vcvars64.bat.
Kind 1: state — a Debug build fills memory for you
A Debug build is not more correct. It is neater. MSVC’s debug CRT fills a fresh allocation with 0xCD and a freed one with 0xDD. Turn on /RTC1 and the stack is filled with 0xCCCCCCCC too — that is the famous 烫烫烫 in a Chinese console. So a piece of memory nobody initialized holds leftover data in the release build, and one fixed poison value forever in the Debug build.
Full source (uninit.c):
#include <stdio.h>
#include <stdlib.h>
int main(void) {
unsigned char *p = (unsigned char *)malloc(8); /* uninitialized */
printf("heap[0..3] = %02X %02X %02X %02X\n", p[0], p[1], p[2], p[3]);
free(p);
return 0;
}
Build and run, MSVC:
cl /Od /MDd uninit.c /Fe:uninit_debug.exe
uninit_debug.exe
cl /O2 /MD uninit.c /Fe:uninit_release.exe
uninit_release.exe
uninit_release.exe
Measured:
Debug : heap[0..3] = CD CD CD CD <- the same every time
Release : heap[0..3] = B0 A7 D0 BC <- this run
Release : heap[0..3] = A0 EC 47 AE <- run it again, and it moved
In the Debug build that read is 0xCD forever, which looks entirely healthy, so the symptom “goes away.” In the release build it is whatever the allocator left behind, and two runs give two answers.
There is a deeper version of the same thing: the value you read depends on the compiler version, not only on Debug versus Release. This program (signature.c) gives three functions the same size of stack frame, so read_back reuses the frame the previous function just vacated and reads what it left there.
#include <stdio.h>
#include <string.h>
static void leave_a(void) {
volatile char buf[64];
memset((void *)buf, 0xAA, 64);
}
static void leave_b(void) {
volatile char buf[64];
memset((void *)buf, 0xBB, 64);
}
static int read_back(void) {
volatile char buf[64]; /* uninitialized */
return buf[32];
}
int main(void) {
leave_a();
printf("after A: 0x%02X\n", (unsigned char)read_back());
leave_b();
printf("after B: 0x%02X\n", (unsigned char)read_back());
return 0;
}
Build both optimization levels with both compilers:
cl /Od signature.c /Fe:s_o0.exe && s_o0.exe
cl /O2 signature.c /Fe:s_o2.exe && s_o2.exe
gcc -O0 signature.c -o s_o0 && ./s_o0
gcc -O2 signature.c -o s_o2 && ./s_o2
Measured, all four combinations:
MSVC 19.51 gcc 13.3.0
unoptimized 0xAA, 0xBB 0xAA, 0xBB <- exactly what the previous function wrote
optimized 0x1F, 0x1F 0x00, 0x00 <- inlined; the stack is used differently
Unoptimized, the bytes the previous function wrote come back unchanged. That is what an uninitialized read actually is: not a random value, but whatever was written to that memory most recently. Optimized, the functions get folded into the caller, the stack is used differently, and the read returns something else. One defect, four builds, four faces.
The fix is to initialize every path. The compiler does warn about an uninitialized variable on the stack — MSVC’s C4700 really does fire on uninit.c, and then drowns in a few thousand other warnings — and it says nothing at all about the heap. That gap is what the tools are for: MSan on Linux, /analyze with MSVC, and those warnings promoted to errors. One comparison is worth writing down. C# closes most of this family in the language itself, with definite-assignment analysis: an uninitialized local does not compile. C++ leaves it to the programmer. The languages disagree about whose job it is, and the consequence is concrete. On a C++ team the only defense is discipline plus tools.
Kind 2: compiler decisions — the compiler chose differently
Start with the plainest case, assert (assert_side_effect.c):
#include <assert.h>
#include <stdio.h>
static int inited = 0;
static int init_once(int v) {
inited = v;
return v;
}
int main(void) {
assert(init_once(1) == 1); /* Release (NDEBUG): this whole line is gone */
printf("inited=%d\n", inited);
return 0;
}
Build and run. Debug does not define NDEBUG; Release does:
cl /Od /MDd assert_side_effect.c /Fe:a_dbg.exe && a_dbg.exe
cl /O2 /DNDEBUG /MD assert_side_effect.c /Fe:a_rel.exe && a_rel.exe
Measured, and Windows and Linux agree:
Debug : inited=1
Release : inited=0
The point of this one is sharp. The release build does not contain a line that was written wrong. The release build does not contain the line. Define NDEBUG and the preprocessor deletes the whole assert. The init_once hidden inside it never ran. Swap in a local Debug build, the line comes back, and the symptom is gone. You think you fixed something. Nothing was fixed, because the problem was never in the source.
The same family has a quieter member. Both builds are conforming, and they reach opposite verdicts. Floating point (fp_contract.c):
#include <stdio.h>
int main(void) {
volatile float va = 1.0001f;
volatile float vt = 2.0004e-4f;
float a = va, t = vt;
float r = a * a - 1.0f;
printf("r=%.9g (0x%08X)\n", (double)r, *(unsigned *)&r);
if (r > t) printf("TOLERANCE EXCEEDED\n");
else printf("within tolerance: OK\n");
return 0;
}
Build and run. The machine has to be able to emit FMA:
cl /O2 /arch:AVX2 /fp:precise fp_contract.c /Fe:f_p.exe && f_p.exe
cl /O2 /arch:AVX2 /fp:fast fp_contract.c /Fe:f_f.exe && f_f.exe
Measured. /fp:precise evaluates in source order and rounds at each step. /fp:fast may contract the expression into one FMA and round once:
/fp:precise : r=0.000200033188 (0x3951C000) within tolerance: OK
/fp:fast : r=0.000200043185 (0x3951C2AF) TOLERANCE EXCEEDED
One expression, two builds, both within the standard, one says pass and one says fail. I checked the same bit patterns on Linux with gcc -ffp-contract=off and -ffp-contract=fast: not one byte differed. IEEE arithmetic is the same across the two platforms. The disagreement is in the build flags. a and the threshold are read through volatile so the compiler cannot fold the constants at compile time. The only place left for the two builds to diverge is the rounding that happens at run time.
A different version is a different set of decisions
In those two programs the decision came from a flag. More often it comes from the compiler version. The compiler on a developer’s machine keeps getting upgraded. The one on the build pipeline is pinned. So the local compiler is usually newer than the pipeline’s, and it only gets newer. That is true of MSVC, and it is true of the C# compiler, which moves with the SDK and with Visual Studio.
There is a second difference stacked on top of that one. To make debugging easier, a local build is often the Debug configuration, with optimization off. The two binaries then differ on two axes at once:
local build = new compiler × optimization off × local machine
shipped build = old compiler × optimization on × pipeline
The comparison moved two variables. That is why people can spend a week on “fine locally, broken in the build” and get nowhere: every comparison changed the version and the optimization together, so the result can never be attributed. The first rule of a comparison follows from that. Change one thing at a time. First reproduce the shipped behavior locally, with the pipeline’s compiler version and the pipeline’s flags. Once that holds, relax the variables one by one.
A documented case: the C# closure
Compiler version changing behavior is not a rumor. It is in the C# documentation. Teams have hit it like this: the build in the test environment misbehaves, and locally it will not misbehave no matter what you do — the same code is simply correct on the local machine. The cause, in the end, was that the local C# compiler and the pipeline’s were different versions, and their closures were implemented differently. The code captured a loop variable. The two compilers disagreed about whether that variable was one variable for the whole loop or a new one each iteration. Not one character of the source changed. The behavior did.
This is a breaking change the C# documentation records. Before C# 5, the foreach iteration variable was shared across the loop, so every closure that captured it saw the last element. From C# 5 on, each iteration gets its own variable. The observed result goes from 2 2 2 to 0 1 2, and nowhere in the source is that difference written down.
Full experiment (Program.cs):
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
var items = new List<int> { 0, 1, 2 };
var actions = new List<Action>();
foreach (int x in items)
{
actions.Add(() => Console.Write(x + " "));
}
foreach (var a in actions) a();
Console.WriteLine();
}
}
The project file. Set TargetFramework to an SDK you actually have; dotnet --list-sdks will tell you:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<!-- build once as 4, then change this to latest and run again -->
<LangVersion>4</LangVersion>
</PropertyGroup>
</Project>
Run it with dotnet run -c Release. Measured on .NET SDK 11.0.100, which is Roslyn:
LangVersion=4 : 0 1 2 <- pinned at 4, and still not the 2012 behavior
LangVersion=latest : 0 1 2 <- change the 4 in the project file to latest, and run again
(the 2012 compiler: 2 2 2 — the breaking change, as documented)
LangVersion gates syntax and features. It does not restore old behavior. Roslyn made that semantic fix unconditional, so a new compiler cannot even pretend to be the old one. The old behavior is not in any installer. It exists only on the old pipeline. Which leaves one sentence:
The only compiler you can trust to reproduce the pipeline is the pipeline’s own.
The awkward case: the compiler itself is wrong
There is a rarer case, and a worse one. The comparison is finished, the version matches, the flags match, and the failure is still only in the shipped binary. What you eventually find is that the pipeline’s compiler has a bug. The code is legal. The standard allows it. The compiler translated it wrong.
That hits a premise debugging quietly stands on: the whole investigation assumes the compiler is right. “The compiler has a bug” is also the easiest thing to say when you want to stop looking, so it should not be said until four conditions are all met:
- The code is actually correct. It is inside what the language specification allows. A second pair of eyes, or the text of the standard, is worth having. Rule out undefined behavior first.
- The versions disagree. The same source, two compiler versions — or two optimization levels — produce different results, and the specification says they should not.
- It is small. A few dozen lines, and it reproduces on its own.
- The disassembly convicts it. You can point at the instruction that was translated wrong, rather than saying the behavior looks off.
Those four exist first of all to throw out the false cases. Here is the drill (conviction_drill.c). x + 1 > x is never true in mathematics, but when x is INT_MAX, x + 1 is a signed overflow, and that is undefined behavior. Two compilers give this program opposite answers:
#include <stdio.h>
#include <limits.h>
int main(void) {
int x = INT_MAX;
if (x + 1 > x) printf("x+1 > x\n");
else printf("x+1 <= x\n");
return 0;
}
Build and run:
cl /O2 conviction_drill.c /Fe:c_msvc.exe && c_msvc.exe
gcc -O2 conviction_drill.c -o c_gcc && ./c_gcc
Measured:
gcc 13.3.0 -O0 : x+1 > x <- folded away, on the assumption that overflow never happens
gcc 13.3.0 -O2 : x+1 > x
MSVC 19.51 /Od : x+1 <= x <- a wrapping add, generated straight
MSVC 19.51 /O2 : x+1 <= x
The two compilers disagree, which is enough for a lot of people to start the “compiler bug” email. Walk the four conditions and the first one already fails: x + 1 overflowing is undefined behavior, so the fault is in the code, both compilers are right, and there is no bug to report. The same run shows something else. gcc gives the folded answer even at -O0. Decisions like this are not confined to the optimizer. They happen in the front end too, which means “I didn’t turn optimization on, so the behavior should match” is not a safe assumption.
If all four conditions do hold, and it really is the compiler, the fix is a different kind of fix. You are not patching the code in the ordinary sense, and you are not patching the build. You rewrite the code to avoid the pattern that triggers it, you move the compiler version, and you send the reduced case to the vendor. Leave a comment that says, in so many words, that this was rewritten to dodge a bug in compiler version X, so the next person who upgrades does not “clean it up” and put the bug back.
Compiler bugs also cluster at version boundaries. A new optimizer is a new surface for them. A pipeline pinned to an old version is, for that reason, the stable one, and a laptop that always runs the newest compiler means your code is the vendor’s free test suite. So both directions happen — fine locally and broken when shipped, or broken locally and fine when shipped — depending on which version the bug lives in.
What to fix
List every version and every flag that changed at the moment the symptom disappeared, and go through them. Uninitialized reads, aliasing, and integer overflow come first, because they are what gives the compiler room to move. Sanitizers are orthogonal to the optimization level: the same undefined behavior shows up in any build. Non-Invasive Probes is entirely about that.
Kind 3: timing — the shipped build is fast enough to hit the race
A race is not “intermittent.” The race happens. Whether you observe it depends on the gap between two operations, the gap depends on how fast the program runs, and how fast it runs depends on how it was built. A Debug build is slow, the gap is small, and the race misses. An optimized build is fast, and it connects.
Full source (race_spin.c), one file for Windows and Linux:
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
static long stop_flag = 0;
static DWORD __stdcall worker(LPVOID arg) {
(void)arg;
while (!stop_flag) { }
return 0;
}
int main(void) {
HANDLE t = CreateThread(NULL, 0, worker, NULL, 0, NULL);
Sleep(100);
stop_flag = 1;
WaitForSingleObject(t, INFINITE);
printf("joined\n");
return 0;
}
#else
#include <pthread.h>
#include <unistd.h>
static int stop_flag = 0;
static void *worker(void *arg) {
(void)arg;
while (!stop_flag) { }
return NULL;
}
int main(void) {
pthread_t t;
pthread_create(&t, NULL, worker, NULL);
usleep(100000);
stop_flag = 1;
pthread_join(t, NULL);
printf("joined\n");
return 0;
}
#endif
stop_flag is an ordinary variable. The worker reads it in a loop and the main thread writes it. That is a data race. Build and run:
cl /O2 race_spin.c /Fe:r_msvc.exe && r_msvc.exe
gcc -O0 race_spin.c -pthread -o r_o0 && timeout 3 ./r_o0
gcc -O2 race_spin.c -pthread -o r_o2 && timeout 3 ./r_o2
Measured:
GCC 13.3.0 -O0 : joined, rc=0 <- exits normally
GCC 13.3.0 -O2 : (no output) rc=124 <- killed by timeout after 3 seconds: hung
MSVC 19.51 /O2 : joined <- exits normally
At -O2, gcc lifts that load out of the loop and keeps it in a register. The worker never sees the write, and the optimized build hangs. The unoptimized build re-reads memory every iteration, and a local build “fixes” it. MSVC’s /O2 does not do that lift on this code. Both of its levels exit normally.
Put compiler and optimization level in one table and you get the concrete shape of the “local versus shipped” difference from earlier:
MSVC 19.51 gcc 13.3.0
unoptimized joined joined
optimized joined hangs (rc=124)
Change only the optimization level and gcc flips. Change only the compiler and the optimized result flips. Change both at once and what you see is not any cell of this table. It is the two factors tangled together.
Honestly, this example sits in both kind 2 and kind 3. Under gcc it is a compiler decision: the load was hoisted. In the real world there is also a pure timing face. A Debug build is slower and its window is narrower, and the same race shows up the moment you move it to a faster machine.
The fix is to stop letting correctness depend on speed. An atomic, or a lock, rather than “wait a bit longer” or another sleep. TSan, which gcc and clang ship, will name both sides of the race. On Windows the method for this family is the whole of The Harder You Look, the Less It’s There, whose main case is a use-after-free that exists only in the release build.
Kind 4: build identity — the code is fine, and the way it was built is not
This is the deepest of the four, and the one the name fits best. Not one character of the source moved. Both builds are “correct.” The behavior differs anyway.
Example 1: link order picks the function
Three files, main.c, channel_a.c, channel_b.c:
/* main.c */
#include <stdio.h>
int build_channel(void);
int main(void) {
printf("channel=%d\n", build_channel());
return 0;
}
/* channel_a.c — A's SDK ships this little helper too */
int build_channel(void) { return 1; }
/* channel_b.c — B's SDK ships the same helper, with different behavior */
int build_channel(void) { return 2; }
Build both libraries and link them in both orders, MSVC:
cl /c /O2 main.c channel_a.c channel_b.c
lib /nologo /out:feat_a.lib channel_a.obj
lib /nologo /out:feat_b.lib channel_b.obj
link main.obj feat_a.lib feat_b.lib /out:a_first.exe && a_first.exe
link main.obj feat_b.lib feat_a.lib /out:b_first.exe && b_first.exe
Measured:
a_first.exe : channel=1
b_first.exe : channel=2
dumpbin /symbols shows build_channel sitting in both libraries. The linker takes the first one that satisfies the reference and never pulls the second library in at all, so there is not even a duplicate-symbol error. Which one gets used is not written anywhere in the source. It is written only on the link command line. The real-world version is two SDKs that each statically carry the same logging helper, the same JSON parser, the same allocation hook. Which one runs depends on the order of the link line, and recreating the project locally changes that order. The behavior changes, and you think the bug was fixed.
Linux does the same thing: gcc main.o liba.a libb.a against gcc main.o libb.a liba.a.
Example 2: the header moved on, and half the code is still built against the old one
Five files. Two versions of the header:
/* layout_v1.h — size is at offset 4 */
struct job {
int id;
int size;
};
/* layout_v2.h — prio was inserted in the middle, so size moved to offset 8 */
struct job {
int id;
int prio;
int size;
};
Two sources and a main program, each including layout.h:
/* producer.c */
#include <stdio.h>
#include <stddef.h>
#include "layout.h"
struct job make_job(void) {
struct job j;
j.id = 1;
j.size = 100;
printf("[producer] sizeof(job)=%zu offsetof(size)=%zu\n",
sizeof(struct job), offsetof(struct job, size));
fflush(stdout); /* a crash should still leave this line on screen */
return j;
}
/* consumer.c */
#include <stdio.h>
#include <stddef.h>
#include "layout.h"
int consume(struct job j) {
printf("[consumer] sizeof(job)=%zu offsetof(size)=%zu size=%d\n",
sizeof(struct job), offsetof(struct job, size), j.size);
fflush(stdout);
return j.size == 100 ? 0 : 1;
}
/* main.c */
#include <stdio.h>
#include "layout.h"
struct job make_job(void);
int consume(struct job j);
int main(void) {
struct job j = make_job();
int rc = consume(j);
printf("rc=%d\n", rc);
fflush(stdout);
return rc;
}
Three stages. These are the MSVC commands. On Linux, cl /c becomes gcc -c, and link a.obj b.obj c.obj /out:x.exe becomes gcc a.o b.o c.o -o x.
:: stage 1: the v1 header, a full build
copy /y layout_v1.h layout.h
cl /c /O2 producer.c consumer.c main.c
link producer.obj consumer.obj main.obj /out:clean_v1.exe
:: stage 2: header moved to v2, but only producer is rebuilt — half new, half old
copy /y layout_v2.h layout.h
cl /c /O2 producer.c
link producer.obj consumer.obj main.obj /out:mixed.exe
:: stage 3: rebuild everything
cl /c /O2 consumer.c main.c
link producer.obj consumer.obj main.obj /out:clean_v2.exe
Measured:
stage 1 clean_v1 : producer offsetof=4 consumer offsetof=4 size=100 rc=0
stage 2 mixed : MSVC -> 0xC0000005, crash, before producer's first printf
gcc -> producer offsetof=8, consumer offsetof=4, size=0, rc=1
stage 3 clean_v2 : producer offsetof=8 consumer offsetof=8 size=100 rc=0
Running mixed.exe from stage 2 crashes. That is the result, not a mistake in the steps.
Why: an 8-byte struct in v1 is passed and returned in registers, and a 12-byte struct in v2 goes through a hidden pointer. Change the layout and the calling convention between the two modules changes with it. In the half-new binary, the producer and the consumer disagree about how a job is handed over. The two compilers even fail differently. MSVC’s mixed binary dies on the first cross-module call. gcc’s mixed binary does not crash; it quietly returns the wrong number, and the program’s own check catches it. One mismatch, two ways of failing.
The MSVC crash is worth a closer look. The mixed binary never reaches producer’s first printf. There is nothing mysterious about that. Disassemble producer.obj:
make_job:
mov rbx,rcx ; v2 believes rcx is the hidden return buffer
mov dword ptr [rcx],1 ; j.id = 1, written to an address the caller never set up
mov dword ptr [rcx+8],64h ; j.size = 100
mov edx,0Ch ; sizeof, for the printf: 12
lea rcx,[format string]
mov r8d,8 ; offsetof(size), for the printf: 8
call printf ; <- never reached
The two stores through [rcx] are scheduled before the printf, and that rcx is not a return buffer in the calling convention of main, which was built against v1. It is a leftover value nobody owns. There is more in the same listing: sizeof=12 and offsetof=8 are immediate constants. The v2 layout lives in those constants. Disassembly does not lie, because it is read out of the binary, not inferred from the source.
Stage 3 is a swap-and-heal in the most literal sense. A full rebuild, and the symptom is gone. What it proves is not that some bug in the code got fixed along the way. It proves that the old binary’s build history contained a disagreement nobody had seen. Source is the recipe. The binary is the dish. Something was wrong, you took the dish away, and then you went looking for the cause in the recipe.
The fix, for this kind only: the pipeline ships full rebuilds, incremental products never get deployed, duplicate symbols across libraries get hunted down, and a checksum is checked before anything is deployed. Answering this kind with “more training” or with a code change is answering the wrong question. The bug is not in the code.
3. What to do when a rebuild makes it go away
That is the taxonomy. The method is one sentence: a swap-and-heal is not where the investigation ends. It is where the investigation starts. Four steps.
First, secure what is on the scene, before anyone touches a keyboard.
Keep the binary that failed: the binary itself, its PDB, its checksum, and the record of how it was built. Compiler version — the local one and the pipeline’s, on the first line — every flag, every dependency version, the source revision, the build machine. The old rule of debugging applies: without symbols, a scene is something you can only look at. After the binary has been replaced, that record is all of it that remains.
Second, compare, and change one thing at a time.
The suspect list is the difference between the two binaries, not the diff of the source. Walk it: toolchain version, optimization and warning level, runtime library, dependency versions and link order, stale objects left by an incremental build, the build machine itself. The side-by-side method in “It Works on My Machine” applies here as it stands. What changed is the thing being compared: the build, rather than the machine. The rule from earlier still holds. Reproduce the shipped behavior first, with the pipeline’s version and the pipeline’s flags, confirm the failure is still there, and only then relax one variable at a time. Move two, and the result cannot be attributed.
Third, read the disassembly.
Do not stop at “the symptom is gone.” Diff the machine code of the same function in the two binaries with dumpbin /disasm. Was the assert deleted? Did the multiply-add become a vfmadd? Is the load still inside the loop? Disassembly does not lie. The make_job listing above is how that one was obtained. It is read from the binary, not deduced from the source, and every example in kind 2 is just as plain in the listing. When the question is whether the compiler itself is wrong, this is the last piece of evidence before you say so.
Fourth, name the kind, and then decide what to fix.
- State and timing: fix the code. Initialize every path, add the synchronization, then rerun under a sanitizer and confirm the bug cannot hide in any build.
- Compiler decisions: clear the undefined behavior. If all four conditions hold and it really is the compiler, avoid the pattern, move the version, and report it, as above.
- Build identity: fix the build. Full rebuilds only, no incremental product deployed, duplicate symbols across libraries removed, checksums checked before deploy. “More training” or a code change is the wrong answer to this kind. The bug is not in the code.
One more rule, and it is the one most often broken. Never replace the binary in a real environment with one you built locally. Not even a build you made for debugging. A debugging build has to come off the same pipeline as the shipped one: same compiler, same version, same flags, same dependencies. Otherwise every “let me swap in a build so I can look at it” repeats the act of destroying the scene.
The steps are done. Steps are rigid, and they need a few principles under them, or they stop applying the moment the problem or the language changes. Fold the argument up and six are left. None of them belongs to a language. Each one has a case in this piece, and each one works somewhere else.
One level up: six principles
1. The symptom disappearing is not the problem being solved.
That sentence is the whole piece. “The rebuild fixed it” and “the problem is solved” have a full comparison experiment between them, and most people spend the relief of the first one as if it were the second. The principle reaches past compilation. A dashboard going green is not a root cause removed. A customer who stopped complaining is not a defect gone. A postmortem where nobody mentions it again is not a process repaired. Wherever “I can’t see it” gets used as “it isn’t there,” it comes back.
2. What you are debugging is the binary, not the code.
Source and binary have to be kept apart. Source is what you meant to do. The binary is what got done — the recipe and the dish. Only the binary is evidence, and every binary has coordinates: which machine, what time, which version, which pipeline. Before asking where the code is wrong, ask which specific binary the thing you are looking at belongs to. If that has no answer, everything after it is a guess.
3. Write down every behavior change you did not plan.
“It suddenly worked.” “It suddenly broke.” “Changing the build made it go away.” Every unplanned change of behavior during an investigation is a lead, and they share one bad property: once they have passed, they cannot be recovered. They are not “another try.” Write down which binary, under what conditions, and how the behavior moved. That is what an investigation log is for.
4. Change one thing at a time.
This is the ordinary rule of an experiment, and it is the first one dropped when the investigation is urgent, because changing three things looks faster. The table above is the answer: an experiment that moves two variables cannot be attributed. Performance work is the same — one parameter at a time. So is changing a process after an incident. So is the everyday “I tried a few things and it got better.” A fix you cannot say which change produced is a fix you did not make.
5. Before you act, ask what the action will destroy.
Rebuilding, rebooting, redeploying, clearing caches, upgrading, “it didn’t reproduce, try again” — a lot of the ordinary moves of an investigation also destroy a lead you have not used yet. Before each one, ask whether it will throw away something you still need. Evidence that is gone is gone. The action can be repeated. That is the order.
6. The more comfortable the conclusion, the more evidence it should cost.
“The compiler has a bug.” “It’s the environment.” “The AI wrote it.” The easier a conclusion is to say, the more evidence it should require. The reason is simple: the easier a conclusion is, the more readily people believe it, and it is usually not the truth. The spirit of the four conditions is one line. Leave the most comfortable conclusion for last, and set the highest bar of evidence in front of it. Blaming an incident on “someone slipped” is the same kind of comfort. The discipline on that side, in What a Postmortem Is Actually Reviewing, is this one.
The six fold back into the third thing from the opening. Evidence does not survive being handled. Everything you can do points at one action: put two things that can be compared side by side, hold them still, and let the difference speak. A difference does not lie. It is only very easy to throw away.
4. Keeping it from happening
Everything above is after the fact. The real prevention is making the binary and the source reconcilable.
Pin the toolchain at both ends. Pinning the pipeline is common sense. The other half, from earlier, is that local machines have to be pinned to that same version. Automatic updates of the local toolchain are what makes the gap keep growing. C# pins the SDK with global.json. MSVC can be pinned with a container or an image at a fixed workload version. The setup list for a new machine names the version. “Install the latest” comes off that list.
Reproducible builds. /Brepro on MSVC, dependencies pinned, link order written down. This is not fussiness. Once two binaries can be shown to be identical byte for byte, the “difference between the binaries” stops being a place a bug can hide, and the whole class of problem this piece is about is gone at the source.
The binary carries its own provenance. Each one ships with enough to rebuild it: compiler and version, every flag, the dependency list, the source revision, a checksum. The aim is that “how was this binary built” stops depending on someone remembering. A swap-and-heal stops being an observation that gets thrown away, and becomes a comparison that was recorded.
Only a pipeline binary gets deployed. A binary built on a laptop stays on the laptop. It can be a draft. It cannot be the “fix” for any environment.
5. AI makes this worse
All of that was already hard on a team of people. AI adds three layers.
First, “local” is less trustworthy than it used to be. The local build now has the model’s edits mixed in, so you are not even aligned at the source, let alone at the binary. “Works on my machine” is quietly becoming “works under today’s prompt.” The two sides of the comparison don’t even share source, and a comparison like that has nothing to say.
Second, the build scripts and the pipeline itself are increasingly written by a model. Compiler version, flags, link order — the decisions in kind 4 that exist only on a command line — used to have at least one person who remembered why they were ordered that way. That person is going away too.
Third, one of the suggestions a model reaches for most readily is “try upgrading the dependency” or “try upgrading the toolchain.” In the terms of this piece, that is deliberately widening the gap between the laptop and the pipeline. An upgrade changes thousands of compiler decisions, reshuffles what uninitialized memory contains, and exposes the code to a new compiler’s new bugs. Sometimes it is the fix. When it is, it belongs in the pipeline as a controlled change with a full verification, not as a command typed into a local terminal because it was convenient.
So the question goes one layer further down, and it is the same question as the postmortem piece:
Who built this binary, on which machine, with what configuration? If that cannot be answered, what you are investigating is not only a bug. It is something whose origin you cannot state.
6. Closing
The relief at the moment of a swap-and-heal is real. The conclusion drawn from it is wrong.
A symptom disappears for one of two reasons. You removed the bug, or you removed the conditions under which you could see it. The first requires you to say what the difference was. The second requires you to admit there was one. Both start with the same move: put the two binaries on the table and compare them.
Most teams start by rebuilding in another directory instead. The problem goes quiet, and waits for the next release. Compiler versions move, the bytes in uninitialized memory move, and the rules for closures move. This class of bug does not go away on its own.
A bug never lives in the source. It lives between two builds.
