Skip to content

fix(electron): wait for Python detection output before resolving - #122

Merged
protocorn merged 1 commit into
protocorn:mainfrom
BitsRevenge:fix/python-detection-close-event
Nov 25, 2026
Merged

protocorn merged 1 commit into
protocorn:mainfrom
BitsRevenge:fix/python-detection-close-event

Conversation

@BitsRevenge

Copy link
Copy Markdown
Contributor

Pull Request

Description

Fixes a potential race condition in Python version detection during first-time setup.

Previously, runCommand() resolved on the child process's exit event, which can occur before stdout and stderr have been fully read. This could cause Python detection to receive an empty version output even when Python 3.11+ is installed.

The change waits for the close event and improves Python detection diagnostics to make failures easier to investigate.

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 refactoring
  • Performance improvement
  • Test coverage improvement

Related issue

Closes #114

Changes made

  • Changed runCommand() to resolve on close instead of exit, ensuring stdout and stderr streams have closed before returning the result.
  • Added an optional process-spawn dependency to enable deterministic child-process tests without changing normal runtime behavior.
  • Improved Python detection diagnostics to report the actual executable, exit code, and stderr on failures, including post-installation verification.
  • Added regression tests for delayed stdout/stderr, spawn errors, Python detection diagnostics, fallback paths, and successful detection.

Testing

  • Tested on Windows
  • Tested on macOS
  • Tested on Linux
  • Added/updated unit tests
  • Ran existing test suite
  • Manual testing performed

Test results

Child-process regression tests

node --test electron/lib/api-spawn.test.js

  • Original exit behavior: 2 failed, 1 passed.
  • Fixed close behavior: 3 passed, 0 failed.

The tests simulate a child process emitting exit before the final stdout/stderr data, confirming that the original implementation resolves too early.

Python setup diagnostics

node --test electron/lib/setup-diagnostics.test.js

  • 8 tests passed, 0 failed.
  • Covered failure diagnostics, incompatible versions, post-installation verification, fallback paths, and successful detection.

Existing Electron test suite

npm test

  • 44 tests passed, 0 failed.

These tests use simulated processes and setup dependencies. The original intermittent Linux AppImage issue was not reproduced manually.

Checklist

  • Code follows the project's style guidelines
  • 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
  • Any dependent changes have been merged and published

Screenshots

Not applicable — this change affects process handling and setup diagnostics rather than the user interface.

Additional notes

The original issue was intermittent and could not be consistently reproduced by QA.

This PR addresses the suspected exit/close race condition through a deterministic regression test and adds diagnostic logging to make future Python detection failures easier to investigate.

The normal child-process spawning behavior is preserved.

@protocorn protocorn left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks @BitsRevenge — this is a solid fix for #114, and we appreciate you picking it up.

Review of 6e78290988de6dc42528e7dfb4749089596b01a9

What's good

  • Switching runCommand() from 'exit' to 'close' is the right fix. 'close' fires after stdout and stderr have ended, so the version check no longer races a late Python 3.x line.
  • The optional spawnProcess hook keeps runtime behavior the same and lets the tests drive a fake child.
  • The tests cover the actual race (exit, then late stdout, then close), a non-zero exit with stderr, and a spawn error. Promise resolution is naturally one-shot, so a later close after error does not overwrite the result.
  • Diagnostics now log the real executable (not a hardcoded python --version), plus the exit code and stderr, including after winget/Homebrew install and on an incompatible version. That covers the Windows, macOS, and Linux probe paths.
  • CI on this head is green: Test and Electron MCP paths on Ubuntu and Windows, Electron renderer lint, Linux and Windows builds, and GitGuardian. The macOS build was skipped, which is the usual pattern here.

Notes (not blocking)

  • runCommand() still has no timeout, same as before this PR. That is fine for this fix.
  • This PR and #121 both add electron-ui/electron/lib/api-spawn.test.js from main. The api-spawn.js edits themselves should combine cleanly, but the new test file will conflict. After one of them is merged, the other will need a short rebase so both test suites are kept.

Verdict: Looks good to merge, pending Sahil.

(Clippy GitHub Maintainer Bot, an AI assistant helping maintain this repo.)

@protocorn
protocorn merged commit 6da76bc into protocorn:main Nov 25, 2026
9 checks passed
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.

Setup sometimes says "Python 3.11+ was not found" when it is installed (Retry finds it)

2 participants