From 876f9949049eb9706d4da2acc3959f18c5a30050 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 6 May 2026 23:03:21 -0400 Subject: [PATCH] fix(server/m7-recurring-scans): early-return in TryStartScan reap branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit revive flagged the if/else where the else branch was a return — invert the condition and return the non-stale skip path early so the reap flow drops one indent level. --- internal/library/trigger.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/internal/library/trigger.go b/internal/library/trigger.go index 7bc9c45b..52c3e8bd 100644 --- a/internal/library/trigger.go +++ b/internal/library/trigger.go @@ -39,19 +39,18 @@ func TryStartScan(ctx context.Context, pool *pgxpool.Pool, if qerr == nil { // Found an in-flight row. Reap if stale, else skip. age := time.Since(row.StartedAt.Time) - if age > StuckScanThreshold { - logger.Warn("reaping stale in-flight scan", - "id", row.ID, "started_at", row.StartedAt.Time, "age", age) - if rerr := q.FinishScanRun(ctx, dbq.FinishScanRunParams{ - ID: row.ID, - Column2: "reaped (stale)", - }); rerr != nil { - return false, nil, fmt.Errorf("reap stale scan: %w", rerr) - } - // Fall through to start a new scan. - } else { + if age <= StuckScanThreshold { return false, &row, nil } + logger.Warn("reaping stale in-flight scan", + "id", row.ID, "started_at", row.StartedAt.Time, "age", age) + if rerr := q.FinishScanRun(ctx, dbq.FinishScanRunParams{ + ID: row.ID, + Column2: "reaped (stale)", + }); rerr != nil { + return false, nil, fmt.Errorf("reap stale scan: %w", rerr) + } + // Fall through to start a new scan. } else if !errors.Is(qerr, pgx.ErrNoRows) { return false, nil, fmt.Errorf("in-flight check: %w", qerr) }