Skip to content

Commit d8c47f3

Browse files
committed
fix(web): resolve healthz cache warning by using lightweight count query
The getCachedAgentsLite function was trying to cache ~19MB of agent data, exceeding the unstable_cache 2MB limit. Created a new getAgentCount() function that only performs a COUNT(*) query, avoiding the cache entirely. This fixes the warning: "Failed to set Next.js data cache for unstable_cache /api/healthz, items over 2MB can not be cached"
1 parent e4d4cdf commit d8c47f3

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

web/src/app/api/healthz/route.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { NextResponse } from 'next/server'
2-
import { getCachedAgentsLite } from '@/server/agents-data'
2+
import { getAgentCount } from '@/server/agents-data'
33

44
export const GET = async () => {
55
try {
6-
// Warm the cache by fetching agents data
7-
// This ensures SEO-critical data is available immediately
8-
const agents = await getCachedAgentsLite()
6+
// Get a lightweight count of agents without caching the full data
7+
// This avoids the unstable_cache 2MB limit warning
8+
const agentCount = await getAgentCount()
99

1010
return NextResponse.json({
1111
status: 'ok',
12-
cached_agents: agents.length,
12+
cached_agents: agentCount,
1313
timestamp: new Date().toISOString(),
1414
})
1515
} catch (error) {
16-
console.error('[Healthz] Failed to warm cache:', error)
16+
console.error('[Healthz] Failed to get agent count:', error)
1717

18-
// Still return 200 so health check passes, but indicate cache warming failed
18+
// Still return 200 so health check passes, but indicate the error
1919
return NextResponse.json({
2020
status: 'ok',
21-
cache_warm: false,
21+
agent_count_error: true,
2222
error: error instanceof Error ? error.message : 'Unknown error',
2323
})
2424
}

web/src/server/agents-data.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,17 @@ export const getCachedAgentsMetrics = unstable_cache(
455455
tags: ['agents', 'metrics'],
456456
},
457457
)
458+
459+
// ============================================================================
460+
// LIGHTWEIGHT COUNT - For healthz endpoint, avoids unstable_cache 2MB limit
461+
// ============================================================================
462+
463+
export const getAgentCount = async (): Promise<number> => {
464+
const result = await db
465+
.select({
466+
count: sql<number>`COUNT(*)`,
467+
})
468+
.from(schema.agentConfig)
469+
470+
return Number(result[0]?.count ?? 0)
471+
}

0 commit comments

Comments
 (0)