Awesome Testing

Field note

Chaos Engineering for Agents: Breaking the System on Purpose

Nov 21, 202618 min read

TestingAI#Testing#AI#AI agents#Agentic Testing#Chaos Engineering#Exploratory Testing#Distributed Systems

About a year ago, in Agentic Testing - The New Testing Approach, I wrote about agentic testing. The topic stirs up quite a lot of emotion, because in practice it is about replacing a human with an agent. I listed several problems there that were fairly significant at the time. What has changed since then is, above all, the cost. Models have become much cheaper when we measure dollars per unit of intelligence (I looked at the numbers in AI-Powered Testing: Introducing e2e Framework).

I also think agentic testing is heavily underrepresented on the internet. Relatively few software testers work with it, which honestly surprises me. Many other AI topics, such as MCP servers, skills or Jev, were overrepresented and, let's say, slightly overhyped. Here I have the opposite impression: agentic testing already works better than many people think. There is not much research yet showing that agents find many bugs, let alone most of them. Then again, human testers do not find all the bugs either. And there were a few situations where an agent genuinely impressed me. That alone makes it worth coming back to the topic and exploring it on your own project.

Some time ago I wrote about one of the tools we can give an agent. In Mutation Testing for Agent-Written Code the agent creates so-called mutants and checks whether its unit tests (most often written by the agent itself, and less and less often by a human) detect the change. Mutation testing does not find bugs in the product directly. It finds blind spots in the tests, and bugs come out later, when the agent closes those gaps with better assertions. Today I would like to cover a technique that goes straight for the bugs: chaos engineering. I will describe how we can inject failures into our system and let the agent check how it copes with unexpected situations: error handling, service recovery and resilience in the broad sense.

As usual, I will back the post with an example from my local testing stack. As I mentioned last week, it recently got an upgrade: it is now a system made of several separate services, which makes it a much better target for chaos engineering. I added a fault-injection lab to it, and with it the agent found a real race condition that the unit, integration and end-to-end suites had all missed.

Awesome LocalStack architecture: browser, tests and agents reach an nginx gateway; inside one Docker network run the React frontend, the backend, and the warehouse, payment and notification services. The backend sends stock commands to the warehouse, the other services poll the backend event feed, and each service keeps its own schema in PostgreSQL.

One simplification is worth mentioning. In a textbook setup every service would have its own database server. Here they share one PostgreSQL, and each service owns a separate schema with its own role, so no service can read another's tables. This is a practical decision: the stack has to fit on my small server and on my students' laptops, and one PostgreSQL fits in 256 MiB where several would multiply that cost. The trade-off is shared fate: when PostgreSQL goes down, all services go down with it.

What chaos engineering is

Chaos engineering is not a new concept. It was popularised by Netflix, which around 2010 moved its streaming platform to AWS and wrote Chaos Monkey: a tool that randomly switched off production instances during working hours. The reasoning was simple. Instances fail in the cloud anyway, so it is better to make them fail when engineers are at their desks and can see what happens. In 2011 Netflix described a whole Simian Army built around the same idea, with monkeys that added latency or took down a whole availability zone. Later the approach was formalised as the Principles of Chaos Engineering and in the paper Chaos Engineering by Netflix engineers.

The important word is experiment. Chaos engineering is not about breaking things at random. Every experiment has the same shape:

  1. Define the steady state: a measurable signal that the system works, for example orders placed per minute or stock that matches the order list.
  2. Form a hypothesis: the steady state will hold even when something goes wrong.
  3. Inject a real-world fault: a crashed instance, a slow dependency, a network partition, a stalled database.
  4. Try to disprove the hypothesis by comparing the system with its steady state. Every difference is a weakness found before a customer found it.

On top of that comes a safety rule: keep the blast radius small. Break one thing at a time, start where the damage is cheap, and always know how to stop the experiment.

The chaos engineering loop with an agent in the middle: define the steady state, form a hypothesis, inject one fault, observe logs, traces and data, then fix and heal before the next experiment.

