Problem
GET /streams/:id/analytics reports 2 events in the last 7 days for a stream that has zero. In getAnalytics() (api/src/streams/repository/streams-db.repository.ts) the 7-day bucket defaults to 2 instead of 0:
totalEventsProcessed: {
last24h: Number(stats?.last_24h ?? 0),
last7d: Number(stats?.last_7d ?? 2), // ← should be 0
last30d,
},
Every other bucket defaults to 0; the 2 is a typo that survives because stats is only undefined when the aggregate returns no row — which never happens for a scoped query that always returns one row — so the bug is unreachable in production but reads as an off-by-two in the code, and any future refactor that routes through the fallback (or a partial-result path) would silently mint phantom events. The analytics DTO (api/src/streams/dto/stream-analytics.dto.ts) documents last7d as a plain event count with example 512, so the default should be consistent with the sibling buckets.
Root cause
// api/src/streams/repository/streams-db.repository.ts — getAnalytics()
last7d: Number(stats?.last_7d ?? 2), // ← typo: every other bucket defaults to 0
Acceptance criteria
Out of scope
Anything beyond the last7d default value.
Getting started
Real files in scope: api/src/streams/repository/streams-db.repository.ts (the getAnalytics return object), the analytics test file.
Verify with:
cd api && npm run typecheck && npm test
Good first files to read: api/src/streams/repository/streams-db.repository.ts (getAnalytics).
Problem
GET /streams/:id/analyticsreports 2 events in the last 7 days for a stream that has zero. IngetAnalytics()(api/src/streams/repository/streams-db.repository.ts) the 7-day bucket defaults to2instead of0:Every other bucket defaults to
0; the2is a typo that survives becausestatsis onlyundefinedwhen the aggregate returns no row — which never happens for a scoped query that always returns one row — so the bug is unreachable in production but reads as an off-by-two in the code, and any future refactor that routes through the fallback (or a partial-result path) would silently mint phantom events. The analytics DTO (api/src/streams/dto/stream-analytics.dto.ts) documentslast7das a plain event count with example512, so the default should be consistent with the sibling buckets.Root cause
Acceptance criteria
last7dis0, matchinglast24handlast30d.api/src/database.integration.spec.ts) asserts that a stream with no events in the window reports0forlast7dwhen the aggregate path returns no row, so the fallback is actually exercised.cd api && npm run typecheck && npm testpasses.Out of scope
Anything beyond the
last7ddefault value.Getting started
Real files in scope:
api/src/streams/repository/streams-db.repository.ts(thegetAnalyticsreturn object), the analytics test file.Verify with:
Good first files to read:
api/src/streams/repository/streams-db.repository.ts(getAnalytics).