Преглед изворни кода

docs: plan metric key migration dedup

Problem: Todo 50 review reproduced database-open failure when pre-index experiment rows contain duplicate metric keys.

Risk: Cleanup must retain one deterministic row and must not collapse legacy NULL keys.
zhenyu.hu пре 2 недеља
родитељ
комит
44256c611f
2 измењених фајлова са 27 додато и 0 уклоњено
  1. 26 0
      docs/plans/todo-50.1-metric-key-migration-dedup.md
  2. 1 0
      docs/plans/todos.md

+ 26 - 0
docs/plans/todo-50.1-metric-key-migration-dedup.md

@@ -0,0 +1,26 @@
+# 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`

+ 1 - 0
docs/plans/todos.md

@@ -97,4 +97,5 @@
 | 49.2 | done | `docs/plans/todo-49.2-session-load-race-and-visible-repair.md` | Prevent stale session loads from overwriting the selected session and preserve visible text while stripping incomplete tool protocol. | Out-of-order loads cannot mutate the active session UI; whitespace-only protocol bubbles stay hidden; incomplete tool rounds retain provider-valid visible content. |
 | 49.3 | done | `docs/plans/todo-49.3-stale-replay-token-order.md` | Prevent a stale replay invocation from invalidating an already-running replay for the current session. | A late stale invocation exits before advancing the replay token; the current session still restores normally. |
 | 50 | in_progress | `docs/plans/todo-50-comparable-model-tool-metrics.md` | Record mode-aware model/tool spans and include EventAgent usage so both architectures can be compared fairly. | Persistence/API tests report agent, call kind, tokens, TTFT, tool latency, fallback usage, and total turn wall time without double counting. |
+| 50.1 | in_progress | `docs/plans/todo-50.1-metric-key-migration-dedup.md` | Deduplicate legacy metric keys before creating the idempotency index so existing experiment databases remain openable. | Migration keeps the earliest row for each duplicate non-null session/metric key, creates the unique index, and remains safe under concurrent initialization. |
 | 51 | pending | `docs/plans/todo-51-comparison-matrix-closeout.md` | Add repeatable comparison fixtures, update project documentation, and close the experimental implementation. | Both modes pass the same scenario matrix; full tests, JS syntax, app import, and documentation checks pass. |