However, implementing chaos engineering was not easy, and above all it required the work and analysis of many engineers. Someone had to understand the system well enough to choose a meaningful fault, set up monitoring, run the experiment, go through logs and dashboards, and figure out what the results meant. In practice only companies with dedicated reliability teams could afford it.

Today the situation is completely different. An agent with the right access, a good understanding of the system (through an internal wiki, RAG, Confluence or another source of knowledge), the logs and the implementation can reason very quickly. It can spot potential gaps, look for improvements and implement them directly. That makes chaos engineering much more effective and much cheaper to apply, above all in engineering time. With the right setup, an agent can run its own exploratory testing session and check situations that would be relatively hard to create in normal manual testing: a payment that settles after the reservation expired, a service that loses the backend for two minutes, a database link that stalls in the middle of a checkout.

In a distributed system those interesting failures live between the services: a call that takes 7 seconds instead of 70 milliseconds, a dependency that refuses connections, a database link that stalls. Happy-path tests never exercise those paths, yet that is where a customer loses an order or a warehouse loses stock. And you do not need production or Netflix scale to learn from them. A local stack is a perfect place to start, because the blast radius is your own laptop.

So the definition I use with testers is practical: inject a fault into one link, observe what the user sees, what the data looks like, and how long the system needs to agree with itself again.

The chaos loop at Anthropic

This is not only my impression. A few days ago Anthropic described how it prepared the launch of Claude Docs with what it calls a chaos loop. For two weeks before the launch, a Claude Code session ran non-stop against a staging cluster that mirrored production. It generated traffic of over a million documents a day, broke core components on purpose (killed servers while they loaded documents, stalled the database, reconnected thousands of clients at once), read the telemetry, proposed a fix, deployed it to staging and started again.

A few details are worth noting, because they match what I see on a much smaller scale:

  • One session acted as a coordinator and handed most of the work to subagents: usually around 11 at a time, 30 at the peak.
  • Before the loop started, the engineer wrote down the invariants the service must never break, for example that an edit acknowledged by the server is never lost. That is the steady state from the previous section.
  • Claude stopped and asked a human only for decisions that are hard to undo, like changing the database schema.
  • According to the post, seven of the ten scenarios rehearsed on staging really happened in production, and across 2 billion requests after the launch the service returned only 60 server errors.

The cost was about $125,000 of inference, which the author compares with roughly six months of work for a team of engineers. For a small stack the author estimates a similar two-week push at $3,000 to $10,000, while admitting this has not been tried. The post also notes that this only became possible recently: older models tended to forget the goal after a dozen or so iterations. These are numbers reported by the model vendor about its own product, so I treat them with some caution, but the direction is clear. What used to require a dedicated reliability team can now be delegated to an agent with good observability and clear invariants.

Introducing Toxiproxy

To break the links between services we need a tool that sits between them. I chose Toxiproxy, a TCP proxy for simulating network and system conditions. It was written and is still maintained by Shopify, which has used it in all its development and test environments since 2014. It is open source (MIT), written in Go, and has over 12 thousand stars on GitHub.

The idea is simple. Toxiproxy consists of two parts: the proxy itself and an HTTP API that controls it. You point your application at Toxiproxy instead of the real dependency, so traffic flows through the proxy, and then you change that traffic while it flows by adding so-called toxics:

  • latency: every answer arrives later (optionally with jitter),
  • down: the proxy is disabled, so connections are closed and refused,
  • timeout: data stops flowing and the connection hangs or closes after a delay,
  • reset_peer: the connection is reset at the TCP level,
  • bandwidth: the connection is limited to a given number of KB/s,
  • slow_close, slicer, limit_data and packet_loss for less common cases.

Toxics are directional (downstream or upstream) and can hit only a share of the connections (toxicity), so a flaky link is as easy to model as a dead one. You can control everything with toxiproxy-cli, with plain curl, or with one of the client libraries. The same goes for an agent: thanks to the CLI and the simple HTTP API, a coding agent can add and remove faults on its own, just like any other command it runs in the terminal. Shopify maintains the Go and Ruby clients, and the community added clients for Python, Java, .NET, Node.js and other languages. Testcontainers also ships a Toxiproxy module, which makes it easy to use in integration tests.

