Skip to content

Preserve Git, GitHub, and task text under legacy locales - #1529

Closed
eowca wants to merge 7 commits into
mainfrom
lean178/1504-1506-utf8-boundaries
Closed

eowca wants to merge 7 commits into
mainfrom
lean178/1504-1506-utf8-boundaries

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Preserve Git, GitHub, and task text under legacy locales

Context and goal

  • Goal: Keep UTF-8 Git branch names, GitHub JSON and task handoffs intact under legacy locales.
  • Problem: Python's locale defaults can corrupt these bytes. Status can look up a different branch, and a draft PR can lose or fail to read its title.
  • Context: Git paths must stay usable as filesystem names. Decode GitHub JSON and task Markdown as UTF-8 at their existing read boundaries.

Closes #1504
Closes #1505
Closes #1506

Acceptance

  • Status opens a Unicode checkout and looks up its exact Unicode branch under ASCII and ISO-8859-2. Preserve branch whitespace and Git path bytes.
  • Preserve Unicode in offline GitHub REST and GraphQL responses under a legacy locale, including existing retries and diagnostics.
  • Preserve task handoff text and heading extraction under a legacy locale, including existing template and missing-file behavior.
  • Extend existing tests with zero net lines.

Base

Base: a68ef3b

Notes

Keep raw filesystem bytes reversible through Git output. Decode protocol text and task Markdown explicitly. Status can escape characters a legacy stream cannot print without changing its lookup values. Decoding does not change the data sources, credential selection, or trust authority.

Validation

(no loopzero check run recorded)


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Review

  • primary, claude, 8bd260d, request_changes
  • delta, claude, 742752c, request_changes

eowca and others added 2 commits November 26, 2026 04:36
Architecture-Review: unchanged; machine text is decoded at existing process and file boundaries without changing delivery state or authority.
Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loopzero primary review by claude on 8bd260d70c9ae0901c32ab36b741eb223f629c53, 61.9s: request_changes (0 critical, 1 important, 1 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/worktree.py Resolved
Comment thread src/loopzero/cli.py Outdated
print(f"branch: {branch}")
print(f"head: {head}")
print(f"base: {config.base_branch}")
if isinstance(sys.stdout, io.TextIOWrapper):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Status reconfigures the global sys.stdout for the rest of the process

sys.stdout.reconfigure(errors="backslashreplace") changes process-wide state and stays in effect after cmd_status returns, including in tests that share the stream. Only status gets this treatment. Other commands that print branch names (for example the merge-cleanup warnings) can still raise UnicodeEncodeError on an ASCII stdout. Consider setting this once in main() for all commands, or escaping the branch value only at the print site.

eowca and others added 4 commits November 26, 2026 04:40
Architecture-Review: unchanged; local Git commands retain native filesystem bytes and GitHub branch names use UTF-8.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; the existing force-with-lease still guards deletion with the same remote SHA.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; Git path and ref operations preserve native bytes while GitHub responses retain their UTF-8 contract.
Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loopzero delta review by claude on 742752c80f92c5f334a2624c69768fb641650a9c, 63.6s: request_changes (0 critical, 2 important, 0 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/cli.py
def _git_push(wt: Path, args: list[str], *, force_lease: bool) -> None:
done = _proc.run(["git", *args], cwd=wt, env_allowlist=worktree.GIT_ENV,
extra_env={"LC_ALL": "C"}, timeout=PUSH_TIMEOUT)
argv = ["git", *(os.fsdecode(arg.encode("utf-8", "surrogateescape")) for arg in args)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer location src/loopzero/cli.py:699 is not in the diff; anchored here.

important: Force-lease reflog lookup still passes the UTF-8 branch view to git without converting it to native form

worktree.branch(wt) now returns the UTF-8 view of the branch name (os.fsencode(name).decode("utf-8", "surrogateescape")). This delta converts that view back to the filesystem form in _git_push, _delete_tracking_ref and github.delete_remote_branch. It does not convert _git(wt, "reflog", "show", "--format=%H", f"refs/heads/{branch}") on the force-lease path of cmd_pr, so the plain str goes straight to Popen, which encodes it with the filesystem encoding.

What goes wrong:

  • Under ASCII, a branch such as lz/Łódź raises UnicodeEncodeError.
  • Under ISO-8859-2, Ł is encoded as 0xA3 instead of UTF-8 C5 81. Git reads a different ref, the reflog lookup fails or comes back empty, and loopzero pr refuses a legitimate force-with-lease update with an error saying the PR head is absent from the branch history.

The acceptance criterion says Unicode branches must survive legacy locales, and this path breaks it.

Smallest fix: build the ref with the same conversion used elsewhere. Better, add one helper (for example worktree.native_ref(text)) and use it at every call site: here, in _git_push, _delete_tracking_ref, delete_remote_branch, and for the inverse in branch() / _lock_verified_ref. The four copies of the conversion in this diff are what let this call be missed.

Comment thread src/loopzero/cli.py
def _git_push(wt: Path, args: list[str], *, force_lease: bool) -> None:
done = _proc.run(["git", *args], cwd=wt, env_allowlist=worktree.GIT_ENV,
extra_env={"LC_ALL": "C"}, timeout=PUSH_TIMEOUT)
argv = ["git", *(os.fsdecode(arg.encode("utf-8", "surrogateescape")) for arg in args)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer location tests/test_worktree.py:45 is not in the diff; anchored here.

important: The merge resolution removed every legacy-locale test, so the new conversions are never exercised

Resolving the merge with origin/main dropped these tests:

  • test_branch_preserves_unicode_whitespace (it forced an ASCII _text_encoding)
  • the subprocess._text_encoding ASCII monkeypatch in test_status_full
  • the subprocess-based test_pr_title_prefers_human_heading, which ran with LC_ALL=C and -X utf8=0

The tests that remain (test_branch_reads_valid_names..., test_cleanup_removes_worktree_and_branch with zażółć, test_pr_pushes_and_creates_draft with lz/zażółć , and test_status_full with Łódź) all run with a UTF-8 filesystem encoding. Under that encoding, os.fsencode(x).decode("utf-8", "surrogateescape") and os.fsdecode(x.encode("utf-8", "surrogateescape")) return their input unchanged, so branch(native=...), _git_push, _delete_tracking_ref, delete_remote_branch, _lock_verified_ref and the status backslashreplace path could all be wrong and every test would still pass.

The retained test_pr_title_prefers_human_heading monkeypatches Path.read_text, but task_text now reads through read_local_state/os.fdopen, so that test also checks nothing about the locale.

The acceptance criteria call for status and branch lookup to work under ASCII and ISO-8859-2, so they are no longer verified.

Smallest fix: restore at least one subprocess-based test that runs status (or branch and the push/cleanup ref construction) with LC_ALL=C or an ISO-8859-2 locale, PYTHONCOERCECLOCALE=0 and -X utf8=0, extending an existing test so the net line change stays at zero. The removed _pr_title subprocess form is a good template.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1907, which fixes the legacy-locale reflog lookup and restores automated status, guarded push, and cleanup coverage.

@eowca eowca closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant