CognxSafeTrack commited on
Commit
8fde072
·
1 Parent(s): 90b1788

fix(ai): remove double day incrementation on success and queue remediation correctly

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. apps/whatsapp-worker/src/index.ts +11 -13
Dockerfile CHANGED
@@ -41,7 +41,7 @@ EXPOSE 7860
41
  ENV PORT=7860
42
 
43
  # Force Docker cache invalidation - bump date to trigger clean rebuild
44
- ENV REBUILD_DATE="2026-03-01-v13-xamle-v2-rules"
45
 
46
  # SAFETY: Default to skipping DB push to prevent schema drift.
47
  # Only Railway (api service) should push schema — it overrides SKIP_DB_PUSH=false in its variables.
 
41
  ENV PORT=7860
42
 
43
  # Force Docker cache invalidation - bump date to trigger clean rebuild
44
+ ENV REBUILD_DATE="2026-03-01-v14-fix-day-increment"
45
 
46
  # SAFETY: Default to skipping DB push to prevent schema drift.
47
  # Only Railway (api service) should push schema — it overrides SKIP_DB_PUSH=false in its variables.
apps/whatsapp-worker/src/index.ts CHANGED
@@ -224,17 +224,9 @@ const worker = new Worker('whatsapp-queue', async (job: Job) => {
224
  }
225
  }
226
 
227
- // 🚨 Hardening: Only update currentDay if we are in remediation or diagnostic
228
- // For normal success, we wait for "SUITE" to increment
229
- if (nextDay !== currentDay) {
230
- await prisma.enrollment.updateMany({
231
- where: { userId, trackId, status: 'ACTIVE' },
232
- data: {
233
- currentDay: nextDay,
234
- lastActivityAt: new Date()
235
- }
236
- });
237
- }
238
 
239
  // 🌟 Adaptive Pedagogy: Streak Management 🌟
240
  const lastActivity = user.lastActivityAt ? new Date(user.lastActivityAt) : null;
@@ -266,11 +258,17 @@ const worker = new Worker('whatsapp-queue', async (job: Job) => {
266
 
267
  const q = new Queue('whatsapp-queue', { connection: connection as any });
268
  await q.add('send-content', { userId, trackId, dayNumber: currentDay + 1 });
269
- } else if (currentDay >= totalDays && feedbackData?.isQualified === false) {
270
  await sendTextMessage(user.phone, language === 'WOLOF'
271
  ? "🚨 Am na lo xamni leerul bu baax. Xoolal missal yi ma la yónnee te tàmbaleet ko ndànk."
272
- : "🚨 Certains points sont encore à renforcer pour valider ce module. Regarde bien mes conseils et réessaie."
273
  );
 
 
 
 
 
 
274
  } else {
275
  await sendTextMessage(user.phone, language === 'WOLOF'
276
  ? "Baax na ! Yónnee *SUITE* ngir dem ci kanam."
 
224
  }
225
  }
226
 
227
+ // 🚨 Hardening: We DO NOT update `currentDay` here for normal or remediation flows.
228
+ // The `send-content` job will update `enrollment.currentDay` right before sending the lesson!
229
+ // This prevents the 'double incrementation' bug (+2 days) when the user types SUITE.
 
 
 
 
 
 
 
 
230
 
231
  // 🌟 Adaptive Pedagogy: Streak Management 🌟
232
  const lastActivity = user.lastActivityAt ? new Date(user.lastActivityAt) : null;
 
258
 
259
  const q = new Queue('whatsapp-queue', { connection: connection as any });
260
  await q.add('send-content', { userId, trackId, dayNumber: currentDay + 1 });
261
+ } else if (feedbackData?.isQualified === false) {
262
  await sendTextMessage(user.phone, language === 'WOLOF'
263
  ? "🚨 Am na lo xamni leerul bu baax. Xoolal missal yi ma la yónnee te tàmbaleet ko ndànk."
264
+ : "🚨 Certains points sont encore à renforcer pour valider. Regarde mes conseils et réessaie."
265
  );
266
+
267
+ // Si on a un jour de remédiation (ex 1.5), on l'envoie automatiquement
268
+ if (nextDay !== currentDay && nextDay % 1 !== 0) {
269
+ const q = new Queue('whatsapp-queue', { connection: connection as any });
270
+ await q.add('send-content', { userId, trackId, dayNumber: nextDay }, { delay: 2000 });
271
+ }
272
  } else {
273
  await sendTextMessage(user.phone, language === 'WOLOF'
274
  ? "Baax na ! Yónnee *SUITE* ngir dem ci kanam."