The project is not moving fast, but it is alive. Version 2.13.0 was released in October 2026, more than a year and a half after 2.12.0. It added optional token authentication for the API and fixed a few cases where removing a toxic could hang. It is a mature tool that simply does its job.

Toxiproxy in Awesome LocalStack

In my awesome-localstack Toxiproxy sits in the middle of every link between the services. The services do not know about it. The chaos overlay (docker-compose.chaos.yml) only changes the addresses they use, so for example the backend reaches the warehouse through toxiproxy:14005 instead of going there directly. Each link has its own proxy, so the warehouse can lose the backend while the payment service still reaches it.

Fault-injection lab in awesome-localstack: the gateway reaches the backend, warehouse, payment and notification services directly, while every connection between the services and from each service to PostgreSQL goes through its own Toxiproxy proxy, controlled by scripts/chaos or the agent.

The gateway is never behind the proxy. Your browser, Swagger and test suite always reach the services; only the links between them break. That keeps every experiment observable.

Start the lab, with tracing, in one command:

git clone https://github.com/slawekradzyminski/awesome-localstack.git
cd awesome-localstack
scripts/chaos up lightweight tracing

Break one link, look, heal:

scripts/chaos warehouse-slow 7000   # backend -> warehouse answers 7 s late
scripts/chaos status                # what is broken right now
scripts/chaos heal                  # everything back to normal

This is how it looks on my machine. One command slows down the warehouse, and scripts/chaos status shows all twelve proxies with the one active fault. The four *-to-activemq proxies are used only when the optional message broker runs, which is why I left them out of the diagram above.

Terminal output from awesome-localstack: scripts/chaos warehouse-slow 7000 adds a 7000 ms latency fault, and scripts/chaos status lists twelve Toxiproxy proxies with the backend-to-warehouse proxy highlighted as the only one with an active fault.

There is no magic in the script. warehouse-slow 7000 is one call to the Toxiproxy API:

curl -X POST http://127.0.0.1:8474/proxies/backend-to-warehouse/toxics \
  -H 'Content-Type: application/json' \
  -d '{"name":"warehouse-slow","type":"latency","stream":"downstream","attributes":{"latency":7000}}'

The faults are real. Connections are delayed, reset or refused at the TCP level; nothing in the application is mocked. The available scenarios cover latency, outages, flaky connections, low bandwidth, database stalls and full network partitions of one service.

The real beauty of this setup is that the agent understands it on its own. It can read the stack, simulate specific situations, and search for and simulate unusual situations at a pace that is impossible for a human.

An exploratory testing session with an agent

Let's put that thesis to the test. I started a fresh agent session and gave it one task: run an exploratory testing session against the lab and look for bugs in how the system behaves when the network between the services misbehaves.

The agent got the same things a new tester on the team would get:

  • the awesome-localstack repository with its documentation: the student guide, the fault-injection lab description, architecture decisions, the event feed and the contracts between services,
  • a running lightweight profile with Toxiproxy on every link,
  • scripts/chaos, the Toxiproxy API, Docker logs and read-only access to PostgreSQL,
  • permission to restart the lab with tracing or shorter timeouts, and to start its own subagents if it saw a need.

I asked it to work like a disciplined tester: for every experiment define the steady state, state a hypothesis, inject one fault, observe the API, logs, database and traces, and write down a verdict with real numbers. It had to stay local, change no code, and heal the system after every experiment.

I deliberately did not give it this draft or any hints about known problems. I wanted to see what it would find on its own.

What the agent did

The session took about 45 minutes. The agent read the documentation and parts of the source code of the backend, warehouse and notification services, then ran 16 experiments (20 runs in total). It started with a baseline (an order paid in 48 ms) and moved on to slow and dead links, flaky connections, a database that refuses connections, and slow database transactions. For the hardest cases it went beyond Toxiproxy: it held a row lock in PostgreSQL from psql to make exactly one transaction slow, a technique it found in the lab's own exercises.

