[object Object]

← back to Wallco Ai

fix(generator_tick): guard finishRun against non-numeric runId (no more WHERE id=; spam)

1d9bacf5f842e19a7e58364f30387db0133b2301 · 2026-05-29 17:04:51 -0700 · Steve Abrams

The mac2 wallco-generator launchd job spammed 1083 CNCP failures on 2026-05-15:
the id sequence had fallen behind max(id), so the INSERT...RETURNING id collided
(duplicate PK), recordRunStart came back empty, and finishRun built 'WHERE id=;'
-> SQL syntax error every tick. The sequence has since self-healed (max=3665 <
seq=3697), so it is no longer firing, but a future prod-PG restore could resync
ids without advancing the sequence and reopen the cascade. Guard finishRun to
skip the UPDATE on a missing/non-numeric runId.

Files touched

Diff

commit 1d9bacf5f842e19a7e58364f30387db0133b2301
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Fri May 29 17:04:51 2026 -0700

    fix(generator_tick): guard finishRun against non-numeric runId (no more WHERE id=; spam)
    
    The mac2 wallco-generator launchd job spammed 1083 CNCP failures on 2026-05-15:
    the id sequence had fallen behind max(id), so the INSERT...RETURNING id collided
    (duplicate PK), recordRunStart came back empty, and finishRun built 'WHERE id=;'
    -> SQL syntax error every tick. The sequence has since self-healed (max=3665 <
    seq=3697), so it is no longer firing, but a future prod-PG restore could resync
    ids without advancing the sequence and reopen the cascade. Guard finishRun to
    skip the UPDATE on a missing/non-numeric runId.
---
 scripts/generator_tick.js | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/scripts/generator_tick.js b/scripts/generator_tick.js
index 6777cfe..dbcebf2 100644
--- a/scripts/generator_tick.js
+++ b/scripts/generator_tick.js
@@ -102,6 +102,14 @@ function recordRunStart(recipeId, prompt, seedIds) {
 }
 
 function finishRun(runId, ok, designId, err) {
+  // Guard: a missing/non-numeric runId (e.g. recordRunStart returned empty
+  // because the id sequence had fallen behind max(id)) must NOT build
+  // "WHERE id=;" — that SQL syntax error spammed 1083 ledger failures on
+  // 2026-05-15. Bail loudly instead of emitting malformed SQL every tick.
+  if (!/^\d+$/.test(String(runId).trim())) {
+    console.log(JSON.stringify({ event: 'finishRun_skipped_bad_runId', runId: runId ?? null }));
+    return;
+  }
   psql(`
     UPDATE wallco_generator_runs
        SET status='${ok ? 'done' : 'error'}',

← c42d61a admin/rooms list: filter out soft-deleted rooms (AND removed  ·  back to Wallco Ai  ·  elements bake — recover 4 truncated Round-1 PNGs via targete cf8fd5d →