Skip to content

Claude Sonnet 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 Sonnet 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.05
Wall time
12s
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-sonnet-5.5: $0.053583. 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.05
Wall time
12s
Human step-ins
0
Turns
5
Model usage
ModelInput tokOutput tokCost
AClaude Sonnet 5.5anthropic/claude-sonnet-5.5effort default (no --effort flag) · thinking on78,3111,486$0.05

Reproduce this run

  1. Use the use case prompt on the use case page.
  2. Same setup: Claude Sonnet 5.5 (anthropic/claude-sonnet-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": 11275,
  "stop_reason": "end_turn",
  "session_id": "[REDACTED]",
  "total_cost_usd": 0.053582599999999994,
  "usage": {
   "input_tokens": 8,
   "cache_creation_input_tokens": 7917,
   "cache_read_input_tokens": 70386,
   "output_tokens": 1486,
   "output_tokens_details": {
    "thinking_tokens": 133
   },
   "server_tool_use": {
    "web_search_requests": 0,
    "web_fetch_requests": 0
   },
   "service_tier": "standard",
   "cache_creation": {
    "ephemeral_1h_input_tokens": 7917,
    "ephemeral_5m_input_tokens": 0
   },
   "inference_geo": "global",
   "iterations": [
    {
     "input_tokens": 2,
     "output_tokens": 410,
     "cache_read_input_tokens": 20247,
     "cache_creation_input_tokens": 209,
     "cache_creation": {
      "ephemeral_5m_input_tokens": 0,
      "ephemeral_1h_input_tokens": 209
     },
     "type": "message"
    }
   ],
   "speed": "standard",
   "fallback_credit": null
  },
  "modelUsage": {
   "claude-sonnet-5-5": {
    "inputTokens": 8,
    "outputTokens": 1486,
    "cacheReadInputTokens": 70386,
    "cacheCreationInputTokens": 7917,
    "webSearchRequests": 0,
    "costUSD": 0.053582599999999994,
    "contextWindow": 1000000,
    "maxOutputTokens": 128000,
    "thinkingTokens": 133,
    "canonicalModel": "claude-sonnet-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` so it no longer depends on the clock, the hash seed or the global `random` state. pytest isn't installed here, so I called the three test functions directly under `PYTHONHASHSEED` 0, 1 and 2. All passed each time. I didn't test other dates or confirm that different months give different samples.\n\nWhat was causing the flakiness:\n- **Ignored `today`:** the function overwrote the argument with `date.today()`. That is why the due-date test failed on certain days. It now uses the current date only when `today` isn't passed.\n- **Unordered customers:** customers were iterated from a `set`, so invoice order and numbering changed with the hash seed. They are now sorted case-insensitively, with ties broken by the exact name, and numbered in that order.\n- **Global random state:** the audit sample came from the global `random`. It now comes from a private `random.Random` seeded with a SHA-256 hash of the date, `audit_size` and the invoice customers and totals. The same inputs always give the same sample, the global state is left untouched, and the sample still looks random.\n\nThe seed uses the full date rather than just the month, so two runs in the same month on different days can pick different samples. I left `tests/test_billing.py` and the function signature unchanged.",
  "ttft_ms": 1282,
  "type": "result",
  "duration_ms": 11685,
  "uuid": "[REDACTED]",
  "ttft_stream_ms": 956,
  "time_to_request_ms": 214,
  "first_content_frame_ms": 957,
  "queued_turn_count": 0,
  "result_index": 0
 }
]

Get new runs and ranking changes weekly