loopx icon indicating copy to clipboard operation
loopx copied to clipboard

cp936 hosts: bundled extension providers fail on non-ASCII requests because they do not pin stdio to UTF-8

Open JasonBuildAI opened this issue 1 month ago • 0 comments

What happens

loopx.extensions.runtime speaks a byte-oriented JSON contract with a provider: it writes one UTF-8 JSON request to the provider's stdin and decodes one UTF-8 JSON object from the provider's stdout (_serialize_extension_request / _parse_extension_response). The provider runs as a separate ordinary interpreter, so its sys.stdin / sys.stdout fall back to the host locale codec - cp936 on a zh-CN Windows host - unless that process pins them.

The bundled OpenViking entrypoints never pin:

  • loopx/extensions/openviking_semantic_preference/provider.py -> json.load(sys.stdin)
  • loopx/extensions/openviking_periodic_report/provider.py -> json.load(sys.stdin) and json.dump(..., sys.stdout, ensure_ascii=False)
  • loopx/extensions/openviking_semantic_preference/history_export.py -> json.dump(..., sys.stdout, ensure_ascii=False)

The shipped CLI process was pinned in #6119 (loopx/entrypoint.py, _pin_utf8_stdio), but the entrypoints LoopX launches for the extension transport were not.

Reproduction (Windows, zh-CN, cp936)

Run the real semantic-preference provider as the transport launches it, with a UTF-8 request carrying non-ASCII text on stdin and PYTHONIOENCODING=gbk, PYTHONUTF8=0:

{"schema_version": "semantic_preference_provider_request_v0", "query": "中文偏好", "limit": 3}

Observed: exit 2, empty stdout, and OpenViking project peer provider failed: UnicodeDecodeError.

The same run with an ASCII query ("query": "ascii pref") exits 0 and returns the response JSON, so only the request encoding differs.

The same environment also breaks the other two entrypoints:

Entrypoint Observed failure
loopx.extensions.openviking_periodic_report.provider UnicodeDecodeError: 'gbk' codec can't decode byte 0xad
loopx.extensions.openviking_semantic_preference.history_export UnicodeEncodeError: 'gbk' codec can't encode character '\U0001f680'

The semantic-preference provider returns 2 for a valid request, so the extension records an unexplained provider failure instead of an actionable diagnostic.

Impact

On any host whose locale codec is not UTF-8 (zh-CN Windows cp936 being a common case), the OpenViking semantic-preference and periodic-report capabilities cannot serve a non-ASCII query or summary, and the history exporter cannot report a non-ASCII output path. ASCII-only payloads still work, which makes the failure look transient rather than deterministic.

Suggested fix

Pin the process's own stdio to UTF-8 at each entrypoint, reusing the existing loopx.entrypoint pin from #6119. PR follows.

AI disclosure

This issue was drafted with AI assistance at my request, under my direction and review.

JasonBuildAI avatar Oct 10 '26 19:10 JasonBuildAI