[object Object]

← back to Wallco Ai

harden generator_tick id-reconciliation: parse authoritative Created IDs line from stdout, snapshot heuristic as fallback

0c8a15cd9f2c15ba2d5321e2f9a98ff65a04cf9d · 2026-05-31 18:41:18 -0700 · Steve Abrams

Files touched

Diff

commit 0c8a15cd9f2c15ba2d5321e2f9a98ff65a04cf9d
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Sun May 31 18:41:18 2026 -0700

    harden generator_tick id-reconciliation: parse authoritative Created IDs line from stdout, snapshot heuristic as fallback
---
 scripts/generator_tick.js | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/scripts/generator_tick.js b/scripts/generator_tick.js
index dbcebf2..6b4f1ec 100644
--- a/scripts/generator_tick.js
+++ b/scripts/generator_tick.js
@@ -205,13 +205,27 @@ function main() {
     return 1;
   }
 
-  // Find the design this tick inserted — must be NEWER than the snapshot,
-  // else generation produced nothing and there is nothing to verify.
+  // Find the design this tick inserted. PRIMARY: parse the authoritative IDs
+  // line that generate_designs.js prints — "Created X/N designs · IDs: a,b" —
+  // so we record THIS tick's actual output even if a concurrent writer (the
+  // /api/generator/batch endpoint, which isn't under the wallco-gen lock, or a
+  // still-running auto_variations fan-out from a prior tick) inserted rows in
+  // the same window. FALLBACK: the id>snapshot heuristic, which can mis-grab a
+  // concurrent writer's newer row — only used if the log line is unparseable.
   let designId = null;
   try {
-    const raw = psql(`SELECT id FROM spoon_all_designs WHERE id > ${maxIdBefore} ORDER BY id DESC LIMIT 1;`);
-    designId = raw ? parseInt(raw, 10) : null;
+    const m = (r.stdout || '').match(/Created\s+\d+\/\d+\s+designs\s*·?\s*IDs?:\s*([0-9,\s]+)/i);
+    if (m) {
+      const ids = m[1].split(',').map(s => parseInt(s.trim(), 10)).filter(Number.isFinite);
+      if (ids.length) designId = ids[0];
+    }
   } catch {}
+  if (!designId) {
+    try {
+      const raw = psql(`SELECT id FROM spoon_all_designs WHERE id > ${maxIdBefore} ORDER BY id DESC LIMIT 1;`);
+      designId = raw ? parseInt(raw, 10) : null;
+    } catch {}
+  }
 
   if (!designId) {
     finishRun(runId, false, null, 'generation produced no design row');

← ef32cc7 admin: draggable+popout modal kit (all 19 pages) + windowed  ·  back to Wallco Ai  ·  deploy.conf: exclude prod-authored data/cactus-decisions.jso 70362eb →