Skip to content

About

Crash test for AI agents: cut streams, lost replies and retries, replayed offline

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

CrossTrace

A crash test for AI agents. CrossTrace records real runs of your agent, replays them with no API cost, and breaks one model call at a time the way providers and networks really break: a stream cut short, a stalled connection, a reset, a 429, an overloaded API. For every failure it tells you what your agent did next. It runs in CI on every pull request.

Your agent needs no code changes and no SDK. It runs as it is, with its real SDK and framework code paths.

Warning: your tools really run. CrossTrace replays the model, not your code. During record, test and check, your agent runs for real, and so does every tool it calls in its own process or over a plain API: payments, emails, database writes, file changes. test runs your agent many times, with faults. Use test accounts, sandboxes and throwaway data only. Never live keys or real records. The one exception is tools behind the MCP wrapper: in test, those are answered from the recording unless you turn on real tools. In record they run for real too.

crosstrace-site.vercel.app: the short version, with an animated walkthrough.

What it finds in a stock LangGraph agent

A support agent written the way most LangGraph tutorials write one (create_react_agent, streaming ChatOpenAI, default settings, three tools; source), recorded once against a real model on OpenRouter, then tested offline:

✗ tool_args_cut          WRONG_ACTION 2/3, REPROMPTED 1/3
                         e.g. path 0 exchange 0: MEASURED: get_order(order_id=4) really ran; the healthy run never called it with
                         these values
✗ stream_stall           HANG 5/5
                         e.g. path 0 exchange 0: no exit within 60 s (no retry)
✗ stream_cut_clean       PARTIAL 2/5, ENDED_EARLY 3/5
                         e.g. path 0 exchange 0: printed nothing and exited 0 after exchange 0 failed
✓ server_error           RECOVERED 5/5
✓ overloaded!persistent  SURFACED 5/5
✓ rate_limit             RECOVERED 5/5
✓ reset_before_response  RECOVERED 5/5
✓ context_length         SURFACED 5/5
! connection churn       1.0 new connections per model call
  • The stream broke inside a tool call, and the agent acted on the broken value. The model asked for order 42. LangChain completed the half-received JSON, and get_order(order_id=4) really ran, with no error anywhere. A tracking number cut to "BD1234" ran too (2 of 3 cut calls). In the third, the arguments came out empty ({}), validation rejected them, the tool did not run and the model was told.
  • A stalled stream froze the agent. ChatOpenAI has no read timeout by default; the openai SDK waits up to 10 minutes per attempt. Setting ChatOpenAI(timeout=30) turns the hang into an error (SURFACED 5/5), but not into a recovery: the SDK's retries stop once response headers have arrived, so a mid-stream timeout is never retried.
  • A cut final answer was printed as the answer. "Your order 42" and "I'm sorry your mug arrived broken, Asha." with exit code 0, or nothing at all with exit code 0.
  • What it handled well: HTTP errors before the stream starts. The SDK's retries cover those.

Each finding comes with the fix for the SDK it detected, and the exact command that reruns that one trial.

These are not exotic faults. A clean cut without the final event is what a gateway produces when its upstream dies but it closes the response politely. The same behaviour shows up across SDKs: what the OpenAI, Anthropic and Vercel SDKs do under each fault.

Bugs found in real projects

The same two failures, a reply cut mid tool call and a write whose reply is lost, tried against open-source projects. Each was reproduced with a standalone script and reported upstream. Status as of 2026-12-06.

Project What happened Status
CowAgent a cut-off write call was repaired and overwrote a file with partial content fixed, our PR merged
OpenAI Agents SDK with max_retry_attempts set, an MCP write whose reply was lost ran twice docs changed by OpenAI, crediting the report; issue closed, retry behaviour unchanged
Vercel AI SDK with maxRetries set, an MCP write was sent again after a 5xx and ran twice our PR in review
DeerFlow a stream that ended early made write_file overwrite a file with partial content fixed, our PR merged
AnythingLLM a cut-off reply made the file-writing tool overwrite a file with partial content reported; closed as not planned
LangChain ToolRetryMiddleware with its defaults retried an MCP write whose reply was lost, so it ran twice reported
Haystack MCPTool over SSE (the older MCP transport) re-sent a write after a dropped connection, so it ran twice reported

