fix: use 24h window for MetricSamples (matches in-memory retention)

The in-memory MetricsHistory only retains 24 hours of data, not 7 days.
Changed computeGuestMetricSamples to use trendWindow24h instead of
trendWindow7d, and reduced sample count from 24 to 12 points.

This ensures the LLM actually receives metric samples in the context,
which wasn't happening before because the 7-day query returned empty data.
This commit is contained in:
rcourtman 2025-12-21 22:19:40 +00:00
parent f44073a57d
commit 9176e54b80
2 changed files with 7 additions and 6 deletions

View file

@ -478,16 +478,17 @@ func (b *Builder) computeGuestMetricSamples(guestID string) map[string][]MetricP
return samples
}
// Get 7 days of data - enough to see weekly patterns and determine normalcy
allMetrics := b.metricsHistory.GetAllGuestMetrics(guestID, b.trendWindow7d)
// Get 24 hours of data (matches in-memory retention)
// This lets the LLM see recent patterns and changes
allMetrics := b.metricsHistory.GetAllGuestMetrics(guestID, b.trendWindow24h)
for metric, points := range allMetrics {
if len(points) < 3 {
continue
}
// Downsample to ~24 points (roughly 3 per day over 7 days)
// This lets the LLM see: daily patterns, weekly cycles, and recent changes
sampled := DownsampleMetrics(points, 24)
// Downsample to ~12 points (roughly every 2 hours over 24h)
// This gives the LLM a compact view of recent trends
sampled := DownsampleMetrics(points, 12)
if len(sampled) >= 3 {
samples[metric] = sampled
}

View file

@ -64,7 +64,7 @@ func FormatResourceContext(ctx ResourceContext) string {
// Raw metric samples - let the LLM interpret patterns directly
// This is more reliable than pre-computed trends for edge cases
if len(ctx.MetricSamples) > 0 {
sb.WriteString("**History (7d sampled, oldest→newest)**: ")
sb.WriteString("**History (24h sampled, oldest→newest)**: ")
var sampleLines []string
for metric, points := range ctx.MetricSamples {
if len(points) >= 3 {