agent-crashtest 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. agent_crashtest-0.4.1.dist-info/METADATA +295 -0
  2. agent_crashtest-0.4.1.dist-info/RECORD +44 -0
  3. agent_crashtest-0.4.1.dist-info/WHEEL +5 -0
  4. agent_crashtest-0.4.1.dist-info/entry_points.txt +2 -0
  5. agent_crashtest-0.4.1.dist-info/licenses/LICENSE +21 -0
  6. agent_crashtest-0.4.1.dist-info/top_level.txt +1 -0
  7. crashtest/__init__.py +1 -0
  8. crashtest/checker.py +137 -0
  9. crashtest/cli.py +711 -0
  10. crashtest/control_token.py +72 -0
  11. crashtest/controller.py +410 -0
  12. crashtest/examples/check_status_agent.py +92 -0
  13. crashtest/examples/naive_retry_agent.py +56 -0
  14. crashtest/examples/stable_key_agent.py +64 -0
  15. crashtest/experiment/__init__.py +0 -0
  16. crashtest/experiment/crash_common.py +107 -0
  17. crashtest/experiment/cut_points.py +304 -0
  18. crashtest/experiment/dbos_crash.py +427 -0
  19. crashtest/experiment/langgraph_crash.py +424 -0
  20. crashtest/experiment/local_stack.py +275 -0
  21. crashtest/experiment/model_retry.py +667 -0
  22. crashtest/experiment/model_retry_validate.py +558 -0
  23. crashtest/experiment/resume.py +299 -0
  24. crashtest/experiment/run.py +316 -0
  25. crashtest/experiment/single_call.py +428 -0
  26. crashtest/experiment/trial.py +366 -0
  27. crashtest/faults/__init__.py +0 -0
  28. crashtest/faults/drop_proxy.py +438 -0
  29. crashtest/refund_mcp/__init__.py +0 -0
  30. crashtest/refund_mcp/event_store.py +66 -0
  31. crashtest/refund_mcp/server.py +211 -0
  32. crashtest/refund_run.py +1113 -0
  33. crashtest/results/__init__.py +1 -0
  34. crashtest/results/__main__.py +72 -0
  35. crashtest/results/report_check.py +109 -0
  36. crashtest/results/reverdict.py +140 -0
  37. crashtest/results/schema.sql +34 -0
  38. crashtest/results/store.py +182 -0
  39. crashtest/results/table.py +315 -0
  40. crashtest/scenarios.py +343 -0
  41. crashtest/sink/__init__.py +0 -0
  42. crashtest/sink/__main__.py +38 -0
  43. crashtest/sink/app.py +224 -0
  44. crashtest/sink/schema.sql +50 -0
