Repository navigation
fix(examples): fail GitFlic and Gerrit jobs when ocr review fails - #2032
Conversation
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
|
| if [ -s result.json ]; then | ||
| python3 examples/gerrit_ci/post_review.py \ | ||
| --input result.json \ | ||
| --revision "$GERRIT_PATCHSET_REVISION" | ||
| else | ||
| echo "OCR review produced no output, skipping post." | ||
| exit 0 | ||
| fi | ||
| python3 examples/gerrit_ci/post_review.py \ | ||
| --input result.json \ | ||
| --revision "$GERRIT_PATCHSET_REVISION" | ||
| if [ -s ocr-exit-code ]; then | ||
| echo "ocr review exited with code $(cat ocr-exit-code); failing the build." | ||
| exit "$(cat ocr-exit-code)" | ||
| fi |
There was a problem hiding this comment.
Bug: If post_review.py fails (e.g., network error, auth issue) but ocr review succeeded (no ocr-exit-code file), this script exits with code 0, silently swallowing the posting failure.
The second if [ -s ocr-exit-code ] evaluates to false when ocr succeeded, and an if without an else returns exit status 0 when the condition is false. This overrides whatever exit code post_review.py produced.
Consider capturing the post exit code similarly to how the GitFlic example does it, e.g.:
POST_EXIT=0
if [ -s result.json ]; then
python3 examples/gerrit_ci/post_review.py \
--input result.json \
--revision "$GERRIT_PATCHSET_REVISION" || POST_EXIT=$?
else
echo "OCR review produced no output, skipping post."
fi
if [ -s ocr-exit-code ]; then
echo "ocr review exited with code $(cat ocr-exit-code); failing the build."
exit "$(cat ocr-exit-code)"
fi
exit "$POST_EXIT"|
@thejesh23 Thanks for the fix and the follow-up on Gerrit posting failures. The one remaining change I'd like before merging is to bump the Gerrit example's OCR pin from If OCR and posting both fail, what matters for this example is that the job fails. The precedence in your latest commit is fine as-is. Once the pin is updated and CI is green, I'm happy to merge. |
Description
The GitFlic and Gerrit CI examples finish green when
ocr reviewfails. GitFlic also posts the failure message to the MR behind a ✅.Where:
examples/gitflic_ci/gitflic-ci.yaml(review and post steps) andexamples/gerrit_ci/Jenkinsfile(ReviewandPost to Gerritstages).Root cause: both templates end
ocr reviewwith|| true. Then, if stdout is empty, the posting step runsexit 0.ocr reviewexits non-zero when a run fails outright, when every item failed, or when a partial review has operational failures.reviewResultErrorincmd/opencodereview/review_cmd.gosays this is "so CI cannot mistake incomplete coverage for success".|| truediscards exactly that signal:exit 0, and the job is green.status: failedorpartial). The poster publishes it and exits 0, so the job is green again. GitFlic's poster prefixes the note with ✅, so the MR shows "✅ OpenCodeReview: Review failed: …".The Jenkinsfile comment that justifies
|| true("exits non-zero only when EVERY sub-agent fails; partial failures still exit 0") is stale too: operational partial failures now exit non-zero as well.The GitLab template (
OCR_EXIT_CODEgate) and the Bitbucket template already fail the job on a non-zeroocrexit. These two are the outliers.Fix: keep publishing whatever
ocrproduced, then fail the job withocr's exit code.OCR_EXIT_CODE(|| OCR_EXIT_CODE=$?) and write it to/tmp/ocr-exit-code. The post step posts if the result is non-empty, then exits with the saved code. Ifocrsucceeded, it exits with the poster's code. The code goes through a file, so this works whether or not the runner shares one shell acrossscript:entries.|| echo "$?" > ocr-exit-code, withrm -ffirst because Jenkins workspaces are reused between builds. The post stage then posts if the result is non-empty and fails the build with the saved code. The stale comment is corrected.A run with no failures behaves exactly as before. The ✅ prefix in the posters is left alone to keep this PR small, because a red job is the signal that matters.
Type of Change
How Has This Been Tested?
There is no test harness for the CI templates, so I tested the shell directly.
Real binary, current
main(39515dc).ocrwas built from this commit (local Go 1.27.4; only the exit code matters here). It ran on a one-file diff with the LLM pointed at a dead port:Behaviour diff,
mainvs this branch. I extracted the review and post scripts verbatim from both templates (YAML via js-yaml, Groovysh '''blocks) and ran them with a fakeocr(exit code and output controlled) and a fake poster. GitFlic was run two ways: all entries in onebash -eand each entry in its ownsh -e. Jenkins stages were run withsh -xein a shared workspace. The numbers are the job's exit code, as main → this branch:ocr-exit-codefrom an earlier buildWhen the review fails but produced JSON, the poster still runs before the job fails, so the results are still published.
Follow-up
a41580d, from the review bot's comment: the Gerrit post stage now records the poster's exit code too (|| POST_EXIT_CODE=$?). A posting failure therefore still fails the build whensh -eis off, for example when a#!/bin/bashline is added to the block. I re-ran the Jenkins column withsh -xas well assh -xe, and every row above holds in both modes. Before the follow-up, "review OK, poster fails" gave 0 undersh -x.Also run:
scripts/verify-license.sh,scripts/verify-action-pins.sh,go run scripts/verify-english-only.go,git diff --check, and the unchangedpost_review_test.pysuites for gitflic_ci and gerrit_ci. All pass.make testpasses locally (no Go code changed)Checklist
go fmt,go vet)AI disclosure: I found this issue and drafted the fix and the test harness with Claude Code (Claude Opus 5.5). The commit has no AI attribution.
Related Issues
None. I searched issues and PRs for "gitflic exit code", "gerrit exit code", "gitflic-ci" and "Jenkinsfile". No open PR touches either template.
🤖 Generated with Claude Code