From 992fa1d57319b2d72d7d817bacf41fa1ac960a13 Mon Sep 17 00:00:00 2001 From: jedarden Date: Fri, 24 Apr 2026 18:07:29 -0400 Subject: [PATCH] fix(worker): crash cooldown passes time.Time not time.Duration to pq MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Passing time.Duration (int64 nanoseconds) as $2 in NOW() + $2 caused PostgreSQL to interpret the nanosecond value as seconds, setting cooldown_until to year ~59066 instead of +30 minutes. Fix: pre-compute time.Now().Add(CrashCooldownDuration) and pass the resulting time.Time — pq encodes it as a proper timestamptz. Co-Authored-By: Claude Sonnet 4.6 --- cmd/acb-worker/db.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/acb-worker/db.go b/cmd/acb-worker/db.go index 8d9ef81..a8639a2 100644 --- a/cmd/acb-worker/db.go +++ b/cmd/acb-worker/db.go @@ -524,18 +524,23 @@ func updateCrashStrikes(ctx context.Context, tx *sql.Tx, crashedBots map[string] return nil } + cooldownUntil := time.Now().Add(CrashCooldownDuration) + for botID, crashed := range crashedBots { if crashed { - // Increment strikes; if threshold reached, set cooldown + // Increment strikes; if threshold reached, set cooldown. + // Pass cooldownUntil as time.Time so pq encodes it as a proper + // timestamptz — passing time.Duration directly sends raw nanoseconds + // which PostgreSQL interprets as seconds, resulting in a ~57000-year cooldown. _, err := tx.ExecContext(ctx, ` UPDATE bots SET crash_strikes = crash_strikes + 1, cooldown_until = CASE - WHEN crash_strikes + 1 >= $1 THEN NOW() + $2 + WHEN crash_strikes + 1 >= $1 THEN $2 ELSE cooldown_until END WHERE bot_id = $3 - `, MaxCrashStrikes, CrashCooldownDuration, botID) + `, MaxCrashStrikes, cooldownUntil, botID) if err != nil { return fmt.Errorf("failed to increment crash strikes for %s: %w", botID, err) }