CrossTrace records real runs of your AI agent, replays them with no API cost, and injects one realistic failure at one model call at a time: a stream cut short, a stalled connection, a reset, a rate limit, a provider error. For each trial it reports what your agent did next.
pip install crosstrace # from this repo for now: pip install .
crosstrace init --command "python agent.py {input}"
crosstrace record # runs your agent for real, once per input
crosstrace test # replays with faults; exit code 1 if your agent hides a failure
Your agent needs no code changes. It must read its provider base URL from the environment, which the official OpenAI and Anthropic
SDKs, LangChain, LangGraph, LiteLLM, pydantic-ai and the Vercel AI SDK all do (see framework-matrix.md).
CrossTrace sets OPENAI_BASE_URL and ANTHROPIC_BASE_URL to its local proxy for every run.
crosstrace check [--input TEXT ...] [--no-save] [-- COMMAND ...] runs the narrow test in one step. The first run needs the command that
starts your agent (use {input} where each --input goes); it writes crosstrace.toml, records if there is no recording (real model
calls, your key), and runs test --mode cutoff (tool_args_cut, stream_cut_clean, length_cut, lost_response).
| verdict | meaning | counts as |
|---|---|---|
RECOVERED |
the agent retried (or fell back to another model) and finished with the healthy output | ok |
SURFACED |
the agent stopped with an error (non-zero exit) | ok |
WRONG_ACTION |
a tool function really ran with values the healthy run never used (Python 3.12+ agents; see the README) | problem |
SILENT |
the agent moved on to its next model call without a successful answer to the failed one | problem |
PARTIAL |
the agent printed the cut answer and exited 0 | problem |
HANG |
no exit within the trial budget | problem |
RETRY_STORM |
more than 6 attempts at one call | problem |
IGNORED_RETRY_AFTER |
retried a 429 before Retry-After |
problem |
WRONG_RETRY |
retried a non-retryable error (400, 401) | problem |
ENDED_EARLY |
exited 0 without the failed call; check its output says the task failed | review |
DIVERGED |
after a defective reply, sent a request that matches nothing recorded and nothing shows it acted on the reply or carried on as before; settled by how the continued run ends (RECOVERED, SURFACED or RETRY_STORM), a review only if the replay cannot answer a later request |
review |
REPROMPTED |
answered the failure with a different request instead of retrying the same call: told the model its reply failed (one new message, nothing run on it), had a cut tool call refused and the model told, or rewrote the request after a context-length error; the text is shown | review |
RECOVERED_DIFFERENT |
recovered, but the output differs from the healthy run | review |
REPLAY_UNSTABLE, NOT_REACHED, N/A |
the trial says nothing about the agent (setup) | - |
The verdict is decided from the agent's next move after the fault, not by comparing final answers, so it is objective and needs no LLM judge. Trials whose verdict is already certain are stopped early.
Many agents call the model without streaming, with an SDK or a hand-written HTTP client. Three faults return a response that looks fine
to the HTTP layer and is not: length_cut (HTTP 200, the answer cut short, with the provider's own length signal: finish_reason: "length",
stop_reason: "max_tokens", or Responses status: "incomplete"; when an OpenAI-format reply ends in a tool call, the call's argument string
is what gets cut), empty_content (HTTP 200, a valid body with no answer text) and
malformed_body (HTTP 200, a correct Content-Length, JSON cut off part way). They do not apply to streamed calls, which have their own
faults. length_cut and malformed_body are in pr mode, empty_content in nightly.
Launch your MCP server through the wrapper in your agent's MCP config: ["crosstrace", "mcp-wrap", "--", "python", "server.py"]. Outside
CrossTrace the wrapper just runs the server. Under crosstrace record it passes everything through and records each request with its
response; under crosstrace test it answers from the recording and never starts the real server.
Your MCP client must give the wrapper CROSSTRACE_MCP (CrossTrace sets it for the agent process). Clients that start servers with a reduced
environment, such as the official Python SDK, need it passed on explicitly. With several servers, name each wrapper:
["crosstrace", "mcp-wrap", "--name", "github", "--", ...]; recorded calls carry the name and each wrapper replays only its own.
Remote servers (streamable HTTP). List each URL in crosstrace.toml and have your agent connect to the address CrossTrace gives it:
[mcp.http]
shop = "https://mcp.example.com/mcp" # the agent reads CROSSTRACE_MCP_URL_SHOP (falling back to the real URL)Under record a local stand-in forwards to the real URL (your headers and tokens pass through) and records the exchange; under test it
answers from the recording and never calls the server. A GET gets 405 (no server-to-client stream).
crosstrace test --real-tools runs the real MCP servers in lost_response trials (the model stays replayed), so a retried write really
reaches the server and the report says what it answered. Use a test account or a sandbox.
lost_response ([faults.lost_response]: how = "error" (default: a transport error, or a 504 over HTTP), "drop" (HTTP only: the connection is closed with no reply) or "silent" (nothing; an agent with no tool timeout
hangs), persistent = true to keep failing the retries) loses the response to each recorded tool call in turn. The tool counts as having run.
UNCONFIRMED_DUPLICATE (review, real tools only): the write was sent again and, because the server answered with an error, a second change
is not confirmed. It is not ruled out either: check the server's data. A run that failed for another reason keeps that verdict.
DUPLICATE: a write was sent more often than in the healthy run (calls are counted, not changes made). It is checked in every trial, including model faults, so an agent that recovers
from a model failure by redoing a tool call is caught. Which tools are writes comes from the server's own annotations when it gives
them (readOnlyHint: true is a read; readOnlyHint: false without idempotentHint: true is a write; idempotentHint: true is never a
repeat), otherwise it is guessed from their names; override it:
[mcp]
writes = ["run_report"] # tools that change something although their name does not say so
reads = ["send_preview"] # tools that only read although their name sounds like a writeMany agents call a REST or GraphQL API directly (Shopify, Stripe, an ERP) instead of an MCP tool. api-proxy sits in front of that API:
the agent's API base URL points at the proxy, every request is forwarded unchanged and logged, and for ONE write the real API is called and
does the work, then the reply is lost on the way back. The writes really happen: use a sandbox or test account (for Shopify, a
development store).
crosstrace api-proxy --upstream https://my-dev-store.myshopify.com \
--write "POST /admin/api/*/orders/*/refunds.json" --fault error --log api-ledger.jsonl
# point the agent at http://127.0.0.1:8787, run one task that makes the write, stop the proxy, then:
crosstrace api-report api-ledger.jsonl--fault:error(HTTP 504),drop(connection closed, no reply),silent(no reply for--holdseconds, default 300),late:N(the real reply, N seconds late, so an agent with a shorter timeout may retry while it is on its way).--write: which requests count as writes (METHOD /path/glob, repeatable). Without it every POST/PUT/PATCH/DELETE is a write.--at N: lose the reply to the N-th write (default 1).--reply-chars N: characters of the faulted write's reply kept in the log (default 200,0for none). Every other reply is logged only asreply_bytesandreply_sha256: replies can hold customer data or tokens.
A request body sent with Transfer-Encoding: chunked is read whole and forwarded with a Content-Length. A body that cannot be read
(a bad Content-Length, a broken chunk, a body that ends early) gets HTTP 400 and is never forwarded.
api-report compares requests without their idempotency key (header Idempotency-Key / X-Idempotency-Key, or a body field such as
idempotency_key), so a retry with a new key is still the same request, and requests that share a key count as one operation. Verdicts:
| verdict | meaning | exit |
|---|---|---|
DUPLICATE |
the same request was accepted by the real API more than once | 1 |
REPEAT_REJECTED |
it was sent again, but the API accepted it only once (a shared idempotency key, or a refusal); check the API's data | 0 |
NOT_REPEATED |
not sent again; the report says whether the agent read anything back first | 0 |
NO_FAULT |
no write matched --write / --at, so nothing was tested |
2 |
UPSTREAM_ERROR |
the faulted write never reached the real API (wrong --upstream, or it was down), so nothing was tested |
2 |
READBACK_MISMATCH |
the API accepted the write, but the read-back shows no new item: --readback lists something else, so the data decided nothing (the report also gives the verdict from the answers alone) |
2 |
Without read-back the report counts what the API answered: an accepted answer is a strong sign of a second change, not proof of one.
Read-back: let the real data decide. Give a GET path that lists what the write creates, and the proxy counts it before the agent
runs and again when you stop the proxy (Ctrl+C). The difference is the number of real changes, and it decides the verdict: each
different accepted request of the faulted write's kind (same method and path) may add one item, and any item beyond that is a
DUPLICATE, even if the answers looked fine. One refund repeated: 2 new items for 1 different request, DUPLICATE. Two refunds of
different amounts on one order: 2 new items for 2 different requests, not a duplicate. One new item is never a duplicate, even if the
API accepted the request twice.
Credentials for the read-back come from an environment variable and are never written to the log.
crosstrace api-proxy --upstream https://api.example.com --write "POST /orders/*/refunds" \
--readback /orders/42/refunds --readback-list refunds --readback-header "Authorization=EXAMPLE_API_AUTH"Shopify preset (a development store, refunds on one test order). It sets the write rule, the read-back of that order's refunds and
the X-Shopify-Access-Token header from SHOPIFY_ACCESS_TOKEN:
export SHOPIFY_ACCESS_TOKEN=... # an Admin API token of the development store
crosstrace api-proxy --upstream https://my-dev-store.myshopify.com --shopify-order 1234567890 --fault error
# point the agent's Shopify base URL at http://127.0.0.1:8787, ask it to refund order 1234567890 once, then Ctrl+C and:
crosstrace api-report api-ledger.jsonl--shopify-version sets the Admin API version used for the read-back (default 2025-10). The preset was checked against a local
Shopify-shaped server, not yet against a real store.
One run is one trial: run the agent a few times, and with each --fault.
After a fault, a request that matches nothing recorded is answered with the next healthy reply of the plan (the reply to the failed call first, then the following ones; the last one again after the end), of the same provider and the same kind (streamed or not). Without this the replay would answer with an error, the agent would die, and the verdict would have to be guessed from one request.
- Bounded or not. After 8 such answers the agent is flagged as not stopping and cut off:
RETRY_STORM. - Persistent faults follow the agent.
"empty_content!persistent"makes every answer defective again, so an agent that re-prompts shows whether it gives up (SURFACED) or asks forever (RETRY_STORM). - What it cannot show. A real model might answer a re-prompt badly or well; CrossTrace answers with the healthy reply. It shows that the agent stops and how, not that its re-prompt works. Without a fitting recorded reply (another provider, or streamed versus not) it falls back to an error, and the result stays a review.
- Live: ask a real model.
crosstrace test --live --fault context_length --path 0 --at 0sends those requests to the real provider (the URL from[record] upstreams, else the provider's own) with the key inOPENAI_API_KEYorANTHROPIC_API_KEY, so the agent's re-prompt gets a real answer. The agent never sees the key (it keeps its replay placeholder; the proxy swaps it on the outgoing request), the key is not written to the log or the report, and a trial makes at most--live-max-calls(default 6) real calls before the agent is judged as not stopping. A fault is not injected on a real answer. It spends money, so it is opt-in. A provider with no key set still gets the recorded reply. - Off:
crosstrace test --no-continueor[test] continue = false.
crosstrace record records each input runs times; every recording is one path through your agent. crosstrace test injects each fault
at every model call where it applies (--mode nightly), or at a fixed, seeded sample that always includes the first and the last call
(--mode pr, default). The same commit always gets the same trials. Every failing trial prints the command that reruns exactly it:
crosstrace test --path 0 --fault stream_cut_clean --at 2
Before any fault, each recording is replayed with no fault and must match exactly. If a prompt contains a value that changes on every run
(a random id, a counter), the check names the field and both values and prints a ready-to-paste [replay] masks = [...] line. The regex is built from the two
values and checked to make them equal before it is offered; it keeps a few characters of context so it does not mask unrelated text. Read it
before pasting: it cannot know whether a value that differs was meant to differ. Timestamps and UUIDs are
masked by default. An unstable recording is a setup error (exit 3), never a pass.
| code | meaning |
|---|---|
| 0 | no problems |
| 1 | problems found |
| 2 | usage or config error |
| 3 | setup problem: no recordings, unstable replay, the agent failed its healthy run, nothing was tested (no fault applied, or no trial could be judged), or more than 20% of the trials were REPLAY_UNSTABLE/NOT_REACHED with no failing trial |
The report prints how many trials ran and how many were judged either way (21 trial(s): 21 judged).
crosstrace test --junit FILE also writes the report as JUnit XML for CI test reporters: one testcase per trial (classname
crosstrace.<fault>, name path P exchange N or path P tool call N). A failing trial is a <failure> whose text is the detail and
the rerun command; a trial to review passes with its detail in <system-out>; an unjudged trial and a fault that applies to nothing are
<skipped>; a setup problem is one <error> testcase.
crosstrace record --clean records into a new folder next to the recordings and replaces them only when every run succeeded. If a run
fails, the existing recordings are kept and the new ones (if any) are left in that folder.
| 4 | internal error in CrossTrace (never reported as a problem with your agent) |
crosstrace init writes a commented file. Keys: [agent] command, inputs, timeout_s, cwd, env, sdk; [record] runs, upstreams;
[replay] masks; [test] allow, trial_timeout_s; [modes.<name>] faults, max_exchanges, stability_runs, jobs;
[faults.<fault>] <parameters>. Unknown keys are errors. Faults are names ("server_error", heals after one failed attempt) or
"server_error!persistent" (never heals), or { name = "overloaded", heal = 2, params = { ... } }. crosstrace faults lists them.
[agent] sdk names the SDK the fix advice is written for (openai-python, openai-agents, pydantic-ai, anthropic-python, openai-js,
anthropic-js, vercel-ai). By default it is read from the User-Agent the proxy logged, and the report says what it detected. A framework built on
an SDK sends that SDK's User-Agent (CrewAI and LangChain send OpenAI/Python); an unrecognised one gets every fix listed under its SDK's name,
never one guessed fix.
[record] upstreams points recording at an OpenAI-compatible gateway instead of the provider (e.g. a LiteLLM proxy or vLLM).
Recordings hold your prompts and the model's answers; API keys and request headers are never stored. They are meant to be committed so CI can replay without keys. Review them, and mask anything sensitive.
See action.yml and examples/github/crosstrace.yml: pr mode on pull requests,
nightly on a schedule. The Markdown report goes to the job summary.
- Model calls only (OpenAI chat completions and Responses, Anthropic Messages). Tool calls: MCP servers over stdio (see "MCP tool calls" below); other tool kinds are not tested.
- Plain HTTP/1.1 between your agent and the local proxy; connection findings carry that protocol.
- Agents that make model calls concurrently are matched correctly, but the verdict assumes the faulted call's result is needed before the next call.