---
id: 18837
lang: en
title: "Green AI Agent Test, Wrong Service: The Sum Check Missed 5 of 5 Isolation Bugs"
published_at: "2026-12-01 14:32:39"
source_name: "Habr AI"
source_url: "https://habr.com/ru/companies/otus/articles/1101918/?utm_campaign=1101918&utm_source=habrahabr&utm_medium=rss"
canonical_url: "https://news.hamidun.com/en/news/18837"
categories: ["llm", "autonomous"]
publisher: "AI News by Jemal Hamidun (news.hamidun.com)"
---

# Green AI Agent Test, Wrong Service: The Sum Check Missed 5 of 5 Isolation Bugs

> **Краткая суть (BLUF):** Two AI agents work on the same service in separate git branches, but the second agent's test hits the first agent's process and still passes: the order there also costs 120 rubles. Tech Lead Sergey Proshchaev reproduced five such isolation bugs with a script. A single sum check accepted all five (5 of 5), while an environment check on five fields rejected all five. So before checking the logic, confirm the request actually reached your own process.  - Five fields are compared: worktree root, revision, build, run ID, and data label - The port is taken (EADDRINUSE), yet a request to the old port returned the first agent's order - Take the port from the service itself: a socket on 127.0.0.1:0 and a wait for a line of output for up to 10 seconds

Imagine two AI agents working on the same service, each in its own git branch and its own working directory. The first fixes order calculation, the second changes discount handling. The second launches the service and gets an error: "port in use" (EADDRINUSE). But the test still calls the usual address, where the first agent's process is already running. That process responds: an order for 120 rubles. The sum check passes, the test is green, even though the code from the second branch never ran. Tech Lead Sergey Proshchaev, who leads Java and Kotlin development in fintech and e-commerce, reproduced five variants of this confusion on Habr: a foreign port, a stale process, a foreign database, a foreign build artifact, and a foreign working directory. The simple sum check missed all five (that is, 5 of 5), while an environment check on five diagnostic fields rejected all five and accepted the control scenario without errors.

## How a Green Test Deceives

A git worktree isolates files, the index, and HEAD, but ports, processes, and external dependencies are configured separately. If tests from two worktrees read the same address from a config, both will send requests to the same place. Harmse H. described a similar conflict while working on OxO2 at EMBL-EBI: E2E tests spun up Solr, a Spring Boot backend, a React frontend, and a data-loading pipeline. During parallel runs, one agent cleared the index that the second was querying. After that, ports, directories, and addresses were derived from a number assigned to each worktree.

The author built a setup with two worktrees, alpha and bravo, each with a separate SQLite database. The GET /order handler is identical everywhere, and the sum is 120 everywhere, so the sum alone cannot tell a foreign process from its own. Five fields were added to the response:

- checkout: the root of the working tree the process was started from;
- revision: the HEAD commit at launch time;
- build_revision: the revision from the JSON build-metadata file;
- instance: the launch-attempt identifier the script issues before startup;
- fixture: a label from the order row actually read from the database.

The script sets expectations before the request and compares them with the response. A mismatch in even one field means the test reached the wrong place.

## Five Traps

**The launch failed, but the request went to the old port.** The address lives in a static config, and the startup error was lost in the logs of a neighboring terminal. All five fields diverged here. The fix: the service binds its socket to 127.0.0.1:0, the OS assigns a free port, the service reports it to the script, and the script waits up to 10 seconds for the line. No line, or an invalid number, and the launch is considered failed.

**New commit, old process.** The agent committed a change, but the previous code is still running in memory. revision, build_revision, and instance diverge. If HEAD is recalculated on every request, revision will show the new commit and hide the symptom, so the revision is captured at startup.

**Different ports, shared database.** The bravo process listens on its own port, but the config still points to the SQLite path from alpha. Only fixture diverges. For PostgreSQL, a broker, or search, you need a separate instance or its own data scope, and migrations and cleanup must respect that boundary. For SQLite, PRAGMA database_list run over the same connection that reads the order helps.

**An artifact from a shared directory.** The process is fresh, but build_revision carries alpha's revision. In Java this happens when the build tool puts the JAR in the task directory while the launch runs the shared app.jar. You need to compute the digest of the built package and run exactly the verified file; for Docker, reference the image by digest. A commit SHA alone is not enough: agents often run uncommitted changes, and two different packages can be built from the same HEAD.

**Someone else's working directory.** The terminal is open in bravo, but a hook or IDE task starts the service with cwd set to alpha. The sum and labels match, while checkout and revision diverge. An explicit cwd and git rev-parse --show-toplevel run from that directory help.

## What to Do in Practice

The author proposes a short checklist: verify the tree and the launch revision, get the address from a service that started successfully, compare the launch ID and build version, keep mutable data separate, and deliberately point the test at a neighboring environment once to confirm it rejects it. The agent's report should save the launch command with its working directory, the actual address, and any mismatches found, so diagnostics can continue without the chat history.

There are also honest limitations. The scenarios were set up by hand, so they cannot estimate how often such errors occur with real agents. In the demo the diagnostic fields can be trusted, but in production they would still need to be added to the service. If requests pass through a proxy and several services, the comparison must cover the whole route: one backend's response confirms only its own part of the chain.

The experiment repository is verified on Python 3.12+, Git 2.28+, and Bash 3.2+ on macOS or Linux. The expected outcomes of all scenarios are recorded in expected.txt, and runs go through ./run.sh and unittest. For commands that launch several agents in parallel, this is an inexpensive way to close off a class of false green results before review.

---
- **Первоисточник:** [Habr AI](https://habr.com/ru/companies/otus/articles/1101918/?utm_campaign=1101918&utm_source=habrahabr&utm_medium=rss)
- **Каноническая ссылка:** https://news.hamidun.com/en/news/18837
- **Экосистема автора:** [Бесплатный интенсив по вайбкодингу — предзапись в Нике](https://t.me/vibecodeguidebot?start=agent_intensive_news_md) · [Nomad AI](https://nomadnet.ai) · [Telegram @jemal_hamidun](https://t.me/jemal_hamidun)
