# Bugs Investigation Plan

**Architect:** Claude Architect
**Date:** Jan 23, 2026
**Source:** dev_queue table + Slack #growth-alerts (direct read)

---

## Executive Summary

Found **19 open bugs** in dev_queue + **3 additional issues** from Slack Quality Audits.

After investigation:
- **7 bugs ALREADY FIXED** (verified in code)
- **2 bugs DUPLICATES**
- **6 bugs NEED FIX**
- **4 feature requests** (mislabeled as bugs)
- **1 NEW BUG** from Slack: "Failed SMS still advances sequence"
- **2 PERFORMANCE ISSUES** from Quality Audit: LCP 7.5s, CLS 0.28

---

## SECTION 1: ALREADY FIXED ✅

These bugs are already fixed based on code review. Should be closed in dev_queue.

### Bug #15, #11, #10 - Voice Assistant Timeout (DUPLICATE x3)
**Report:** "Voice assistant doesn't work, times out after 5 seconds"
**Status:** ✅ FIXED in Session 27

**Evidence:**
- `admin/src/components/VoiceAssistant.jsx:37` - `SILENCE_TIMEOUT = 15000` (15 seconds)
- Also has continuous recognition mode (`recognition.continuous = true`)

**Action:** Close bugs #15, #11, #10 as fixed

---

### Bug #9 - Leads Page Can't Scroll to Bottom
**Report:** "On leads page you can't scroll down to the bottom"
**Status:** ✅ FIXED in Session 27

**Evidence:**
- `admin/src/pages/Leads.jsx:295` - `className="min-h-screen bg-slate-50 dark:bg-slate-900 pb-32 md:pb-6"`
- `pb-32` = 128px padding, more than enough for BottomNav (80px)

**Action:** Close bug #9 as fixed

---

### Bug #5 - Messages Scroll Triggers Click
**Report:** "When I scroll through the messages when I lift my finger it clicks into the lead"
**Status:** ✅ FIXED

**Evidence:**
- `admin/src/hooks/useLongPress.js:21-70` - Has `cancelledByScroll` ref that detects touch movement >10px and prevents click trigger
- Movement detection in `handleMove` callback

**Action:** Close bug #5 as fixed

---

### Bug #4, #3 - Phone Number Missing +61 (DUPLICATE)
**Report:** "Phone number didn't have +61 on it so follow up message didn't send"
**Status:** ✅ FIXED (documented in LESSONS.md)

**Evidence from LESSONS.md:**
- Line 119: "Phone normalization must apply when sending by leadId"
- Fix applied to `/api/sms/send` endpoint to normalize phone from lead record

**Action:** Close bugs #4 and #3 as fixed

---

## SECTION 2: ACTUAL BUGS REQUIRING FIX 🐛

### Bug #7 - Leads Page Scroll Triggers Call ⚠️ HIGH PRIORITY
**Report:** "When you scroll down through the leads if you lift your finger it clicks into them and starts ringing"
**Page:** `/leads`
**Device:** iPhone / Safari

**Root Cause Analysis:**
The `Leads.jsx` page uses a custom `SwipeableLeadCard` component with its own touch handlers (`onTouchStart`, `onTouchMove`, `onTouchEnd`) that DO NOT use the `useLongPress` hook.

**Evidence:**
- `admin/src/pages/Leads.jsx:30-55` - SwipeableLeadCard has manual touch handlers
- Line 84: `onClick={() => !isSwiping && swipeX === 0 && onTap()}` - Only checks swipeX, not vertical scroll

**The Problem:**
When user scrolls vertically, `swipeX` stays at 0 (horizontal swipe detection only). When they lift their finger, `!isSwiping && swipeX === 0` is true, triggering `onTap()`.

