Skip to content

fix(verify): translate git's decode fault and add a bytes mode (#377) - #387

Merged
pbean merged 2 commits into
mainfrom
fix/377-run-git-bytes-mode
Jul 29, 2026
Merged

fix(verify): translate git's decode fault and add a bytes mode (#377)#387
pbean merged 2 commits into
mainfrom
fix/377-run-git-bytes-mode

Conversation

@pbean

@pbean pbean commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

What

verify._run_git now translates a strict-decode fault into GitError, and gained a bytes mode
(binary=, plus the public git_bytes accessor).

Why

Fixes #377

The chokepoint exists to give git's pre-returncode faults a type its ~50 except GitError guards
can catch. It translated a timeout (#156) and a spawn OSError (#343) — but UnicodeDecodeError is
a third such fault, and being a ValueError it matched neither arm, so it escaped untyped: the
one thing its own docstring says must not happen. One POSIX filename that is not valid in the run's
encoding is enough, wherever git's own quoting is off — the -z callers (merge pre-flight),
worktree list --porcelain (crashes the unguarded stale-run reconcile at every run/sweep start),
and git diff, whose content is verbatim (a failed unit's forensic capture bypasses the valve that
preserves its uncaptured work).

The bytes mode is the second half #377 asks for: install._shield_git stands outside the chokepoint
AGENTS.md requires because it needs raw bytes and needs a non-zero rc as an answer (config --get of an unset key exits 1), and its docstring names this issue as the blocker.

How

No caller on main yet: #385/#386 are still open, so install._shield_git does not exist here.
This is the API half; the rewiring stays with #384's stack.

Testing

5 tests in tests/test_verify.py, all on the conftest project fixture. The decode test uses a
real bad-byte filename and real git — monkeypatching subprocess.run hands the code str and
never runs the stdlib's decoding, so that version passes with the fix ablated
(tests/test_install.py:1996 documents the same trap). It reuses the needs_strict_codec guard
from #378 (hoisted to the top of the file, since it now serves both), because 0xff decodes fine
under ISO-8859-x/cp125x.

Full suite 3703 passed, 24 skipped (main: 3698 + 24, i.e. exactly the 5 new tests);
pyright@1.1.411 0 errors; trunk fmt + full trunk check clean.

Ablations run (AGENTS.md rule)

Deleted Result
except UnicodeDecodeError arm test_z_output_undecodable_path_becomes_git_error FAILS with raw UnicodeDecodeError
binary=True in git_bytes ..._returns_bytes_and_reads_rc_as_an_answer + ..._inherits_locale_pin_and_timeout FAIL ✅
except subprocess.TimeoutExpired arm test_git_bytes_timeout_still_becomes_git_error FAILS with raw TimeoutExpired
except OSError arm test_git_bytes_spawn_oserror_still_becomes_git_spawn_error FAILS with raw OSError

Plus the vacuity check the #378 follow-up exists for: under LC_ALL=et_EE.iso885915 the decode test
skips with its stated reason rather than falsely passing.

Summary by CodeRabbit

  • Bug Fixes

    • Git operations no longer crash when encountering filenames with non-UTF-8 characters.
    • Undecodable output is now reported as a clear Git error.
    • Git timeouts and startup failures are consistently surfaced as application errors.
  • Improvements

    • Added support for safely processing raw Git output, improving handling of unusual filenames.

pbean added 2 commits July 29, 2026 10:07
`_run_git` decoded git's output strictly and translated only a timeout
and a spawn OSError. A UnicodeDecodeError is a third fault raised before
any return code exists, and being a ValueError it matched neither arm —
so it escaped untyped past every `except GitError` guard, which is the
one thing the chokepoint's docstring says must not happen.

Reachable wherever git's own quoting is off: `-z` disables core.quotePath
(dirty_paths, branch_incoming_paths, commit_paths), `worktree list
--porcelain` never applied it, and `git diff` emits content verbatim.

The test uses a real file with real bytes and real git: monkeypatching
subprocess.run hands the code str objects and never runs the stdlib's
decoding, so that version passes with the fix ablated. The #378 codec
guard moves to the top of the file, since it now serves both.
AGENTS.md requires every git subprocess to go through `_run_git`, but two
properties kept a caller out: it hands back CompletedProcess[str], i.e.
the strict decode, and it raises rather than returning a return code the
caller reads as an answer — `git config --get` of an unset key exits 1,
and that is the reply, not a fault.

A keyword-only `binary` flag with @overload declarations gives the mode a
type, and `git_bytes` is the public accessor so no other module reaches
for the private name. Bytes callers keep what the chokepoint is for: the
LC_ALL=C pin (#236) and the limits.git_timeout_s bound (#156), with the
two faults that have no rc to return still raising.

No caller on main yet — install._shield_git is the intended customer and
lands with #385, whose docstring names this issue as its blocker.

@greptile-apps greptile-apps 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.

pbean has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fda95964-7a2c-4f44-93e4-7d28845049fe

📥 Commits

Reviewing files that changed from the base of the PR and between ad22f79 and 76670d5.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/bmad_loop/verify.py
  • tests/test_verify.py

Walkthrough

The shared git subprocess chokepoint now supports text and raw-bytes execution, converts decode failures into GitError, and exposes git_bytes. Tests cover undecodable filenames, bytes-mode behavior, locale and timeout propagation, and spawn failures.

Changes

Git output taxonomy

Layer / File(s) Summary
Typed git subprocess wrapper
src/bmad_loop/verify.py
_run_git now supports typed text and binary modes, translates UnicodeDecodeError into GitError, and exposes raw output through git_bytes.
Undecodable output validation
tests/test_verify.py, CHANGELOG.md
Regression tests cover invalid filename bytes, bytes-mode subprocess behavior, locale and timeout propagation, spawn errors, and the documented fix.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: dracic

Poem

A bunny found bytes in a filename one day,
And watched Git errors hop safely away.
Raw bytes now travel, decode faults wear a name,
Tests guard the burrow and document the change.
Thump-thump, the subprocess path is tame!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the decode-fault fix and the added bytes mode.
Linked Issues check ✅ Passed The PR translates UnicodeDecodeError into GitError at the _run_git chokepoint as requested by #377.
Out of Scope Changes check ✅ Passed The added bytes-mode helper and tests are aligned with the stated PR objectives, not unrelated scope creep.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/377-run-git-bytes-mode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pbean

pbean commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 76670d5c04

ℹ️ 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".

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.

_run_git's decode fault escapes the GitError taxonomy on -z output

1 participant