Skip to content

A Parent Pinned to UTF-8 Spawning a Python Child Leaves the Child's Encoder on the Locale #1577

Closed

Description

@ptr727

Problem

#1574 pins encoding="utf-8" on every text-mode subprocess call in this repository, so a parent decodes its child as UTF-8 on every host. Where that child is another Python interpreter, its own encoder is still the locale's, and the two sides now disagree on Windows in a way they did not before.

Before that change both sides took the locale codec, so they matched, whatever the locale was. After it the parent names UTF-8 while a redirected Python child on Windows writes its stdout in the ANSI code page, so any non-ASCII character the child prints comes back as a byte sequence the parent cannot decode.

Around fourteen call sites spawn sys.executable this way, in host-setup/agent-safety/claude/test_install.py, scripts/tests/test_build_dist.py, scripts/tests/test_prose_lint.py and scripts/tests/test_spec_validate.py.

Evidence

Constructed, using an environment variable to stand in for a Windows ANSI host, since the fleet has no Windows runner:

subprocess.run([sys.executable, <a script that prints a path>],
               text=True, encoding="utf-8",
               env={..., "PYTHONIOENCODING": "cp1252"})
-> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9

The child prints a path holding a non-ASCII character, encodes it as cp1252, and the parent decodes as UTF-8.

Reach

A test run on a Windows host, which is the platform GOVERNANCE.md "Supported Development Platforms" declares supported and which nothing in CI exercises. A Linux run is unaffected, since both sides resolve to UTF-8 anyway.

One site in the tree already guards this, test_a_filename_that_is_not_utf8_is_scanned_and_reported in scripts/tests/test_prose_lint.py, by passing PYTHONIOENCODING=utf-8 to the child. So the mechanism is known and applied in one place rather than as a rule.

Suggested fix

Decide the rule, then apply it and assert it. A parent that pins its decoder and spawns a Python child owes that child the matching encoder, PYTHONIOENCODING=utf-8 being the one that reaches every output stream. scripts/tests/test_tooling_encoding.py asserts the parent half of this invariant already and is where the child half belongs.

Sibling of #1538. Found by a local review pass on #1574.

Activity

  1. ptr727 commented on Oct 8, 2026

    @ptr727
    OwnerAuthor

    Partly addressed by #2523, from the child's side: spec/validate.py now reconfigures its own stdout and stderr to UTF-8 at the top of main, as scripts/pr_review.py already did. A cp1252 regression case in tests/test_spec_validate.py pins it on every host. So the test_spec_validate call sites named here now decode cleanly on Windows. The full suite at develop's head passed on a Windows host from Git Bash (2245 tests, OK). The other named sites print nothing non-ASCII in the current suite, so this issue's general fix is still open: a child-side reconfigure, or PYTHONIOENCODING=utf-8 on the spawn.

  2. ptr727 commented on Nov 1, 2026

    @ptr727
    OwnerAuthor

    Decision needed (decision triage, 2026-11-01)

    Question: Should the fleet adopt and test a rule that a parent decoding a Python child's output as UTF-8 must pass PYTHONIOENCODING=utf-8 to that child, or is the child-side stdout reconfigure from #2523 (only in spec/validate.py and scripts/pr_review.py) enough?

    Options, recommended first:

    1. Adopt the spawn-side rule and test it (recommended): The parent that pinned the decoder (Name the Encoding on Every Text-Mode Subprocess Call #1574) is the one place that knows which decoder to match, and the rule covers any Python child, including ones the repo does not own. tests/test_tooling_encoding.py already scans these calls and test_prose_lint.py already applies the env fix. The fix touches host-setup/agent-safety/claude/test_install.py and test_model_tier_guard.py, so it needs the human approval agent-safety edits require. No work in flight.
    2. Child-side reconfigure in every hub script: Every script with a main reconfigures stdout/stderr to UTF-8, enforced by a test, which also fixes piping output on Windows, but spans ~20 scripts and cannot reach a child the repo does not author. No work in flight.
    3. Close as sufficient: Nothing the remaining children print is non-ASCII today and the full suite passed on Windows, but the mismatch stays latent with no Windows CI to catch a regression. No work in flight.

    Evidence: The maintainer's 2026-10-08 comment: #2523 fixed only test_spec_validate and "this issue's general fix is still open". reconfigure(encoding appears only in pr_review.py and validate.py, the env fix only at tests/test_prose_lint.py:7401, :7453. sys.executable spawns grew to ~56 references across 12 test files, including agent-safety tests. test_tooling_encoding.py asserts only the parent half.

    Blocks: none

  3. added
    decision
    on Nov 1, 2026
  4. ptr727 commented on Nov 1, 2026

    @ptr727
    OwnerAuthor

    Maintainer answer (decision triage, 2026-11-01): Option 1: adopt the spawn-side rule (a parent decoding a Python child's output as UTF-8 passes PYTHONIOENCODING=utf-8) and assert it in tests/test_tooling_encoding.py. The edits it needs under host-setup/agent-safety/claude/ (test_install.py, test_model_tier_guard.py) are approved. This is now work for the next burndown round.

  5. removed
    decision
    on Nov 1, 2026
  6. ptr727 commented on Nov 22, 2026

    @ptr727
    OwnerAuthor

    Backlog burndown claim (round 3, 2026-11-22): branch burndown/python-child-utf8-spawn. Files: tests/test_tooling_encoding.py; .agents/skills/python-codestyle/references/code-style.md (and its generated copies), where the #1574 encoding rule lives; host-setup/agent-safety/claude/test_install.py; host-setup/agent-safety/claude/test_model_tier_guard.py. Extended 2026-11-22 to the flagged spawn sites: tests/import_probe.py, tests/test_agent_policy.py, tests/test_backlog_metrics.py, tests/test_docker_lint.py, tests/test_gh_graphql.py, tests/test_git_env.py, tests/test_global_rules.py, tests/test_hub_fetch_run.py, tests/test_pr_cleanup.py, tests/test_prose_lint.py, tests/test_secrets_sync.py, tests/test_spec_validate.py. Extended 2026-11-22 after #4340 merged: tests/test_pr_review.py (one site) and scripts/pr_review.py (one line, the receipt_reading spawn's env). No other group may edit these files while this claim stands.

  7. added a commit that references this issue on Nov 22, 2026
    9296e25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions