davila7/claude-code-templates · error
Failed to update states
Error message
Failed to update states
What it means
Generic 500 from the POST fast-update endpoint of the local analytics Express server. The handler computes updated analytics state and any thrown error (file I/O on ~/.claude/projects, JSON parse of conversation files, cache issues) escapes to the catch, which discards the real error and returns 'Failed to update states'.
Source
Thrown at cli-tool/src/analytics.js:1073
// Slice for response only — do not mutate this.data.conversations
const responseConversations = this.data.conversations
? this.data.conversations
.slice()
.sort((a, b) => new Date(b.lastModified) - new Date(a.lastModified))
.slice(0, 150)
: [];
const dataWithTimestamp = {
conversations: responseConversations,
summary: this.data.summary,
timestamp: new Date().toISOString(),
lastUpdate: new Date().toLocaleString(),
};
res.json(dataWithTimestamp);
} catch (error) {
console.error('Fast update error:', error);
res.status(500).json({ error: 'Failed to update states' });
}
});
// Remove duplicate endpoint - this conflicts with the correct one above
// System health endpoint
this.app.get('/api/system/health', (req, res) => {
try {
const stats = this.performanceMonitor.getStats();
const systemHealth = {
status: 'healthy',
uptime: stats.uptime,
memory: stats.memory,
requests: stats.requests,
cache: {
...stats.cache,
dataCache: this.dataCache.getStats()
},View on GitHub (pinned to a0851ed10c)
Solutions
- Check the server console — the handler logs 'Fast update error:' with the underlying error before responding 500
- Retry the request once the Claude Code session that owns the files is idle
- Delete stale cache (POST /api/clear-cache?type=all) and retry
- Inspect ~/.claude/projects for truncated/corrupt .jsonl files and remove or fix them
Example fix
// before
res.status(500).json({ error: 'Failed to update states' });
// after (expose the cause for debugging)
res.status(500).json({ error: 'Failed to update states', message: error.message }); Defensive patterns
Strategy: retry
Validate before calling
const health = await fetch(`${base}/api/system-health`).then(r => r.json());
if (health.status !== 'ok') await new Promise(r => setTimeout(r, 2000)); Try / catch
try { const r = await fetch(base + '/api/update-states', { method: 'POST' }); if (r.status === 500) { await clearCachesAndRetry(); } } catch (e) { console.error('update failed, will retry', e.message); } Prevention
- Poll a readiness/health endpoint before triggering updates
- Avoid running updates while Claude Code sessions are actively writing
- Clear conversation caches after abrupt shutdowns
When it happens
Trigger: POST /api/update-states (fast update route) while a conversation JSONL file is corrupted, a tracked file is locked/removed mid-scan, or the data cache holds a stale/invalid entry.
Common situations: Running the analytics dashboard while Claude Code is actively writing session files; very large projects dir causing timeouts; partial writes after a crash.
Related errors
- Failed to get system health
- Failed to get Claude session info
- Failed to get performance metrics
- 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/de53404933eddaa4.
Report an issue: GitHub.