Skip to content

fix(windows): patch platform._syscmd_ver to survive non-UTF-8 output under PEP 540 - #16

Closed
webtecnica wants to merge 2 commits into
mainfrom
fix/69413-windows-utf8
Closed

webtecnica wants to merge 2 commits into
mainfrom
fix/69413-windows-utf8

Conversation

@webtecnica

Copy link
Copy Markdown
Owner

Fixes NousResearch#69413

Description

Windows subprocess reader thread crashes on non-UTF-8 output when platform._syscmd_ver() calls subprocess.check_output with encoding='locale'.

Changes

File Change
hermes_bootstrap.py Added _patch_platform_syscmd_ver() function + module-level call
tests/test_hermes_bootstrap.py Added TestPatchPlatformSyscmdVer class (5 tests)

Test results

All 23 tests pass, 5 Windows-only skipped on Linux.

…large contexts (NousResearch#69424)

Three-pronged fix for the stale-stream detector killing connections
before a slow local/cloud model finishes prompt prefill:

1. Apply context-size scaling to local endpoints too
   The local-endpoint stale-timeout branch (default 900s) skipped the
   context-token scaling that the cloud path applied, so a 900s flat
   ceiling could still fire before a 122B model finishes prefilling
   140K+ tokens.  Move scaling out of the  branch so both local
   and cloud paths get proportional timeouts:
   - >200K tokens → 1800s (30 min)
   - >100K tokens → 1200s (20 min)
   - >50K  tokens → 600s  (10 min)

2. Add stale-streak backoff
   After 2+ consecutive stale kills, apply a progressive multiplier
   (1× → 2.5× → 4× … up to 10×) to the stale timeout so each retry
   waits longer, eventually outlasting the prefill and breaking the
   infinite retry loop.  Resets on successful response.

3. Raise the non-streaming stale timeout tiers consistently
   The non-streaming path () and
   Bedrock path () now share the same
   increased floors for consistency.

Closes NousResearch#69424.
…under PEP 540

On Windows with PYTHONUTF8=1 (PEP 540 UTF-8 mode),
platform._syscmd_ver() calls subprocess.check_output(...,
text=True, encoding='locale', shell=True) to run the Windows
'ver' command.  Under PEP 540, locale.getencoding() returns
'utf-8', but the 'ver' command emits output in the system's
active ANSI code page (cp1252 on US-English).  Bytes that are
valid in cp1252 but not in UTF-8 — e.g. 0xe9 (é) — raise a
UnicodeDecodeError inside the subprocess reader thread.

The patch wraps platform._syscmd_ver with a try/except that
catches UnicodeDecodeError and gracefully returns input defaults,
matching the existing OSError/CalledProcessError fallback that
_win32_ver already handles.

Fixes NousResearch#69413
@webtecnica

Copy link
Copy Markdown
Owner Author

This PR accidentally targets my own fork (webtecnica/hermes-agent) as base instead of upstream NousResearch/hermes-agent. The same work is already tracked in upstream PR NousResearch#69522 (closed), so this fork-side PR is redundant. Closing it to avoid duplication — the branch remains available in the fork if needed.

@webtecnica webtecnica closed this Aug 25, 2026
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.

Windows subprocess reader thread crashes on non-UTF-8 output

1 participant