fix: disable Rich Live transient mode on Windows to prevent PS 5.1 hang#2938
Open
mnriem wants to merge 1 commit into
Open
fix: disable Rich Live transient mode on Windows to prevent PS 5.1 hang#2938mnriem wants to merge 1 commit into
mnriem wants to merge 1 commit into
Conversation
d520ae6 to
d3fead3
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a Windows-specific hang in PowerShell 5.1 by disabling Rich Live(transient=True) cleanup behavior on win32, preventing deadlock during cursor restoration.
Changes:
- Set
transient=Falseon Windows for theLiveprogress UI inspecify init. - Set
transient=Falseon Windows for theLiveUI used by_console.select_with_arrows(). - Add regression tests to confirm the
win32platform guard remains present.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/commands/init.py |
Disables Live(transient=True) on Windows during init scaffolding progress rendering. |
src/specify_cli/_console.py |
Disables Live(transient=True) on Windows for the interactive arrow-key selection UI. |
tests/test_live_transient_windows.py |
Adds regression tests covering the Windows transient behavior and guarding against removal of the platform check. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 2
Comment on lines
+1
to
+16
| """Tests for Rich Live transient=False on Windows (GitHub issue #2927). | ||
|
|
||
| PowerShell 5.1's legacy console host does not support VT escape sequences | ||
| reliably. Rich's ``Live(transient=True)`` attempts cursor restoration on | ||
| exit, which hangs indefinitely on that console. The fix disables transient | ||
| mode when ``sys.platform == "win32"``. | ||
|
|
||
| These tests patch ``sys.platform`` and intercept the ``Live`` constructor | ||
| to verify the correct ``transient`` value reaches Rich. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest |
d3fead3 to
f71cb2f
Compare
PowerShell 5.1's legacy console host does not reliably support VT escape sequences. Rich's Live(transient=True) attempts cursor restoration on context exit, which hangs indefinitely on that console. Set transient=False when sys.platform == 'win32' in both init.py (progress tracker) and _console.py (select_with_arrows). The only cosmetic effect is that progress output remains visible after completion on Windows. Fixes #2927 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
f71cb2f to
984efd8
Compare
Comment on lines
+50
to
+60
| class TestSelectWithArrowsLiveTransient: | ||
| """Verify that select_with_arrows passes transient=False on Windows.""" | ||
|
|
||
| def test_transient_false_on_windows(self): | ||
| assert _invoke_select_with_arrows("win32") is False | ||
|
|
||
| def test_transient_true_on_linux(self): | ||
| assert _invoke_select_with_arrows("linux") is True | ||
|
|
||
| def test_transient_true_on_macos(self): | ||
| assert _invoke_select_with_arrows("darwin") is True |
Comment on lines
+73
to
+75
| init_src = Path(__file__).resolve().parent.parent / "src" / "specify_cli" / "commands" / "init.py" | ||
| content = init_src.read_text(encoding="utf-8") | ||
| assert '_transient = sys.platform != "win32"' in content |
Comment on lines
+79
to
+81
| console_src = Path(__file__).resolve().parent.parent / "src" / "specify_cli" / "_console.py" | ||
| content = console_src.read_text(encoding="utf-8") | ||
| assert '_transient = sys.platform != "win32"' in content |
|
|
||
| select_with_arrows({"a": "Option A", "b": "Option B"}, "Pick one", "a") | ||
|
|
||
| return captured.get("transient") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2927 —
specify inithangs indefinitely on Windows PowerShell 5.1 after writing files.Root Cause
Rich's
Live(transient=True)attempts cursor restoration via VT escape sequences when the context manager exits. PowerShell 5.1's legacy console host (conhost.exe) does not reliably support these sequences, causing the cleanup to deadlock.The hang occurs at line 297 of
init.pywhen theLiveblock exits — after all files have been written successfully but before "Project ready" prints.Fix
Set
transient=Falsewhensys.platform == "win32"in both locations that useLive(transient=True):src/specify_cli/commands/init.py— progress tracker during scaffoldingsrc/specify_cli/_console.py—select_with_arrows()interactive menuThe only cosmetic effect is that progress output remains visible after completion on Windows (not erased). No functional impact.
Tests
Added
tests/test_live_transient_windows.pywith 8 tests:transient=Falseonwin32transient=Trueonlinuxanddarwin