Skip to content

fix(gitlab_ci): fail on review publication errors - #2002

Open
gengwg wants to merge 3 commits into
alibaba:mainfrom
gengwg:fix/gitlab-ci-publication-gate
Open

gengwg wants to merge 3 commits into
alibaba:mainfrom
gengwg:fix/gitlab-ci-publication-gate

Conversation

@gengwg

@gengwg gengwg commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

examples/gitlab_ci/post_review.py now returns a non-zero exit status when:

  • the OCR result is missing or is not valid JSON;
  • one or more inline discussions could not be posted; or
  • the MR summary note could not be created or updated.

Summary writes now carry an explicit success outcome instead of using summary_url as a proxy for success. A stale URL from a failed update no longer hides the failure, and a successful GitLab response without a note URL does not cause a false failure. ZERO_STATS exposes the same summary_failed field on early exits.

The publishing flow still finishes and renders failed inline findings into the summary before returning the error. Findings with no line information and findings intentionally routed to the summary remain nonfatal. The existing .gitlab-ci.yml gate already captures POST_EXIT_CODE, so these failures now reach the pipeline status as its comments describe.

Tests

Added coverage for failed inline posts, summary read and update failures, malformed JSON, early-exit stats, summary-only findings, and a successful summary response without a URL.

  • python -m unittest discover -s examples/gitlab_ci -p '*_test.py': 161 tests passed.
  • The same new test file against the unmodified upstream script reports five failing regression cases, confirming that the control detects the old behavior.
  • make check, make test, and make build passed. For the local Go test run, submodule recursion was disabled because the host's global Git setting conflicts with the tests' git grep --untracked mode.
  • CLI smoke test: malformed JSON exited 1; a valid dry run exited 0.
  • OCR review completed with no findings.

AI/LLM disclosure

This change was implemented and tested with AI assistance using OpenCode with Kimi K3.1 Pro, based on publication failures observed in a real private GitLab MR pipeline. The complete diff and the failure-path control were reviewed before submission. No private repository links or credentials are included, and no AI attribution is included in the commit.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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

  • ✅ Successfully posted inline: 1 comment(s)

Comment on lines +1278 to +1279
"routed": 0, "skipped": 0, "failed": 0, "summary_url": None,
"summary_failed": True}

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 · medium
ZERO_STATS is missing the new summary_failed key that was added to the stats dict returned by publish(). While write_stats_file currently uses .get() and won't crash, this creates an inconsistent schema: any caller or test that directly accesses stats["summary_failed"] after receiving ZERO_STATS (e.g., from the error paths at lines 1603, 1607, 1623) will get a KeyError. Add the key to keep the constant consistent with the documented stats structure.

Suggestion:

Suggested change
"routed": 0, "skipped": 0, "failed": 0, "summary_url": None,
"summary_failed": True}
"routed": 0, "skipped": 0, "failed": 0, "summary_url": None,
"summary_failed": True}
# Also update ZERO_STATS (line 1492-1493) to include the new key:
# ZERO_STATS = {"total": 0, "inline": 0, "summary": 0,
# "routed": 0, "skipped": 0, "failed": 0, "summary_url": None,
# "summary_failed": False}

@chaojixinren

Copy link
Copy Markdown
Contributor

@gengwg resolve conflicts

@gengwg
gengwg force-pushed the fix/gitlab-ci-publication-gate branch from 22a31b0 to 8ef3c53 Compare November 19, 2026 16:27

@chaojixinren chaojixinren 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.
Reproduced locally: main returns 0 on posting failure, PR returns 1. Fix is precise and tests are comprehensive.

upsert_summary(poster, body, config.get("sticky_summary", True),
tag=summary_tag_for(run_tag))
return 0
return 1

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.

Could you update the README’s “skip if already reviewed” example alongside this change? Returning 1 here is correct when OCR was expected to produce a result. But that example deliberately exits the Python wrapper before creating ocr-result.json when it finds an existing review. The next YAML step still invokes post_review.py, so a subsequent push to an already-reviewed MR now fails the job. The default template is unaffected.

I reproduced this with a mocked existing MR note in a clean directory: the wrapper exited 0 without running OCR or writing JSON; the subsequent poster exited 0 on the base commit and 1 on this PR.

Please invoke the poster only in the branch that actually runs OCR, and propagate its exit status there. That keeps an intentional skip green without masking a genuinely missing result. Those two cases would make a useful regression check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 703cd71 and c298ff1, including the docs-site copies.

This branch has not been deployed

No deployments
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