davila7/claude-code-templates · error
Failed to get performance metrics
Error message
Failed to get performance metrics
What it means
500 from the performance metrics endpoint. The handler merges performanceMonitor stats with dataCache stats; if either object shape is unexpected (undefined cache, missing method), the property access throws and this 500 is returned.
Source
Thrown at cli-tool/src/analytics.js:1153
res.status(500).json({
error: 'Failed to get Claude session info',
timestamp: Date.now()
});
}
});
// Performance metrics endpoint
this.app.get('/api/system/metrics', (req, res) => {
try {
const timeframe = parseInt(req.query.timeframe) || 300000; // 5 minutes default
const stats = this.performanceMonitor.getStats(timeframe);
res.json({
...stats,
dataCache: this.dataCache.getStats(),
timestamp: Date.now()
});
} catch (error) {
res.status(500).json({
error: 'Failed to get performance metrics',
timestamp: Date.now()
});
}
});
// Cache management endpoint
this.app.post('/api/cache/clear', (req, res) => {
try {
// Clear specific cache types or all
const { type } = req.body;
if (!type || type === 'all') {
// Clear all caches
this.dataCache.invalidateComputations();
this.dataCache.caches.parsedConversations.clear();
this.dataCache.caches.fileContent.clear();
this.dataCache.caches.fileStats.clear();View on GitHub (pinned to a0851ed10c)
Solutions
- Wait for the server's startup logs before hitting /api/performance
- Restart the analytics server
- Clear caches via POST /api/clear-cache to reset dataCache state
- Check console for the underlying exception and report if getStats() itself fails
Defensive patterns
Strategy: retry
Validate before calling
const ready = await fetch(base + '/api/conversations').then(r => r.ok); // server initialized if data endpoints work
Type guard
const isPerfStats = (d) => d && d.dataCache && typeof d.timestamp === 'number';
Try / catch
try { return await getPerformance(); } catch { await delay(1500); return await getPerformance(); } // one retry after init race Prevention
- Don't scrape metrics during startup
- Add jitter/backoff in monitoring loops
When it happens
Trigger: GET /api/performance when this.dataCache is not initialized (endpoint hit before initialize() completed) or when getStats() throws due to internal state corruption.
Common situations: Polling metrics immediately at server startup; a partially failed cache warm-up.
Related errors
- Failed to update states
- Failed to get system health
- Failed to get Claude session info
- Failed to clear cache
- Failed to generate activity data
AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28).
Data as JSON: /api/errors/8e2ac5e7378e9e8d.
Report an issue: GitHub.