# Ask AI Button — Debug Session Notes (March 10, 2026)

## Problem
The Ask AI floating button is not visible on research pages (e.g., `/show/ceca3ef6a4c44e`).

## What We Fixed
- **Route Error**: `playground_activate_trial` route didn't exist in template line 2052
- **Fix Applied**: Changed `var trialUrl = "{{ path('playground_activate_trial') }}"` to `var trialUrl = subscribeUrl;`
- **Commit**: `ecff8fc5` pushed to production
- **Result**: Route error no longer appears in logs ✅

## Current Status: Button Still Not Rendering

### Confirmed Facts
1. **Template has button code**: `show.html.twig` line 1506 has Ask AI button
2. **Compiled cache has button code**: Line 3281 in `/var/cache/prod/twig/67/6720de8f2ff85e8730adb0eb17b4dfb7.php`
3. **No errors in prod.log**: After the fix, no CRITICAL/ERROR entries related to button
4. **Cache rebuilt**: Multiple `rm -rf var/cache/prod && cache:warmup` runs completed successfully
5. **HTML output missing button**: curl output (2735 lines) has 0 matches for `ask-ai`, `askAiFab`

### Suspicious Findings
- **citationModal also missing**: The `id="citationModal"` div (template line ~1384) is also NOT in HTML output
- **shareModalOverlay missing**: Expected since it's behind `{% if app.user %}`, but citationModal is NOT
- Both modals should render for all users (they're outside the auth conditional)

### Redirect Behavior
- `curl http://127.0.0.1/show/ceca3ef6a4c44e -H 'Host: shamra-academia.com'` returns a **redirect page** (11 lines)
- Need to use `-L` flag to follow redirect and get actual content
- Even with `-L`, full page renders but button section is missing

## Next Steps to Investigate

1. **Check for partial template rendering**
   - Look for `{% endblock %}` placement — maybe body block ends prematurely
   - Search for any `{% return %}` or early termination in the template
   
2. **Check block inheritance**
   - The template extends `all.html.twig` — verify `{% block body %}` isn't overridden elsewhere
   - Look for `{{ parent() }}` calls

3. **Check template conditionals around line 1384-1506**
   - There might be a `{% if ... %}` wrapping the missing content that evaluates to false
   - Look for `{% if research.someProperty %}` that might fail for this specific research

4. **Test a different research**
   - Try `/show/[another-slug]` to see if issue is specific to `ceca3ef6a4c44e`

5. **Enable Twig debug**
   - Temporarily set `twig.debug: true` in prod to see template blocks
   - Or add a visible marker like `<!-- ASK_AI_MARKER -->` right before the button

6. **Check PHP output buffering**
   - Unlikely, but check if there's ob_end_clean() or output truncation

## Files Involved

| File | Purpose |
|------|---------|
| `src/syndex/AcademicBundle/Resources/views/Research/show.html.twig` | Main research page template |
| `templates/all.html.twig` | Base template that show.html.twig extends |
| `translations/Ocr.ar.yml` / `Ocr.en.yml` | Button text translations |
| `var/cache/prod/twig/67/6720de8f2ff85e8730adb0eb17b4dfb7.php` | Compiled template |

## Commands for Tomorrow

```bash
# SSH to server
ssh -i shamramain_user.pem azureuser@20.241.4.71

# Test curl with redirect follow
curl -sL 'http://127.0.0.1/show/ceca3ef6a4c44e' -H 'Host: shamra-academia.com' | grep -c 'ask-ai'

# Check logs
tail -50 /var/www/html/academia_v2/var/log/prod.log | grep -i error

# Check template around button insertion point
grep -n -B5 -A5 'ask-ai-fab-container' /var/www/html/academia_v2/src/syndex/AcademicBundle/Resources/views/Research/show.html.twig

# Check what's at lines 1380-1520 in template (where citationModal + Ask AI should be)
sed -n '1380,1520p' /var/www/html/academia_v2/src/syndex/AcademicBundle/Resources/views/Research/show.html.twig
```

## Hypothesis
The button code exists but something between lines 1384-1738 is not being rendered. This could be:
- A conditional block that evaluates to false
- A block override in the parent template
- An unclosed tag causing HTML to be eaten
- A Twig error that's being silently caught somewhere
