# Local coding task card: a synthetic backoff arithmetic bug

**Status: not_run.** This is a fictional teaching fixture, not a production retry library or a measured coding-model benchmark. Candidate patches and test results are unobserved. No request, sleep, scheduler, model call, or retry loop is implemented.

## Contract and scope

- Inputs under evaluation are the finite cases listed below; unspecified types and very large attempts are outside this exercise.
- Preserve calculate_backoff(attempt, base_delay=1.0, max_delay=30.0, factor=2.0).
- Attempt 1/defaults =>1.0; attempt 2/defaults =>2.0; attempt 10/defaults =>30.0.
- Attempt 3/base 0.5/max 10.0/factor 3.0 =>4.5.
- Attempts 0 and −1 raise ValueError.
- Propose a change only to retry.py; do not alter the tests, add dependencies, execute commands, or commit.
- Those instructions express the task; actual client/tool permissions must enforce the desired access separately.

## Fictional implementation: retry.py

```python
def calculate_backoff(
    attempt: int,
    base_delay: float = 1.0,
    max_delay: float = 30.0,
    factor: float = 2.0,
) -> float:
    if attempt < 1:
        raise ValueError("Attempt must be >= 1")
    # Intentional arithmetic defect for this teaching exercise.
    delay = base_delay * (factor ** attempt)
    return min(delay, max_delay)
```

## Standard-library test fixture: tests/test_retry.py

```python
import unittest
from retry import calculate_backoff


class BackoffContractTests(unittest.TestCase):
    def test_first_attempt(self):
        self.assertEqual(calculate_backoff(1), 1.0)

    def test_second_attempt(self):
        self.assertEqual(calculate_backoff(2), 2.0)

    def test_cap(self):
        self.assertEqual(calculate_backoff(10), 30.0)

    def test_custom_parameters(self):
        self.assertEqual(
            calculate_backoff(3, base_delay=0.5, max_delay=10.0, factor=3.0),
            4.5,
        )

    def test_zero_attempt(self):
        with self.assertRaises(ValueError):
            calculate_backoff(0)

    def test_negative_attempt(self):
        with self.assertRaises(ValueError):
            calculate_backoff(-1)
```

## Prompt for the assistant

```text
Investigate the first-attempt backoff calculation in the supplied fixture.
Explain the defect, then propose a minimal patch to retry.py.
Preserve the function signature and invalid-attempt behavior.
Satisfy the six supplied tests without changing them.
Do not add dependencies, run commands, edit files, or commit.
If another file or contract is required, identify it first.
```

## Reader workflow

1. Put only this synthetic fixture in an isolated exercise directory or task repository; preserve unrelated work.
2. Choose the documented ask/planning workflow available in the client. A prompt alone is not a permissions boundary.
3. Inspect the proposed patch and scope before choosing whether to apply it.
4. From the exercise root, run `python3 -m unittest discover -s tests` yourself.
5. Record actual test output, exit status, diff and dependency changes in the scorecard. No passing result is assumed here.

## Observation record

- Client/runtime versions and actual model identity:
- Effective context and client mode:
- Proposed patch:
- Actual test command/result: not_run
- Scope/dependency review: not_run
- Decision and remaining limits:

Production retry design needs separate requirements for idempotency, errors, jitter, limits, cancellation and safe scheduling. This arithmetic fixture does not establish any of those behaviors.