What really ran, not what the model traffic says

Model traffic only shows what an agent said it called. For Python agents (3.12+), CrossTrace also records which tool functions actually executed, and with what values, with no change to your code: it watches the functions named like the tools your model was offered, in your own files only, using Python's sys.monitoring.

  • It compares each fault trial with two healthy replays. A tool that ran with values the healthy run never used is WRONG_ACTION; a write that ran more often is DUPLICATE.
  • It blames the agent only for what ran before CrossTrace had to answer with a stand-in reply (the next healthy one, for a request that was never recorded). Later runs may have been asked for by that reply, so they are listed in the report and not judged. With --live the real model replies, and everything counts. The same rule covers repeated MCP writes.
  • It judges only tools it saw run in the healthy replays, and skips any whose arguments change from run to run.
  • If your app routes a tool to a function with another name, map it: [tools] send_reply = "Mailer.deliver".
  • Not observed: tools whose function has another name than the tool and is not mapped, tools living in installed packages or in another process (use the MCP wrapper for MCP servers), non-Python agents and Python 3.11. Then the verdict comes from model traffic alone and says so.

Other agents checked

The same faults against other popular frameworks, each recorded once on a cheap real model and then replayed offline (recordings not published). Every row is what CrossTrace reported after its verdicts were corrected against what the framework really did.

Framework Cut stream or cut tool call Stalled or silent response Other
LangGraph (create_react_agent) tools really ran with cut values (2 of 3 cut calls; the third was rejected); printed a cut answer as complete hangs (no read timeout) errors before the stream recovered
OpenAI Agents SDK (Responses API) raised an error (it waits for the completed event) hangs; set_default_openai_client(AsyncOpenAI(timeout=...)) turns it into an error errors before the stream recovered
pydantic-ai refused the cut tool call and told the model (one case: arguments were already complete and it ran the tool); printed a cut answer as complete, also for a Responses incomplete status hangs; model_settings={"timeout": ...} turns it into an error empty reply re-prompted
CrewAI (native openai client) printed a cut answer as complete hangs; LLM(timeout=...) recovers context-length error summarised and continued; a persistent outage retried 7+ times in about 3 s
LlamaIndex (FunctionAgent) no retry: a cut get_order call was rejected before running, but a cut tracking number really ran as track_shipment(None); printed a cut answer as complete hangs (no read timeout) errors before the stream recovered
smolagents (ToolCallingAgent, stream_outputs=True) refused a cut tool call (argument validation) and told the model; returned a cut final answer as the result hangs (no read timeout) errors before the stream recovered; in its default non-streaming mode every HTTP error was handled

More frameworks, and what each does when an MCP write's reply is lost (CrewAI runs a refund twice by default; the OpenAI Agents SDK, LangChain and Vercel AI SDK do with their retry options on): docs/failure-library.md.

The timeout fixes were run, not assumed (with 10 seconds). In the three streamed agents (LangGraph, the Agents SDK, pydantic-ai) a stall in the middle of a stream is raised, not retried. LlamaIndex and smolagents were run on 2026-11-20 against their latest releases (llama-index-core 0.14.26, smolagents 1.26.0), recorded twice on separate runs with the same results.

One command, one question

pip install crosstrace
crosstrace check --input "where is order 42?" -- python agent.py {input}

check writes the config if there is none, records one healthy run per input (this calls your real model, with your key), then replays it with only the cut-off and lost-reply faults and ends with a plain answer: did your agent do the wrong thing? Later runs reuse the recording, so they are offline: just crosstrace check. It says YES only for actions that were measured, and says so when execution could not be observed.

Try it (no API key)

examples/broken_agents is a small agent on the official openai SDK whose failure handling can be switched between good and deliberately broken. Its recording (made against a local mock provider) is in the repo, so the test runs offline:

git clone https://github.com/mac146/crosstrace && cd crosstrace
python3 -m venv .venv && . .venv/bin/activate     # Windows: py -m venv .venv, then .venv\Scripts\activate
pip install . openai
cd examples/broken_agents
crosstrace test                                   # the naive agent: hidden failures, exit code 1
crosstrace --config crosstrace.good.toml test     # the same recording, a fixed agent: exit code 0

