fix(build-script): rerun commit-embedding scripts when git cannot open the repository #1074
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1074"
general
weight: 0.35
jdx
A binary that embeds the commit hash could keep reporting the previous commit after
HEADmoved, whengitcould not open the repository the build ran in. mbx now runs such a build script again instead of replaying its earlier result.When it happened
All three of these had to hold:
1. mbx asks
gitfor the checked-out commit instead of reading git's files itself. It does that whenGIT_DIR,GIT_COMMON_DIR,GIT_CEILING_DIRECTORIES,GIT_DISCOVERY_ACROSS_FILESYSTEMorGIT_WORK_TREEis set, when the repository stores its references as reftable, or when a.gitfile names no directory.2.
gitfails there although a checkout with a commit is on disk. The common case isfatal: detected dubious ownership in repository, in a container that mounts a checkout made by another user without asafe.directoryentry. A repository format or configuration thatgitrejects does the same, and so does aGIT_DIRthat names a directory that is not a repository.3. The build script reads the commit without running
git: throughgixorgit2, or by reading.git/HEAD. Those are not stopped by what stops thegitcommand.Before and after
Before, mbx took every failure of
git rev-parseto mean that no commit is checked out. It stored the script's result under a key without the commit, and replayed it on the next commit, so the binary reported a stale hash.Now only two answers from
gitmean "no commit": it finds no repository, or it finds one whoseHEADnames no commit (a new branch before its first commit). After any other failure mbx treats the commit as unknown and does not store the script's result. The script then runs on every build, which shows in the statistics as abuild-script-unreadable-headbypass. Adding the checkout tosafe.directoryletsgitanswer, and the results are cached again.GIT_DIRgets one more check, because it keepsgitfrom searching: whengitfinds no commit whereGIT_DIRpoints and a.gitis on disk above the package, the commit also counts as unknown.Builds outside a repository are unchanged: a source tarball built with
GIT_CEILING_DIRECTORIESset still has its build scripts cached.How the cases are told apart
gitexits 128 for every fatal error, so the exit status alone cannot separate them. mbx runsgit rev-parse --verify --quiet HEADwithLC_ALL=Cand reads its error. This is what git 2.53.0 answers:| Case | Exit | Message | mbx reads it as |
| --- | --- | --- | --- |
| Branch with no commit yet | 1 | none | no commit |
| No repository | 128 |
fatal: not a git repository (or any of the parent directories): .git| no commit || Search stopped at a filesystem boundary | 128 |
fatal: not a git repository (or any parent up to mount point /)| no commit || A
.gitfile naming a directory that is not a repository | 128 |fatal: not a git repository: <path>| no commit ||
GIT_DIRnaming a directory that is not a repository | 128 |fatal: not a git repository: '<path>'| unknown if a.gitis on disk above the package, otherwise no commit || Checkout owned by another user | 128 |
fatal: detected dubious ownership in repository at '<path>'| unknown || Bare repository with
safe.bareRepository=explicit| 128 |fatal: cannot use bare repository '<path>' …| unknown || Unsupported repository format | 128 |
fatal: Expected git repo version <= 1, found 99| unknown || Unparseable repository configuration | 128 |
fatal: bad config line 1 in file .git/config| unknown |A line starting with
fatal: not a git repositoryis the only message read as "no repository". Git's source has every form of that error starting this way since at least 1.7.0, with a capitalNbefore git 2.17, which is matched too. A message mbx does not recognize counts as unknown, so a wording change in a future git costs cache hits rather than correctness.Validation
gitagainst a directory with no repository, aGIT_DIRthat is not a repository, a branch with no commit, a repository with a commit, a repositorygittreats as another user's, an unsupported format, an unparseable configuration, and agitthat cannot be started. Two more check the message matching against the wordings above, including the olderunsafe repositoryand capitalized forms, and theGIT_DIRcheck against a checkout on disk..git/HEAD, one whilegitrefuses the repository and one withGIT_DIRnaming a missing directory. Without the matching change the second build's binary printed the first commit in each; with it both print the second.cargo fmt --check,cargo clippy -p mbx --all-targets -- -D warnings,cargo test -p mbx --lib build_scriptand thea_build_scripttests incargo test -p mbx --test buildpass.Limits: the tests that make
gitrefuse a repository useGIT_TEST_ASSUME_DIFFERENT_OWNER, which git has had since 2.35.3. Older git wordings were checked in git's source, not by running old versions. No translated git was installed where this was tested, soLC_ALL=Coverriding a translated locale was not exercised. AGIT_DIRthat names a different repository with a commit of its own is not covered: mbx keys on the commitgitreports there.AI-assisted — Tool: Claude Code; model: anthropic/claude-fable-5-2; version: 2.1.332.
🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Bug Fixes
Build information now distinguishes repositories with no commit from cases where Git cannot determine the commit.
Checkout commit information is preserved when Git cannot read repository metadata, including when repository settings point to an unavailable location.
These changes make reported build information more accurate across detached checkouts and other Git access failures.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->