Founder Notes
Determinism Is Shared State
A pipeline failed on a branch whose diff was comments only. That is the kind of fact that ought to stop you, because it rules out the explanation you were reaching for. Nothing I had written could have broken a test. So either the test was already broken, or it was broken by something that wasn't code.
It was the second one, and the cause turned out to be a property I had deliberately engineered in.
The setup
Several test modules need a real database rather than an in-memory stand-in, because the behaviour under test is behaviour the real engine has and the substitute does not. They share one. The fixtures they build are seeded with identifiers derived by hashing a name: same input, same identifier, every run, forever.
That determinism is not incidental. It is the point. Those tests exist partly to prove the seeding is reproducible — that the same input yields the same records, and that you can reason about a fixture by its name rather than by whatever number a sequence happened to hand out. Randomising the ids would make the tests pass and stop them testing the thing they were written for.
The suite runs in parallel. The configuration had chosen a distribution mode, with a comment beside it saying, in effect, that this keeps the real-database tests from interleaving their writes.
What the flag actually says
It doesn't say that. It says a module stays on one worker.
Module affinity and database exclusivity are different properties, and the first does not imply the second. Keeping every test in a file on the same worker means those tests don't race each other. It says nothing whatsoever about a different file, on a different worker, writing to the same database in the same instant. Nine files shared that database. The flag constrained scheduling. I had read it as constraining access.
The collision
Two of those modules build the same fixture under the same deterministic id, because that is what deterministic means.
One inserts it inside a transaction it then rolls back. That module is isolated correctly — textbook, even. Nothing it does should be visible to anyone else.
The other commits for real, and brackets itself with a delete on that same id, also committed, so it can begin from a known state.
On one worker, in sequence, the two are fine. On two workers in the same moment against one database, they are either a duplicate key or a row that disappears underneath an assertion, depending on how the writes interleave. Which is precisely the flake I was looking at: intermittent, unrelated to the diff, and gone on a retry.
The part I keep turning over is that the correctly isolated module is a victim here. It did everything right. Rolling back your own transaction protects the database from you; it does nothing to protect you from a neighbour who commits. You cannot make yourself safe alone inside a namespace you share.
Why the obvious fix is the wrong one
The reflex is to randomise the fixture ids. Collisions vanish, the suite goes green, and the tests quietly stop proving the property they were written to prove. The determinism is load-bearing. The sharing is the accident.
Which points at the real shape of the problem. The id was never only an id. It was a name in a namespace, and the namespace was the database. Every module that hashed that name was claiming the same slot, and nothing anywhere recorded that as a claim. No lock, no lease, no allocation — just a convention that stayed unique per module right up until the day two modules ran at once.
The general form
Anything you make deterministic, you have also made shared.
A value is reproducible precisely because it does not vary with who computed it, or when. Inside a single process that is a gift: you can recompute it instead of storing it, compare it instead of tracking it, name it instead of looking it up. Across concurrent processes pointed at one store, that identical property makes it a contended resource — and it will not look like one, because it has no allocator, no registry and no obvious owner. It looks like a pure function.
The list of things this covers is longer than it first appears. Cache keys derived from inputs. Idempotency keys. Temporary paths named after a job. Lock names assembled from a tuple. Any identifier you can compute instead of request is an identifier two things can compute at the same time.
Underneath it sits a smaller lesson I keep relearning: read the flag, not the comment beside it. Configuration that constrains scheduling gets read as though it constrained access, because from a distance the failure it prevents looks like the failure you are worried about. That comment had been true of an earlier and smaller suite. It aged into a false statement without anyone editing a line.