**Fix Required:**
Add vertical movement tracking similar to useLongPress:
```javascript
const startY = useRef(0);
const verticalScrolled = useRef(false);

const handleTouchStart = (e) => {
  startX.current = e.touches[0].clientX;
  startY.current = e.touches[0].clientY;  // NEW
  verticalScrolled.current = false;       // NEW
  setIsSwiping(true);
};

const handleTouchMove = (e) => {
  if (!isSwiping) return;
  const currentX = e.touches[0].clientX;
  const currentY = e.touches[0].clientY;  // NEW
  const diffX = currentX - startX.current;
  const diffY = Math.abs(currentY - startY.current);  // NEW

  // If vertical scroll > 10px, mark as scrolled
  if (diffY > 10) {                        // NEW
    verticalScrolled.current = true;       // NEW
  }

  const limitedDiff = Math.max(-100, Math.min(100, diffX));
  setSwipeX(limitedDiff);
};

// Update onClick:
onClick={() => !isSwiping && swipeX === 0 && !verticalScrolled.current && onTap()}
```

**Files to Change:**
- `admin/src/pages/Leads.jsx` - SwipeableLeadCard component (lines 24-122)

---

### Bug #19 - Call Page Can't See Recommended Scripts ⚠️ MEDIUM PRIORITY
**Report:** "Page needs more padding on mobile can't see recommended scripts"
**Page:** `/calls`
**Device:** Android / Chrome (384x753)

**Investigation:**
- `CallList.jsx:370` has `pb-32` padding
- `CallList.jsx:486` has floating bottom bar with `fixed bottom-20`
- Script recommendation is rendered conditionally

**The Problem:**
The ScriptRecommendation component may be rendered below the visible area when:
1. Sticky header is tall
2. Card content is expanded
3. Multiple elements stacked

**Needs Builder Investigation:**
- Test on 384px width mobile viewport
- Check if ScriptRecommendation is visible when Call Prep panel is open
- May need to move script above sticky elements or add scroll-to

**Files to Check:**
- `admin/src/pages/CallList.jsx` - line 486+ (floating bar positioning)
- `admin/src/components/ScriptRecommendation.jsx` - position/visibility

---

### Bug #18 - Message Box Contrast Hard to See ⚠️ MEDIUM PRIORITY
**Report:** "Contrast on the message box at the top of this page is hard to see the text"
**Page:** `/calls`
**Device:** Android / Chrome (dark mode?)

**The Problem:**
In dark mode, some text elements may not have enough contrast. Need to check:
1. AI coaching message boxes
2. Priority badges with light backgrounds
3. Message preview text

**Investigation Needed:**
Check CallList.jsx for elements without `dark:` variants. Look for:
- `text-slate-500` without `dark:text-slate-400`
- Light backgrounds (`bg-slate-100`) without `dark:bg-slate-700`

**Files to Check:**
- `admin/src/pages/CallList.jsx` - message/coaching box styling

---

### Bug #13 - Lead Profile Dark Mode Incomplete ⚠️ MEDIUM PRIORITY
**Report:** "Lead profile page still has boxes without dark mode"
**Page:** `/leads/:id`

**Investigation:**
Found dark mode classes are present on main containers. Need to check nested components:

**Likely Problem Areas:**
1. Intel cards/sections
2. Activity history items
3. Notes/edit modals
4. Sequence status cards

**Files to Check:**
- `admin/src/pages/LeadProfile.jsx` - Nested component dark classes
- `admin/src/components/IntelCard.jsx` (if exists)
- Modal components used in LeadProfile

---

### Bug #14, #8 - Screenshot Capture Doesn't Work (DUPLICATE)
**Report:** "Screen capture on bug report doesn't work"
**Page:** Various

**Root Cause Analysis:**
`BugReportButton.jsx` uses `html2canvas` for screenshot capture.

**Evidence:**
- Line 23-24: Hides modal, captures body
- Line 27-31: Uses `html2canvas(document.body)`

**Possible Issues:**
1. `html2canvas` may not be installed in production
2. Cross-origin content (images, fonts) may block capture
3. Certain CSS properties not supported

**Investigation Needed:**
1. Check if `html2canvas` is in `admin/package.json` dependencies
2. Test screenshot capture in different scenarios
3. Check browser console for errors during capture

**Fallback Option:**
Change to "Upload Screenshot" instead of capture - user takes manual screenshot and uploads via file input.

---

### Bug #6 - "No Active Sequences" Shows When Sequences Started
**Report:** "It says no active sequences although I've started 2"
**Page:** `/playbook`

**Root Cause Analysis:**
The `SequenceQueue.jsx` fetches enrollments with `status: 'active'`.