@@ -0,0 +1,295 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-crashtest
3
+ Version: 0.4.1
4
+ Summary: Crash-test your AI agent's MCP tool calls: after a lost response, did the refund happen once, twice, or not at all?
5
+ Author: Munendra
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/munendra07-tech/agent-crashtest
8
+ Project-URL: Documentation, https://github.com/munendra07-tech/agent-crashtest#readme
9
+ Project-URL: Issues, https://github.com/munendra07-tech/agent-crashtest/issues
10
+ Project-URL: Changelog, https://github.com/munendra07-tech/agent-crashtest/blob/main/CHANGELOG.md
11
+ Keywords: mcp,ai-agents,testing,idempotency,retries,fault-injection
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Software Development :: Testing
18
+ Requires-Python: >=3.12
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: mcp==2.3.0
22
+ Requires-Dist: fastapi>=0.115
23
+ Requires-Dist: uvicorn[standard]>=0.30
24
+ Requires-Dist: httpx>=0.27
25
+ Requires-Dist: psycopg[binary,pool]>=3.2
26
+ Provides-Extra: local
27
+ Requires-Dist: pgserver>=0.1.4; extra == "local"
28
+ Provides-Extra: m5
29
+ Requires-Dist: anthropic; extra == "m5"
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=8; extra == "dev"
32
+ Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
33
+ Requires-Dist: pytest-cov>=5; extra == "dev"
34
+ Requires-Dist: pgserver>=0.1.4; extra == "dev"
35
+ Requires-Dist: ruff>=0.6; extra == "dev"
36
+ Requires-Dist: mypy>=1.11; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # agent-crashtest
40
+
41
+ [![CI](https://github.com/munendra07-tech/agent-crashtest/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/munendra07-tech/agent-crashtest/actions/workflows/ci.yml) [![Release](https://img.shields.io/github/v/release/munendra07-tech/agent-crashtest)](https://github.com/munendra07-tech/agent-crashtest/releases/latest) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/munendra07-tech/agent-crashtest/blob/main/LICENSE) [![Python 3.12+](https://img.shields.io/badge/python-3.12%2B-blue.svg)](https://github.com/munendra07-tech/agent-crashtest/blob/main/pyproject.toml)
42
+
43
+ **Crash-test your AI agent's tool calls.** Does your agent refund a customer twice when a tool's response is lost?
44
+
45
+ <p align="center"><img src="https://raw.githubusercontent.com/munendra07-tech/agent-crashtest/main/docs/media/demo.gif" alt="Animation: a refund response is lost, the agent retries and the database holds two refunds; then a real agent-crashtest report showing a duplicate for every order" width="800"></p>
46
+
47
+ <p align="center">▶ <a href="https://github.com/munendra07-tech/agent-crashtest/releases/download/v0.4.0/agent-crashtest-demo-v0.4.0.mp4"><b>Watch the 1:40 demo</b></a>: an animated explainer and a real run on Windows (recorded with v0.3.1; these results are unchanged in v0.4.0; synthetic narration).</p>
48
+
49
+ Agents call tools that move money, send email and write records. When a response is lost or a connection drops mid-call, something usually retries, and the effect can happen twice, or the agent gives up on a refund that never happened. `agent-crashtest` gives your agent a fake refund tool over MCP, breaks the call on purpose, and counts how many refunds actually happened. You get a PASS/FAIL report that says what was observed, the likely cause and how to fix it.
50
+
51
+ **What it tests, exactly:** one simulated refund tool (`issue_refund`) over MCP, and three faults, called scenarios:
52
+
53
+ | Scenario | What breaks | Was a refund made? | What a safe agent does |
54
+ |---|---|---|---|
55
+ | `refunds` (the reference) | The refund commits, then the reply is held past your agent's timeout | Yes | Retries with the same idempotency key, so nothing doubles |
56
+ | `refunds-cut-before-request` | The connection is cut before the call reaches the server | No | Retries, so the refund still happens |
57
+ | `refunds-cut-mid-stream` | A progress update arrives, then the connection is cut before the commit | No | Retries, so the refund still happens |
58
+
59
+ From the agent's side all three look alike: an error with no answer. One stable idempotency key per refund, enforced where the refund is made, is the fix that is safe in all three. It does not test payment idempotency in general, a real payment provider, or any other effect or fault.
60
+
61
+ **It is a sandbox.** The tool is a test double: it writes only to a local PostgreSQL database that it starts on your machine, moves no money, and nothing is hosted. Never point it, or an agent under test, at real payment credentials or production systems.
62
+
63
+ ## Why it matters
64
+
65
+ A lost response is ordinary: a timeout, a dropped connection, a restarted worker. The agent cannot tell whether the refund went through, so it tries again, and the customer is refunded twice while the agent reports one refund. Most retry logic is never tested against that case, because it is hard to reproduce on purpose. Here it is one command, and the answer comes from the database that holds the refunds, not from what the agent says.
66
+
67
+ ## Quickstart
68
+
69
+ Python 3.12 or later; no Docker needed. Install:
70
+
71
+ ```powershell
72
+ pip install "agent-crashtest[local] @ git+https://github.com/munendra07-tech/agent-crashtest@v0.4.1"
73
+ ```
74
+
75
+ Before testing your agent, run `crashtest selftest`. It checks that the harness itself works on your machine, using the two example agents as controls (the unsafe one must FAIL with a duplicate in every trial, the safe one must PASS), and takes about 40 seconds:
76
+
77
+ ```powershell
78
+ crashtest selftest
79
+ ```
80
+
81
+ ```text
82
+ selftest passed: on this machine the harness detects a duplicate refund and passes a safe agent, so its counts for your own agent are reliable here; a PASS covers only this scenario, not your agent's safety in general
83
+ ```
84
+
85
+ If a control misbehaves, it says which one, that the harness (not your agent) is at fault, and exits 1; an environment error exits 2.
86
+
87
+ To see the two controls' full reports, run the unsafe example agent, which retries with no idempotency key:
88
+
89
+ ```powershell
90
+ crashtest run refunds --agent naive
91
+ ```
92
+
93
+ It starts PostgreSQL, a sink and the MCP server, runs five trials and prints (order IDs shortened):
94
+
95
+ ```text
96
+ crashtest run refunds: FAIL - 5 of 5 trials refunded more than once
97
+ agent: naive; fault: lost response (held 5 s, agent timeout 2 s); exit code 1
98
+
99
+ What was tested: one simulated refund tool (issue_refund) over MCP and one fault, a lost response: the sink commits the refund, then withholds the reply past the agent's timeout. No other effect or fault is tested.
100
+ The tool is a test double: it writes only to a local PostgreSQL database and moves no money. Never point it, or an agent under test, at real payment credentials or production systems.
101
+
102
+ OBSERVED (from the sink and the harness)
103
+ trials: 5
104
+ sink (ground truth): expected refunds 5, actual refunds (in the sink): 10
105
+ sink (ground truth): extra refunds per trial: 1, 1, 1, 1, 1
106
+ sink (ground truth): refund requests received: 10
107
+ sink (ground truth): fault fired in 5 of 5 trials: the sink committed the refund, then withheld its response for 5 s, past the agent's 2 s timeout (the harness does not observe the agent's side of the call)
108
+ agent-reported (not verified): what the agent told its caller: done 5
109
+ agent-reported (not verified): agrees with the sink in 0 of 5
110
+ checker: confirmed success (one correct refund in the sink, the agent said done, the fault fired): 0 of 5
111
+ checker: safety failures (a duplicate, a wrong amount, or a refund lost after the fault fired): 5 of 5
112
+ checker: not confirmed (no safety failure, but the agent's answer was uncertain or contradicted the sink, or the fault did not fire): 0 of 5
113
+ checker: verdicts (crashtest.checker): duplicate 5
114
+ 0 of 5 trials refunded exactly once. This is repeatability under the stated configuration (fault delay 5 s, agent timeout 2 s), not a rate.
115
+
116
+ trial order refunds requests fault fired agent said agrees with sink verdict
117
+ 1 ord-6f1c... 2 2 yes done NO duplicate
118
+ ...
119
+
120
+ LIKELY CAUSE (inference from the observations above, not observed directly)
121
+ - The first request committed and its response was lost (the fault held it past the agent's timeout); the agent retried without an idempotency key. It then told its caller that one refund was made.
122
+
123
+ RECOMMENDED FIX
124
+ - Derive one idempotency key from the business operation (for example refund-<order_id>), send the same key on every attempt, and let the system that makes the refund enforce it (here the sink does, in its database). A key made fresh for each attempt does not help. Before retrying after a timeout, check whether the refund already exists.
125
+ ```
126
+
127
+ Then the safe one, which sends the same key on every attempt:
128
+
129
+ ```powershell
130
+ crashtest run refunds --agent stable_key
131
+ ```
132
+
133
+ ```text
134
+ crashtest run refunds: PASS - 5 of 5 trials refunded exactly once (verdict correct)
135
+ ...
136
+ ```
137
+
138
+ Each run takes about 30 seconds on a laptop, including starting the stack. The trials are deterministic, so the report gives "N of N trials": repeatability under the stated configuration (fault delay, agent timeout), not a rate.
139
+
140
+ ### Test your own agent
141
+
142
+ Copy [`examples/stable_key_agent.py`](https://github.com/munendra07-tech/agent-crashtest/blob/main/examples/stable_key_agent.py) (or [`examples/naive_retry_agent.py`](https://github.com/munendra07-tech/agent-crashtest/blob/main/examples/naive_retry_agent.py)) and replace its body with your agent or client. The contract is small:
143
+
144
+ - **Arguments:** `--mcp-url URL --order-id ID --amount-cents N --timeout SECONDS`. Call the MCP tool `issue_refund` at that URL for that order and amount, with that client timeout. The tool also takes an optional `idempotency_key`.
145
+ - **Output:** the last line on stdout is one JSON object, `{"report": "done"}`, `"unknown"` or `"not_done"`: what your agent would tell its caller about the refund. Anything else counts as no report.
146
+
147
+ ```powershell
148
+ crashtest run refunds --agent path/to/my_agent.py --trials 10
149
+ ```
150
+
151
+ `--python PATH` runs your script with another interpreter, such as your agent's own virtual environment.
152
+
153
+ [`examples/check_status_agent.py`](https://github.com/munendra07-tech/agent-crashtest/blob/main/examples/check_status_agent.py) shows another pattern: after a timeout it looks the refund up with the read-only tool `check_refund_status(order_id)` before retrying. It passes both scenarios here, but it is weaker than a key. In this test a lookup always sees the refund, because the sink commits before it holds the response. In a real system the first request can still be in flight when the lookup runs and commit after the retry, or another worker can act between the check and the retry: two refunds. Rely on an enforced idempotency key, and use a lookup as an extra on top of it.
154
+
155
+ Agents built with a framework: [`examples/frameworks/`](https://github.com/munendra07-tech/agent-crashtest/blob/main/examples/frameworks/README.md) has a Pydantic AI agent and a LangGraph agent, each driven by a scripted model (no API key), each checked in CI (naive FAIL, stable key PASS).
156
+
157
+ ### Reports and exit codes
158
+
159
+ `--format text|json|markdown|junit` picks the report's format (`markdown` suits a PR comment, `junit` a CI test report); `--output FILE` writes it to a file, and `--junit-file FILE` and `--markdown-file FILE` write a second copy. Every format keeps the three parts apart: **observed** (from the sink and the harness), **likely cause** (an inference) and **recommended fix**. Each trial's verdict comes from the project's checker, as defined in the [contract](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/contract.md); PASS means every trial's verdict is `correct`.
160
+
161
+ Each line of the observed section says where it comes from. **`sink (ground truth)`** is what the database holds: refunds, requests, and whether the fault fired (the sink committed the refund, then withheld its response for the stated seconds, past the agent's timeout; the harness cannot see the agent's side of that call). **`agent-reported (not verified)`** is what the agent told its caller, which can contradict the sink. **`checker`** combines the two: *confirmed success* is one correct refund in the sink that the agent also reported as `done`; *not confirmed* is an outcome with no safety failure that is uncertain (the agent said `unknown`) or whose report contradicts the sink; *safety failures* are duplicates, wrong amounts and refunds lost after the fault fired. `crashtest run` and `crashtest verdict` take your agent's `done` as confirmed, because the harness cannot see inside the agent, so the `unconfirmed_success` verdict (a claim the agent could have checked but did not) cannot occur on this path.
162
+
163
+ | Exit code | Result | Meaning |
164
+ |---|---|---|
165
+ | 0 | PASS | Every trial refunded exactly once and the agent reported it |
166
+ | 0 | WARN | The sink holds exactly one refund per order, but the agent said something else (for example "unknown"). Shown in the report; exits 1 with `--fail-on-report-mismatch` if what the agent said contradicts the sink. Use that flag in CI if agents must report honestly |
167
+ | 1 | FAIL | A duplicate or lost refund: the sink does not hold exactly one correct refund for an order |
168
+ | 2 | | An environment or configuration error (the stack did not start, the agent script was not found) |
169
+ | 3 | INCONCLUSIVE | The fault could not be confirmed: no refund reached the sink while it was armed, so the trial tested nothing |
170
+
171
+ ## How it works
172
+
173
+ ```
174
+ arm the fault, read the refunds
175
+ crashtest run ─────────────────────────────────────────────┐
176
+ │ one fresh order per trial ▼
177
+ └─> your agent ──MCP──> refund MCP server ──HTTP──> sink ──> PostgreSQL
178
+ (a script) tool: issue_refund commits the refund, then
179
+ holds the response past
180
+ report <── checker (verdicts) <── the sink's rows the agent's timeout
181
+ ```
182
+
183
+ The sink plays the outside world: each row in its `refunds` table is a refund that happened, and it enforces idempotency keys in the database. The fault makes it commit the first refund for an order and then withhold the response, so the agent never hears back. What the agent does next decides how many rows there are. The verdict comes from those rows; what the agent says is recorded beside it, not trusted.
184
+
185
+ ## In CI: the GitHub Action
186
+
187
+ ```yaml
188
+ - uses: munendra07-tech/agent-crashtest@v0.4.1
189
+ with:
190
+ agent: path/to/my_agent.py # or naive, stable_key
191
+ scenario: all # both scenarios; the default is refunds
192
+ trials: 5
193
+ fail-on-duplicate-effect: true
194
+ ```
195
+
196
+ **Run both scenarios** with `scenario: all` (since 0.3.1). It runs both scenarios, one after the other, and the step's result is the worse of the two. Use it: an agent that reports "done" after an error, without retrying, passes `refunds` alone (the refund had committed) and fails the connection cut (nothing had). `scenario: refunds` stays the default. `scenario: refunds-cut-mid-stream` runs the third scenario on its own; it is not in `all`, because it needs an MCP client that asks for progress, and adding it would change existing builds.
197
+
198
+ The Action installs the package with Python 3.12, runs `crashtest run` for the scenario (`refunds` unless you choose another), writes the JUnit report to `crashtest-junit.xml` in the workspace (`crashtest-junit-<scenario>.xml` for the cut) and the Markdown report to the job summary, and fails the step on a duplicate (or lost) refund. With `fail-on-duplicate-effect: false` it reports and passes. Its outputs are `result`, `exit-code` and `junit-file`. The Action does not pass `--fail-on-report-mismatch`, so a WARN (one refund in the sink, but the agent's report was uncertain or contradicted it) exits 0; run `crashtest run refunds --fail-on-report-mismatch` yourself if that should fail the build.
199
+
200
+ **Security: your agent script runs inside the CI job.** A custom `agent:` script is ordinary code executed on the GitHub Actions runner, with whatever environment the workflow gives that step, and on your own machine when you run `crashtest run` locally. Do not give it secrets or production credentials it does not need: no payment-provider keys, no production database URLs, no cloud tokens. The Action passes none, and its job needs only `contents: read`. Run it on `pull_request`, not `pull_request_target`, so code from a fork gets no secrets. The refund tool is a test double: point nothing real at it.
201
+
202
+ ## Step by step: serve, arm, verdict
203
+
204
+ To drive a client by hand instead of through an agent script:
205
+
206
+ 1. **Start the server and the sink**, and leave it running. It prints the MCP server's URL:
207
+
208
+ ```powershell
209
+ crashtest serve
210
+ ```
211
+
212
+ 2. **In another terminal, in the same folder, arm the fault** for an order ID you choose. The next refund for it commits, then its response is held for 5 seconds:
213
+
214
+ ```powershell
215
+ crashtest arm ord-123 --delay 5
216
+ ```
217
+
218
+ 3. **From your client, call the tool** `issue_refund` with `order_id="ord-123"` and `amount_cents=2500`, with a client timeout shorter than 5 seconds, and let your client do whatever it does: retry, give up or report.
219
+
220
+ 4. **Ask for the verdict**, saying what your client told its caller (`done`, `unknown`, `not_done` or `none`):
221
+
222
+ ```powershell
223
+ crashtest verdict ord-123 --report done
224
+ ```
225
+
226
+ It prints how many refunds the sink committed, the verdict (`correct`, `duplicate`, ...) and whether your client's report agrees with the sink. It exits 0 only for `correct`, so you can use it in your own tests.
227
+
228
+ The tool's arguments, the idempotency key and the same steps with `curl` and Python: [docs/connect-your-client.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/connect-your-client.md).
229
+
230
+ ## Connect an MCP client
231
+
232
+ Three steps: start the stack with `crashtest serve`, add the refund server to your client, then use `crashtest arm` and `crashtest verdict` as in the step-by-step section above. For an HTTP client, `crashtest serve --mcp-port 8102` keeps the URL at `http://127.0.0.1:8102/mcp` across restarts (since 0.4.0).
233
+
234
+ | Client | How it connects | Status |
235
+ |---|---|---|
236
+ | Python `mcp` client | stdio or HTTP | Verified in CI ([guide](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/clients/python-mcp.md)) |
237
+ | MCP Inspector, CLI mode | stdio or HTTP | Verified in CI ([guide](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/clients/mcp-inspector.md)); its web UI has not been run |
238
+ | Claude Desktop | stdio | Verified by hand on Windows, one trial ([guide](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/clients/claude-desktop.md)) |
239
+ | Claude Code | stdio or HTTP | Not yet verified ([guide](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/clients/claude-code.md)) |
240
+ | VS Code, Cursor | HTTP, or stdio | Not yet verified ([guide](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/clients/vscode-cursor.md)) |
241
+
242
+ "Not yet verified" means the setup follows that client's documentation but nobody has run it against agent-crashtest. If you try one, please say whether it worked, with a [Tester report](https://github.com/munendra07-tech/agent-crashtest/issues/new?template=tester_report.yml).
243
+
244
+ `crashtest serve` serves the tool over Streamable HTTP at the URL it prints. For clients that launch a command instead, `crashtest mcp --stdio --stack-file <path to .crashtest-stack.json>` serves the same tool over stdio on the running sink (or `--sink-url URL`); without a running sink it says so on stderr and exits 2. Both transports run the same server code against the same sink, and CI checks that the same agent gets the same verdict over both. Copy-ready setup for the Python `mcp` client, the MCP Inspector, Claude Desktop, Claude Code, VS Code and Cursor, each marked with whether it has been verified: [docs/clients/](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/clients/README.md).
245
+
246
+ **Security.** The agent under test sees only the simulated tools (`issue_refund`, and the read-only `check_refund_status` lookup). Arming faults, resetting and judging stay with you: the sink's `/control/*` endpoints require a control token that `serve` stores in `.crashtest-stack.json` (never sent over MCP, never given to an agent that `crashtest run` starts), while the read-only ground truth (`GET /refunds`) stays open. An agent that can read that file can read the token, so keep the agent out of that folder. Everything listens on `127.0.0.1`, and the HTTP MCP server refuses requests whose `Host` or `Origin` header names any other host (DNS-rebinding protection).
247
+
248
+ ### Drive tests from your own client: the test controller
249
+
250
+ `crashtest controller --stdio` (or `--http`, token required) is a second MCP server, for you and never for the agent under test, with five tools: `create_test_run`, `configure_scenario`, `arm_fault`, `get_run_status` and `get_test_report`. It has no reset or delete tool. Reports carry a run ID and the scenario's name and version, and the verdict comes only from the sink, judged by the same checker and report code as `crashtest run`; a regression test checks that both give the same result, verdicts and counts for the same agent behaviour. See [docs/controller.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/controller.md).
251
+
252
+ ## More scenarios
253
+
254
+ `refunds` (a lost response after the commit) is the reference scenario. Two more come from the project's experiment 008; run them too, because an agent can pass one and fail another.
255
+
256
+ ### The connection cut before the request
257
+
258
+ ```powershell
259
+ crashtest run refunds-cut-before-request --agent naive
260
+ ```
261
+
262
+ A proxy between your agent and the MCP server cuts the agent's first call before it reaches the server, so nothing is refunded and even a naive retry refunds once (PASS). The point is the error: your agent sees the same disconnect as when the cut comes after the commit, where the naive retry refunds twice (experiment 008). It cannot tell the two apart from the error, so only a stable idempotency key is safe in both (looking the refund up passes here too, but can race in a real system; see above); run both scenarios. An agent that reports "done" without a success result gets `lost` (FAIL). Ground truth: the sink's rows plus the proxy's record that the call was withheld. `crashtest selftest --scenario refunds-cut-before-request` checks the harness for it. Details and limitations: [docs/scenarios.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/scenarios.md).
263
+
264
+ ### The connection cut mid-stream
265
+
266
+ ```powershell
267
+ crashtest run refunds-cut-mid-stream --agent naive
268
+ ```
269
+
270
+ The tool sends a progress notification, then the proxy cuts the connection before the response, while the tool is still paused before the refund; the server cancels the tool, so nothing is refunded and a retry refunds once. Seeing the call start is not evidence that it finished. Your agent's MCP client must ask for progress (`progress_callback` with the Python client), or the trial is INCONCLUSIVE. One stated server configuration (stateful SSE, no event store), from experiment 008. The test controller runs it too, and the Action takes `scenario: refunds-cut-mid-stream` (not part of `scenario: all`). Details: [docs/scenarios.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/scenarios.md).
271
+
272
+ ## Limitations
273
+
274
+ - **Client guides.** Only the Python `mcp` client (stdio and HTTP) and the MCP Inspector's CLI are verified in CI; Claude Desktop was run by hand once on Windows (not macOS); the Claude Code, VS Code, Cursor and Inspector web-UI steps follow those clients' documentation and have not been run yet ([docs/clients/](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/clients/README.md)). `crashtest serve` picks a free port each time unless you fix one with `--mcp-port` (since 0.4.0); otherwise an HTTP client's configuration must be updated after a restart.
275
+ - **Three scenarios.** A refund through one MCP tool, with one of three faults: the first response is lost after the refund commits (`refunds`, the reference), the connection is cut before the request reaches the server (`refunds-cut-before-request`), or it is cut mid-stream, before the commit (`refunds-cut-mid-stream`, one server configuration); both cuts are from experiment 008. Cuts during the effect, crashes of the agent's own process and other effects (bookings, inventory) are not in `crashtest run` yet. See [docs/scenarios.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/scenarios.md) for each scenario's ground truth and limitations.
276
+ - **What a PASS shows.** One correct refund per order in the sink, and the agent said `done`. It does not show that the agent received a success or reasoned correctly: the harness sees only the sink and the agent's final report. An agent that says `done` after an error passes `refunds` (the refund landed anyway) and fails `refunds-cut-before-request` (`lost`), so run both.
277
+ - **The agent runs as a script**, once per order, with the arguments above. An agent that needs a model, credentials or a long-running process has to be wrapped in such a script.
278
+ - **A test double, not a payment provider.** A PASS says your agent's retries are safe against this test double, a sink that enforces idempotency keys in its database; it says nothing about whether your real provider does.
279
+ - **Repeatability, not a rate.** "5 of 5 trials" says the outcome repeated under the stated configuration (fault delay, agent timeout); it is not a probability and carries no confidence interval. An agent whose behaviour depends on timing or on a model may need more trials, or other timings.
280
+ - **Platforms, as CI shows.** On every push CI installs the package into a fresh virtual environment (not editable), runs `crashtest selftest` and both example agents on Ubuntu, Windows and macOS (GitHub's `ubuntu-latest`, `windows-latest` and `macos-latest` runners, Python 3.12): all three passed ([run](https://github.com/munendra07-tech/agent-crashtest/actions/runs/45485719103)). The full test suite also runs in CI on all three ([run](https://github.com/munendra07-tech/agent-crashtest/actions/runs/45653846654)); on the Windows runner it runs from the runner's temp folder, because PostgreSQL's setup cannot use the checkout folder there. Other macOS versions, chips and Python versions are not tested. On Windows, `pgserver` (PostgreSQL) cannot create a data directory under a path with characters outside the system's ANSI code page; see [Run it on Windows](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/development.md#run-it-on-windows-powershell). The Action runs your agent with its own Python 3.12, which has the `mcp` client; whether packages your agent needs can be installed into that Python in an earlier step has not been tested yet.
281
+
282
+ ## Roadmap
283
+
284
+ What comes after this release will be chosen from early users' feedback, so please open an issue with what you tried and what you need. Plans and their status: [ROADMAP.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/ROADMAP.md).
285
+
286
+ ## Contributing and license
287
+
288
+ Bug reports, reproductions and "my agent failed and I don't know why" questions are all welcome: open an issue with one of the templates. Setup, checks and good first issues are in [CONTRIBUTING.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/CONTRIBUTING.md). MIT licensed: see [LICENSE](https://github.com/munendra07-tech/agent-crashtest/blob/main/LICENSE).
289
+
290
+ ## Further reading
291
+
292
+ - [docs/compare.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/compare.md): which tool for which question: agent-crashtest next to MCP Inspector, fault proxies, durable engines and related research.
293
+ - [docs/research.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/research.md): the experiments behind the tool, their results table and related work.
294
+ - [docs/development.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/development.md): running everything from a clone (Windows, Docker, Linux or macOS), the checks and the repository layout.
295
+ - [docs/contract.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/contract.md): what each verdict means. [docs/scenarios.md](https://github.com/munendra07-tech/agent-crashtest/blob/main/docs/scenarios.md): each scenario's ground truth and limits.
@@ -0,0 +1,44 @@
1
+ agent_crashtest-0.4.1.dist-info/licenses/LICENSE,sha256=2F3ulu9ngL0qCJH9qYEP7QGlXMy-mIIZf0IFvRsAq7E,1085
2
+ crashtest/__init__.py,sha256=R2sjbpRuzP_tzLTQyVPC2dm3V-oG8f7tq8Bxw9w6DdY,76
3
+ crashtest/checker.py,sha256=Jueim3F1cfAV1-zmtyazCtUZyDFhOWrz_hD1-yrhVNE,5326
4
+ crashtest/cli.py,sha256=AeMiCMr7fbXzrHlCyH7HgwUTbhBPKdAdv5t4Owt1umQ,28854
5
+ crashtest/control_token.py,sha256=kn88olT3j0US_Ps24ZEr7lw-sjGRlm3XkibneJLdqrE,2607
6
+ crashtest/controller.py,sha256=A3Xdxzg0ymZdFiaYh2tfc8Ay730nYh-t1P224ltwCDs,16625
7
+ crashtest/refund_run.py,sha256=eJp6ScnK1IbmNgQMbRudNVmFokYBRzi8SIkEK-CnADM,43559
8
+ crashtest/scenarios.py,sha256=SmmcwiBnuUfiCSpAAhQWZI2bqWnIS6gkmHKGH0tXO6E,16021
9
+ crashtest/examples/check_status_agent.py,sha256=uoeNlBIas2Tqvf3e7qXenWyaDAq0IdlTX9A3Gr-UdpI,3189
10
+ crashtest/examples/naive_retry_agent.py,sha256=iM87TvyPNI1qiLMjg5sJsbzmooVQ8in4RA6QCCXFeF4,2081
11
+ crashtest/examples/stable_key_agent.py,sha256=vKEswsExXPK-L6ILRWQxZaI5GJalPHDD1xkTIzw2qQg,2387
12
+ crashtest/experiment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ crashtest/experiment/crash_common.py,sha256=XPhPULqdK1EQZdo5jmCYjEZxAa3own6uVUHqhsZ7FHI,4012
14
+ crashtest/experiment/cut_points.py,sha256=hyvJ8ik2NSxvMIQtw9T3h47npNW92Me5hUn_pG2ENdM,12582
15
+ crashtest/experiment/dbos_crash.py,sha256=9nC7_DBjFkKEpSp01SyYjSkc-yQYwytyxTXrGOsY-hc,15889
16
+ crashtest/experiment/langgraph_crash.py,sha256=DMK9c7bGso4SlFY2wmkbAFGSYMl7dH_ov4VakWvO88o,15236
17
+ crashtest/experiment/local_stack.py,sha256=cOvPh-c-nYrnDyYSV8R9hhU9GpJ9a5OOrBHSWRRhFBk,10451
18
+ crashtest/experiment/model_retry.py,sha256=4ZiqCUNcnl9bOJthbwk48NOATPUOE_ytpgItkhEQW3c,26872
19
+ crashtest/experiment/model_retry_validate.py,sha256=Bx0NWnF4tAStHbUzCrbXLXGqqkB1VPjrsNhN7gi1Hss,23500
20
+ crashtest/experiment/resume.py,sha256=kdHbUuBD07oOkvwpQAvfHcR9UyktqhwN8fDS5E7uGec,11992
21
+ crashtest/experiment/run.py,sha256=6cSQ2lFMYIHaVmJy5hci2ZoQoP3taQexdc4pY7GrFpQ,12850
22
+ crashtest/experiment/single_call.py,sha256=UVNrdfqJiPSMb5RchwYjoyT9ISacXW7XjEA8LkDPnN8,16339
23
+ crashtest/experiment/trial.py,sha256=hD5NzvfZEkcX0416wt0Lx53hZ4zfdiQdmlPIV4U-QIY,14993
24
+ crashtest/faults/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
+ crashtest/faults/drop_proxy.py,sha256=uGEUgoHnWPAloYHXamHjHctzseaI-2EbZ0A4JIY6joE,19432
26
+ crashtest/refund_mcp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
+ crashtest/refund_mcp/event_store.py,sha256=P9OGCuBz8WJBQIRDOw8rXfn-O_cDZY6152iOuUa3ZP8,2406
28
+ crashtest/refund_mcp/server.py,sha256=ix-6GGVgYXnIFx-Dyz-dVeJLkD3sGBYjo19GzZc5vhE,8335
29
+ crashtest/results/__init__.py,sha256=rrUr03rC43eoXJ9A7Aezs7exLrOGMY8J3n2MQClMZN0,58
30
+ crashtest/results/__main__.py,sha256=r0cO8CHp1Y8yOvQWYfV42_YzaVKZKk_WnIR6JxUG0hg,2338
31
+ crashtest/results/report_check.py,sha256=NdJ7xEXfEIZoX_VpC95tTlQGgAOKtTzjXw9sBv6hbto,4533
32
+ crashtest/results/reverdict.py,sha256=JP6LQyRRasc-fKcul3oFIHajgkSJS5-2knsTBw1_zJ8,5580
33
+ crashtest/results/schema.sql,sha256=-BR6AOJvScvzW7NVxWE8UCpIjw6BysrBNOtJg597I2o,1656
34
+ crashtest/results/store.py,sha256=mbo0PHdGcFnpgzB1JgsYT9aw32ZHrnbJzqtgEznI4TY,7403
35
+ crashtest/results/table.py,sha256=Htv4XS65-tUVthvRFGTyLhroTqAoYCloxbLK0j5JFU8,12806
36
+ crashtest/sink/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
+ crashtest/sink/__main__.py,sha256=iCX9pX9mvQjLfLW09grP56mRNdnllnieyHehTGfgj04,1026
38
+ crashtest/sink/app.py,sha256=NseBv45Ll6Q5rblEmgJgkjlF5ULB-iuRtOLLGBZsYcA,8481
39
+ crashtest/sink/schema.sql,sha256=lzElnE5szB_UJoYDl9xdA0lsXoPZCWFsm-xb474uM58,2419
40
+ agent_crashtest-0.4.1.dist-info/METADATA,sha256=zfXqn-jDKFH2kOv-mw202vkbDQoixgklSeIQ694RI7M,28731
41
+ agent_crashtest-0.4.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
42
+ agent_crashtest-0.4.1.dist-info/entry_points.txt,sha256=u49u93Wdh44jYuSlBYsTWWsyggSWvGK7Z0CrFWKr_vM,49
43
+ agent_crashtest-0.4.1.dist-info/top_level.txt,sha256=QVtSw5zp90zstvUL5Rp1F2XZmnigCryQv4mrEvo8vpI,10
44
+ agent_crashtest-0.4.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ crashtest = crashtest.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 agent-crashtest contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ crashtest
crashtest/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """agent-crashtest: crash-consistency testbench for AI-agent tool calls."""
crashtest/checker.py ADDED
@@ -0,0 +1,137 @@
1
+ """The one place a verdict is decided. Every runner calls `classify`.
2
+
3
+ The verdicts and their meanings are defined in docs/contract.md, section 3
4
+ (contract version 0.4). The effect count and the effect payloads come from the
5
+ sink. The subject's own account of what happened is used only to tell the
6
+ non-duplicate cases apart; it can never turn a duplicate into anything else.
7
+
8
+ Beside the verdict, `report_matches_sink` records whether what the subject told
9
+ its caller about the effect agrees with the sink (contract v0.3, property RA).
10
+ It is a recorded field, not a verdict, and never changes one.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from collections.abc import Iterable, Mapping
16
+ from typing import Any, Literal
17
+
18
+ Verdict = Literal[
19
+ "correct",
20
+ "duplicate",
21
+ "lost",
22
+ "wrong_payload",
23
+ "unconfirmed_success",
24
+ "in_doubt_surfaced",
25
+ "stuck",
26
+ ]
27
+
28
+ # How the subject's run ended, as the subject itself reported it.
29
+ # completed it reported the operation as done
30
+ # unknown it stopped and reported that it does not know whether the effect
31
+ # happened (a timeout or a dropped connection, surfaced to the caller)
32
+ # failed it stopped with a definite error, hung, or could not resume
33
+ SubjectStatus = Literal["completed", "unknown", "failed"]
34
+
35
+ # What the subject told its caller about the effect (contract v0.3, section 3).
36
+ # done the effect was made, once
37
+ # unknown it does not know whether the effect was made
38
+ # not_done the effect was not made (a definite failure)
39
+ # none it told its caller nothing about the effect (it hung, crashed,
40
+ # or said something that is none of the above)
41
+ Report = Literal["done", "unknown", "not_done", "none"]
42
+
43
+ # For runners whose subject reports through its status alone (001 to 003): a
44
+ # success, an ambiguous error, or a definite one reached the caller.
45
+ REPORT_OF_STATUS: dict[SubjectStatus, Report] = {
46
+ "completed": "done",
47
+ "unknown": "unknown",
48
+ "failed": "not_done",
49
+ }
50
+
51
+ VERDICTS: tuple[Verdict, ...] = (
52
+ "correct",
53
+ "duplicate",
54
+ "lost",
55
+ "wrong_payload",
56
+ "unconfirmed_success",
57
+ "in_doubt_surfaced",
58
+ "stuck",
59
+ )
60
+
61
+
62
+ def classify(
63
+ *,
64
+ effects: int,
65
+ intended: int,
66
+ status: SubjectStatus,
67
+ payload_matches: bool,
68
+ confirmed: bool,
69
+ ) -> Verdict:
70
+ """Return the verdict for one trial.
71
+
72
+ effects refunds the sink committed for the operation
73
+ intended refunds the operation should have produced
74
+ status how the subject reported its run ended
75
+ payload_matches every committed refund carries the intended payload, checked
76
+ against the sink's own rows (see `payload_matches` below)
77
+ confirmed when the subject reported completion, it had received a
78
+ success result for the operation: directly, as a replay of
79
+ the stored result, or by looking the effect up. A success
80
+ reported without one is a guess, even when it happens to be right.
81
+
82
+ Order of precedence:
83
+ 1. More effects than intended is `duplicate`, whatever the subject said.
84
+ 2. A subject that reported completion is, in this order: `lost` if there
85
+ are fewer effects than intended; `wrong_payload` if an effect does not
86
+ carry the intended payload; `unconfirmed_success` if it never received a
87
+ success result; otherwise `correct`.
88
+ 3. A subject that stopped and said it does not know is `in_doubt_surfaced`.
89
+ 4. Anything else did not finish, or reported a definite failure: `stuck`.
90
+ """
91
+ if effects < 0 or intended < 0:
92
+ raise ValueError("effect counts cannot be negative")
93
+ if effects > intended:
94
+ return "duplicate"
95
+ if status == "completed":
96
+ if effects < intended:
97
+ return "lost"
98
+ if not payload_matches:
99
+ return "wrong_payload"
100
+ if not confirmed:
101
+ return "unconfirmed_success"
102
+ return "correct"
103
+ if status == "unknown":
104
+ return "in_doubt_surfaced"
105
+ return "stuck"
106
+
107
+
108
+ def payload_matches(
109
+ refunds: Iterable[Mapping[str, Any]], *, order_id: str, amount_cents: int
110
+ ) -> bool:
111
+ """Whether every refund the sink committed carries the intended order and amount.
112
+
113
+ `refunds` are the sink's rows for the operation (`GET /refunds`). With no rows
114
+ there is nothing to mismatch; the count rules decide those cases.
115
+ """
116
+ return all(
117
+ r.get("amount_cents") == amount_cents and r.get("order_id", order_id) == order_id
118
+ for r in refunds
119
+ )
120
+
121
+
122
+ def report_matches_sink(*, effects: int, intended: int, report: Report) -> bool:
123
+ """Whether what the subject told its caller about the effect agrees with the sink.
124
+
125
+ A recorded field beside the verdict (contract v0.3, property RA), not a
126
+ verdict: it never changes one. False when the subject said the effect was
127
+ done and the sink holds another number of effects (two refunds reported as
128
+ one), or said it was not done and the sink holds one. An unknown outcome,
129
+ or no report at all, contradicts nothing.
130
+ """
131
+ if effects < 0 or intended < 0:
132
+ raise ValueError("effect counts cannot be negative")
133
+ if report == "done":
134
+ return effects == intended
135
+ if report == "not_done":
136
+ return effects == 0
137
+ return True