- Replay models: StepType enum, ReplayStep, ReplayPage frozen dataclasses
- Checkpoint transformer: PostgresSaver JSONB -> structured timeline steps
- Replay API: GET /api/conversations (paginated), GET /api/replay/{thread_id}
- Analytics models: AgentUsage, InterruptStats, AnalyticsResult
- Analytics event recorder: Protocol + PostgresAnalyticsRecorder + NoOp
- Analytics queries: resolution_rate, agent_usage, escalation_rate, cost, interrupts
- Analytics API: GET /api/analytics?range=Xd with envelope response
- DB migration: analytics_events table + conversations column additions
- 74 new tests, 399 total passing, 92.87% coverage
3.5 KiB
3.5 KiB
Phase 4: Conversation Replay + Analytics -- Development Log
Status: COMPLETED Phase branch:
phase-4/analytics-replayDate started: 2026-03-31 Date completed: 2026-03-31 Related plan section: Phase 4 in DEVELOPMENT-PLAN
What Was Built
- Replay data models (StepType enum, ReplayStep, ReplayPage frozen dataclasses)
- Checkpoint transformer converting PostgresSaver JSONB to structured timeline steps
- Replay API: GET /api/conversations (paginated list), GET /api/replay/{thread_id} (paginated timeline)
- Analytics data models (AgentUsage, InterruptStats, AnalyticsResult)
- Analytics event recorder with Protocol interface (PostgresAnalyticsRecorder + NoOpAnalyticsRecorder)
- Analytics queries: resolution_rate, agent_usage, escalation_rate, cost_per_conversation, interrupt_stats
- Analytics API: GET /api/analytics?range=Xd with envelope response
- DB migration: analytics_events table + conversations column additions (resolution_type, agents_used, turn_count, ended_at)
Code Structure
New files created:
| File | Purpose | Lines |
|---|---|---|
app/replay/__init__.py |
Module entry | 2 |
app/replay/models.py |
StepType enum, ReplayStep, ReplayPage | ~80 |
app/replay/transformer.py |
Checkpoint JSONB -> ReplayStep[] | ~120 |
app/replay/api.py |
FastAPI router /api/replay + /api/conversations | ~80 |
app/analytics/__init__.py |
Module entry | 2 |
app/analytics/models.py |
AgentUsage, InterruptStats, AnalyticsResult | ~55 |
app/analytics/event_recorder.py |
AnalyticsRecorder Protocol + implementations | ~40 |
app/analytics/queries.py |
SQL query functions + get_analytics aggregator | ~130 |
app/analytics/api.py |
FastAPI router /api/analytics | ~50 |
Modified files:
app/db.py-- Added analytics_events DDL + conversations migrationapp/main.py-- Wired replay + analytics routers, registered NoOpAnalyticsRecorder
Test files (74 new tests):
tests/unit/replay/test_models.pytests/unit/replay/test_transformer.pytests/unit/replay/test_api.pytests/unit/analytics/test_models.pytests/unit/analytics/test_event_recorder.pytests/unit/analytics/test_queries.pytests/unit/analytics/test_api.pytests/unit/test_db_phase4.py
Test Coverage
- 399 total tests passing (74 new + 325 existing)
- Overall coverage: 92.87% (requirement: 80%)
Per-module coverage:
- replay/models.py: 100%
- replay/transformer.py: 82%
- replay/api.py: 100%
- analytics/models.py: 100%
- analytics/event_recorder.py: 100%
- analytics/queries.py: 81%
- analytics/api.py: 100%
Deviations from Plan
- Frontend UI deferred: React pages (ReplayListPage, ReplayPage, DashboardPage) not implemented. Backend APIs are complete and testable.
- ws_handler event recording deferred: Analytics event recording from WebSocket handler not wired yet (NoOpAnalyticsRecorder registered). Actual recording to be done in Phase 5.
- conversations.agents_used not populated yet: Column added but not populated by existing ws_handler. Backfill logic deferred to Phase 5.
Known Issues / Tech Debt
- Frontend pages need implementation (React Router, ReplayTimeline component)
- WebSocket handler needs to record analytics events via PostgresAnalyticsRecorder
- conversations.agents_used TEXT[] column needs population logic
- Checkpoint transformer depends on LangGraph JSONB structure -- may need version adaptation
- No auth on replay/analytics endpoints (same as Phase 3 -- Phase 5 concern)