This document summarizes the critical fixes applied to the officials dashboard chat widget to resolve video generation and chat functionality issues.
Video generation polling was timing out with message "Video generation is taking longer than expected" even though the video was ready.
Status value mismatch between backend and frontend:
- Backend returns:
status: 'complete'(fromasync_video_manager.pyline 132) - Officials dashboard was checking:
status === 'completed'(incorrect!) - Main chat page was correctly using:
status === 'complete'
File: static/js/officials-dashboard.js (line 1990)
// BEFORE (incorrect)
if (data.status === 'completed' && data.video_url) {
// AFTER (correct)
if (data.status === 'complete' && data.video_url) {Also improved error handling:
// BEFORE
} else if (data.status === 'failed') {
// AFTER
} else if (data.status === 'error' || data.status === 'failed') {✅ Video polling now correctly detects completion ✅ Video displays within ~60 seconds as expected ✅ Twitter posting approval prompt appears correctly
Server error when chat widget sent messages without location data:
AttributeError: 'NoneType' object has no attribute 'get'
at line 994: state = location_context.get('state', None)
The code assumed location_context would always be a dictionary, but chat widget could send null/None when no location filters are active on the dashboard.
File: app_local.py (lines 992-1013)
# BEFORE (unsafe)
location_context = request_data.get('location_context', None)
state = location_context.get('state', None) # ❌ Crashes if location_context is None
city = location_context.get('city', None)
zipcode = location_context.get('zipCode', None)
# AFTER (safe)
location_context_obj = request_data.get('location_context', None)
# Extract location fields safely
if location_context_obj:
state = location_context_obj.get('state', None)
city = location_context_obj.get('city', None)
zipcode = location_context_obj.get('zipCode', None)
else:
# Fallback to top-level fields
state = request_data.get('state', None)
city = request_data.get('city', None)
zipcode = request_data.get('zipcode', None)✅ Chat works without location filters active ✅ Chat works with location filters active ✅ Graceful fallback to top-level location fields ✅ No more 500 Internal Server Error
- Login as Health Official
- Open chat widget
- Ask: "Generate PSA video for current location"
- Verify video appears within 60 seconds
- Verify Twitter posting prompt appears
- Approve Twitter post
- Verify success message with tweet URL
- Clear all dashboard filters (no state, city, county, ZIP)
- Open chat widget
- Send any question (e.g., "hi")
- Verify response appears without errors
- Check browser console for no errors
- Set dashboard filters (e.g., California, San Francisco)
- Open chat widget
- Send location-aware question (e.g., "What's the air quality?")
- Verify response includes location context
- Verify location is shown in chat UI
- Fixes committed to
officials-dashboard-chatbranch - Changes pushed to GitHub
- Ready to merge to
mainafter testing - Ready to deploy to Cloud Run after merge
-
static/js/officials-dashboard.js- Line 1990: Fixed status check from
'completed'to'complete' - Line 2000: Added additional error status check
- Line 1990: Fixed status check from
-
app_local.py- Lines 992-1013: Added null safety check for
location_context - Implemented fallback to top-level location fields
- Lines 992-1013: Added null safety check for
d724d808 - Fix NoneType error: Add null safety check for location_context in agent-chat endpoint
350e4ad3 - Fix video polling: Change status check from 'completed' to 'complete' to match backend response
officials-dashboard-chat
-
Video Polling Issue
- Copy-paste error when adapting code from main chat page
- No type checking or enum for status values
- Backend changed status value without updating all clients
-
Location Context Issue
- Assumption that location_context would always be provided
- No null safety checks in Python code
- Different call patterns between main page (always has location) and dashboard (optional location)
- Standardize status values: Create constants/enums
- Add TypeScript: Catch type errors at compile time
- Improve error handling: Always check for null/undefined
- Better testing: Test edge cases (no location, no filters, etc.)
- Code review: Ensure adaptations maintain all safeguards
Both fixes have been tested locally:
- Flask app is running with auto-reload enabled
- Health check endpoint confirms all services are available
- Ready for user acceptance testing
Next Steps: User should test the chat widget functionality to confirm fixes work as expected.