Skip to content

fix(chatbot): patch windows startup crashes, sqlite thread segfaults, and clipboard temp images#570

Open
TaherBatterywala wants to merge 1 commit into
FOSSEE:eSim-Chat-Bot-Semester-Long-Internship_Autumn-2025from
TaherBatterywala:eSim-Chat-Bot-Semester-Long-Internship_Autumn-2025
Open

fix(chatbot): patch windows startup crashes, sqlite thread segfaults, and clipboard temp images#570
TaherBatterywala wants to merge 1 commit into
FOSSEE:eSim-Chat-Bot-Semester-Long-Internship_Autumn-2025from
TaherBatterywala:eSim-Chat-Bot-Semester-Long-Internship_Autumn-2025

Conversation

@TaherBatterywala

Copy link
Copy Markdown

This PR addresses and resolves critical stability issues, performance bottlenecks, and resource leaks within the eSim AI Copilot / Chatbot module on Windows. The changes ensure a stable startup experience, prevent backend crashes during queries, make the interface highly responsive, and clean up temporary storage leaks on the filesystem.


Key Fixes

1. Windows Startup Crashes (Missing Configuration Files)

  • Problem: On fresh Windows environments, the required configuration directories and config.ini files under library/config/ did not exist. The application encountered a traceback (No section: 'eSim') during initialization and closed instantly.
  • Solution: Integrated self-healing logic at import time in both Appconfig.py files. If directories or configurations are missing, they are dynamically generated with default parameters pointing to correct absolute paths relative to the project root.

2. PyQt5 / ChromaDB Threading Conflict (Memory Access Violations)

  • Problem: ChromaDB (using SQLite and native Rust engines) clashes with PyQt5's threading model on Windows, throwing an access violation segfault as soon as a query runs inside a background thread.
  • Solution: Wrapped ChromaDB client creation to be thread-local. Refactored the search workflow to dispatch database queries into an isolated subprocess using sys.executable. User queries and matching contexts are piped securely via standard streams using Base64 encoding to prevent encoding issues.

3. Chat Input Submission Lag

  • Problem: Running database searches synchronously on the main thread blocked the Qt event loop, creating a noticeable 1.5-second freeze whenever the user hit Enter.
  • Solution: Moved the subprocess database search entirely into the background QThread (OllamaWorker). The main thread remains fluid and renders the "thinking..." animation instantly.

4. Clipboard Image Disk Space Leaks

  • Problem: Screenshots pasted into the chatbot were saved under .esim/clipboard_images/ but never deleted, leading to storage leaks.
  • Solution: Designed a garbage collection routine (_cleanup_unused_clipboard_images) that matches folder contents against staged assets and active conversation contexts. This routine runs during:
    • Application startup and chatbot widget closure.
    • Image staging, model switches, and input clear events.
    • Chat session deletions (regex scans the target session's JSON file to locate and delete linked files before removing the session file).

Files Changed

  • src/configuration/Appconfig.py: Added self-healing configuration creation block.
  • nghdl/src/Appconfig.py: Added self-healing configuration block for NGHDL workspace config.
  • src/frontEnd/Application.py: Corrected Windows platform checks and propagated app close events to the chatbot widget.
  • src/chatbot/knowledge_base.py: Refactored database client connections to load lazily on a thread-local level.
  • src/chatbot/chatbot_thread.py: Refactored RAG search to execute in a thread-safe background subprocess.
  • src/frontEnd/Chatbot.py: Integrated image garbage collection hooks and reverted blocking main thread events.
  • .gitignore: Added exceptions to ignore local runtime config.ini files, .nghdl/ directory, local workspace.txt, and subfolder __pycache__ directories.

Verification and Testing

  1. Compilation Check: Verified all modified python files compile cleanly with py_compile.
  2. Startup & Recovery: Deleted the local .esim and .nghdl directories and verified the files automatically regenerated on launch.
  3. Threading & Stability: Sent multiple prompts, verifying that RAG search results stream back without crashes or freezes.
  4. Storage Cleanup: Tested adding screenshots, switching chats, deleting individual sessions, and closing the app. Verified that referenced files are successfully deleted from the .esim/clipboard_images/ directory.

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