Skip to content

fix(examples): fail GitFlic and Gerrit jobs when ocr review fails - #2032

Merged
lizhengfeng101 merged 3 commits into
alibaba:mainfrom
thejesh23:fix/examples-ci-exit-code
Nov 22, 2026
Merged

lizhengfeng101 merged 3 commits into
alibaba:mainfrom
thejesh23:fix/examples-ci-exit-code

Conversation

@thejesh23

@thejesh23 thejesh23 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

The GitFlic and Gerrit CI examples finish green when ocr review fails. GitFlic also posts the failure message to the MR behind a ✅.

Where: examples/gitflic_ci/gitflic-ci.yaml (review and post steps) and examples/gerrit_ci/Jenkinsfile (Review and Post to Gerrit stages).

Root cause: both templates end ocr review with || true. Then, if stdout is empty, the posting step runs exit 0. ocr review exits non-zero when a run fails outright, when every item failed, or when a partial review has operational failures. reviewResultError in cmd/opencodereview/review_cmd.go says this is "so CI cannot mistake incomplete coverage for success". || true discards exactly that signal:

  • Run-level failure (bad token, unreachable endpoint, missing model): stdout is empty, the post step prints "skipping post" and runs exit 0, and the job is green.
  • All or some items failed: the JSON is non-empty (status: failed or partial). 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_CODE gate) and the Bitbucket template already fail the job on a non-zero ocr exit. These two are the outliers.

Fix: keep publishing whatever ocr produced, then fail the job with ocr's exit code.

  • GitFlic: capture 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. If ocr succeeded, it exits with the poster's code. The code goes through a file, so this works whether or not the runner shares one shell across script: entries.
  • Gerrit: || echo "$?" > ocr-exit-code, with rm -f first 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

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

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). ocr was 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:

raw ocr exit: 1
stdout: 4120 bytes, status=failed | "Review failed: 0 finding(s); 1 of 1 selected item(s) failed."
same command with `|| true` (current templates): 0

Behaviour diff, main vs this branch. I extracted the review and post scripts verbatim from both templates (YAML via js-yaml, Groovy sh ''' blocks) and ran them with a fake ocr (exit code and output controlled) and a fake poster. GitFlic was run two ways: all entries in one bash -e and each entry in its own sh -e. Jenkins stages were run with sh -xe in a shared workspace. The numbers are the job's exit code, as main → this branch:

Scenario GitFlic (one shell) GitFlic (separate shells) Jenkins
review OK, JSON 0 → 0 0 → 0 0 → 0
items failed, JSON (exit 1) 0 → 1 0 → 1 0 → 1
run-level failure, no output (exit 1) 0 → 1 0 → 1 0 → 1
review OK, poster fails (exit 2) 2 → 2 2 → 2 2 → 2
review fails and poster fails 2 → 1 2 → 1 2 → 1
review OK, no output 0 → 0 0 → 0 0 → 0
stale ocr-exit-code from an earlier build 0 → 0 0 → 0 0 → 0

When 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 when sh -e is off, for example when a #!/bin/bash line is added to the block. I re-ran the Jenkins column with sh -x as well as sh -xe, and every row above holds in both modes. Before the follow-up, "review OK, poster fails" gave 0 under sh -x.

Also run: scripts/verify-license.sh, scripts/verify-action-pins.sh, go run scripts/verify-english-only.go, git diff --check, and the unchanged post_review_test.py suites for gitflic_ci and gerrit_ci. All pass.

  • make test passes locally (no Go code changed)
  • Manual testing (described above)

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works (no harness for the CI templates; the shell matrix above shows the change)
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable): the in-template comments
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

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

@CLAassistant

CLAassistant commented Nov 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 1 comment(s)

Comment on lines +97 to +107
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

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.

bug · high
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"

@lizhengfeng101

Copy link
Copy Markdown
Contributor

@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 1.7.12 to 1.14.0. Please keep the exit-code handling you added: the old || true would mask failures on any version, and 1.7.12 can still exit with 0 when one file hits a provider error but another is reviewed successfully. Updating the pin is enough; there's no need for a workaround for older versions.

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.

@lizhengfeng101 lizhengfeng101 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.

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 78c2e0e into alibaba:main Nov 22, 2026
12 checks passed
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