fix(db): add LIMITs to unbounded queries to prevent OOM

- Add LIMIT 50000 to fetchLineage (evolution programs table)
- Add LIMIT 10000 to fetchBots
- Add LIMIT 5000 to fetchSeries

These queries had no bounds and could grow arbitrarily large,
causing acb-index-builder to OOM during build cycles.
The lineage table in particular grows unbounded with evolution.

Fixes CrashLoopBackOff that has persisted for 45 days.
This commit is contained in:
jedarden 2026-06-25 00:23:48 -04:00
parent 5e83945683
commit 1832ff439b

View file

@ -289,6 +289,7 @@ func fetchBots(ctx context.Context, db *sql.DB) ([]BotData, error) {
FROM bots
WHERE status != 'retired'
ORDER BY rating_mu DESC
LIMIT 10000
`
rows, err := db.QueryContext(ctx, query)
@ -467,6 +468,7 @@ func fetchSeries(ctx context.Context, db *sql.DB) ([]SeriesData, error) {
JOIN bots ba ON s.bot_a_id = ba.bot_id
JOIN bots bb ON s.bot_b_id = bb.bot_id
ORDER BY s.created_at DESC
LIMIT 5000
`
rows, err := db.QueryContext(ctx, query)
@ -1171,12 +1173,13 @@ func fetchEvolutionMeta(ctx context.Context, db *sql.DB) (*EvolutionMeta, error)
}
// fetchLineage queries the evolver database for the full lineage tree.
// Returns all programs with their parent relationships.
// Returns up to 50000 most recent programs with their parent relationships.
func fetchLineage(ctx context.Context, db *sql.DB) ([]LineageNode, error) {
query := `
SELECT id, parent_ids, generation, island, fitness, promoted, language, created_at
FROM programs
ORDER BY generation ASC, id ASC
LIMIT 50000
`
rows, err := db.QueryContext(ctx, query)