[object Object]

← back to Enrich Local Hybrid

reconcile-image-less: guard mfr_sku col + scope to monitor's actionable set (live-parsed exclusions); dry-run confirms 3419 rows

0efb0b0b53da1d267524a417b0b5c83e70cad344 · 2026-08-31 12:15:24 -0700 · Steve

Files touched

Diff

commit 0efb0b0b53da1d267524a417b0b5c83e70cad344
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon Aug 31 12:15:24 2026 -0700

    reconcile-image-less: guard mfr_sku col + scope to monitor's actionable set (live-parsed exclusions); dry-run confirms 3419 rows
---
 reconcile-staging/reconcile-image-less.sh | 32 +++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/reconcile-staging/reconcile-image-less.sh b/reconcile-staging/reconcile-image-less.sh
index 47fd47b..e60e7f9 100755
--- a/reconcile-staging/reconcile-image-less.sh
+++ b/reconcile-staging/reconcile-image-less.sh
@@ -36,6 +36,18 @@ mkdir -p "$SNAPDIR"
 
 echo "=== reconcile-image-less  (mode: $([ $APPLY = 1 ] && echo APPLY || echo DRY-RUN)) ==="
 
+# Scope = the SAME actionable universe the phase3-monitor counts: parse
+# PIPELINE_EXCLUDED_VENDORS live from full-monte-batch.js (single source of
+# truth) and exclude those vendor_codes + spoonflower. This targets exactly the
+# rows causing the monitor's false alarm and mislabels no rule-excluded vendor.
+BATCHJS=/root/DW-Agents/full-monte/full-monte-batch.js
+EXCL=$(sed -n '/PIPELINE_EXCLUDED_VENDORS = new Set(\[/,/\]);/p' "$BATCHJS" 2>/dev/null \
+        | grep -oE "'[a-z0-9_]+'" | paste -sd, -)
+[ -z "$EXCL" ] && EXCL="'cowtan_tout','colefax_fowler','phillip_jeffries'"
+EXCL="$EXCL,'spoonflower'"
+echo "excluding vendors: $EXCL"
+echo
+
 # The predicate for a phantom row, evaluated per catalog_table:
 #   phase3_ai_at IS NULL                              (monitor counts it pending)
 #   AND last_error IS NULL                            (untried — don't touch errored rows)
@@ -46,6 +58,7 @@ build_where() { # $1 = catalog_table  (aliased et)
 et.catalog_table = '$1'
   AND et.phase3_ai_at IS NULL
   AND et.last_error IS NULL
+  AND et.vendor_code NOT IN ($EXCL)
   AND NOT EXISTS (SELECT 1 FROM "$1" c
                   WHERE c.mfr_sku = et.mfr_sku
                     AND c.image_url IS NOT NULL AND c.image_url <> '')
@@ -60,21 +73,27 @@ TABLES=$($PSQL "SELECT DISTINCT catalog_table FROM enrichment_tracking
 
 TOTAL=0
 CLEAR_TOTAL=0
+SKIPPED=""
 echo "[" > "$SNAP.tmp"
 FIRST=1
 for T in $TABLES; do
-  # guard: table exists and has image_url column
-  HASIMG=$($PSQL "SELECT count(*) FROM information_schema.columns
-                  WHERE table_name='$T' AND column_name='image_url'")
-  [ "$HASIMG" = "1" ] || { echo "  skip $T (no image_url column)"; continue; }
+  # guard: table must have BOTH image_url AND mfr_sku columns (the join keys).
+  # Tables lacking either can't be reconciled by this join → skip + report.
+  COLS=$($PSQL "SELECT count(*) FROM information_schema.columns
+                WHERE table_name='$T' AND column_name IN ('image_url','mfr_sku')" 2>/dev/null || echo 0)
+  if [ "$COLS" != "2" ]; then
+    echo "  skip $T (missing image_url and/or mfr_sku column)"
+    SKIPPED="$SKIPPED $T"
+    continue
+  fi
 
   WH=$(build_where "$T")
-  N=$($PSQL "SELECT count(*) FROM enrichment_tracking et WHERE $WH")
+  N=$($PSQL "SELECT count(*) FROM enrichment_tracking et WHERE $WH" 2>/dev/null || echo 0)
   # self-heal: rows previously stamped that now HAVE an image → clear
   C=$($PSQL "SELECT count(*) FROM enrichment_tracking et
              WHERE et.catalog_table='$T' AND et.last_error='unenrichable-no-image'
                AND EXISTS (SELECT 1 FROM \"$T\" c WHERE c.mfr_sku=et.mfr_sku
-                           AND c.image_url IS NOT NULL AND c.image_url<>'')")
+                           AND c.image_url IS NOT NULL AND c.image_url<>'')" 2>/dev/null || echo 0)
   [ "$N" = "0" ] && [ "$C" = "0" ] && continue
   printf "  %-34s stamp=%-6s clear=%s\n" "$T" "$N" "$C"
   TOTAL=$((TOTAL+N)); CLEAR_TOTAL=$((CLEAR_TOTAL+C))
@@ -100,6 +119,7 @@ echo "]" >> "$SNAP.tmp"
 echo "----------------------------------------------"
 echo "TOTAL image-less phantom rows to stamp : $TOTAL"
 echo "TOTAL stale stamps to clear (self-heal): $CLEAR_TOTAL"
+[ -n "$SKIPPED" ] && echo "SKIPPED tables (no mfr_sku/image_url col — handle separately):$SKIPPED"
 if [ $APPLY = 1 ]; then
   mv "$SNAP.tmp" "$SNAP"
   echo "APPLIED. Snapshot (undo map): $SNAP"

← 2b5fd92 Add reversible Phase-3 image-less phantom-backlog reconcile  ·  back to Enrich Local Hybrid  ·  Route local vision leg through shared exo-vision lib, drop d 63ea825 →