**Possible Causes:**
1. Enrollments are in 'pending' or 'paused' status, not 'active'
2. API query doesn't match actual enrollment status
3. Frontend filter defaults to 'due_today' which may exclude enrollments

**Evidence:**
- `SequenceQueue.jsx:26` - Default filter is `'due_today'`
- `SequenceQueue.jsx:32-35` - Adds `due_today: 'true'` param to query

**Investigation Needed:**
1. Query database for the user's enrollments - check actual status
2. Check if sequences that were "started" have status='active' or status='pending'
3. Test with filter='all' instead of 'due_today'

**Likely Fix:**
The enrollment might be created but not yet active (scheduled for future). Change default filter to 'all' or add "Scheduled" section.

---

## SECTION 3: FEATURE REQUESTS (NOT BUGS) 💡

These are reported as "bugs" but are actually feature enhancement requests.

### Bug #20 - Inbox Lead Selection for Sequences
**Request:** "Should I be able to see list of lead messages and pick a lead and put them on a specific [sequence]"

**This is a feature request for:**
- Select multiple leads from inbox
- Bulk enroll in sequence

**Recommendation:** Move to feature queue, not a bug fix.

---

### Bug #17 - Speech-to-Text for Bug/Feature Buttons
**Request:** "The bug report button should have a speech to text option"

**This is a feature request for:**
- Voice input on bug report modal
- Voice input on feature request modal

**Implementation if desired:**
Use Web Speech API (same as VoiceAssistant) for description field.

---

### Bug #16 - Messages Page Deep Investigation
**Request:** "What does a top 0.1% messages page look like? Do a deep investigation."

**This is not a bug - it's a UX audit request.**

**Recommendation:**
Create separate UX audit task for Messages page comparison with best-in-class CRMs.

---

### Bug #2 - AI Sequence Recommendation
**Request:** "Should AI recommend if you should put person on SMS sequence and give a 1 button option?"

**This is a feature request for:**
- AI suggestion to enroll leads in sequences
- One-click enrollment from suggestion

**Note:** Partial implementation may exist in CallOutcomeSheet/PostCallSummarySheet.

---

### Bug #1 - Post-Call No-Answer Sequence Option
**Request:** "Does not give me the option to activate when I press no answer in the post call data sheet"

**Status:** POTENTIALLY FIXED

**Evidence from SYSTEM-INTEL.md:**
- Session 21: "Sequence toggle missing in PostCallSummarySheet - Added (parity with CallOutcomeSheet)"
- Auto-enrollment on no-answer added to calls.js backend

**Investigation Needed:**
Verify PostCallSummarySheet shows sequence toggle. May be a stale report.

---

## SECTION 4: ACTION PLAN FOR BUILDER

### Phase 1: Close Fixed Bugs
Close bugs #15, #11, #10, #9, #5, #4, #3 as FIXED.

### Phase 2: Fix Remaining Bugs (Priority Order)
1. **Bug #7** - Leads swipe/scroll fix (HIGH - users accidentally calling)
2. **Bug #18** - Dark mode contrast on CallList
3. **Bug #13** - Lead Profile dark mode gaps
4. **Bug #19** - Script visibility on mobile CallList
5. **Bug #6** - Sequences showing "no active"
6. **Bug #14/#8** - Screenshot capture

### Phase 3: Convert to Feature Requests
Move bugs #20, #17, #16, #2 to feature queue.

### Phase 4: Verify Fixed
Retest bug #1 to confirm sequence option appears in PostCallSummarySheet.

---

## Database Commands for Builder

### Close fixed bugs:
```sql
UPDATE dev_queue
SET status = 'closed', completed_at = NOW(), cc_notes = 'Verified fixed in code'
WHERE id IN (15, 11, 10, 9, 5, 4, 3);
```

### Convert to feature requests:
```sql
UPDATE dev_queue
SET type = 'feature', cc_notes = 'Reclassified as feature request'
WHERE id IN (20, 17, 16, 2);
```

---

## Notes for QA

