Skip to content

fix(git): decode workbench text output as UTF-8 - #226

Open
dipeshbabu wants to merge 2 commits into
openai:mainfrom
dipeshbabu:agent/fix-windows-git-utf8
Open

fix(git): decode workbench text output as UTF-8#226
dipeshbabu wants to merge 2 commits into
openai:mainfrom
dipeshbabu:agent/fix-windows-git-utf8

Conversation

@dipeshbabu

Copy link
Copy Markdown
Contributor

Fixes #192

Summary

  • Decode text-mode Git subprocess output as UTF-8 in the bundled workbench.
  • Leave binary Git output unchanged for snapshots and object data.
  • Add a Windows regression using a real Cyrillic worktree while forcing Python's locale decoder to cp1252.

Root cause

subprocess.run(..., text=True) used Python's locale encoding. On Windows systems with a non-UTF-8 code page, Git's UTF-8 worktree path was decoded into a different string, so Path.relative_to() incorrectly concluded that the scan target was outside its repository.

Impact

Windows scans can inspect valid Git worktrees whose paths contain Cyrillic or other non-ASCII characters without requiring PYTHONUTF8=1. POSIX behavior and byte-oriented Git commands are unchanged.

Validation

  • pnpm dlx bun test --timeout 30000 ./tests-ts/workbench-canonical-paths.test.ts — 4 passed, 2 platform skips
  • pnpm dlx bun test --timeout 30000 ./tests-ts/scan-recovery.test.ts — 16 passed
  • pnpm exec tsc --noEmit
  • python -m py_compile sdk/typescript/_bundled_plugin/scripts/workbench_target.py
  • pnpm exec prettier --check tests-ts/workbench-canonical-paths.test.ts
  • git diff --check

@github-actions github-actions Bot added the bug Something isn't working label Aug 3, 2026
@mldangelo-oai

Copy link
Copy Markdown
Collaborator

@codex review exact head 87e9aa2

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 87e9aa2d9f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

full_command,
check=False,
capture_output=True,
encoding="utf-8" if text else None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve locale-encoded Git paths on POSIX

On POSIX filesystems, Git emits pathnames as their raw filesystem bytes rather than guaranteeing UTF-8. If a repository path is valid in the host locale but not UTF-8 (for example, caf\xe9 under a Latin-1 locale), rev-parse --show-toplevel now raises UnicodeDecodeError before git_worktree_context() can inspect the return code, whereas the previous locale-based decoding produced the correct path. Limit the UTF-8 override to Windows or decode pathname output in a way that preserves non-UTF-8 filesystem bytes.

Useful? React with 👍 / 👎.

"from pathlib import Path",
"sys.path.insert(0, sys.argv[1])",
"import workbench_target as target",
"locale.getencoding = lambda: 'cp1252'",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Force the legacy decoder in every supported Python

This assignment does not reliably force subprocess to use cp1252: Python 3.10 (which the package explicitly supports) passes the special "locale" encoding directly to its text wrappers and does not have locale.getencoding, while Python 3.11+ ignores this function when UTF-8 mode is enabled. In either environment, removing the production encoding="utf-8" change can still leave this regression test green, so the test does not consistently exercise the failure it is intended to prevent. Launch the probe with a deterministically non-UTF-8 decoder or intercept the subprocess decoding path in a version-independent way.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 87e9aa2d9f

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: valid Git worktree scans fail for non-ASCII target paths

2 participants