Skip to content

terminating connection due to administrator command: two test runs sharing one database

Three integration failures, three different error signatures, none reproducible alone. A rate-limit counter was blamed; the cause was the database name.

Error message
terminating connection due to administrator command

Also searched as: "my tests fail randomly when several agents run in parallel"

In short

Symptom
An integration suite fails on a perfectly correct business assertion, then goes green again when rerun alone. From one run to the next, it is never the same tests that fail, nor the same error signature.
Real cause
Each suite names its PostgreSQL database with a hard-coded constant, and the test harness force-drops that database before recreating it. Two concurrent runs (two agents, two workspaces, one server) target the same name: the second destroys the first one's database mid-run.
Fix
Add a run identifier to the database name, and make the creation function refuse any database that does not carry it. The lock then sits on the path everyone takes, and not in a naming convention the next file will forget.
Prevention
If a failure disappears when the suite runs alone, twice in a row, it does not come from its assertion: look for what was running at the same time. Every shared resource of a test harness must carry its run identifier to be isolated.

The answer, in three lines

An integration suite failed three times in a row, on three different groups of tests, with three different error signatures. Rerun alone, it passed in full, twice in a row.

The intermittency pointed to a plausible culprit: a shared rate-limit counter, in a key-value store, with a one-minute window. That verdict was written down in a report.

It was wrong, or rather too narrow. The cause was the name of the test database: a hard-coded constant, identical in every workspace, on a single PostgreSQL server. The agent that found it was running next door, and the one that had got it wrong corrected its report.

The symptom

The setting is an ordinary fleet day: three agents work in parallel, on three unrelated batches of fixes, each in its own git workspace and on its own branch. The repository is the same, and the service containers (database, cache, fake mail server) come from the same compose file, started once.

One of the agents runs the full integration pipeline before handing in its work. It fails. The agent runs it again, and it fails again, somewhere else.

Pipeline runWhat failsWhat the error says
4th runthe authentication suite, 4 testssocket hang up
5th runthe bookings suite, 10 testsdatabase "app_test_reservations" does not exist
6th runan admin suite and an imports suite, 7 tests500s and 404s instead of the expected responses

The three runs bring down suites that have nothing to do with each other, with signatures that have nothing to do with each other either. Yet the integration step run alone passes in full: 47 suites, 626 tests, twice in a row.

The wrong diagnosis

The reasoning held, but it stopped too early. A hypothesis that explains the observed facts is only a possible cause, as long as nothing has tried to tell it apart from another one.

This one was also very tempting: it pointed at a resource that was shared and sensitive to concurrency, and its remedy, rerunning the suite alone, worked.

Yet it is precisely the remedy that works that leads you astray. Running alone removes concurrency, so it removes every concurrency-related cause at once. An experiment that does not tell two hypotheses apart confirms neither.

What is actually happening

The harness drops before it creates

To start from a clean state, the function that prepares the test database begins by destroying it: a forced drop, which closes any connections still open on it. That is the right move, since leftovers from the day before would skew everything. It is also the move that lets two simultaneous runs destroy each other.

The database name is a hard-coded constant, at the top of the test file:

// bookings suite, top of file
const DB_NAME = 'app_test_reservations';   // ← a constant, the same everywhere

// the shared harness module, one line further down
//   … a single PostgreSQL server address, for everyone

A git workspace is a copy of the repository, so the constant is identical down to the character in each of them. The PostgreSQL server, on the other hand, is unique: it is the one from the compose file, started once for the whole machine.

This was not an isolated oversight: the inventory taken at fix time found 40 integration suites that hard-coded their database name the same way. It was the repository's convention, and it was correct as long as only one run happened at a time.

The timeline of the collision

  1. agent A starts its suite, creates app_test_reservations, sets up its schema and starts its tests;
  2. agent B starts the same suite a few seconds later, in another workspace;
  3. B's harness does what it is supposed to do: it drops app_test_reservations, A's database, and recreates it;
  4. A's connections are closed in the middle of a test, with this message: terminating connection due to administrator command;
  5. B finishes without trouble. It is green, and it saw nothing.

Whoever starts second always wins. Whoever starts first gets a failure that describes the neighbouring breakage, in a place that has nothing to do with it.

Why the error changes face every time

This is what makes the diagnosis so hard, and the mechanism is simple: the message depends on the moment the destruction lands.

  • during a query: terminating connection due to administrator command;
  • between two suites, before a reconnection: database "…" does not exist;
  • on a connection already re-established but against an emptied schema: 500s and 404s, that is, business code answering wrongly, with nothing mentioning a database.

The third case is the most expensive to diagnose: it looks exactly like an application regression, and nothing in the output suggests looking elsewhere.

What the agent that settled it could see

It did not guess: it looked at the running processes. Two other agents had their test runner going during its runs, in two other workspaces, with the same constant in the same file. The rest follows from reading the harness: a forced drop, a constant name, a single server.

That observation proved the cause, where the previous agent only had a hypothesis. That is what allowed the earlier report to be corrected without argument.

