Why does my agent’s tool pass its tests but break the next tool?
Because each tool is tested alone, and the bug lives in the hand-off. One tool returns a value that looks right to a person, and the next tool cannot use it. Test the chain instead of the tool: feed the first tool’s real output into every tool that uses it, in every state the first tool can be in.
The symptom
The first tool call succeeds. Every call after it fails, often with an error that blames the second tool. The agent then tells the user it could not do the task. Nothing crashed at the first step, so the logs point at the wrong place.
In issue #5641 in the official MCP git server, an agent listed branches with git_branch, then could not switch to one. git_branch returned git’s display text, with a marker in front of each name:
git_branch(repo_path, branch_type="local") -> " feature\n* main"
git_checkout(" feature") -> error
git_checkout, git_diff, git_show, git_merge: Ref '* main' did not resolve to an object
The agent told its user: “Sorry, I couldn't switch branches: git said the ref '* main' does not exist.” The repo’s own test suite passed on that code: 203 tests. None of them caught it.
Write a downstream check
- Name the producer and its consumers. The producer is the tool whose output gets reused; the consumers are every tool that takes that output as input.
- List the producer’s states. Each different situation that changes its output: the current item, names with slashes, a detached state, forced colour and so on.
- Chain them in a test. For each state, call the producer for real, pass its output to each consumer, and assert the consumer works.
- Run it on today’s code. It must fail. A check that passes on the buggy code does not catch the bug.
- Only then write the fix, and keep the check as a regression test.
These are the lines Rokan printed when it wrote the check for #5641:
chain: git_branch -> git_checkout, git_diff, git_show, git_merge
in 9 producer states: branch_type_local, branch_type_remote, branch_type_all,
current_item, slash_name, detached_head, remote_head_symref, forced_color,
worktree_branch
on today's code it FAILS: 9 failed in 8.00s
Fix the producer or the consumer?
Both can work. Rokan tried three fixes for #5641, each from a different idea of where the bug was: in git_branch (the producer), in git_checkout (the consumer that crashed), and in code both share. Five attempts broke existing tests and were sent back. In the end all three passed the full suite and the downstream check in 9 of 9 states.
- Fixing the producer repairs every consumer at once. For #5641 it was also the smallest change, 27 code lines, and the one Rokan picked.
- The cost: the producer’s output changes for every caller. Here,
git_branchno longer marks the active branch, so anything that read that marker has to change. Say so in the pull request. - Fixing only the consumer leaves the bad value for the next tool that uses it.
With the fix, the downstream check went from 0 to 9 of 9 states, and the suite from 203 to 210 tests passing, for $0.77 of model use.
Short answers
Why do all my tool tests pass while the agent still fails?
Each test checks one tool alone. When the bug is in the hand-off, one tool’s output is fine on its own and unusable by the next tool, so only a test that chains the two can see it.
What is a downstream check?
A test that calls the producing tool for real, passes its output to every tool that uses it, in every state the producer can be in, and asserts they all work. It must fail on today’s code before you write a fix.
Should I fix the tool that made the bad value or the tool that crashed?
Fixing the tool that made it repairs every consumer at once, but changes its output for every caller, so say that in the pull request. Fixing only the tool that crashed leaves the bad value for the next one.
How Rokan handles it
Rokan writes the downstream check first and proves it fails on today’s code, then tries several fixes and blocks any that break an existing test. You get the fix that passes everything, with its test and a write-up.
This guide as Markdown: agent-tool-passes-tests-breaks-next-tool.md