The application actually succeeded in the final run (lines 620-652 in backend logs), but there were several issues that caused problems earlier:
Problem: All data is stored in Python dictionaries in memory:
questions_store- stores uploaded questionsprocess_statuses- tracks processing progressvisualizations_store- stores generated visualizations
Impact:
- When the backend server restarts, all data is lost
- Questions become "not found" after restarts (lines 250, 256, 419-420, 422-423)
- Process IDs become invalid after restarts
- This is why you see "Question not found" errors after server restarts
Evidence from logs:
18:01:13 | WARNING | Question not found: be71e3a7-af85-45da-b66a-80fbce49c5a9
18:02:44 | WARNING | Question not found: dff81407-b059-49d7-aca7-8f41b923c741
Problem:
- Initially had invalid OpenAI API key
- User exported key in terminal:
export OPENAI_API_KEY=...(line 228, 563) - This is not persistent - key is lost when terminal closes
Impact:
- API calls fail with 401 errors when key is missing/invalid
- Need to re-export key every time server restarts
Solution: Create .env file in backend/ directory with:
OPENAI_API_KEY=your_key_hereProblem:
- Frontend uses Next.js rewrites to proxy
/api/*→http://localhost:8000/api/* - "Socket hang up" errors occur when:
- Backend restarts (due to code changes with
--reload) - Backend crashes during processing
- Network timeout
- Backend restarts (due to code changes with
Evidence from logs:
Failed to proxy http://localhost:8000/api/process/fe5c9f48-63f0-44fe-b340-dd49dfa48b36
Error: socket hang up
Impact:
- Frontend loses connection to backend during processing
- Progress polling fails
- User sees errors even though backend might be working
Problem:
- Backend uses
--reloadflag which restarts on code changes - Multiple restarts visible in logs (lines 130-227, 395-227, etc.)
- Each restart loses all in-memory data
Impact:
- Questions uploaded before restart are lost
- Process IDs become invalid
- Frontend polling fails because process_id no longer exists
Problem:
- Frontend polls every 2 seconds for progress
- After 5 consecutive errors, it stops polling (line 127 in preview/page.tsx)
- Doesn't handle backend restarts gracefully
Impact:
- If backend restarts during processing, frontend gives up after 10 seconds
- User sees error even if backend is working again
The final run was successful (lines 620-652):
- ✅ Question uploaded successfully
- ✅ Question analysis completed (Type: coding, Subject: Data Structures and Algorithms)
- ✅ Story generated successfully ("The Fusion of Crystal Streams")
- ✅ HTML visualization generated (2060 characters)
- ✅ Pipeline completed successfully
- ✅ Visualization stored with ID:
ec1fe1df-d422-4439-a004-76a4dc397edb
- No persistent storage - Everything in memory
- API key not in .env file - Must be exported manually
- Development server restarts - Loses all data
- Frontend doesn't handle backend restarts - Gives up too quickly
- Create
.envfile inbackend/directory with API key - Add better error handling in frontend for connection issues
- Add retry logic for progress polling
- Add database (SQLite for dev, PostgreSQL for prod) instead of in-memory storage
- Add health check endpoint for frontend to detect backend availability
- Add connection retry logic in frontend
- Consider using Redis for process status tracking (survives restarts)
- Create
.envfile with valid API key - Test the successful flow (it worked in the last run!)
- Consider adding persistent storage for production use
- Improve frontend error handling and retry logic