fix(cli): set SPT_NOENV only on Linux

SPT_NOENV only keeps the title out of /proc/PID/environ on Linux. On macOS
it confines the title to the argv area, where setproctitle drops the last
byte, and its import-time getproctitle() then fails to decode a command
line ending in a multibyte character, so every such CLI call crashed.

Fixes #6231
This commit is contained in:
cristianchiriac authored and chengyongru committed 2026-10-16 00:17:47 +08:00
1 parent 12e869d047
commit a148eabc9f
2 files changed
+29 -4

No files matched your search

+3 -3
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
import hashlib
import os
import sys
from pathlib import Path
from typing import Final
@@ -11,9 +12,8 @@ _ROLES: Final = {"agent", "gateway", "webui"}
def _set_process_title(title: str) -> None:
# Process titles are short; do not trade Linux /proc environment visibility for
# extra title storage. setproctitle reads this switch when it is imported.
os.environ.setdefault("SPT_NOENV", "1")
if sys.platform == "linux":
os.environ.setdefault("SPT_NOENV", "1")
from setproctitle import setproctitle
setproctitle(title)