From 1832ff439b6f87492ad3d9c8f5e2ca84b7b33d7a Mon Sep 17 00:00:00 2001 From: jedarden Date: Thu, 25 Jun 2026 00:23:48 -0400 Subject: [PATCH] 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. --- cmd/acb-index-builder/db.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/acb-index-builder/db.go b/cmd/acb-index-builder/db.go index def514b..5699af4 100644 --- a/cmd/acb-index-builder/db.go +++ b/cmd/acb-index-builder/db.go @@ -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)