Skip to content

fix: migrate frontEnd PyQt6 enum scoping and add standalone chatbot launcher#578

Open
apurvafx wants to merge 5 commits into
FOSSEE:eSim-Chat-Bot-Semester-Long-Internship_Autumn-2025from
apurvafx:eSim-Chat-Bot-Semester-Long-Internship_Autumn-2025
Open

fix: migrate frontEnd PyQt6 enum scoping and add standalone chatbot launcher#578
apurvafx wants to merge 5 commits into
FOSSEE:eSim-Chat-Bot-Semester-Long-Internship_Autumn-2025from
apurvafx:eSim-Chat-Bot-Semester-Long-Internship_Autumn-2025

Conversation

@apurvafx

@apurvafx apurvafx commented Jun 16, 2026

Copy link
Copy Markdown

Related Issues

Relates to the chatbot module PyQt6 migration task under the FOSSEE eSim eSim AI Chatbot internship.

Purpose

  • PyQt6 Migration: The chatbot module (src/chatbot/ + src/frontEnd/Chatbot.py) had already been migrated to PyQt6 but the rest of the frontEnd (Application.py, DockArea.py, Workspace.py) was still on PyQt5, causing AttributeError crashes at runtime. The entire frontEnd has now been migrated to PyQt6 for compatibility.
  • User Experience Enhancement: Previously, users had to manually open separate terminals to run ollama serve and ollama pull to download required models before launching the chatbot. This setup has been automated to make the assistant completely ready on startup without requiring any terminal interaction.
  • Robustness & Security Fixes: Resolved critical robustness vulnerabilities in the core chatbot logic (including memory exhaustion, database data-loss risk, mic initialization crashes, and decompression bomb vulnerabilities) to prevent application hangs and data corruption.
  • Automated Verification: Added a comprehensive unit testing suite to the src/chatbot/tests/ module to assert the correct, secure, and robust behavior of all chatbot pipeline handlers.

Approach

1. Front-End PyQt6 Migration

Migrated all PyQt5-style unscoped enums to PyQt6 scoped equivalents across Application.py, DockArea.py, Workspace.py, and Chatbot.py covering:

  • AlignmentFlag, Orientation, WindowType, ScrollBarPolicy
  • TextElideMode, TextFlag, TextFormat
  • CursorShape, ItemDataRole, CheckState
  • QFrame.Shape/Shadow, QTextCursor.MoveOperation/MoveMode
  • QSizePolicy.Policy, QDialog.DialogCode, QMessageBox.StandardButton/Icon

2. Standalone Chatbot Launcher (Deprecated)

  • Added src/run_chatbot.py as a standalone launcher to verify the ChatbotGUI in isolation during the PyQt6 migration. Now that integration is complete and verified, this temporary test script has been removed.

3. Headless Ollama Auto-Start & Model Pulling

  • Background Headless Startup: Implemented start_ollama in src/chatbot/chatbot_thread.py to start the server headlessly (with the CREATE_NO_WINDOW flag on Windows) without spawning any terminal popups. Added fallback checks to search standard Windows installation directories if ollama is not in the system's PATH.
  • Sequential In-App Model Puller: Added a ModelPullWorker background thread that checks for missing required models (qwen2.5-coder:3b and nomic-embed-text) on startup and downloads them sequentially, displaying live percentage progress directly in the chatbot status bar.
  • Race Condition & Thread Safety Fixes: Cleaned up the initial models fetching race condition in Chatbot.py's constructor and resolved QThread signal naming conflicts (finished to result_ready) to ensure background booting threads exit and transition status safely.

4. Critical Security & Robustness Fixes

  • Knowledge Base (RAG):
    • Implemented paragraph streaming using a lazy reader generator to prevent Out-of-Memory (OOM) / DoS when parsing large text documents.
    • Restructured ingest_pdfs to perform atomic-like updates. All chunks/embeddings are computed in-memory first; database collection deletion and recreation only execute on 100% success to prevent data-loss.
  • Speech-to-Text (STT):
    • Bounded the recording queue size (maxsize=1000) and updated the audio callback to discard overflow frames silently, preventing memory exhaustion.
    • Wrapped the recording stream in a try-except block to gracefully handle missing/denied microphone hardware instead of crashing.
    • Secured JSON result decoding from the Vosk model against invalid/malformed JSON outputs.
  • Image Handler:
    • Configured a MAX_IMAGE_PIXELS = 10_000_000 limit and dimension check to guard against decompression bombs.
    • Integrated dimension violations into analyze_and_extract so they are surfaced cleanly as design errors in the GUI instead of causing backend OOM failures.

5. Automated Verification Suite

Added a dedicated testing module under src/chatbot/tests/ containing:

  • test_knowledge_base.py: Verifies non-destructive builds, memory-safe streaming, and relevance thresholds.
  • test_stt_handler.py: Verifies queue limits, graceful microphone exception handling, and safe JSON parsing.
  • tests_image_handler.py: Verifies decompression bomb detection and dimension validation constraints.
Screenshot 2026-06-18 155840 Screenshot 2026-06-18 160125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant