Skip to content

Fix windows bug#19

Merged
filippostanghellini merged 17 commits intomainfrom
fix/windows-bug
Dec 15, 2025
Merged

Fix windows bug#19
filippostanghellini merged 17 commits intomainfrom
fix/windows-bug

Conversation

@filippostanghellini
Copy link
Copy Markdown
Owner

Description

This PR fixes the silent crash on Windows and macOS when starting the bundled application. The root cause was missing torch.cuda module in PyInstaller bundle and lack of proper multiprocessing.freeze_support() handling for frozen apps.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🎨 Code style update (formatting, renaming)
  • ♻️ Code refactor (no functional changes)
  • ⚡ Performance improvement
  • ✅ Test update
  • 🔧 Configuration change
  • 🏗️ Build/CI update

Related Issues

Fixes #18

Changes Made

  • Added multiprocessing.freeze_support() for PyInstaller-bundled apps compatibility
  • Added torch.cuda and related hidden imports to PyInstaller spec for proper bundling
  • Added collect_all("torch") to ensure all torch submodules are included
  • Added persistent file logging to platform-specific locations for debugging
  • Added native Windows error dialog on startup failures
  • Fixed Search button CSS jumping on hover
  • Added CI smoke tests for macOS, Windows, and Linux
  • Added push and pull_request triggers to build workflow for early testing
  • Improved multiprocessing handling with early child process detection

Testing

  • Existing tests pass locally
  • Added new tests for the changes
  • Manual testing performed

Test Coverage

  • Coverage before: 50%
  • Coverage after: 80%

Checklist

  • My code follows the project's code style (passes ruff check and ruff format)
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Screenshots (if applicable)

N/A - Bug fix for startup crash

Additional Context

The bug was reported by a Windows 11 25H2 user who experienced the app terminating silently within a minute of launch, with no visible window appearing. The fix ensures:

  1. Proper torch module bundling for all platforms
  2. Early detection and termination of multiprocessing child processes
  3. Logging to file for debugging when console is hidden
  4. User-friendly error dialogs on Windows

Deployment Notes

No special deployment considerations. The fix is backward compatible.

This update adds cross-platform smoke tests to the CI workflow for macOS, Windows, and Linux to verify that bundled apps start correctly and log output. The PyInstaller spec is updated to include torch.cuda and related hidden imports for proper bundling.
Copilot AI review requested due to automatic review settings December 15, 2025 14:54
@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 15, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes critical startup crashes on Windows and macOS for the bundled application. The root cause was missing PyTorch CUDA modules in the PyInstaller bundle and improper multiprocessing handling for frozen applications. The fix ensures proper bundling of all required torch modules, adds early multiprocessing child process detection, and implements comprehensive logging for debugging.

Key changes:

  • Added multiprocessing freeze support and early child process detection to prevent GUI windows from spawning in worker processes
  • Enhanced PyInstaller spec to bundle torch.cuda and torch.backends modules explicitly for all platforms
  • Added platform-specific file logging and Windows error dialogs for better debugging of startup issues
  • Fixed CSS hover effect on Search button to prevent layout jumping
  • Implemented comprehensive smoke tests for macOS, Windows, and Linux in CI workflow

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/docfinder/gui.py Added multiprocessing freeze_support, child process detection, platform-specific file logging, and Windows error dialogs
DocFinder.spec Added torch.cuda/backends modules collection and hidden imports; updated version to 1.1.2
src/docfinder/web/templates/index.html Fixed Search button hover effect to prevent translateY transform
src/docfinder/web/app.py Moved cleanup endpoint definition earlier in file for better organization
tests/test_web_app.py Added comprehensive test coverage for web API endpoints
tests/test_frontend.py Added tests for frontend template loading and routing
tests/test_cli.py Added comprehensive CLI command tests
.github/workflows/build-desktop.yml Added smoke tests for all platforms and push/pull_request triggers for early testing
CHANGELOG.md Documented all changes for version 1.1.2 release
src/docfinder/init.py Updated version to 1.1.2
pyproject.toml Updated version to 1.1.2
Comments suppressed due to low confidence (1)

tests/test_web_app.py:410

  • This test creates a directory in the user's home directory. If the test fails before reaching the cleanup in the finally block, the directory could be left behind. Consider using the tmp_path fixture or adding additional cleanup logic to ensure the directory is always removed.
                "updated": 0,
                "skipped": 0,
                "failed": 0,
                "processed_files": [],
            }

            response = client.post("/index", json={"paths": [str(test_dir)]})
            assert response.status_code == 200
            assert response.json()["status"] == "ok"
        finally:
            test_dir.rmdir()


class TestFrontendRouter:
    """Tests for the frontend HTML routes."""

    def test_index_page(self) -> None:
        """Returns HTML for index page."""
        response = client.get("/")
        assert response.status_code == 200
        assert "text/html" in response.headers["content-type"]
        assert "DocFinder" in response.text


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -212,7 +252,7 @@ if sys.platform == "darwin":
"CFBundleName": "DocFinder",
"CFBundleDisplayName": "DocFinder",
"CFBundleVersion": "1.1.1",
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a version mismatch: CFBundleVersion is set to "1.1.1" but CFBundleShortVersionString is set to "1.1.2". Both should be "1.1.2" to match the version being released in this PR.

Suggested change
"CFBundleVersion": "1.1.1",
"CFBundleVersion": "1.1.2",

Copilot uses AI. Check for mistakes.

# Include torch subpackages explicitly (required by transformers dynamic imports)
import torch
import os
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The os module is imported twice in this file - once at line 13 at the top of the file, and again here at line 48. Remove this redundant import statement.

Suggested change
import os

Copilot uses AI. Check for mistakes.
"""Get path to log file for debugging startup issues."""
if sys.platform == "win32":
# On Windows, use LOCALAPPDATA for logs
import os
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The os module is imported twice - once at the module level (line 27) and again here inside the function (line 51). The module-level import should be sufficient, so remove this redundant import.

Suggested change
import os

Copilot uses AI. Check for mistakes.
Comment on lines +369 to +379
def test_index_path_outside_home(self, tmp_path: Path) -> None:
"""Returns 403 for path outside home directory."""
# Try to access /etc which is definitely outside home
response = client.post("/index", json={"paths": ["/etc"]})
assert response.status_code == 403
assert "outside allowed directory" in response.json()["detail"]

@patch("docfinder.web.app._run_index_job")
def test_index_success(
self, mock_run_index: MagicMock, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests create files directly in the user's home directory, which could potentially interfere with existing files or leave test artifacts if the test fails. Consider using the provided tmp_path fixture instead to create test files in isolated temporary directories. This would make tests more robust and avoid polluting the user's home directory.

Copilot uses AI. Check for mistakes.
Comment on lines +260 to 261
pass
raise SystemExit(1)
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
pass
raise SystemExit(1)
# Ignore all exceptions here: if showing the error message box fails,

Copilot uses AI. Check for mistakes.
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 13.63636% with 76 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/docfinder/gui.py 0.00% 76 Missing ⚠️

📢 Thoughts on this report? Let us know!

@filippostanghellini filippostanghellini changed the title Fix/windows bug Fix windows bug Dec 15, 2025
@filippostanghellini filippostanghellini merged commit 9eda144 into main Dec 15, 2025
21 checks passed
@filippostanghellini filippostanghellini deleted the fix/windows-bug branch December 15, 2025 18:39
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.

[Bug]: program not running

3 participants