GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix: decode subprocess output with the encoding each child actually writes by simin-yuan · Pull Request #16 · Neboy72/nexus-memory Conversation
|
| Child | Sites | Encoding |
|---|---|---|
git |
mcp_server update tool |
encoding="utf-8" |
bash (install scripts) |
setup._install_plugin, serve_daemon.ensure_serve_daemon |
encoding="utf-8" |
icacls |
env_secret_store._restrict_windows_acl |
encoding="oem" (Windows console programs write the OEM code page) |
child python / pip |
wizard._ensure_package ×2, chat_wizard, mcp_server update tool |
env={**os.environ, "PYTHONIOENCODING": "utf-8"} + encoding="utf-8" |
systemctl |
serve_daemon unit check |
encoding="utf-8" |
The four None-crashing error paths also read the value with (proc.stderr or proc.stdout or ""), so a mis-detected encoding reports the failure instead of replacing it with an AttributeError. wizard._run_cmd now returns "" instead of None, which is what its tuple[int, str, str] annotation already promised.
No behaviour change for any locale that already decoded successfully.
I left the engine pin alone: plugins/memory/nexus/pyproject.toml and plugins/memory/nexus/__init__.py still name cc83c82, so the pin is yours to move at merge — the way the guardrail fix was pinned in bf50e92 after it landed.
pytest tests/ -v)ruff check . (no new findings: the six touched files report the same 248 findings before and after, all pre-existing)print() debugging (uses logging where needed)[Unreleased]cp936), which CI cannot covertests/test_subprocess_decoding.pyEach test drives a real function with a child that prints a readable install-marker and then writes b"\xff\xfe" (invalid UTF-8 and not a valid GBK sequence), so the guard fails on any platform before this change, not only on a non-UTF-8 locale. Three guard tests:
| Test | Guards |
|---|---|
test_run_cmd_returns_text_for_undecodable_output |
wizard._run_cmd returns strings, never None |
test_plugin_install_reports_script_failure_instead_of_losing_it |
setup._install_plugin reports failed + the script's own message; before, the outer except Exception swallowed it as error: "'NoneType' object has no attribute 'strip'" |
test_ensure_serve_daemon_returns_failure_instead_of_raising |
the failure report carries the script's own output (install_serve.sh failed (rc=1) and the install-marker the fake script prints); before, Windows raised AttributeError and Linux reported the codec error instead |
Same test file, same interpreter (3.11), same clean environment (env -u PYTHONUTF8 -u PYTHONIOENCODING), run on unmodified main and on this branch:
| Where | main (6f18173) |
this branch |
|---|---|---|
Windows 11, Chinese locale (cp936), this machine |
3 failed | 3 passed |
Ubuntu (GitHub Actions, ubuntu-latest, Python 3.11) — run 41336521533 |
3 failed | 3 passed |
The two platforms lose the detail in different ways, and both are covered by the third test: on Linux the same input raises UnicodeDecodeError inside subprocess.run and the caller's except Exception reports that codec text; on Windows it surfaces as AttributeError from (proc.stderr or proc.stdout).strip(). Either way the user loses the failure detail, so this is not limited to CJK Windows installs — any platform loses the child's message whenever its output is not valid in the parent's encoding.
icacls has no guard test: its failure is silent today (the decode fails, the ACL is still applied by the child, nothing is raised), so there is no observable to assert on besides the decoded text itself. Verified manually instead — on this machine, icacls under PYTHONUTF8=1 returns stdout=None with the old call and a correct Unicode path with encoding="oem".
| Check | Before | After |
|---|---|---|
git log -1 --format=%s with commit message 修复:中文提交信息, through wizard._run_cmd |
UnicodeDecodeError: 'gbk' codec can't decode byte 0xae, stdout=None |
decodes to the exact commit subject |
icacls <non-ASCII path> under PYTHONUTF8=1 |
stdout=None |
correct path text |
The Audit job stops on the first failure (pytest tests/ -q -x), and that failure is this:
FAILED tests/test_pin_chain_is_closed.py::test_chain_is_closed_no_engine_change_after_the_pin
the engine changed after the pin: ['src/nexus_memory/chat_wizard.py', 'src/nexus_memory/env_secret_store.py',
'mcp_server.py', 'serve_daemon.py', 'setup.py', 'wizard.py']
That is the un-pinned state of any engine change, not something specific to this patch: appending a single comment line to one file under src/ reproduces it on a clean checkout. Pinning it inside the PR only swaps this failure for test_engine_ref_is_reachable_from_a_remote_ref ("not reachable from origin/main"), so I left the pin to you.
Python 3.11, clean environment, complete clone:
main (6f18173): 10 failed, 2468 passed, 56 skipped (1366.94s)Ten of the eleven failures are identical between the two runs (diffing the sorted FAILED node-id lists leaves exactly one line) and are environmental on this machine — four resolve example.com into 198.18.0.0/15 through a fake-IP DNS, one shells out to a broken python3 on PATH, five depend on this machine's Windows locale setup.
The eleventh is test_pin_chain_is_closed.py::test_chain_is_closed_no_engine_change_after_the_pin: the pin still names cc83c82, so an unpinned engine change is reported. Any commit under src/ produces it — see the CI note below.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
f8291ff to
3dd6a59
Compare
…rites Ten `subprocess.run(..., capture_output=True, text=True)` calls decoded their child's output with the parent's preferred encoding and passed no `errors=`. When the child writes bytes that encoding cannot represent, CPython's reader thread raises and the call returns `returncode=0` with `stdout=None` — no exception in the caller. On a Chinese Windows install (`cp936`) a plain `git log` whose commit message is not ASCII is enough; in UTF-8 mode (`PYTHONUTF8=1`, the default from 3.15) the same happens to `icacls`, which writes the OEM code page. Four error paths then crashed on that None (three `AttributeError` on `.strip()`, one `TypeError` on `out[:200]`), `setup._install_plugin` reported "'NoneType' object has no attribute 'strip'" instead of the script's message, and five sites silently lost the child's output. Each call site now names its child's encoding — UTF-8 for `git`/`bash`, `oem` for `icacls`, `PYTHONIOENCODING=utf-8` for child Python — plus `errors="replace"` as a backstop, and the four error paths read `(proc.stderr or proc.stdout or "")`. Fixes Neboy72#15
3dd6a59 to
a63830f
Compare
There was an error while loading. Please reload this page.
Bumps the version across manifest, engine, plugin metadata, README badge, release table and footer, and records both fixes of this release in the changelog: the dashboard label for points without a category, and the subprocess decoding fix contributed in #16 (Patch and tests by Simin Yuan).
…rites Patch and tests by Simin Yuan (@simin-yuan). Windows: child output the parent locale cannot decode no longer becomes None. Fixes #15.
Bumps the version across manifest, engine, plugin metadata, README badge, release table and footer, and records both fixes of this release in the changelog: the dashboard label for points without a category, and the subprocess decoding fix contributed in #16 (Patch and tests by Simin Yuan).
…rites Patch and tests by Simin Yuan (@simin-yuan). Windows: child output the parent locale cannot decode no longer becomes None. Fixes #15.
Bumps the version across manifest, engine, plugin metadata, README badge, release table and footer, and records both fixes of this release in the changelog: the dashboard label for points without a category, and the subprocess decoding fix contributed in #16 (Patch and tests by Simin Yuan).
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Subprocess output decoding breaks on non-UTF-8 Windows locales: error paths raise AttributeError
There was an error while loading. Please reload this page.