GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@simin-yuan

@simin-yuan simin-yuan commented Nov 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #15

Description

Ten subprocess.run(..., capture_output=True, text=True) calls in src/nexus_memory/ 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, stderr=None — no exception in the caller. Downstream, four error paths then crashed on that None (AttributeError: 'NoneType' object has no attribute 'strip', one TypeError on out[:200]), one reported the wrong reason, and five silently lost the child's message.

Reachable with plain git on a Chinese Windows install: a non-ASCII commit message is UTF-8 on the wire, and the parent decodes it as cp936. Also reachable today with PYTHONUTF8=1 for icacls (OEM code page) and for every child, once UTF-8 mode becomes the default in 3.15 (PEP 686).

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would break existing functionality)
  • Documentation update
  • Dependency update

What changed

Each call site now names the encoding its child actually writes, and every call falls back to errors="replace" so a wrong guess degrades to a few mangled characters instead of None:

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.

Checklist

  • Tests pass locally (pytest tests/ -v)
  • Code is typed and passes ruff check . (no new findings: the six touched files report the same 248 findings before and after, all pre-existing)
  • No print() debugging (uses logging where needed)
  • Documentation updated (README, docstrings, or docs/) if needed — not needed; the docstrings of the touched functions already describe the contract
  • Changelog updated under [Unreleased]
  • I have followed the contributing guidelines

How has this been tested?

  • Unit tests
  • Manual test on a Chinese Windows install (cp936), which CI cannot cover

Regression tests — tests/test_subprocess_decoding.py

Each 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".

Real-world verification on a Chinese Windows install

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

CI note

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.

Full suite

Python 3.11, clean environment, complete clone:

  • this branch: 11 failed, 2470 passed, 56 skipped (993.46s)
  • unmodified 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@simin-yuan
simin-yuan force-pushed the fix/subprocess-decoding branch 2 times, most recently from f8291ff to 3dd6a59 Compare November 1, 2026 18:01
@simin-yuan
fix: decode subprocess output with the encoding each child actually w…
a63830f
…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
@simin-yuan
simin-yuan force-pushed the fix/subprocess-decoding branch from 3dd6a59 to a63830f Compare November 1, 2026 18:25
@Neboy72
Neboy72 merged commit f0676fc into Neboy72:main Nov 1, 2026
0 of 2 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Neboy72 added a commit that referenced this pull request Nov 1, 2026
@Neboy72
chore(release): 0.22.45
989dbe3
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).
Neboy72 added a commit that referenced this pull request Nov 16, 2026
@Neboy72
Merge PR #16: decode subprocess output with the encoding each child w…
200bdd1
…rites

Patch and tests by Simin Yuan (@simin-yuan). Windows: child output the parent locale cannot decode no longer becomes None.

Fixes #15.
Neboy72 added a commit that referenced this pull request Nov 16, 2026
@Neboy72
chore(release): 0.22.45
bf18f7b
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).
Neboy72 added a commit that referenced this pull request Nov 17, 2026
@Neboy72
Merge PR #16: decode subprocess output with the encoding each child w…
2450fce
…rites

Patch and tests by Simin Yuan (@simin-yuan). Windows: child output the parent locale cannot decode no longer becomes None.

Fixes #15.
Neboy72 added a commit that referenced this pull request Nov 17, 2026
@Neboy72
chore(release): 0.22.45
9232b28
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Subprocess output decoding breaks on non-UTF-8 Windows locales: error paths raise AttributeError

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@simin-yuan @Neboy72
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.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.