todo-50.1-metric-key-migration-dedup.md 1.2 KB

Todo 50.1 Metric Key Migration Dedup Plan

Status: done

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

Observe / Update

  • Migration retains MIN(id) for each duplicate non-null (session_id, metric_key) and preserves all legacy NULL keys.
  • Cleanup and unique-index creation run inside the serialized BEGIN IMMEDIATE migration.
  • SQLite focused tests passed (12 passed), concurrent initialization passed 20 repeated runs, and the full suite passed (405 passed).