The fix

Step 1: Suffix with a run identifier, not a suite name

The database name becomes the output of a function: the suite's subject, plus an identifier specific to the current run, inherited from the environment. Two simultaneous runs thus get two different names without knowing anything about each other, and a runner that wants to name its run can impose its identifier through an environment variable.

The identifier has to come from the run, not from the workspace: two runs in the same workspace get in each other's way in exactly the same manner.

Step 2: Make the creation function refuse any name without the identifier

Without this step, the fix stays a wish. The computed name only protects the files that use it, and the next test file, written by someone who has not read this one, will copy a constant.

The function that creates the database therefore refuses any name that does not carry the identifier. The lock sits on the path everyone takes, and not in a convention you have to know about.

Step 3: Look for the other shared resources before declaring victory

The database was the most visible shared resource, but not the only one. Three other resources were shared between runs, without it showing at first glance: a pre-filled template database, a directory of files that the final cleanup deletes recursively, and the job queue prefix.

They are fixed in a different place. The identifier has to be set before the worker processes are created, in the only entry point that runs once per run and that the workers inherit from. Set any later, each worker draws its own, and the isolation disappears.

Step 4: Prove the isolation with two concurrent runs, both ways

Rerunning the suite proves nothing. To prove the isolation, start two simultaneous runs: once with the identifier forced to the same value, which reproduces the original state exactly, and once normally.

Run ARun B
identifier forced identical (the state before)48 tests failing out of 4848 out of 48 green
per-run identifier (after)48 out of 48 green48 out of 48 green

On the top row, A carries the expected message: terminating connection due to administrator command. Look at column B too, green in both cases: the winner of the race does not know there was a race.

Prevention

The second rule concerns the harness itself, and it goes beyond databases: every resource a test harness creates or wipes must carry its run identifier, or it is not isolated. A database, a directory, a queue prefix, a port, a container name, a cache key: the list is long, and you only find it by searching for the destructive verbs, such as drop, empty or reset.

The third applies to writing the fix. An isolation that rests on a naming convention holds only through the discipline of whoever writes the code: as long as a file can write a constant name and nothing refuses it, the isolation eventually gives way.

Why this matters with agents

This failure does not exist for a developer working alone. They run a suite, they wait, then they run another one. The hard-coded constant can live for years without ever doing harm: the defect existed before the fleet, and it is the fleet that made it reachable.

It is the mark of fleet work, and it goes beyond tests. A resource that had only one user becomes shared the day you move to three agents, without anyone having decided to share it. And state that nobody is responsible for only causes trouble at the moment two processes touch it at once.

The second lesson concerns how an agent reaches a conclusion. The one that got it wrong had not been careless: it had a consistent hypothesis and a remedy that worked, and it wrote it down in its report, saying what it rested on. Neither a review nor a doubt corrected it: it took proof supplied by another agent, which was looking at the same machine at the same moment.

What this entry does not cover

The time lost was not timed. The agent that established the cause mentions three false failures and about an hour of narrowing down: that is its estimate, written after the fact, not a record. The cost of the earlier false lead was never put into figures at all.

Hosted CI is not affected in the same way: when each job gets its own database container, the collision cannot happen. The defect only concerns runs that share a server, which in practice means the developer's machine and their fleet's, exactly where nobody looks.

The reverse case was not explored: nobody checked whether the collision could have produced a false green. The timeline makes it unlikely, since whoever loses the race fails. But "unlikely" does not mean "verified": a suite running against a schema someone else has just recreated can see an assertion pass for the wrong reasons.

Where this entry comes from

A campaign of fixes on a product under construction, in July and August 2026, carried out by several agents in parallel on the same repository. The domain terms of the original application were replaced by their structural equivalent, and the database names along with them: the mechanism is intact, and the business domain is not recognisable.

The two successive verdicts are preserved word for word, each in its author's report: the first attributed the failures to the shared counter, the second established the cause by reading the harness and the list of running processes. The first was corrected in the same document, without anything being erased.

The table of the two concurrent runs reproduces command output quoted in full: the two test count lines, before and after, come from it. The three error signatures come from the integration report of the same day.

Four other documents confirm the mechanism. They come from four distinct workstreams, and were written between 27 July and 4 August 2026. The first notes that the database server is shared between workspaces, and warns that its figures come from runs made alone. The second describes a database left orphaned by an interrupted run, which poisons the following ones. The third notes that a security barrier only holds thanks to its single-worker setting. The last, written the same day, correctly attributes a failure to the collision and leaves the assertion untouched.

These two origins together, a preserved original text and command output that can be rerun, allow the entry to be published without marking it "to be verified". What is not established is stated above, in plain words.


This entry is part of a notebook of 27 production failures hit between February and September 2026. Some are public and free: see the notebook.

The others are published as they are written, along with the modules and their exercises, as part of the paid product. In that product, the modules are in English; the exercises and the other entries are in French. Nothing on this page is a teaser for it.

Related notes

The method that handles this kind of failure