# 🔍 Troubleshooting TAT Alerts Not Showing
## Quick Diagnosis Steps
### Step 1: Check if Redis is Connected
**Look at your backend console when you start the server:**
✅ **Good** - Redis is working:
```
✅ [TAT Queue] Connected to Redis
✅ [TAT Worker] Worker is ready and listening
```
❌ **Bad** - Redis is NOT working:
```
⚠️ [TAT Worker] Redis connection failed
⚠️ [TAT Queue] Redis connection failed after 3 attempts
```
**If you see the bad message:**
→ TAT alerts will NOT be created because the worker isn't running
→ You MUST setup Redis first (see `START_HERE.md`)
---
### Step 2: Verify TAT Alerts Table Exists
**Run this SQL:**
```sql
SELECT COUNT(*) FROM tat_alerts;
```
**Expected Result:**
- If table exists: You'll see a count (maybe 0)
- If table doesn't exist: Error "relation tat_alerts does not exist"
**If table doesn't exist:**
```bash
cd Re_Backend
npm run migrate
```
---
### Step 3: Check if TAT Alerts Exist in Database
**Run this SQL:**
```sql
-- Check if ANY alerts exist
SELECT
ta.alert_id,
ta.threshold_percentage,
ta.alert_sent_at,
ta.alert_message,
ta.metadata->>'requestNumber' as request_number,
ta.metadata->>'approverName' as approver_name
FROM tat_alerts ta
ORDER BY ta.alert_sent_at DESC
LIMIT 10;
```
**If query returns 0 rows:**
→ No alerts have been created yet
→ This means:
1. Redis is not connected, OR
2. No requests have been submitted, OR
3. Not enough time has passed (wait 3 min in test mode)
---
### Step 4: Check API Response
**Option A: Use Debug Endpoint**
Call this URL in your browser or Postman:
```
GET http://localhost:5000/api/debug/tat-status
```
**You'll see:**
```json
{
"success": true,
"status": {
"redis": {
"configured": true,
"url": "rediss://****@upstash.io:6379",
"testMode": true
},
"database": {
"connected": true,
"tatAlertsTableExists": true,
"totalAlerts": 0
}
}
}
```
**Option B: Check Workflow Details Response**
For a specific request:
```
GET http://localhost:5000/api/debug/workflow-details/REQ-2025-XXXXX
```
**You'll see:**
```json
{
"success": true,
"structure": {
"hasTatAlerts": true,
"tatAlertsCount": 2
},
"tatAlerts": [
{
"alertType": "TAT_50",
"thresholdPercentage": 50,
"alertSentAt": "...",
...
}
]
}
```
---
### Step 5: Check Frontend Console
**Open browser DevTools (F12) → Console**
**When you open Request Detail, you should see:**
```javascript
// Look for the API response
Object {
workflow: {...},
approvals: [...],
tatAlerts: [...] // ← Check if this exists
}
```
**If `tatAlerts` is missing or empty:**
→ Backend is not returning it (go back to Step 3)
**If `tatAlerts` exists but not showing:**
→ Frontend rendering issue (check Step 6)
---
### Step 6: Verify Frontend Code
**Check if tatAlerts are being processed:**
Open `Re_Figma_Code/src/pages/RequestDetail/RequestDetail.tsx`
**Search for this line (around line 235 and 493):**
```typescript
const tatAlerts = Array.isArray(details.tatAlerts) ? details.tatAlerts : [];
```
**This should be there!** If not, the code wasn't applied.
**Then search for (around line 271 and 531):**
```typescript
const levelAlerts = tatAlerts.filter((alert: any) => alert.levelId === levelId);
```
**And in the JSX (around line 1070):**
```tsx
{step.tatAlerts && step.tatAlerts.length > 0 && (
{step.tatAlerts.map((alert: any, alertIndex: number) => (
```
---
## 🐛 Common Issues & Fixes
### Issue 1: "TAT alerts not showing in UI"
**Cause**: Redis not connected
**Fix**:
1. Setup Upstash: https://console.upstash.com/
2. Add to `.env`:
```bash
REDIS_URL=rediss://default:...@upstash.io:6379
TAT_TEST_MODE=true
```
3. Restart backend
4. Look for "Connected to Redis" in logs
---
### Issue 2: "tat_alerts table doesn't exist"
**Cause**: Migrations not run
**Fix**:
```bash
cd Re_Backend
npm run migrate
```
---
### Issue 3: "No alerts in database"
**Cause**: No requests submitted or not enough time passed
**Fix**:
1. Create a new workflow request
2. **SUBMIT** the request (not just save as draft)
3. Wait:
- Test mode: 3 minutes for 50% alert
- Production: Depends on TAT (e.g., 12 hours for 24-hour TAT)
---
### Issue 4: "tatAlerts is undefined in API response"
**Cause**: Backend code not updated
**Fix**:
Check `Re_Backend/src/services/workflow.service.ts` line 698:
```typescript
return { workflow, approvals, participants, documents, activities, summary, tatAlerts };
// ^^^^^^^^
// Make sure tatAlerts is included!
```
---
### Issue 5: "Frontend not displaying alerts even though they exist"
**Cause**: Frontend code not applied or missing key
**Fix**:
1. Check browser console for errors
2. Verify `step.tatAlerts` is defined in approval flow
3. Check if alerts have correct `levelId` matching approval level
---
## 📊 Manual Test Steps
### Step-by-Step Debugging:
**1. Check Redis Connection:**
```bash
# Start backend and look for:
✅ [TAT Queue] Connected to Redis
```
**2. Create and Submit Request:**
```bash
# Via frontend or API:
POST /api/workflows/create
POST /api/workflows/{id}/submit
```
**3. Wait for Alert (Test Mode):**
```bash
# For 6-hour TAT in test mode:
# Wait 3 minutes for 50% alert
```
**4. Check Database:**
```sql
SELECT * FROM tat_alerts ORDER BY alert_sent_at DESC LIMIT 5;
```
**5. Check API Response:**
```bash
GET /api/workflows/{requestNumber}/details
# Look for tatAlerts array in response
```
**6. Check Frontend:**
```javascript
// Open DevTools Console
// Navigate to Request Detail
// Check the console log for API response
```
---
## 🔧 Debug Commands
### Check TAT System Status:
```bash
curl http://localhost:5000/api/debug/tat-status
```
### Check Workflow Details for Specific Request:
```bash
curl http://localhost:5000/api/debug/workflow-details/REQ-2025-XXXXX
```
### Check Database Directly:
```sql
-- Total alerts
SELECT COUNT(*) FROM tat_alerts;
-- Alerts for specific request
SELECT * FROM tat_alerts
WHERE request_id = (
SELECT request_id FROM workflow_requests
WHERE request_number = 'REQ-2025-XXXXX'
);
-- Pending levels that should get alerts
SELECT
w.request_number,
al.approver_name,
al.status,
al.tat_start_time,
CASE
WHEN al.tat_start_time IS NULL THEN 'No TAT monitoring started'
ELSE 'TAT monitoring active'
END as tat_status
FROM approval_levels al
JOIN workflow_requests w ON al.request_id = w.request_id
WHERE al.status IN ('PENDING', 'IN_PROGRESS');
```
---
## 📝 Checklist for TAT Alerts to Show
Must have ALL of these:
- [ ] Redis connected (see "Connected to Redis" in logs)
- [ ] TAT worker running (see "Worker is ready" in logs)
- [ ] Request SUBMITTED (not draft)
- [ ] Enough time passed (3 min in test mode for 50%)
- [ ] tat_alerts table exists in database
- [ ] Alert records created in tat_alerts table
- [ ] API returns tatAlerts in workflow details
- [ ] Frontend receives tatAlerts from API
- [ ] Frontend displays tatAlerts in workflow tab
---
## 🆘 Still Not Working?
### Provide These Details:
1. **Backend console output** when starting server
2. **Result of**:
```bash
curl http://localhost:5000/api/debug/tat-status
```
3. **Database query result**:
```sql
SELECT COUNT(*) FROM tat_alerts;
```
4. **Browser console** errors (F12 → Console)
5. **Request number** you're testing with
---
## 🎯 Most Common Cause
**99% of the time, TAT alerts don't show because:**
❌ **Redis is not connected**
**How to verify:**
```bash
# When you start backend, you should see:
✅ [TAT Queue] Connected to Redis
# If you see this instead:
⚠️ [TAT Queue] Redis connection failed
# Then:
# 1. Setup Upstash: https://console.upstash.com/
# 2. Add REDIS_URL to .env
# 3. Restart backend
```
---
## 🚀 Quick Fix Steps
If alerts aren't showing, do this IN ORDER:
```bash
# 1. Check .env file has Redis URL
cat Re_Backend/.env | findstr REDIS_URL
# 2. Restart backend
cd Re_Backend
npm run dev
# 3. Look for "Connected to Redis" in console
# 4. Create NEW request (don't use old ones)
# 5. SUBMIT the request
# 6. Wait 3 minutes (in test mode)
# 7. Refresh Request Detail page
# 8. Go to Workflow tab
# 9. Alerts should appear under approver card
```
---
**Need more help? Share the output of `/api/debug/tat-status` endpoint!**
---
**Last Updated**: November 4, 2025
**Team**: Royal Enfield Workflow