Conversation
added 7 commits
January 16, 2026 20:11
The /api/statistics endpoint was returning {pending: true} indefinitely
when the statistics snapshot build got stuck. This could happen due to:
- Worker thread deadlocks or promises that never resolve
- Slow or hanging getCacheCoverage() calls with large caches
- Redis operations that never complete
- Stale snapshots in Redis not triggering refresh
Changes:
- Add 10-minute timeout to snapshot builds to prevent infinite hangs
- Detect and automatically reset stuck builds in SnapshotCache
- Wrap getCacheCoverage() in try-catch to prevent blocking failures
- Detect stale snapshots (>2x refresh interval) and force refresh
- Add comprehensive logging for build duration and stuck detection
- Clear dirty flag on timeout/error to allow retry
The timeout mechanism ensures that even if a build hangs, it will
eventually timeout and allow the next refresh attempt to proceed.
Error handling ensures snapshot builds complete even if cache coverage
fails, returning partial statistics instead of hanging.
Fixes issue where statistics endpoint hung for 12+ hours while server
remained responsive (indicating deadlock/promise issue, not CPU bound).
TypeScript couldn't narrow the type of refreshStartTime in the compound condition. Store it in a local variable to allow proper type narrowing.
# Conflicts: # .specstory/history/2026-01-17_11-32Z-statistics-endpoint-hanging.md # src/stats.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.