It found three problems:

SeverityWhat happened
F1HighThe event feed can skip an event for good. In one run a customer was charged 399.99 for a cancelled order and never got a refund.
F2MediumA checkout that times out on the warehouse link returns 503, but the stock stays reserved for about 2.5 minutes. Each retry reserves another unit.
F3LowWhen PostgreSQL refuses connections, every request after the first one waits 30 seconds and then gets a generic 500.

F1 is the most interesting one, so I describe it in detail in the case study below.

What held up

The list of things that worked is just as valuable. A lost payment acknowledgement was deduplicated and nothing was charged twice. Payment retries with the same idempotency key returned the first payment. The warehouse restored stock exactly once for ten cancellations over a link that failed 60% of the time. Refunds survived database connection resets. And after every scripts/chaos heal the system recovered on its own, apart from the events F1 had already skipped.

A lesson about the tool

The agent also found a trap in its own test design, and I think it is worth sharing. To provoke a race it needed some database calls to be slow and others fast, so that a slow cancellation could be overtaken by a fast one. The natural choice was a toxic with toxicity: 0.5, which should slow down half of the traffic. It did not work as expected. Toxiproxy picks the connections a toxic applies to, not individual requests, and the services keep long-lived connection pools. Most traffic ran over connections the toxic never selected: in one experiment only one of about forty cancellations hit a slow connection. The agent marked those experiments as inconclusive instead of reporting them as passed.

Then it changed tactics twice. First it slowed down every connection (toxicity: 1.0), which reproduced the bug with a pure network fault, but only in one run out of three: when everything is slow, the two transactions are rarely far enough apart for one to overtake the other. Then it dropped Toxiproxy for this case and slowed down exactly one transaction with a database lock, which made the bug appear every time. If you need a fault to hit only part of the traffic, restart the connection pools after adding the toxic, or target one specific transaction instead of the network.

How good was the session?

I read the whole report and checked the most serious finding myself, so here is my honest assessment.

What impressed me:

  • Discipline. Every experiment had a hypothesis, a single fault, an observation and a verdict with real numbers. That is more than I usually see in human exploratory testing notes.
  • From flaky to deterministic. The first reproduction of F1 worked in one run out of three. Instead of stopping there, the agent built a deterministic version that shows the bug every time.
  • From symptom to code. Every finding points to the responsible class and comes with fix proposals. F1 needed knowledge of PostgreSQL transaction visibility, and the proposed fix looks like the right direction.
  • Using every tool, not just the main one. When Toxiproxy was not precise enough, the agent did not keep forcing it. It slowed down exactly one transaction with a database lock, a technique my lab exercises use too. Network faults are a blunt tool for timing bugs, and the agent noticed that on its own.
  • Honesty. Experiments where the fault did not land were marked as inconclusive, not as passed, and the list of things that held up is as detailed as the list of bugs.
  • Speed. 16 experiments in about 45 minutes. A human tester would need at least a few days to prepare, run and analyse the same set.

What was weaker:

  • The agent read backend source code from a local repository that was older than the running image (3.22.0 versus 3.24.0). Its explanation matched what I saw in the database, but it could just as well have chased code that no longer exists. By the way, this one is on me, not on the agent. It is a typical human mistake: I did not keep my local checkout up to date, and something like that can easily waste hours of work. Such failures are worth writing down as lessons learned, or simply adding to AGENTS.md, for example as a rule to check that the local source matches the running version before reading it.
  • Some threads were left half-finished. The agent marked the experiments with partial faults as inconclusive, but it did not go back to them, for example by restarting the connection pools and running them again, and it did not propose that as a follow-up either. The same goes for the lab: it was left with test data (extra products and dozens of pending orders) without a clean-up or at least a suggestion to do one. I would expect a good tester to either dig deeper or clearly hand over what is still open.
  • Severity is a judgement call. F2 is partly a design trade-off, because the reaper exists exactly to release such reservations. A human should decide whether it is a bug or an accepted cost.

