# Todo 50.1 Metric Key Migration Dedup Plan **Status:** in_progress ## Goal Allow additive metrics migration to open an experimental database that already contains duplicate non-null metric keys. ## Scope - Before creating `usage_stats_metric_key_uq`, delete duplicate rows for the same `(session_id, metric_key)` while retaining the earliest row by `id`. - Never deduplicate `NULL` metric keys used by legacy usage rows. - Keep cleanup and unique-index creation inside the serialized migration transaction. - Cover concurrent store initialization after duplicate cleanup. ## Files - Modify: `src/agent_lab/infrastructure/sqlite_store.py` - Modify: `tests/test_sqlite_store.py` ## Verification - `uv run pytest tests/test_sqlite_store.py -q` - repeat concurrent migration test - `uv run pytest` - `git diff --check`