[object Object]

← back to Dw Activation Calendar

cadence prune: adopt DTD-C — union activator audit ids on mirror filter

9d72db846f621d6da37fc9a6d6b518d2f557d9a3 · 2026-07-22 11:06:55 -0700 · Steve Abrams

Keep mirror status='DRAFT' as the base filter, but also drop any shopify_id the
rotation activator recorded as action:'activated' in the last 2 days' audit
JSONL. Closes the mirror-resync lag (zero-lag for items this system flips)
without live Shopify calls or a competing status oracle. DTD 5/5 unanimous.

Files touched

Diff

commit 9d72db846f621d6da37fc9a6d6b518d2f557d9a3
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Wed Jul 22 11:06:55 2026 -0700

    cadence prune: adopt DTD-C — union activator audit ids on mirror filter
    
    Keep mirror status='DRAFT' as the base filter, but also drop any shopify_id the
    rotation activator recorded as action:'activated' in the last 2 days' audit
    JSONL. Closes the mirror-resync lag (zero-lag for items this system flips)
    without live Shopify calls or a competing status oracle. DTD 5/5 unanimous.
---
 scripts/prune-active.js | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/scripts/prune-active.js b/scripts/prune-active.js
index c1a20d4..faccc83 100644
--- a/scripts/prune-active.js
+++ b/scripts/prune-active.js
@@ -21,11 +21,38 @@
  *   node scripts/prune-active.js --dry-run  # report what would be pruned, no write
  */
 const fs = require('fs');
+const os = require('os');
 const path = require('path');
 const { Pool } = require('pg');
 
 const DRY = process.argv.includes('--dry-run');
 const FILE = path.join(__dirname, '..', 'data', 'activation-schedule.json');
+// The rotation activator's per-day audit trail of exactly which ids it flipped
+// live. Downstream of the activator (it only ever confirms "this system just
+// activated X"), so it closes the mirror-resync lag WITHOUT introducing a second
+// status oracle. DTD verdict C (2026-07-22, unanimous 5/5).
+const ACTIVATOR_OUT = path.join(os.homedir(), 'Projects', 'dw-rotation-activator', 'out');
+
+// Collect shopify_ids the activator recorded as action:'activated' in the last
+// couple of days' audit files (covers the day-boundary window; older activations
+// are long since mirror-synced). Read-only; a missing/partial file is ignored.
+function justActivatedIds() {
+  const ids = new Set();
+  const day = (offset) => {
+    const d = new Date(); d.setDate(d.getDate() - offset);
+    return d.toISOString().slice(0, 10);
+  };
+  for (const stamp of [day(0), day(1)]) {
+    const f = path.join(ACTIVATOR_OUT, `rotation-activations-${stamp}.jsonl`);
+    let txt; try { txt = fs.readFileSync(f, 'utf8'); } catch { continue; }
+    for (const line of txt.split('\n')) {
+      if (!line) continue;
+      try { const r = JSON.parse(line); if (r.action === 'activated' && r.shopify_id) ids.add(String(r.shopify_id)); }
+      catch { /* skip a torn/partial line */ }
+    }
+  }
+  return ids;
+}
 
 const pool = process.env.DATABASE_URL
   ? new Pool({ connectionString: process.env.DATABASE_URL, max: 2 })
@@ -70,8 +97,18 @@ async function main() {
     draft = new Set(r.rows.map(x => x.id));
   } finally { c.release(); await pool.end(); }
 
-  const kept = skus.filter(s => draft.has(String(s.shopify_id)));
+  // Zero-lag layer: even if the mirror hasn't re-synced yet, an id the activator
+  // just flipped (its own audit) is no longer staged — drop it now.
+  const flipped = justActivatedIds();
+
+  // Keep only ids that are still DRAFT in the mirror AND weren't just activated.
+  const kept = skus.filter(s => {
+    const id = String(s.shopify_id);
+    return draft.has(id) && !flipped.has(id);
+  });
   const removed = skus.length - kept.length;
+  const lagCaught = skus.filter(s => draft.has(String(s.shopify_id)) && flipped.has(String(s.shopify_id))).length;
+  if (lagCaught) console.log(`prune-active: ${lagCaught} of those caught via activator audit before the mirror re-synced (zero-lag).`);
 
   if (removed === 0) { console.log(`prune-active: clean — all ${skus.length} scheduled items are still DRAFT.`); return; }
 

← d320634 cadence: prune already-active SKUs, keep only staged (DRAFT)  ·  back to Dw Activation Calendar  ·  auto-save: 2026-07-22T11:43:42 (1 files) — data/activation-s 1d223be →