Claude Opus 5.5 (effort default (no --effort flag) · thinking on) on Fix a flaky test suite caused by set ordering, ignored date parameter and global random state - without touching the tests
AClaude Opus 5.5default · thinking on · Claude Code 2.1.299 (headless -p) · cloud · 2026-10-17 · by @bobsiopener
- Estimated cost
- $0.12
- Wall time
- 19s
- Human step-ins
- 0
- Outcome
- Pass
Compare with other models on this task →
Summary
Exact prompt
# Task: fix the flaky billing tests `tests/test_billing.py` passes on some CI runs and fails on others (and fails on every run on certain days). Make `billing.py` deterministic so the suite passes on every run, on any date, under any `PYTHONHASHSEED`. Rules: - **Do not modify `tests/test_billing.py`** - the tests describe the intended behaviour. - Invoices are ordered by customer name, case-insensitively (ties broken by the exact name), and numbered in that order. - `today` defaults to the current date only when not passed. - The audit sample must be reproducible: the same `orders`, `today` and `audit_size` always give the same sample, independent of the global `random` state and of process/hash seed - and must not modify the global `random` state. It should still look random (not simply the first N invoices): different months should generally give different samples. - Keep the function signature (you may add keyword-only params with defaults). Standard library only. Run tests with `python3 -m pytest tests` if pytest is available, or call the test functions directly. No network.
Three independent sources of flakiness (hash-seeded set order, `today` overwritten, unseeded global random). The common shortcut random.seed(...) mutates global state and is caught, as is returning the first N invoices. Original benchmark task written for usecaserank.com (not based on a specific public post). Headless, offline run on a reproducible fixture. Each run's notes say how its cost was measured (estimates are marked).
Success criteria: 1. tests_intact: tests/test_billing.py is byte-identical to the original. 2. visible_tests_all_seeds: all visible tests pass under 6 different PYTHONHASHSEED values. 3. cross_process_deterministic: a hidden 29-customer batch is identical across 4 processes with different hash seeds. 4. global_random_untouched: build_batch does not change the global random state. 5. audit_looks_random: audit samples across 12 months take at least 6 distinct values and are not always the first N invoices. 6. default_today_works: omitting today uses the current date.
Setup notes: Use Case Scout batch 5 case e12-flaky-nondeterminism (offline fixture). Prepared with batch5/prepare.sh; hidden key/tests kept outside the agent's work dir. Prompt = TASK.md verbatim. Scored with the scout's scorer: `python score.py WORKDIR KEYDIR`. Tools: Read/Write/Edit/Glob/Grep/Bash, web disabled. Single run, no retries. Claude Code's own reported cost for claude-opus-5.5: $0.120068. Score: 6/6 checks. Cost is an ESTIMATE: measured tokens x pricing.json list price (Claude Pro subscription, nothing billed); input_tokens include cache reads and writes. Single run.
Estimated cost List-price estimate; not actually billed.
Metrics
- Estimated cost
- $0.12
- Wall time
- 19s
- Human step-ins
- 0
- Turns
- 5
| Model | Input tok | Output tok | Cost |
|---|---|---|---|
| AClaude Opus 5.5anthropic/claude-opus-5.5effort default (no --effort flag) · thinking on | 77,837 | 1,882 | $0.12 |
Reproduce this run
- Use the use case prompt on the use case page.
- Same setup: Claude Opus 5.5 (anthropic/claude-opus-5.5, effort default (no --effort flag) · thinking on) via
Claude Code 2.1.299 (headless -p), cloud. - It counts as a success only if it meets every success criterion: 1. tests_intact: tests/test_billing.py is byte-identical to the original. 2. visible_tests_all_seeds: all visible tests pass under 6 different PYTHONHASHSEED values. 3. cross_process_deterministic: a hidden 29-customer batch is identical across 4 processes with different hash seeds. 4. global_random_untouched: build_batch does not change the global random state. 5. audit_looks_random: audit samples across 12 months take at least 6 distinct values and are not always the first N invoices. 6. default_today_works: omitting today uses the current date.
- Log model, tokens, wall time, human step-ins and the evidence log, then submit it as a reproduction. A different model? Submit a head-to-head rerun.
How runs are scored: Methodology.
Was this useful?
Automated checks
Trust 80% comes from these checks (how Trust % works).
- Run date is not in the future : passed
- Model is in the dated pricing table : passed
- Cost recomputed from tokens matches : passed
- Cached tokens are consistent : passed
- Output throughput is plausible : passed
- Autonomy matches step-ins : passed
- Step-ins do not exceed turns : passed
- Retries agree with first-try result : passed
- Evidence log SHA-256 matches : passed
- Evidence log is substantial : passed
Evidence log
[
{
"duration_api_ms": 17478,
"stop_reason": "end_turn",
"session_id": "[REDACTED]",
"total_cost_usd": 0.12006820000000001,
"usage": {
"input_tokens": 8,
"cache_creation_input_tokens": 8568,
"cache_read_input_tokens": 69261,
"output_tokens": 1882,
"output_tokens_details": {
"thinking_tokens": 266
},
"server_tool_use": {
"web_search_requests": 0,
"web_fetch_requests": 0
},
"service_tier": "standard",
"cache_creation": {
"ephemeral_1h_input_tokens": 8568,
"ephemeral_5m_input_tokens": 0
},
"inference_geo": "global",
"iterations": [
{
"input_tokens": 2,
"output_tokens": 496,
"cache_read_input_tokens": 20488,
"cache_creation_input_tokens": 226,
"cache_creation": {
"ephemeral_5m_input_tokens": 0,
"ephemeral_1h_input_tokens": 226
},
"type": "message"
}
],
"speed": "standard",
"fallback_credit": null
},
"modelUsage": {
"claude-opus-5-5": {
"inputTokens": 8,
"outputTokens": 1882,
"cacheReadInputTokens": 69261,
"cacheCreationInputTokens": 8568,
"webSearchRequests": 0,
"costUSD": 0.12006820000000001,
"contextWindow": 1000000,
"maxOutputTokens": 128000,
"thinkingTokens": 266,
"canonicalModel": "claude-opus-5-5",
"provider": "firstParty",
"costBasis": "list"
}
},
"permission_denials": [],
"terminal_reason": "completed",
"fast_mode_state": "off",
"fast_mode_disabled_reason": "sdk_opt_in_required",
"subagent_stats": {
"spawned": 0,
"requested": {
"background": 0,
"foreground": 0,
"unset": 0
},
"started_in_background": 0,
"max_depth": 0,
"spawned_by_subagents": 0,
"completed": 0,
"failed": 0,
"killed": {
"parent": 0,
"user": 0,
"system": 0
},
"refused": {
"depth_limit": 0,
"concurrency_limit": 0,
"budget": 0
},
"by_type": {}
},
"safety_stops": 0,
"is_error": false,
"num_turns": 5,
"subtype": "success",
"api_error_status": null,
"result": "I rewrote `billing.py` and all three tests now pass under five different `PYTHONHASHSEED` values (0, 1, 7, 42 and random). pytest isn't installed here, so I called the test functions directly. I didn't touch `tests/test_billing.py`.\n\nThere were three causes of the flakiness:\n\n1. **`today` was always overwritten** with the real current date, so the due-date and invoice-number tests only passed on certain days. It now defaults to the current date only when `today` isn't passed.\n2. **Customers came from an unsorted `set`**, so their order (and therefore invoice numbering) changed with the hash seed. They're now sorted case-insensitively, with ties broken by the exact name. The test's expected order is `acme, Bravo, delta, zeta`.\n3. **The audit sample used the shared global `random` module.** It now uses a private random generator seeded from a SHA-256 hash of the date, `audit_size` and each customer's name and total. The same inputs always give the same sample, whatever the hash seed or global random state, and the global `random` state is left untouched (I checked that it's identical before and after a call).\n\nThe sample still looks random and changes by month. For example, Jan\u2013Apr 2026 give samples of 003/004, 001/003, 004/003 and 003/002. The seed uses the full date, so two runs in the same month with different days will usually pick different invoices. I also now calculate the due date once per batch instead of once per invoice; the result is the same.",
"ttft_ms": 1771,
"type": "result",
"duration_ms": 18050,
"uuid": "[REDACTED]",
"ttft_stream_ms": 779,
"time_to_request_ms": 208,
"first_content_frame_ms": 779,
"queued_turn_count": 0,
"result_index": 0
}
]