Skip to content

Decode git output and read prompts as UTF-8 - #33

Merged
williamshen-nz merged 2 commits into
mainfrom
recording-encoding-fix
Jul 30, 2026
Merged

williamshen-nz merged 2 commits into
mainfrom
recording-encoding-fix

Conversation

@williamshen-nz

@williamshen-nz williamshen-nz commented Jul 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Splits the UTF-8 file/output-decoding fixes out of #30 into their own PR. Both are the same class of issue: relying on the locale's preferred encoding, which mangles or crashes on non-ASCII bytes under a non-UTF-8 locale.

Changes

  • recording.py — the git helpers used text=True, which decodes subprocess output with the locale encoding. Decode git output explicitly as encoding="utf-8" in _get_git_root, _collect_git_info, and _get_git_diff, and add errors="replace" for the git status --porcelain and git diff calls where arbitrary file content can appear.
  • gemini.py — load_prompt used Path.read_text() (locale encoding); read prompt templates explicitly as encoding="utf-8".

The git helpers relied on text=True, which decodes subprocess output
using the locale's preferred encoding. Under a non-UTF-8 locale that
mangles or crashes on non-ASCII bytes in commit messages, filenames, or
diffs. Decode explicitly as UTF-8, and use errors="replace" for the
porcelain status and diff, where arbitrary file content can appear.

Split out from #30.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR makes git metadata collection in tiptop/recording.py decode subprocess output explicitly as UTF-8, avoiding dependence on the system locale encoding when recording run metadata (including dirty status and diffs).

Changes:

  • Use encoding="utf-8" for git subprocess output decoding in _get_git_root, _collect_git_info, and _get_git_diff.
  • Add errors="replace" for git status --porcelain and git diff output to prevent decode failures when arbitrary bytes appear in status/diff content.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Path.read_text() decodes with the locale's preferred encoding, which
mangles or crashes on non-ASCII prompt text under a non-UTF-8 locale.
Decode explicitly as UTF-8, matching the git-output fix.
@williamshen-nz williamshen-nz changed the title Decode git output as UTF-8 in recording metadata Decode git output and read prompts as UTF-8 Jul 30, 2026
@williamshen-nz
williamshen-nz merged commit 98c843b into main Jul 30, 2026
@williamshen-nz
williamshen-nz deleted the recording-encoding-fix branch July 30, 2026 21:11
@williamshen-nz williamshen-nz mentioned this pull request Jul 31, 2026
6 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants