Repository navigation
fix(verify_commits.sh): replay auto commits in isolated worktrees, surface errors in PR comment - #26
Merged
Merged
Conversation
…PR comment
The commit verification script had several bugs that combined to produce
unhelpful PR comments and cascading false-positive failures:
- Per-commit replay shared the main checkout, so any untracked file an
earlier auto commit's command produced (e.g., from a `> hits.txt`
redirect) blocked the next commit's `git checkout --detach $parent`
with "untracked working tree files would be overwritten". The "fix" to
earlier commit N+1 then reported a confusing checkout error instead of
its real failure.
- JSON output was hand-rolled with `echo "{ \"...\": \"$subject\" }"` and
only escaped quotes. Subjects containing literal newlines (created by
some commit-message generators) produced unparseable JSON, which then
caused the comment-rendering step to fail silently with `jq: parse
error: Invalid escape`.
- The comment surfaced no actual error output. Authors saw "❌ Failed"
and had to dig through CI logs to learn what went wrong.
This rewrite:
- Replays each auto commit in a fresh `git worktree add --detach $parent`
under a single mktemp'd parent. Worktrees are removed after each
iteration, on EXIT (trap), and `git worktree prune` runs at startup so
any stale state from interrupted runs is cleared. The same isolation
applies to the transient-commit cherry-pick replay.
- Captures combined stdout+stderr via `tee` so live CI logs still show
the command's output while we also save it for the JSON report.
- Builds JSON via `jq -nc --arg ...` so commit subjects with arbitrary
bytes (newlines, backslashes, control chars) round-trip safely.
- Records a `failure_kind` (`command_failed`, `timed_out`, or
`tree_mismatch`) plus the last 4KB / 40 lines of output, and for tree
mismatches a truncated `git diff-tree --stat`. The summary script
dispatches on `failure_kind` (no keyword matching on error text — the
underlying tool's message is the diagnosis) and renders each failed
commit as a `<details>` block containing the actual output.
- Caps total comment size at 50KB, falling back to "see CI logs" links
for late-truncated content.
- Replaces the literal `✅`/`❌` escape strings (which only
rendered correctly inside `jq` output) with real UTF-8 ✅/❌.
- Drops the bash-4 `mapfile` and associative-array dependencies; both
scripts now run on bash 3.2+, easing local testing.
- Recovers from unparseable JSON: if `verify_commits.sh` crashes before
writing the JSON file, the summary script emits a fallback comment
pointing to the CI logs rather than producing empty output.
Smoke-tested against the failing run for leanprover-community/mathlib4#38480.
The new comment shows the actual bash parse error / xargs / sed / git rm
output for each commit independently, with no cascading "checkout would
overwrite" noise.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Hard-coded 600s makes the timeout-handling path effectively unreachable
from test harnesses that build a synthetic git history and need a quick
artificial timeout. Use the same `${VAR:-default}` pattern already used
for TRANSIENT_PREFIX et al., so a test scenario can set
TIMEOUT_SECONDS=1 and exercise the timed_out failure_kind path in
seconds.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
kim-em
pushed a commit
to kim-em/mathlib-ci
that referenced
this pull request
May 22, 2026
…rface errors in PR comment (leanprover-community#26) * fix: replay auto commits in isolated worktrees and surface errors in PR comment The commit verification script had several bugs that combined to produce unhelpful PR comments and cascading false-positive failures: - Per-commit replay shared the main checkout, so any untracked file an earlier auto commit's command produced (e.g., from a `> hits.txt` redirect) blocked the next commit's `git checkout --detach $parent` with "untracked working tree files would be overwritten". The "fix" to earlier commit N+1 then reported a confusing checkout error instead of its real failure. - JSON output was hand-rolled with `echo "{ \"...\": \"$subject\" }"` and only escaped quotes. Subjects containing literal newlines (created by some commit-message generators) produced unparseable JSON, which then caused the comment-rendering step to fail silently with `jq: parse error: Invalid escape`. - The comment surfaced no actual error output. Authors saw "❌ Failed" and had to dig through CI logs to learn what went wrong. This rewrite: - Replays each auto commit in a fresh `git worktree add --detach $parent` under a single mktemp'd parent. Worktrees are removed after each iteration, on EXIT (trap), and `git worktree prune` runs at startup so any stale state from interrupted runs is cleared. The same isolation applies to the transient-commit cherry-pick replay. - Captures combined stdout+stderr via `tee` so live CI logs still show the command's output while we also save it for the JSON report. - Builds JSON via `jq -nc --arg ...` so commit subjects with arbitrary bytes (newlines, backslashes, control chars) round-trip safely. - Records a `failure_kind` (`command_failed`, `timed_out`, or `tree_mismatch`) plus the last 4KB / 40 lines of output, and for tree mismatches a truncated `git diff-tree --stat`. The summary script dispatches on `failure_kind` (no keyword matching on error text — the underlying tool's message is the diagnosis) and renders each failed commit as a `<details>` block containing the actual output. - Caps total comment size at 50KB, falling back to "see CI logs" links for late-truncated content. - Replaces the literal `✅`/`❌` escape strings (which only rendered correctly inside `jq` output) with real UTF-8 ✅/❌. - Drops the bash-4 `mapfile` and associative-array dependencies; both scripts now run on bash 3.2+, easing local testing. - Recovers from unparseable JSON: if `verify_commits.sh` crashes before writing the JSON file, the summary script emits a fallback comment pointing to the CI logs rather than producing empty output. Smoke-tested against the failing run for leanprover-community/mathlib4#38480. The new comment shows the actual bash parse error / xargs / sed / git rm output for each commit independently, with no cascading "checkout would overwrite" noise. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix: allow TIMEOUT_SECONDS to be overridden via environment variable Hard-coded 600s makes the timeout-handling path effectively unreachable from test harnesses that build a synthetic git history and need a quick artificial timeout. Use the same `${VAR:-default}` pattern already used for TRANSIENT_PREFIX et al., so a test scenario can set TIMEOUT_SECONDS=1 and exercise the timed_out failure_kind path in seconds. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes a few bugs in
verify_commits.sh:Per-commit replay shared the main checkout, so any untracked file an earlier auto commit's command produced (e.g., from a
> hits.txtredirect) blocked the next commit'sgit checkout --detach $parentwith "untracked working tree files would be overwritten". The "fix" to earlier commit N+1 then reported a confusing checkout error instead of its real failure.JSON output was hand-rolled with
echo "{ \"...\": \"$subject\" }"and only escaped quotes. Subjects containing literal newlines (created by some commit-message generators) produced unparseable JSON, which then caused the comment-rendering step to fail silently withjq: parse error: Invalid escape.The comment surfaced no actual error output. Authors saw "❌ Failed" and had to dig through CI logs to learn what went wrong.
This rewrite:
Replays each auto commit in a fresh
git worktree add --detach $parentunder a single mktemp'd parent. Worktrees are removed after each iteration, on EXIT (trap), andgit worktree pruneruns at startup so any stale state from interrupted runs is cleared. The same isolation applies to the transient-commit cherry-pick replay.Captures combined stdout+stderr via
teeso live CI logs still show the command's output while we also save it for the JSON report.Builds JSON via
jq -nc --arg ...so commit subjects with arbitrary bytes (newlines, backslashes, control chars) round-trip safely.Records a
failure_kind(command_failed,timed_out, ortree_mismatch) plus the last 4KB / 40 lines of output, and for tree mismatches a truncatedgit diff-tree --stat. The summary script dispatches onfailure_kind(no keyword matching on error text — the underlying tool's message is the diagnosis) and renders each failed commit as a<details>block containing the actual output.Caps total comment size at 50KB, falling back to "see CI logs" links for late-truncated content.
Replaces the literal
✅/❌escape strings (which only rendered correctly insidejqoutput) with real UTF-8 ✅/❌.Drops the bash-4
mapfileand associative-array dependencies; both scripts now run on bash 3.2+, easing local testing.Recovers from unparseable JSON: if
verify_commits.shcrashes before writing the JSON file, the summary script emits a fallback comment pointing to the CI logs rather than producing empty output.Smoke-tested against the failing run for leanprover-community/mathlib4#38480. The new comment shows the actual bash parse error / xargs / sed / git rm output for each commit independently, with no cascading "checkout would overwrite" noise.
Prepared with Claude code.