# Plan: Phase 1 — Auto-Delete+Rewrite Guard

**Requirements:** GARD-01, GARD-02, GARD-03

## Tasks

### Task 1: Change overlap_strategy in_write_bars_batch_to_clickhouse()

**File:** `python/opendeviationbar/sidecar.py`

**Change 1 (line 169):**

```python
# Before:
overlap_strategy="off",  # Issue #158: no pre-write check (L1 lock + L2 dedup handle concurrent writes)

# After:
overlap_strategy="replace",  # Issue #300: auto-delete+rewrite guard — atomic DELETE+INSERT for overlapping trade-ID ranges
```

**Change 2 (line 178):**

```python
# Before:
overlap_strategy="off",  # Issue #158: no pre-write check (L1 lock + L2 dedup handle concurrent writes)

# After:
overlap_strategy="replace",  # Issue #300: auto-delete+rewrite guard — atomic DELETE+INSERT for overlapping trade-ID ranges
```

### Task 2: Verify existing tests pass

```bash
mise run test-py -k sidecar
```

No test changes expected — `store_bars_batch(overlap_strategy="replace")` routes to `store_bars_replacing()` which is a superset of the `"off"` path. The only difference is a lightweight DELETE query before INSERT.

## Verification

1. Both calls to `store_bars_batch()` in `_write_bars_batch_to_clickhouse()` pass `overlap_strategy="replace"`
2. All existing tests pass
3. Code review: `store_bars_replacing()` in `maintenance.py:266` does atomic DELETE+INSERT — confirmed safe

## Commit

```
fix: sidecar overlap_strategy "off" → "replace" (auto-delete+rewrite guard)

Every sidecar batch write now atomically deletes overlapping bars by
trade-ID range before inserting. Prevents silent overlap accumulation
from deploy mistakes or concurrent writer races. Cost: ~5ms per batch.

Closes #300.
```
