[{"task_id":"syntax-fix-easy","title":"Fix a syntax-broken username normalizer","difficulty":"easy","task_kind":"syntax_fix","task_description":"You are reviewing a utility function before merge. The submitted patch left the function with syntax errors. Repair the code so it compiles and preserves the intended behavior of trimming, lowercasing, and replacing spaces with underscores.","starter_code":"def normalize_username(raw_name: str) -> str:\n    cleaned = raw_name.strip().lower(\n    if not cleaned:\n        return \"anonymous\"\n    return cleaned.replace(\" \", \"_\")\n","visible_tests":["normalize_username('  Alice Smith  ') == 'alice_smith'","normalize_username('   ') == 'anonymous'","normalize_username('Bob') == 'bob'"],"goal":"","repo_summary":"","changed_files":[],"available_files":[],"max_steps":8},{"task_id":"bug-fix-medium","title":"Repair invoice discount calculation logic","difficulty":"medium","task_kind":"bug_fix","task_description":"A billing helper function is returning the wrong amount after applying discounts. The function signature is correct, but the calculation logic is broken. Inspect the implementation, run visible tests, and fix the bug so all tests pass. Do not change the function signature or validation logic.","starter_code":"from typing import Iterable\n\n\ndef calculate_invoice_total(line_items: Iterable[int], discount_percent: int) -> int:\n    \"\"\"Calculate invoice total with discount applied.\n    \n    Args:\n        line_items: List of item prices in cents.\n        discount_percent: Discount as integer 0-100.\n        \n    Returns:\n        Final invoice total in cents after discount.\n        \n    Raises:\n        ValueError: If discount_percent is outside 0-100 range.\n    \"\"\"\n    if discount_percent < 0 or discount_percent > 100:\n        raise ValueError(\"discount_percent must be between 0 and 100\")\n\n    subtotal = sum(line_items)\n    discounted_total = subtotal - (subtotal * discount_percent // 100)\n    return subtotal  # BUG: returning subtotal instead of discounted_total\n","visible_tests":["calculate_invoice_total([1000, 2000], 0) == 3000","calculate_invoice_total([1000, 2000], 50) == 1500","calculate_invoice_total([1000], 10) == 900","calculate_invoice_total([], 0) == 0"],"goal":"","repo_summary":"","changed_files":[],"available_files":[],"max_steps":10},{"task_id":"optimization-hard","title":"Optimize inefficient user activity summarization","difficulty":"hard","task_kind":"optimization","task_description":"Code review found that `summarize_user_activity` is inefficient for large event streams. The current implementation repeatedly scans the full event list for every user, making it O(n**2). Refactor it to aggregate counts in one pass while preserving the sorted output contract. Style and code quality also matter: use idiomatic Python, proper types, and clear logic. All tests must pass, and the optimized version should be measurably faster.","starter_code":"from typing import Iterable\n\n\ndef summarize_user_activity(events: Iterable[dict]) -> list[tuple[str, int]]:\n    \"\"\"Aggregate user activity counts.\"\"\"\n\n    ordered_users = []\n    for event in events:\n        user_id = event[\"user_id\"]\n        if user_id not in ordered_users:\n            ordered_users.append(user_id)\n\n    summary = []\n    for user_id in ordered_users:\n        count = 0\n        for event in events:\n            if event[\"user_id\"] == user_id:\n                count += 1\n        summary.append((user_id, count))\n    return sorted(summary, key=lambda item: (-item[1], item[0]))\n","visible_tests":["summarize_user_activity([{'user_id': 'alice'}, {'user_id': 'bob'}, {'user_id': 'alice'}]) == [('alice', 2), ('bob', 1)]","summarize_user_activity([{'user_id': 'z'}, {'user_id': 'a'}]) == [('a', 1), ('z', 1)]","summarize_user_activity([]) == []","summarize_user_activity([{'user_id': 'solo'}]) == [('solo', 1)]"],"goal":"","repo_summary":"","changed_files":[],"available_files":[],"max_steps":10}]