Date: June 20, 2026
Status: ✅ BUG ALREADY FIXED IN CODEBASE
Severity: Previously Critical, Now Resolved
Impact: External monitoring systems may still be affected
The telemetry bug where successful retries were double-counted has already been fixed in this codebase through proper SQL-based deduplication. However, external monitoring systems (Prometheus, Datadog, CloudWatch, or custom dashboards) that consume raw execution logs may still experience double-counting.
| Metric | Value |
|---|---|
| Tech Stack | Node.js/TypeScript, SQLite3, custom job scheduler |
| Fix Status | ✅ Implemented (SQL CTE deduplication) |
| Test Coverage | ✅ 6 comprehensive regression tests |
| API Endpoint | /api/schedule/execution-metrics |
| Root Cause | Multiple log entries per retried notification |
| Solution | SQL query using MAX(execution_attempt) |
Before Fix (if querying raw logs):
Notification #100:
Attempt 1: RETRY ←─┐
Attempt 2: RETRY ←─┼── External system counts 3 events
Attempt 3: SUCCESS ←─┘
Result: Dashboard shows 3 successes ❌
After Fix (using deduplication API):
Notification #100:
Final Outcome: 1 SUCCESS ✅
Retry Count: 2
Result: Dashboard shows 1 success with 2 retries ✅
File: listener/src/services/scheduled-notification-repository.ts (line 327)
Uses SQL Common Table Expression (CTE) to deduplicate:
SELECT MAX(execution_attempt)
FROM notification_execution_log
WHERE scheduled_notification_id = ?What it does: For each notification, selects only the final execution attempt, ensuring each notification is counted exactly once.
File: listener/src/services/execution-metrics.test.ts
Critical test case (lines 58-102):
- Creates notification that fails twice, succeeds on 3rd attempt
- Asserts
totalNotifications = 1(not 3) - Asserts
successfulAfterRetry = 1(not 3) - Asserts
totalRetryAttempts = 2(correct)
File: listener/src/api/events-server.ts (line 253)
Endpoint: GET /api/schedule/execution-metrics
Returns deduplicated metrics:
{
"totalNotifications": 1500,
"successfulFirstAttempt": 1200,
"successfulAfterRetry": 250,
"permanentFailures": 50,
"totalRetryAttempts": 400,
"averageRetriesPerNotification": 0.27
}Action: Update dashboard to consume /api/schedule/execution-metrics
File to modify: dashboard/src/services/eventsApi.ts
Urgency: Medium (no double-counting in API, but dashboard not yet integrated)
// Add this method:
export const getExecutionMetrics = async () => {
const response = await fetch('/api/schedule/execution-metrics');
return await response.json();
};Action: Audit all integrations to ensure they use the API endpoint
Urgency: High (if currently showing inflated metrics)
Wrong approach (will double-count):
SELECT COUNT(*) FROM notification_execution_log WHERE status = 'SUCCESS'Correct approach:
curl http://localhost:3000/api/schedule/execution-metricsAction: Create monitoring integration guide
Urgency: High (prevents future misuse)
Template provided: docs/MONITORING_INTEGRATION.md (already created)
Actual: 100 notifications (80 success, 20 failure)
With retries: 150 total execution attempts
Wrong dashboard: 150 events recorded ❌
Reported success rate: 53% (80/150) ❌
Actual: 100 notifications (80 success, 20 failure)
With retries: 150 total execution attempts
Correct dashboard: 100 notifications counted ✅
Reported success rate: 80% (80/100) ✅
Total retry attempts: 50 (accurately tracked) ✅
| Criterion | Status | Evidence |
|---|---|---|
| Zero Duplicate Counting | ✅ PASS | SQL CTE with MAX(execution_attempt) |
| Dashboard Data Integrity | Endpoint exists, needs frontend integration | |
| Regression Test Suite | ✅ PASS | 6 comprehensive tests covering all scenarios |
| Root Cause Analysis | ✅ COMPLETE | Documented in TELEMETRY_BUG_ANALYSIS.md |
| Code Fix | ✅ COMPLETE | Already implemented in repository |
- Risk: Prometheus, Datadog, CloudWatch may query raw logs
- Impact: Inflated success counts, incorrect success rates
- Mitigation: Audit all external integrations (see MONITORING_INTEGRATION.md)
- Risk: ELK/Splunk counting log messages instead of state transitions
- Impact: Counting same notification multiple times
- Mitigation: Filter by "Notification marked as completed" not "delivered successfully"
- Risk: Frontend may implement own querying logic
- Impact: Could bypass deduplication if queries raw database
- Mitigation: Use provided API client code in dashboard
- Audit external monitoring configs - Verify Prometheus/Datadog/CloudWatch queries
- Update dashboard - Integrate
/api/schedule/execution-metricsendpoint - Run tests - Verify all 6 regression tests pass:
npm test -- execution-metrics.test.ts
- Add Prometheus exporter - Expose metrics in Prometheus format
- Create alerting rules - Alert on high retry rates (>50%)
- Document API - Add OpenAPI/Swagger spec for metrics endpoint
- Add idempotency keys - Ensure external webhooks are idempotent
- Historical data audit - Check if past metrics need correction
- Add metrics dashboard - Create Grafana dashboard using deduplicated metrics
# Step 1: Create test notification
curl -X POST http://localhost:3000/api/schedule \
-H "Content-Type: application/json" \
-d '{
"notificationType": "discord",
"targetRecipient": "test-webhook",
"executeAt": "2026-06-20T12:00:00Z",
"maxRetries": 3,
"payload": {"message": "Test"}
}'
# Step 2: Wait for retries to complete (if it fails)
# Step 3: Check metrics
curl http://localhost:3000/api/schedule/execution-metrics | jq
# Expected: totalNotifications increments by 1 (not 2 or 3)cd listener
npm test -- execution-metrics.test.ts
# Expected output:
# ✓ should count a notification with 2 failures + 1 success as exactly 1 successful notification
# ✓ should correctly count multiple notifications with different retry patterns
# ✓ should return retry distribution breakdown
# ✓ should calculate accurate average durations
# ✓ should handle empty database gracefully
# ✓ should only count COMPLETED and FAILED notifications, not PENDING
#
# Test Suites: 1 passed
# Tests: 6 passed- The core bug is fixed - SQL deduplication prevents double-counting ✅
- Tests are comprehensive - 6 regression tests cover all scenarios ✅
- API is ready -
/api/schedule/execution-metricsprovides accurate data ✅ - External systems need audit - Verify they use the API, not raw logs
⚠️ - Dashboard needs integration - Frontend should consume the metrics API
⚠️
| Document | Purpose |
|---|---|
TELEMETRY_BUG_ANALYSIS.md |
Detailed technical analysis and root cause |
docs/MONITORING_INTEGRATION.md |
Guide for Prometheus/Datadog/CloudWatch integration |
listener/src/services/execution-metrics.test.ts |
Regression test suite |
listener/src/services/retry-deduplication.test.ts |
Additional edge case tests |
For questions about:
- SQL implementation: See
scheduled-notification-repository.tsline 327 - API usage: See
docs/MONITORING_INTEGRATION.md - Test failures: See
execution-metrics.test.tssetup - External integrations: See Prometheus/Datadog examples in monitoring guide
Document Status: Final
Last Updated: June 20, 2026
Review Date: Review quarterly or when adding new monitoring systems