After Builder fixes:
1. Test Bug #7 on iPhone Safari - scroll leads list, verify no accidental calls
2. Test dark mode on all pages - LeadProfile, CallList, Messages
3. Test sequence enrollment shows in SequenceQueue
4. Test screenshot capture in BugReportButton

---

## Summary

| Category | Count | IDs |
|----------|-------|-----|
| Already Fixed | 7 | #15, #11, #10, #9, #5, #4, #3 |
| Needs Fix | 6 | #7, #19, #18, #13, #14/#8, #6 |
| Feature Request | 4 | #20, #17, #16, #2 |
| Verify Fixed | 1 | #1 |
| **Total** | **19** | |

---

---

## SECTION 5: SLACK-ONLY FINDINGS (Not in dev_queue)

These issues came from Slack #growth-alerts but weren't in the formal bug queue.

### NEW BUG: Failed SMS Still Advances Sequence ⚠️ HIGH PRIORITY
**Source:** Slack message (not numbered)
**Report:** "Failed SMS still advances sequence"

**ROOT CAUSE FOUND:** `src/jobs/sequenceProcessor.js:450-451`
```javascript
// Don't pause on failure - just skip to next step
// This prevents one bad phone number from blocking the whole sequence
```

The behavior is **intentional but wrong**. When SMS fails, code advances to next step instead of retrying.

**Fix Required:**
Change lines 447-474 to:
1. Track `failed_attempts` count on enrollment
2. On failure: increment failed_attempts, DON'T advance
3. If failed_attempts >= 3: pause enrollment + send Slack alert
4. Next run will retry same step (within 24h window)

**Schema Change Needed:**
```sql
ALTER TABLE sequence_enrollments
ADD COLUMN IF NOT EXISTS failed_attempts INTEGER DEFAULT 0;
```

**Expected Behavior After Fix:**
- Failed SMS → retry up to 3 times
- 3 failures → pause enrollment + alert
- Successful send → reset failed_attempts, advance

**Files to Change:**
- `src/jobs/sequenceProcessor.js` - Add retry logic
- Migration for `failed_attempts` column

---

### PERFORMANCE: LCP 7579ms (Target <2500ms) ⚠️ CRITICAL
**Source:** Daily Quality Audit (Jan 23, 2026)

**The Problem:**
Largest Contentful Paint is 3x slower than target. Users wait 7.5 seconds for page to become usable.

**Likely Causes:**
1. Large bundle size (check if code splitting working)
2. Blocking API calls on page load
3. Large images without lazy loading
4. Too many React re-renders

**Investigation Needed:**
1. Run Lighthouse audit on production
2. Check Network tab for slow resources
3. Review React Query cache settings
4. Check if skeleton loaders are appearing

---

### PERFORMANCE: CLS 0.277 (Target <0.1) ⚠️ HIGH
**Source:** Daily Quality Audit

**The Problem:**
Cumulative Layout Shift is 2.8x target. Content jumping around as page loads.

**Likely Causes:**
1. Images without width/height
2. Fonts loading late causing text reflow
3. Dynamic content inserted above existing content
4. Skeleton loaders wrong size

**Investigation Needed:**
1. Check for `<img>` tags without dimensions
2. Add `font-display: swap` or preload fonts
3. Reserve space for dynamic cards/modals

---

### Quality Audit Confirms: 0 Active Sequences
**Source:** Daily Quality Audit

**Evidence:**
- "Sequences API: 0 sequences found"
- "SMS Sequences: 0 active sequences"

This confirms **Bug #6** - either:
1. No sequences exist in database (need seeding)
2. RLS blocking the audit query
3. Sequences are all `is_active: false`

**Action:** Check sequences table state via Supabase

---

## UPDATED PRIORITY ORDER

1. **Bug #7** - Leads scroll triggers call (users calling accidentally)
2. **NEW: Failed SMS advances sequence** (data integrity)
3. **PERF: LCP 7.5s** (usability)
4. **Bug #18** - Dark mode contrast
5. **Bug #13** - Lead Profile dark mode
6. **PERF: CLS 0.28** (UX polish)
7. **Bug #19** - Script visibility
8. **Bug #6** - Sequences not showing
9. **Bug #14/#8** - Screenshot capture

---

**Plan Ready for Builder: Yes**
**Blockers: None**
