Issue: Retry Double-Counting in Metrics
Status: ✅ FIXED
Date: June 20, 2026
Start here if you need a quick overview:
- EXECUTIVE_SUMMARY.md ⭐ START HERE
- TL;DR of the bug and fix
- Key facts and metrics
- Acceptance criteria status
- Recommended next steps
Read these if you're implementing or verifying the fix:
-
- Detailed root cause analysis
- Code walkthrough of the bug
- SQL deduplication implementation
- Test results and verification
-
- Visual system architecture
- Data flow diagrams
- Component relationships
- SQL query comparison
Follow these for setting up monitoring:
-
docs/MONITORING_INTEGRATION.md
- Prometheus integration examples
- Datadog custom check configuration
- CloudWatch Lambda function
- Grafana dashboard setup
- Wrong vs. correct approaches
-
- Step-by-step verification checklist
- 22 actionable items
- Testing procedures
- Sign-off template
Comprehensive guide with all details:
- TELEMETRY_FIX_README.md
- Complete documentation hub
- API usage examples
- Testing guide
- Troubleshooting section
- Performance considerations
Notify-Chain/
├── EXECUTIVE_SUMMARY.md ⭐ Start here
├── TELEMETRY_BUG_ANALYSIS.md 📊 Technical deep-dive
├── TELEMETRY_FIX_README.md 📖 Complete reference
├── TELEMETRY_FIX_CHECKLIST.md ✅ Verification steps
├── ARCHITECTURE_DIAGRAM.md 🏗️ Visual architecture
├── TELEMETRY_DOCS_INDEX.md 📇 This file
│
├── docs/
│ └── MONITORING_INTEGRATION.md 🔌 Integration guide
│
├── listener/
│ ├── src/
│ │ ├── services/
│ │ │ ├── execution-metrics.test.ts ✅ Main tests (6)
│ │ │ ├── retry-deduplication.test.ts ✅ Edge cases (10)
│ │ │ ├── scheduled-notification-repository.ts 🔧 The fix
│ │ │ └── notification-scheduler.ts ⚙️ Retry logic
│ │ ├── api/
│ │ │ └── events-server.ts 🌐 API endpoint
│ │ └── database/
│ │ ├── database.ts 💾 Database layer
│ │ └── schema.sql 📄 Schema definition
│ └── package.json
Audience: Management, Stakeholders, Product Owners
- EXECUTIVE_SUMMARY.md - Read "TL;DR" and "Quick Facts"
- EXECUTIVE_SUMMARY.md - Review "Acceptance Criteria Status"
- EXECUTIVE_SUMMARY.md - Check "Recommended Next Steps"
Outcome: Understand fix status and remaining work
Audience: Backend Engineers, Full-Stack Developers
- EXECUTIVE_SUMMARY.md - Quick context
- TELEMETRY_BUG_ANALYSIS.md - Root cause analysis
- ARCHITECTURE_DIAGRAM.md - Visual architecture
- Run tests:
npm test -- execution-metrics.test.ts - Review code:
listener/src/services/scheduled-notification-repository.ts(line 327)
Outcome: Understand bug, fix, and test coverage
Audience: Site Reliability Engineers, DevOps Engineers, Platform Engineers
- EXECUTIVE_SUMMARY.md - Context
- docs/MONITORING_INTEGRATION.md - Integration examples
- TELEMETRY_FIX_CHECKLIST.md - Complete checklist
- Audit existing monitoring configurations
- Update Prometheus/Datadog/CloudWatch configs
Outcome: Monitoring systems correctly integrated
Audience: QA Engineers, Test Automation Engineers
- EXECUTIVE_SUMMARY.md - Context
- TELEMETRY_FIX_CHECKLIST.md - Testing section (items 11-15)
- Review test files:
listener/src/services/execution-metrics.test.tslistener/src/services/retry-deduplication.test.ts
- Execute integration tests
- Verify dashboard displays correct counts
Outcome: Verification that fix works end-to-end
Audience: Technical Leads, Architects, New Team Members
- TELEMETRY_FIX_README.md - Overview
- TELEMETRY_BUG_ANALYSIS.md - Deep technical analysis
- ARCHITECTURE_DIAGRAM.md - System architecture
- docs/MONITORING_INTEGRATION.md - Integration patterns
- TELEMETRY_FIX_CHECKLIST.md - Verification procedures
- Review all code files
- Run all tests
- Test API endpoints
Outcome: Complete understanding of system, bug, and solution
| Document | Size | Lines | Estimated Reading Time |
|---|---|---|---|
| EXECUTIVE_SUMMARY.md | 14 KB | 382 | 5 min |
| TELEMETRY_BUG_ANALYSIS.md | 15 KB | 425 | 15 min |
| TELEMETRY_FIX_README.md | 16 KB | 518 | 20 min |
| TELEMETRY_FIX_CHECKLIST.md | 12 KB | 438 | 30 min |
| ARCHITECTURE_DIAGRAM.md | 10 KB | 582 | 10 min |
| docs/MONITORING_INTEGRATION.md | 18 KB | 612 | 15 min |
| Total | 85 KB | 2,957 lines | 95 minutes |
| File | Purpose | Lines of Code |
|---|---|---|
| scheduled-notification-repository.ts | Data layer with fix | ~450 LOC |
| notification-scheduler.ts | Retry orchestration | ~235 LOC |
| events-server.ts | API endpoint | ~320 LOC |
| execution-metrics.test.ts | Main tests | ~420 LOC |
| retry-deduplication.test.ts | Edge case tests | ~650 LOC |
Multiple execution log entries per retried notification led to double-counting when external systems queried raw logs.
SQL Common Table Expression (CTE) using MAX(execution_attempt) to select only the final outcome per notification.
16 comprehensive tests covering:
- Basic retry scenarios
- Edge cases (max retries, immediate success, concurrent)
- High-volume scenarios
- Empty database and missing data
API endpoint /api/schedule/execution-metrics provides deduplicated metrics, shielding consumers from implementation details.
| Criterion | Documentation Coverage |
|---|---|
| Root Cause Analysis | ✅ TELEMETRY_BUG_ANALYSIS.md |
| Code Fix Explanation | ✅ TELEMETRY_BUG_ANALYSIS.md + Code comments |
| Regression Tests | ✅ execution-metrics.test.ts (6 tests) |
| Edge Case Tests | ✅ retry-deduplication.test.ts (10 tests) |
| API Documentation | ✅ TELEMETRY_FIX_README.md |
| Integration Guide | ✅ docs/MONITORING_INTEGRATION.md |
| Verification Checklist | ✅ TELEMETRY_FIX_CHECKLIST.md |
| Visual Architecture | ✅ ARCHITECTURE_DIAGRAM.md |
| Executive Summary | ✅ EXECUTIVE_SUMMARY.md |
All acceptance criteria met! ✅
...understand the bug in 5 minutes → Read EXECUTIVE_SUMMARY.md sections "The Problem" and "The Fix"
...verify the fix is working → Follow TELEMETRY_FIX_CHECKLIST.md items 1-3 (Pre-Flight Checks)
...integrate Prometheus → See docs/MONITORING_INTEGRATION.md "Prometheus" section
...integrate Datadog → See docs/MONITORING_INTEGRATION.md "Datadog" section
...run the tests
cd listener
npm test -- execution-metrics.test.ts
npm test -- retry-deduplication.test.ts...see the API response
curl http://localhost:3000/api/schedule/execution-metrics | jq...understand the SQL query → See ARCHITECTURE_DIAGRAM.md "SQL Deduplication Logic" section
...update the dashboard → See EXECUTIVE_SUMMARY.md "For Internal Dashboards" section
- Check database initialization in test setup
- Review TELEMETRY_FIX_CHECKLIST.md "Troubleshooting" section
- Verify sqlite3 package is installed:
npm list sqlite3
- Verify you're using
/api/schedule/execution-metricsendpoint - Check monitoring system configuration files
- Review docs/MONITORING_INTEGRATION.md "Best Practices"
- Check if notifications exist in database
- Verify notifications have status COMPLETED or FAILED
- Review TELEMETRY_FIX_README.md "Troubleshooting" section
- Read docs/MONITORING_INTEGRATION.md
- Use API endpoint (not raw database queries)
- Reference existing Prometheus/Datadog examples
- Quarterly (check for new monitoring integrations)
- After adding new external monitoring systems
- When metrics appear incorrect
- During onboarding of new team members
- Update code examples when repository changes
- Add new integration examples as tools are adopted
- Keep test coverage metrics up to date
- Review acceptance criteria annually
- v1.0 (June 20, 2026): Initial comprehensive documentation
- Future versions will be tracked here
Documentation Owner: Backend Engineering Team
Code Owner: SRE Team
Last Review: June 20, 2026
Next Review: September 2026
For questions:
- Technical: Review TELEMETRY_BUG_ANALYSIS.md or code comments
- Integration: See docs/MONITORING_INTEGRATION.md
- Testing: See test files with inline documentation
| Document | Status | Last Updated |
|---|---|---|
| EXECUTIVE_SUMMARY.md | ✅ Final | 2026-06-20 |
| TELEMETRY_BUG_ANALYSIS.md | ✅ Final | 2026-06-20 |
| TELEMETRY_FIX_README.md | ✅ Final | 2026-06-20 |
| TELEMETRY_FIX_CHECKLIST.md | ✅ Final | 2026-06-20 |
| ARCHITECTURE_DIAGRAM.md | ✅ Final | 2026-06-20 |
| docs/MONITORING_INTEGRATION.md | ✅ Final | 2026-06-20 |
| TELEMETRY_DOCS_INDEX.md | ✅ Final | 2026-06-20 |
All documentation complete and ready for use! ✅
Last Updated: June 20, 2026
Status: Production Ready
Total Documentation: 6 main documents + 2 test suites + code implementation