You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(session-flow): _pid_alive must not assume a fixed decoder for tasklist output #1512
Follow-up from #1496 (merged as 9175ce6b). Found during independent verification of that PR, not a regression it introduced.
What
_pid_alive calls tasklist with encoding="utf-8". tasklist's piped output follows the console output code page, which is not always UTF-8. Measured on this machine, same command, same session:
GetOEMCP=437, GetACP=1252, and two shells in the same session genuinely differ (PowerShell reports 65001, the Bash-tool console reports 437). So a hardcoded oem would be wrong in the opposite direction — neither fixed decoder is correct everywhere.
Why this is low priority, not a bug today
#1496 added errors="replace", which closes the crash path. Before it, a CP437 console plus a process name containing ü (CP437 0x81, undefined in cp1252) produced:
OLD (text=True, no encoding) -> TypeError: argument of type "NoneType" is not a container or iterable
NEW (utf-8/replace) -> ok, match: True
The decode raised UnicodeDecodeError inside subprocess's reader thread, out.stdout came back None, and str(pid) in out.stdout then raised out of _pid_alive.
Because the predicate only matches ASCII digits, mojibake in a process name cannot change the answer — match: True under both code pages. It is a correctness smell, not a live defect.
Suggested fix
Either:
derive the decoder dynamically — cp{GetConsoleOutputCP()}, or
drop decoding entirely and match str(pid).encode("ascii") against the raw bytes.
The second is simpler and removes the code-page question from the call site altogether.
Related
No linked issue. Follow-up to #1496; #1483 is closed and prescribed encoding="utf-8" literally, so this supersedes that prescription rather than contradicting an open item.
This was generated by AI during work-loop execution.
Done (2026-07-26):_pid_alive no longer hardcodes encoding="utf-8" for tasklist's output. It now matches str(pid).encode("ascii") against the raw stdout bytes, sidestepping the console-output-code-page question entirely (the simpler of the two suggested fixes). Added/rewrote the PidAlive test class in test_observer.py to cover the no-fixed-decoder assertion, a CP437-mojibake process name, and a negative (PID-absent) match. Bumped session-flow to 0.17.9 with a CHANGELOG entry.
Activity
kyle-sexton commentedon Jul 26, 2026
kyle-sexton commentedon Jul 26, 2026
This was generated by AI during work-loop execution.
Done (2026-07-26):
_pid_aliveno longer hardcodesencoding="utf-8"fortasklist's output. It now matchesstr(pid).encode("ascii")against the rawstdoutbytes, sidestepping the console-output-code-page question entirely (the simpler of the two suggested fixes). Added/rewrote thePidAlivetest class intest_observer.pyto cover the no-fixed-decoder assertion, a CP437-mojibake process name, and a negative (PID-absent) match. Bumpedsession-flowto 0.17.9 with a CHANGELOG entry.Fixed in #1521 (will auto-close when it merges).