I broke a Valkey cluster and handed Claude Code 66 tools to fix it
Three faults in a six-node Valkey cluster, one vague prompt, and an AI agent with read access to the monitoring. It found the root cause in 38 seconds, declared the replicas healthy while one was in a resync loop, and could not fix anything. Here is the full run.

"Something is wrong with the cache. Can you take a look?"
That's the whole prompt. No hint about what broke, no dashboard open, no runbook. Just the message every on-call engineer has received at some point, usually at an hour when they'd rather not.
I wanted to know what happens when you send that message to an AI agent instead of a person. So I broke a Valkey cluster on purpose, in three different ways at once, connected Claude Code to our monitoring over MCP, and watched.
Fair warning: this is not a "the AI fixed production while I slept" post.
The setup
Nothing exotic:
- A Valkey 9.1.3 cluster, 3 primaries and 3 replicas, in Docker.
- BetterDB Monitor 0.57.0 pointed at one node, with
cluster-slot-stats-enabled yeson the cluster so the monitor can see load per slot. - Claude Code 2.1.302 (model
claude-fable-5-2) with the BetterDB MCP server and nothing else. No shell, no file access, none of my settings or memory. Whatever it learned, it learned through the tools.
The MCP server gives the agent 66 tools. Slowlog, COMMANDLOG, client lists, hot keys, cluster topology, anomalies, incident timelines. Basically everything the UI shows, as function calls.
On top of the cluster I ran three boring services, so there was a normal day to break:
web: about 1,500 reads and writes a second on small keys.catalog-import: 120 writes a second of 16 KB product documents.checkout: 300 reads a second, with an 8 ms timeout and a retry policy I'll come back to.
I let that run for ten minutes so the monitor had a baseline: about 650 ops/sec and 17 clients per primary.
The tools are the easy part. A model with 66 tools and a healthy database will tell you the database is healthy. What I wanted to see is what it does when several things are wrong at once and one of them is hiding.
What I broke
1. A hot key. A "leaderboard job" that reads one sorted set with 400,000 members, in full, in a loop.
for (;;) await client.zrange('leaderboard:global', 0, -1);
One connection. That's all it takes. Each call holds the primary's main thread for about 87 ms, and everything else on that shard waits behind it.
2. A bad retry loop. This one was already in the building. The checkout service retries on timeout, immediately, twice, up to five levels deep. No backoff, no jitter. You know the one. You've probably written it. I have.
On a healthy cluster it never fires. Behind an 87 ms ZRANGE, an 8 ms timeout fires all the time. At the peak, checkout was logging 1,100 timeouts a second, and the shard went from 650 ops/sec to about 2,300. Most of that was retries.
(Full disclosure: checkout started the run with a 15 ms timeout. That gave me a storm at 1.9 times the normal load, and the monitor's retry detector wants 2 times before it calls it one. Seven minutes in I tightened the timeout to 8 ms. Turns out writing a bug that's bad enough takes a few tries.)
3. A reporting job on a replica. Someone points a slow Lua script at a replica, back to back, because "it's just a replica".
for (;;) await replica.eval(slowScript, 0);
A replica has one main thread too. While the script runs, the replication stream waits.
The reason for these three: 1 causes 2, and 3 is unrelated and on a different shard. A person looking at the dashboards sees "everything is on fire". The useful answer is that there are two fires, and which one started first.
The part I didn't plan
Fault 3 went further than I meant it to. My script stalled the replica for about a minute at a time, which is repl-timeout. So the primary dropped it. Four times. From its log at 10:02:43:
Disconnecting timedout replica (streaming sync): 172.30.0.5:6379
Unable to partial resync with replica 172.30.0.5:6379 for lack of backlog
"For lack of backlog" means a full resync every time. And here's the embarrassing bit: the monitor had told me this would happen. Twenty-five minutes earlier, before I broke anything, it raised this on all three primaries:
Replication backlog covers only 14.9s of writes at 702579 bytes/s: a replica disconnected for longer than that needs a full resync. Raise repl-backlog-size or reduce the write rate.
My import job writes 700 KB a second and the default backlog is 10 MB. I saw the alert, decided it was noise from my demo setup, and moved on. Then I disconnected a replica for longer than 15 seconds.
I shortened the stalls after that so the replica stays connected and just falls behind. But the four full resyncs were in the history when the agent arrived, and so was an open CRITICAL alert about a likely full-resync loop.
The run
At 10:13:25 UTC I sent the prompt. Twelve minutes after the hot key started, with all three faults live.
22 calls, 38 seconds. Roughly in this order:
- Getting oriented (8 calls):
list_instances,select_instance, andget_health,cache_listandai_list_instancestwice each. - History (3):
get_incident_timelinetwice,cache_list_pending_proposals. - The cluster (3):
get_cluster_nodes,get_cluster_node_stats,get_hot_shards. - The hot node (6):
get_infotwice,get_commandlog_patterns,get_slowlog,get_largest_keys,get_clients. - Wrapping up (2):
get_retry_amplification,get_latency_regressions.
The start was clumsy. It fired three calls before selecting an instance, and all three came back with No instance selected. Then, because I said "cache" and BetterDB also monitors semantic caches, it spent a few calls looking for one. There wasn't one. My fault for the wording, but it's the wording people use.
After that it found its feet. get_hot_shards returned the monitor's own verdict:
Hot shard a56d225a at 172.30.0.2:6379: CPU 0.46 cores against a near-idle cluster median (99% of the cluster's slot CPU) for 61s. [...] Hot keys: "leaderboard:global" (freq 244), "user:11276" (freq 8), "user:6456" (freq 7). Rebalancing will not help: slot 5355 alone is 100% of this shard's CPU. Consider client-side caching, reads from replicas, or splitting key "leaderboard:global".
This is the part I was most curious about. The obvious fix for a hot shard is "move some slots off it". It's also the wrong fix here, because one key carries the load, and moving its slot just makes a different node hot. The monitor said so, and the agent didn't argue.
From there it went to the command log (499 of the last 500 entries were ZRANGE leaderboard:global), the slowlog (which names the client), the largest keys (400,000 members, 25 MB), and the client list. Its last stop was the retry detector, which had fired twenty seconds before I sent the prompt:
Retry amplification — commands per client at 2.5× baseline for 12 min while connected clients stay flat at ~18; load stepped up under stress and is holding. Trigger: connection churn. Without client backoff the loop keeps feeding itself.
The verdict
Found it: one client is hammering a single huge key and stalling one of the three shards. The cluster itself is healthy (all 6 nodes up, replicas in sync, no evictions, memory at 63 MB of 1 GB).
It named leaderboard-job, the key, the command, the cost per call (85 to 105 ms), and the time the shard went hot (09:59, correct to the minute). It noticed on its own that the checkout connections were all 0 to 1 seconds old and said that "fits clients timing out and reconnecting, though I haven't confirmed that from the client side".
Its recommendations: stop or throttle the job, replace the full read with a bounded one (ZRANGE leaderboard:global 0 99 REV WITHSCORES), and "Don't rebalance."
That's a good answer. I'd be happy to get it from a person in 38 seconds. It's also wrong in the second sentence.
What it got wrong
"Replicas in sync." They weren't. One replica had been dropped and fully resynced four times, and a CRITICAL alert about it was open the whole time.
The agent never saw it. In 22 calls it didn't once call get_anomalies, the tool that lists open alerts. It didn't call get_replication_divergence either. It looked at the nodes it had numbers for, saw nothing alarming, and wrote "healthy" with the confidence of someone who checked.
The warning I ignored, it never saw either. The backlog alert was open for the entire run. Same reason: no get_anomalies.
Think about what a person does here. You open the alerts page first, because that's where the tool tells you what it already knows. The agent did the opposite. It went straight to raw data, found a real problem, and stopped looking. One fire explained everything it had seen so far, so there was only one fire.
So the score for the first answer: two of the three faults found and connected in the right order, one missed completely, stated as fine.
Asking a second time
I pushed back with one line:
Is that everything? You said the replicas are in sync. Are you sure?
Thirteen more calls, 39 seconds, and this:
No — I was wrong about that, and it isn't everything. One of the three replicas is not in sync:
172.30.0.5, the replica of the primary at172.30.0.4(slots 5461–10922), has been falling out of replication and is behind again right now.
This time it called get_anomalies and rebuilt the timeline correctly: the full resync at 10:05, the drop at 10:06, the replica behind again at 10:14. It spotted that this was "a separate problem" on a different shard, so stopping the leaderboard job wouldn't fix it. It found the backlog issue I'd ignored. And when it couldn't find the cause, it said so: "I don't know the cause."
It was right not to guess. The cause was a client called reporting connected to the replica itself, and nothing it had looked at pointed there.
The thing it couldn't do
Between those two answers I typed:
OK, fix it.
I can't fix this one from here: the tools I have in this session are monitoring-only. I can't kill a client, run a command against Valkey, or touch the
leaderboard-jobcode, and there's no shell or file access in this session. Nothing has been changed.
Then it gave me the CLIENT KILL command to run myself, and warned that killing the connection wouldn't hold if the job reconnects.
It couldn't. Not because the model was being careful, but because none of the 66 tools can run a command against the database. There are a handful of write tools, for semantic caches and agent memory. Nothing that can kill a client, change a config or move a slot. Slot moves exist in the UI, and a person has to turn them on, read the plan and click run.
It's built this way because I don't trust an agent with a slot migration yet. I barely trust myself with one. And after this run I have a better reason than a feeling. An agent that says "replicas in sync" with one replica in a resync loop is exactly the agent you don't want choosing which node receives 2,000 slots.
What I took from it
The diagnosis is the part worth handing over. 38 seconds to go from "something is wrong" to a client name, a key, a command and a fix. On a bad night that's the slow part, and most of it is remembering where things are.
It stops at the first fire. The hot key explained the latency, the timeouts and the reconnects, so the agent had a complete story and no reason to keep looking. The replica was a second, unrelated problem, and a complete story is exactly what hides those.
Ask twice. "Is that everything? Are you sure?" cost me one line and 39 seconds, and it turned a wrong answer into a right one. I wouldn't act on a first answer from an agent any more than I'd merge a first draft.
"I don't know the cause" is a feature. The second answer was better than the first partly because it was less sure of itself. The first one had no doubt in it at all, and it was the one that was wrong.
Read-only is the right default. Nothing bad happened in this run, and that's not luck. The worst the agent could do was be wrong out loud.
Try it yourself
The monitor runs anywhere Docker does:
docker run -d --name betterdb -p 3001:3001 \
-e DB_HOST=your-valkey-host -e DB_PORT=6379 \
betterdb/monitor:latest
The MCP server is on npm. Add it to Claude Code, Cursor, or whatever you use:
{
"mcpServers": {
"betterdb": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@betterdb/mcp"],
"env": { "BETTERDB_URL": "http://localhost:3001" }
}
}
}
The detectors in this post (hot shards, retry amplification, replication alerts) are part of the Pro tier, which is free during early access.
Then break something. The hot key and the replica job above are one line each.
What would you break first? And would you give the agent the write tools? I'd love to hear in the comments.