charmbracelet/crush · error

get recent activity: %w

Error message

get recent activity: %w

What it means

gatherStats fetches the last-30-days activity via queries.GetRecentActivity and wraps any SQL failure with this message. As with the other gatherStats errors, the wrapped cause is almost always SQLite access (lock, permissions, corruption) or schema incompatibility.

Source

Thrown at internal/cmd/stats.go:621

	// Usage by day of week.
	dowUsage, err := queries.GetUsageByDayOfWeek(ctx)
	if err != nil {
		return nil, fmt.Errorf("get usage by day of week: %w", err)
	}
	for _, d := range dowUsage {
		stats.UsageByDayOfWeek = append(stats.UsageByDayOfWeek, DayOfWeekUsage{
			DayOfWeek:        int(d.DayOfWeek),
			DayName:          dayNames[int(d.DayOfWeek)],
			SessionCount:     d.SessionCount,
			PromptTokens:     nullFloat64ToInt64(d.PromptTokens),
			CompletionTokens: nullFloat64ToInt64(d.CompletionTokens),
		})
	}

	// Recent activity (last 30 days).
	recent, err := queries.GetRecentActivity(ctx)
	if err != nil {
		return nil, fmt.Errorf("get recent activity: %w", err)
	}
	for _, r := range recent {
		stats.RecentActivity = append(stats.RecentActivity, DailyActivity{
			Day:          fmt.Sprintf("%v", r.Day),
			SessionCount: r.SessionCount,
			TotalTokens:  nullFloat64ToInt64(r.TotalTokens),
			Cost:         r.Cost.Float64,
		})
	}

	// Average response time.
	avgResp, err := queries.GetAverageResponseTime(ctx)
	if err != nil {
		return nil, fmt.Errorf("get average response time: %w", err)
	}
	stats.AvgResponseTimeMs = toFloat64(avgResp) * 1000

	// Tool usage.

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Close concurrent crush sessions and rerun `crush stats`
  2. Check disk space (`df -h`) and DB integrity (`PRAGMA integrity_check`)
  3. Restore the DB from backup or delete it to regenerate
  4. Point --data-dir at a local filesystem path

Example fix

// before
crush stats  # disk full, I/O error on DB write
// after
df -h  # free space, then rerun crush stats
Defensive patterns

Strategy: retry

Validate before calling

db="${CRUSH_DATA_DIR:-.crush}/crush.db"
[ "$(df -h "$(dirname "$db")" | awk 'NR==2{print $4}')" != "0" ] && sqlite3 "$db" 'PRAGMA integrity_check;' | grep -q ok && echo "ready" || echo "DB or disk problem"

Try / catch

if err := gatherStats(ctx, dbPath); err != nil {
    if strings.Contains(err.Error(), "get recent activity") {
        if backoff(ctx) == nil { // bounded retry for transient I/O/lock
            return gatherStats(ctx, dbPath)
        }
    }
    return err
}

Prevention

When it happens

Trigger: GetRecentActivity fails: DB locked by a concurrent crush session, database file unreadable/corrupt, or schema drift so the prepared query fails.

Common situations: Running stats while a crush session is actively writing; disk-full or I/O errors corrupting the DB; downgraded/older binary vs newer schema; DB on NFS with broken locking.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/186fb39f56225d97. Report an issue: GitHub.