My verdict: this was the work of a good tester on their first day with a system they had never seen, done in less than an hour. It still needs a human to confirm the findings and to decide what matters, but the expensive part, finding the right questions and building the reproductions, was done by the agent.

Case study: the refund that never happened

This one is worth a closer look. The services learn about orders by polling an event feed on the backend. Each event gets a sequence number, and each consumer remembers the last number it processed. To avoid reading events from transactions that are still running, the backend serves only events older than three seconds.

The problem is that those three seconds are counted from the moment the event row was written, not from the moment its transaction committed. A cancellation is a long transaction: it writes order.cancelled, then card-refund.requested, then a few more things. When the database is slow, such a transaction can stay open for 20 seconds or more. If another, faster cancellation commits in the meantime, it gets a higher sequence number and becomes visible first. The consumers move their cursors past it, and the slow cancellation's events, committed a moment later, are never served again.

The agent reproduced it in two ways. With a pure network fault (1000 ms of latency on every connection from the backend to PostgreSQL) the warehouse and notification services skipped an order.cancelled event in one run out of three. Then it made the scenario deterministic: it held a lock that slowed down one cancellation, cancelled a second paid order in the meantime, and waited. The payment service moved its cursor past card-refund.requested. I checked the database myself after the session: the order is CANCELLED, the payment is still CAPTURED for 399.99, and nothing has been refunded. The agent found no reconciliation job that would ever repair it.

The agent also pointed to the code (EventFeedService and the findSettled queries in DomainEventRepository) and proposed fixes, the most robust one being to serve only events from transactions that have already committed, using PostgreSQL's transaction ids instead of a clock.

This is exactly the kind of bug I had in mind when I wrote that happy-path tests never reach these paths. A regular test suite is very unlikely to catch it, because in a test the database answers in milliseconds.

sequenceDiagram
    participant A as Cancel order A (slow)
    participant DB as domain_events
    participant B as Cancel order B (fast)
    participant P as Payment service
    A->>DB: insert card-refund.requested (seq 534)
    Note over A: transaction stalls
    B->>DB: insert card-refund.requested (seq 536)
    B->>DB: commit
    P->>DB: poll after cursor 533
    DB-->>P: seq 536 (534 not committed yet)
    Note over P: cursor = 536
    A->>DB: commit (seq 534 visible now)
    P->>DB: poll after cursor 536
    Note over P,DB: 534 is never read: no refund

Conclusion

We are in a very interesting situation. Some practices that were created ten or more years ago, and that required investment, people, analysis, domain knowledge and both business and technical expertise, may now come back to life. They can return in a world where the limit is no longer the number of engineers, but cost: the number of tokens we can afford and the budget we have. The bottleneck is moving from people to money.

That is also a little worrying. Reading Anthropic's post, where the whole chaos loop cost over $100,000, it is hard not to wince. That is a budget even a large company does not spend just like that. It probably requires approvals and a business analysis of whether the return on investment is really positive. It also shows that companies with access to practically unlimited tokens, and to newer models, possibly even unreleased ones (Anthropic used an internal research model), can gain a real competitive advantage over everyone else. That gives a lot to think about.

The same way of thinking can be applied to other areas, for example security, as long as the model does not refuse to help. We could give an agent access to Burp Suite and let it look for holes during the testing phase. Then we have a loop again: a testing agent with tools for performance, reliability or security testing, agents that fix what it finds, and a feedback loop between the two. Of course, even a first experiment like that costs hundreds or thousands of dollars, so this is potentially a big topic.

What I would encourage you to do is to try agentic testing yourself. I am currently using Opus 5.5 with medium effort in Claude Code. Years ago we talked about mob testing: a group of people testing the same thing, at the same time, on one computer, sharing their knowledge and looking at the application from different angles. Today I sometimes feel as if with one dictated prompt I could set a whole mob of skilled testers loose on my application.