Skip to content

Claude Haiku 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 Haiku 5.5default · thinking on · Claude Code 2.1.299 (headless -p) · cloud · 2026-10-17 · by @bobsiopener

Trust 80%Fully autonomoussuccess · first try
Estimated cost
$0.0050
Wall time
20s
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-haiku-5.5: $0.004983. 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.0050
Wall time
20s
Human step-ins
0
Turns
5
Model usage
ModelInput tokOutput tokCost
AClaude Haiku 5.5anthropic/claude-haiku-5.5effort default (no --effort flag) · thinking on107,2743,599$0.0050

Reproduce this run

  1. Use the use case prompt on the use case page.
  2. Same setup: Claude Haiku 5.5 (anthropic/claude-haiku-5.5, effort default (no --effort flag) · thinking on) via Claude Code 2.1.299 (headless -p), cloud.
  3. 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.
  4. 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?

⇄ Rerun on another model

Automated checks

Trust 80% comes from these checks (how Trust % works).

Evidence log
[
 {
  "duration_api_ms": 19259,
  "stop_reason": "end_turn",
  "session_id": "[REDACTED]",
  "total_cost_usd": 0.004982520000000001,
  "usage": {
   "input_tokens": 10,
   "cache_creation_input_tokens": 11102,
   "cache_read_input_tokens": 96162,
   "output_tokens": 3599,
   "output_tokens_details": {
    "thinking_tokens": 1350
   },
   "server_tool_use": {
    "web_search_requests": 0,
    "web_fetch_requests": 0
   },
   "service_tier": "standard",
   "cache_creation": {
    "ephemeral_1h_input_tokens": 11102,
    "ephemeral_5m_input_tokens": 0
   },
   "inference_geo": "global",
   "iterations": [
    {
     "input_tokens": 2,
     "output_tokens": 696,
     "cache_read_input_tokens": 22672,
     "cache_creation_input_tokens": 969,
     "cache_creation": {
      "ephemeral_5m_input_tokens": 0,
      "ephemeral_1h_input_tokens": 969
     },
     "type": "message"
    }
   ],
   "speed": "standard",
   "fallback_credit": null
  },
  "modelUsage": {
   "claude-haiku-5-5": {
    "inputTokens": 10,
    "outputTokens": 3599,
    "cacheReadInputTokens": 96162,
    "cacheCreationInputTokens": 11102,
    "webSearchRequests": 0,
    "costUSD": 0.004982520000000001,
    "contextWindow": 1000000,
    "maxOutputTokens": 128000,
    "thinkingTokens": 1350,
    "canonicalModel": "claude-haiku-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": "`billing.py` is now deterministic. All three test functions pass under `PYTHONHASHSEED` 0, 1, 2, 42 and 999. I did not modify `tests/test_billing.py`.\n\nThere were three causes of the flakiness:\n\n- **`today` was always overwritten** with `datetime.date.today()`, so any test passing a fixed date failed on every day that wasn't that date. It now defaults only when `None` is passed.\n- **Invoice numbering came from iterating a `set`**, whose order depends on the hash seed. Customers are now sorted by `(name.casefold(), name)`, so the order is case-insensitive with exact-name tie-breaking, and numbering follows that order.\n- **The audit used the global `random.sample`**, so results depended on global state. It now uses a private `random.Random` seeded from a SHA-256 digest of the batch's date, `audit_size`, and the invoice contents. The digest is stable across processes and hash seeds, and the global RNG is never touched.\n\nI also made a few small changes:\n\n- Totals are accumulated in a single pass over `orders`, not one scan per customer.\n- Due dates are computed once rather than per invoice.\n- The signature is unchanged.\n\n**Checks I ran:**\n- pytest isn't installed here, so I called the three test functions directly.\n- Global `random` state is unchanged after calling `build_batch`.\n- Across the 12 months of 2026 with 30 customers and `audit_size=5`, all 12 samples differ, and they are not just the first N invoices.\n- `audit_size` larger than the number of invoices is clamped.\n- Mixed-case names sort as `_x, A, a, B, b`.\n\nThis directory is not a git repository, so I did not commit anything.",
  "ttft_ms": 2345,
  "type": "result",
  "duration_ms": 19744,
  "uuid": "[REDACTED]",
  "ttft_stream_ms": 877,
  "time_to_request_ms": 206,
  "first_content_frame_ms": 877,
  "queued_turn_count": 0,
  "result_index": 0
 }
]

Get new runs and ranking changes weekly