The example's command is python, which the venv provides (a stock macOS or Ubuntu only has python3).

To reproduce the LangGraph results above, record the agent once with an OpenAI-compatible key (an OpenRouter key works as is, a few cents), then test:

pip install -r examples/real_agents/langgraph_support/requirements.txt
cd examples/real_agents/langgraph_support
OPENAI_API_KEY=... crosstrace record && crosstrace test

A real model answers differently from run to run, so your recordings, and the exchanges a fault lands on, will differ from ours; the behaviour under each fault is what to compare.

Use it on your agent

pip install crosstrace
crosstrace init --command "python agent.py {input}"      # writes crosstrace.toml: your inputs, timeouts, faults
crosstrace record     # runs your agent for real, once per input (uses your API key)
crosstrace test       # replays with faults; exit code 1 if your agent hides a failure

Your agent must read its provider base URL from the environment, which the OpenAI and Anthropic SDKs, LangChain, LangGraph, LiteLLM, pydantic-ai and the Vercel AI SDK all do (checked for each). If yours uses its own variable, map it in crosstrace.toml: env = { MY_BASE_URL = "{proxy_url}/v1" }.

Commit crosstrace.toml and .crosstrace/recordings/, and CI tests every pull request without API keys:

# .github/workflows/crosstrace.yml
on: [pull_request]
jobs:
  resilience:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: mac146/crosstrace@v0.3.1   # a release tag (or pin a commit SHA)
        with:
          install: pip install -r requirements.txt

The report goes to the job summary. A nightly run tests every fault at every model call: examples/github/crosstrace.yml.

Other CI systems (GitLab, Jenkins, CircleCI, Azure DevOps, Buildkite) read JUnit XML: crosstrace test --junit crosstrace.xml writes one testcase per trial. A failing trial is a <failure> with what happened and the command that reruns it; a trial that could not be judged, or a fault that applies to nothing recorded, is <skipped>. A run that tested nothing, or where more than 20% of the trials never reached their fault, is a setup problem (exit 3), never a green build.

How it decides

CrossTrace sits between your agent and the provider as a local proxy. It breaks one model call per trial, at the byte level, so your real SDK sees exactly what it would see in production. It then watches the agent's next move: did it retry that call, stop with an error, or carry on as if nothing happened?

