Skip to content

fix: Enter key works in amplifier reset on Windows - #273

Merged
Brian Krabach (bkrabach) merged 1 commit into
mainfrom
fix/windows-reset-enter-key
Aug 18, 2026
Merged

fix: Enter key works in amplifier reset on Windows#273
Brian Krabach (bkrabach) merged 1 commit into
mainfrom
fix/windows-reset-enter-key

Conversation

@bkrabach

Copy link
Copy Markdown
Collaborator

The bug

In amplifier reset, the interactive checklist ignored Enter on Windows — pressing it just re-rendered the menu ("flash") and the reset never confirmed. Only [q] worked. Reported from a real Windows install.

Root cause

amplifier_app_cli/commands/reset_interactive.py, the Windows branch of _get_key(), compared msvcrt.getch() bytes against double-escaped byte literals:

if ch == b"\\xe0":          # 4 chars: backslash x e 0  — never a real keypress
if ch in (b"\\r", b"\\n"):  # 2 chars: backslash r      — never matches Enter
if ch == b"\\x03":          # backslash x 0 3

msvcrt.getch() returns the real byte b"\r" (0x0D) for Enter, which never equals the two-character sequence b"\\r". So Enter fell through to the ch.decode() catch-all, returned "\r", matched no branch in the checklist loop, and the menu simply re-rendered. [q] worked only because "q" is a plain byte needing no escape.

The POSIX branch was already correct (single-escaped "\r", "\x1b"), so POSIX users were never affected — this is Windows-only.

The fix

Single-escape the four literals. Also accept both 0x00 and 0xe0 as the arrow/function-key prefix (Windows uses either) and return "ESC" on an unrecognized prefix, mirroring the POSIX branch. Entirely within the sys.platform == "win32" branch — the POSIX path is byte-identical.

Evidence — native Windows 11, Python 3.14.3

Deterministic teeth test feeding _get_key() the real bytes msvcrt.getch() returns, baseline (main) vs fixed:

[BASELINE] platform=win32
    Enter(b'\r')  -> '\r'      ← not "ENTER": the reported bug
    Up(0xe0 H)    -> ''        ← arrows silently broken too
    VERDICT: Enter confirms + arrows navigate = False

[FIXED] platform=win32
    Enter(b'\r')  -> 'ENTER'
    Space(b' ')   -> ' '
    q             -> 'q'
    Up(0xe0 H)    -> 'UP'
    Up(0x00 H)    -> 'UP'
    VERDICT: Enter confirms + arrows navigate = True

The baseline reproduces the exact symptom (q works, Enter doesn't) and also reveals arrow-key navigation was broken by the same double-escape — invisible because the menu redrew identically.

Limits

One Windows machine, one Python version (3.14.3). No Windows CI leg on this repo yet.

The interactive reset checklist ignored Enter on Windows -- pressing it just
re-rendered the menu ("flash"), and the reset never confirmed. Only [q]
worked.

Root cause: the Windows branch of `_get_key()` compared `msvcrt.getch()`
bytes against DOUBLE-escaped byte literals:

    if ch in (b"\\r", b"\\n"):   # two chars: backslash + r
    if ch == b"\\xe0":            # four chars: backslash x e 0
    if ch == b"\\x03":            # backslash x 0 3

`msvcrt.getch()` returns the real byte `b"\r"` (0x0D) for Enter, which never
equals the two-character sequence `b"\\r"`. So Enter fell through to the
`ch.decode()` catch-all, returned "\r", matched no branch in the checklist
loop, and the menu simply re-rendered. `[q]` worked only because "q" is a
plain byte needing no escape.

The POSIX branch was already correct (single-escaped `"\r"`, `"\x1b"`), so
this was Windows-only -- POSIX users were never affected.

Fix: single-escape the four literals. Also accept both `0x00` and `0xe0` as
the arrow/function-key prefix (Windows uses either) and return "ESC" on an
unrecognized prefix, mirroring the POSIX branch. Change is entirely within
the `sys.platform == "win32"` branch; the POSIX path is byte-identical.

Proven on native Windows 11: Enter confirms, space toggles, arrows navigate,
q quits.

🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
@bkrabach
Brian Krabach (bkrabach) merged commit 60eda4d into main Aug 18, 2026
9 checks passed
@bkrabach
Brian Krabach (bkrabach) deleted the fix/windows-reset-enter-key branch August 18, 2026 17:24
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.

2 participants