verdict meaning
RECOVERED retried (or fell back) and finished with the healthy answer ok
SURFACED stopped with an error ok
WRONG_ACTION a tool really ran with values the healthy run never used (measured inside the agent's process) problem
SILENT carried on with a missing or partial answer in its context problem
PARTIAL printed the cut answer as if it were complete problem
HANG never finished problem
RETRY_STORM, IGNORED_RETRY_AFTER, WRONG_RETRY retried too often, too soon, or what can't succeed problem
ENDED_EARLY, RECOVERED_DIFFERENT exited 0 without the failed step, or recovered with a different answer review
REPROMPTED answered the failure with a different request instead of retrying the same call: told the model its reply failed, had its tool arguments refused and the model told, or summarised after a context-length error (the text is shown, so you can judge it) review
DIVERGED after a reply that arrived but was defective, sent a request that matches nothing recorded, and nothing shows it acted on the reply or carried on as before. The run is then continued and settled by how it ends: RECOVERED if it finishes, SURFACED if it stops with an error, RETRY_STORM if it never stops. Only if the replay cannot answer a later request does it stay a review review

What can fail your build, and what cannot. A verdict fails the build only when it rests on something CrossTrace measured: a hang, too many or too fast retries, a retried request that can never succeed, a write that ran twice, an answer printed cut, or an agent that acted on a defective reply or carried on exactly as if nothing had happened. When an agent changes course in a way CrossTrace can only guess at, the result is a review with the facts shown (what it sent, how many messages), never a failure. Every result in the JSON report carries observed: the attempts, the status of the fault, and the agent's next move.

The run continues past the fault. When an agent answers a failure with a request the recording does not contain (it re-prompts the model, summarises, rewrites its request), CrossTrace answers it with the next healthy reply of the recorded plan instead of an error, so the run reaches its real end and the verdict comes from how it ended. A persistent fault ("length_cut!persistent") keeps hitting the agent's recovery attempts too, which tests whether its recovery has a bound: an agent that keeps asking after 8 different requests is a RETRY_STORM. No model and no key are needed, so it stays deterministic and offline. It cannot tell whether a re-prompted agent would have received a good answer from a real model; it only shows that the agent stops. To check that too, add --live: those requests then go to the real provider with your own key (OPENAI_API_KEY or ANTHROPIC_API_KEY, read from the environment, never stored or logged), at most 6 calls per trial (--live-max-calls), so a re-prompt is answered by a real model and the run ends on its merits. It spends money, so it is opt-in and meant for a handful of trials (--fault, --path, --at), not a whole run. Turn continuation off with --no-continue or [test] continue = false.

No LLM judge and no comparison of free-text answers: the verdict comes from which model call the agent made next, so it is the same every time. Faults are injected at every model call of every recorded path (nightly) or a fixed sample (pull requests), so an agent can't pass by getting lucky on one run. Before any fault, each recording must replay exactly; if your prompts change on every run, CrossTrace names the field to mask instead of reporting a false pass.

Details: docs/cli.md. Fault list: crosstrace faults.

Status and limits

Early (v0.3). Tested end to end on the example agents here and the SDK matrix above; not yet on anyone else's production agent. If you try it on yours, an issue with what it found (or got wrong) is the most useful thing you can send.

  • Model calls: OpenAI chat completions and Responses, Anthropic Messages. Tool calls: MCP over stdio and streamable HTTP, see above.
  • Python 3.11+. Your agent can be in any language; it just has to be runnable as a command.
  • The healthy run must be repeatable enough to replay. Random values in prompts need a mask; heavy run-to-run variation in what your agent does needs several recorded runs.

Tool calls (MCP): a tool that ran but whose reply was lost

A model call that fails is annoying. A tool call that succeeded but whose response was lost can do damage: the email was sent, the card was charged, the form was submitted, the reply never reached the agent, and a retry does it a second time.

CrossTrace tests this for MCP servers over stdio and over streamable HTTP. For a stdio server, one change in your agent's MCP config: launch it as crosstrace mcp-wrap -- <its usual command>. For a remote server, list its URL in [mcp.http] and have the agent read its server address from CROSSTRACE_MCP_URL_<NAME>. The wrapper (or the local stand-in for the URL) records the tool calls in crosstrace record, and in crosstrace test it replays them without starting or calling the real server, so a replayed MCP call causes no side effect. This covers only tools behind the wrapper; your other tools still run, and --real-tools runs the MCP servers too. An agent with several servers names each one (mcp-wrap --name github -- ..., or the key in [mcp.http]).

  • lost_response: one tool call is made (and counted), and its reply is replaced by a transport error. Then we watch what the agent does.
  • Write counting: every call to a tool that changes something is logged. A write that was sent more often than in the healthy run is a DUPLICATE, in every trial, not only this one. A run that recovers and prints the right answer can still have written twice, so recovering is not enough to pass. This counts calls sent, not changes made: in replay no real server runs. The same check catches an agent that recovers from a model failure by starting the task over.
  • Which tools are writes: your [mcp] lists first, then what the server says about itself (a tool it declares readOnlyHint is a read), then a guess from the name (send, submit, pay, delete, click, ...; get, list, status are reads). List the ones it gets wrong in [mcp] writes / reads. For browser tools, click, type, fill_form, file_upload, press_key (Enter submits a form), evaluate and run_code are writes; navigate, snapshot and screenshot are reads. select_option and handle_dialog are ambiguous and count as reads: list them under writes if a choice or a confirmation can change something.
✗ lost_response   DUPLICATE 1/1
                  e.g. path 0 tool call 0: refund({"amount":129.99,"customer_id":"42",...}) was sent 2 time(s), 1 in the healthy run;
                  the agent recovered and finished, but it sent the write again

Runnable without any key: examples/mcp_agents (pip install mcp openai). Also checked by hand against the official @playwright/mcp 0.0.85 (25 tools): a scripted agent, a real Chrome and a local order form. Recording placed one real order; replays and trials placed none. Losing the response to the click made the retrying agent DUPLICATE in replay. With real tools, its second click was answered with an error (the button was gone) and only one new order was placed: UNCONFIRMED_DUPLICATE. The checking agent did not click again. That agent was scripted, so it tests the tool-call handling, not how well a model drives a browser. What this does not do yet:

  • Streamable HTTP is covered for what an agent sends as a POST (answered as JSON or an event stream). A server that pushes messages on its own GET stream is not: that stream gets a 405, which the protocol allows. Checked against the official Python SDK's server and client only. A lost response over HTTP is a 504 by default; with how = "drop" the connection is closed, which the official client turns into a crash of the whole session, so the agent cannot retry at all.
  • Several servers are handled by name. Each name must be used in both record and test; two unnamed stdio servers are not told apart.
  • Your MCP client must start the wrapper with CROSSTRACE_MCP in its environment. The official Python SDK starts servers with a reduced environment, so pass it on (the example does).
  • Replay cannot answer a state check. An agent that asks a read tool "did it go through?" before retrying gets the recorded answer, or "not recorded", so it shows as stopping with an error, not as recovering safely.
  • A retry counts as a repeat unless the server declares the tool idempotent (idempotentHint) or the retry reuses the same idempotency key, sent as a top-level argument (idempotency_key, request_id, client_token and similar). A retry with a new key counts as a repeat, because the server cannot know it is the same request. If a call has both an idempotency_key and a request_id, the idempotency key decides. A request_id or client_token is ignored when comparing two calls only if its value looks machine-made (a UUID, ULID or long hex string); otherwise it may name a record, so a different value is a different call. CrossTrace takes a reused key at its word: it cannot tell whether the server honours it. The official Playwright server declares readOnlyHint for 6 of its 25 tools and no idempotentHint.
  • By default the repeat is counted in replay, from a log of the tool calls. crosstrace test --real-tools runs the real servers in the lost_response trials (the model is still replayed), so the retry really reaches the server and the report quotes what it answered. If an error answer means no second change is confirmed, the verdict is UNCONFIRMED_DUPLICATE: a review, not a failure and not a pass, because an error does not prove that nothing changed. An answer without an error does not prove a second change either (the server may have ignored the repeat), so check the server's data. It is opt-in because it does the work for real: point it at a test account or a sandbox. Once they are, set [mcp] real = true and every run, CI included, sends the retry to the real server (--no-real-tools turns it off for one run). Model-fault trials always stay in replay. If the real server answers differently from the recording, the agent's next model request may match nothing recorded.
  • The lost response is a transport error on a live session, not a dead server process.

Agents that call an API directly (REST, GraphQL)

Many agents call Shopify, Stripe or an ERP over plain HTTP instead of an MCP tool. Put crosstrace api-proxy in front of the API and point the agent's API base URL at it. Every request is forwarded and logged; for one write, the real API does the work and then the reply is lost (a 504, a dropped connection, no reply, or a late reply). crosstrace api-report then says whether the agent sent it again and how many times the API accepted it. The writes really happen: use a sandbox or test account.

crosstrace api-proxy --upstream https://my-dev-store.myshopify.com --write "POST /admin/api/*/orders/*/refunds.json" --fault error
# point the agent at http://127.0.0.1:8787, run one task that makes the write, stop the proxy (Ctrl+C), then:
crosstrace api-report api-ledger.jsonl     # DUPLICATE (exit 1), REPEAT_REJECTED, NOT_REPEATED, NO_FAULT, UPSTREAM_ERROR or READBACK_MISMATCH

The log keeps the first 200 characters of the faulted write's reply (--reply-chars N changes it, 0 keeps none). Every other reply is logged only as its length and sha256, because replies can hold customer data or tokens.

Options and verdicts: docs/cli.md.

Background

CrossTrace started as research on tracing AI agents across the application and the kernel (eBPF): 21 stages, predictions written before each run. A look through real GitHub issues suggested that many agent failures are failure-handling bugs in SDKs and frameworks (no dataset or method is published here, so treat this as motivation, not a measurement), which is why the product tests failure handling. The research is in docs/research.md.

MIT licensed, see LICENSE.

About

Crash test for AI agents: cut streams, lost replies and retries, replayed offline

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages