Skip to content

fix(cmd): return non-zero for partial operational failures - #1030

Merged
lizhengfeng101 merged 6 commits into
alibaba:mainfrom
Qiyuanqiii:codex/fix-partial-failure-exit-code
Nov 17, 2026
Merged

lizhengfeng101 merged 6 commits into
alibaba:mainfrom
Qiyuanqiii:codex/fix-partial-failure-exit-code

Conversation

@Qiyuanqiii

@Qiyuanqiii Qiyuanqiii commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

Summary

  • Return a non-zero process status when a partial review contains an operational review-item failure such as a timeout, provider error, bad configuration, panic, cancellation, or unknown failure.
  • Preserve the completed findings, manifest, warnings, and retry report before returning the process error.
  • Keep the historical successful status for partial reviews caused exclusively by configured budget limits.
  • Use the same success policy for the CLI exit status and SARIF executionSuccessful metadata.
  • Add regression coverage for timeout, provider, budget-only, mixed, fully failed, JSON, text, and SARIF outcomes.
  • Synchronize the exit-code documentation across the English, Chinese, Japanese, Korean, and Russian documentation.

Motivation and Scope

Issue #1027 reports that a review with one timed-out file produces a partial result but exits with status 0. That makes CI unable to distinguish complete coverage from an operationally incomplete review.

The previous aggregate exit logic returned an error only for a fully failed manifest. This PR narrows the successful partial case to declared budget limits and makes other operational review-item failures visible to CI without discarding usable output from completed review items.

Implementation

  • Add a shared reviewManifestRequiresNonZeroExit policy for terminal manifest evaluation.
  • Return review incomplete with selected/failed item counts for operational partial failures.
  • Keep fully failed manifests non-zero regardless of failure classification.
  • Apply the same policy to SARIF invocation success metadata while continuing to publish partial SARIF output.
  • Update JSON and text end-to-end tests so provider failures require a non-zero status while preserving their emitted reports.
  • Cover timeout and mixed failure classifications directly, including the budget-only compatibility boundary.
  • Update CLI reference and FAQ content in all maintained locales.

Compatibility and User Impact

  • Complete and skipped reviews continue to exit 0.
  • Partial reviews caused only by configured budget limits continue to exit 0.
  • Partial reviews containing operational failures now exit 1, allowing CI to detect incomplete coverage.
  • Findings and diagnostics from completed files remain available before the error is returned.
  • No CLI flags, configuration keys, manifest schema, or output formats change.

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?

Initial Validation Environment

  • OS: Windows/amd64, build 26200.9168
  • Go: go1.26.5 windows/amd64
  • Baseline: cfbb62e2296d7684dc648e27fe1b906e8c960f9c

Initial Automated Validation

  • Project make check target through mingw32-make: license headers, English-only source check, go mod tidy, formatting, and go vet
  • Project make test target through mingw32-make: complete Go test suite with the race detector
  • Project make coverage target through mingw32-make: 90.6% total statement coverage, above the required 90%
  • git diff --check
  • LF-only verification for every changed file

Documentation Completion and Main Sync

The Korean CLI reference and FAQ now describe operational partial failures, preserved review output, and budget-only partial success, matching the other four locales.

  • Merged upstream 070805f86cc6ae4b987bfe733dfc14ecd5bb803a in ecbf7dab0b6dfe89e7d0fef181592e698d063db1. The two retry-report E2E assertions now match upstream's four-file fixture.
  • Added the Korean documentation in 91b3bfa4452aaae710d6e4157f4cf4f40ed7ac69.
  • Validation after the sync: make check, make test for cmd/opencodereview and internal/agent with the race detector, and full make coverage passed. Total statement coverage is 91.1%.
  • Documentation translation sync, repository links, UTF-8/LF validation, and git diff --check passed.

Regression Coverage

  • A partial manifest containing a timeout now produces a process error with failed/selected item counts.
  • Provider-failure end-to-end tests require a non-zero status while still parsing the emitted JSON and text retry reports.
  • A budget-only partial remains successful; a mixed budget and timeout partial fails.
  • A fully failed manifest remains non-zero regardless of classification.
  • SARIF marks operational partial runs unsuccessful and budget-only partial runs successful.

The repository-requested self-review completed successfully:

[ocr] Summary: 3 file(s) reviewed, 0 comment(s)
Review complete: 0 finding(s) across 3 selected item(s).

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 the fix works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly
  • I have signed the CLA

Known Limitations

  • Local validation was performed on Windows/amd64; remote CI remains responsible for the repository's other supported environments.
  • The timeout exit boundary is covered deterministically at the manifest layer rather than by waiting for a live slow provider; provider-failure end-to-end tests exercise the same partial-output/non-zero-exit command path.

Related Issues

Closes #1027.

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s).

@Qiyuanqiii
Qiyuanqiii marked this pull request as ready for review August 21, 2026 10:44

@wu21-web wu21-web 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.

Good job.

@Qiyuanqiii
Qiyuanqiii force-pushed the codex/fix-partial-failure-exit-code branch from c6ea09f to 4469700 Compare August 25, 2026 13:38
@crestonepeaks

Copy link
Copy Markdown
Contributor

@lizhengfeng101, would you be able to review the current head when you have a chance? We’re successfully using OpenCodeReview downstream, and we’re treating the fix for #1027 as the remaining upstream blocker before enabling a broader rollout. The current checks are green and GitHub reports the PR as mergeable. If additional changes are needed—or if you can share an approximate review timeline—we’d appreciate the guidance. We’re also happy to help with this PR in any way that would be useful. Thank you!

@NanaseInori NanaseInori left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for addressing #1027. The implementation correctly distinguishes operational partial failures from budget-only truncation, preserves the emitted manifest/results before returning the process error, and aligns SARIF executionSuccessful with that manifest-based policy. I also checked the 14 successful GitHub checks on the current head.

Changes requested — update the remaining public exit-code contract:

  • cmd/opencodereview/shared_flags.go still states for --max-tokens-budget that "Partial results are published and review exits 0; it exits non-zero only if every selected item failed". With this PR, a partial review containing a timeout/provider error exits non-zero, even if some items completed.
  • action.yml and the CI integration guides still describe partial review exit 0 without restricting that statement to budget-only partial runs. Please qualify these texts to match the new policy. This should be a small documentation/help-text change.

Integration caveat (please clarify, or address separately): The current GitHub composite Action runs Fail job on OCR error when OCR_EXIT_CODE != '0' and executes Post review comments only when OCR_EXIT_CODE == '0'. After this fix, operationally partial reviews retain their CLI JSON/results (and optional artifacts) but their completed findings are not posted as PR review comments by this Action. If Action-level publication is out of scope, please make that distinction explicit.

I did not find a further blocking problem in the manifest classification logic itself.

This review was conducted by NanaseInori's review bot, using the model GPT-6. If you need a human review, please manually @NanaseInori.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Thanks for addressing #1027. The core exit-code policy and the shared CLI/SARIF success check look right. From the maintainer side, please address both items below in this PR before merging, rather than deferring them to follow-ups.

1. Synchronize the public exit-code contract

The CLI reference and FAQ have been updated, but cmd/opencodereview/shared_flags.go, the input description in action.yml, and the localized CI integration guides still contain the old partial-success wording. Please make these consistent:

  • Partial reviews with operational failures, such as timeouts or provider errors, exit non-zero even when other items completed.
  • Budget-only partial reviews with usable coverage continue to exit 0.
  • Fully failed reviews remain non-zero, including when every selected item failed because of budget limits.

Please also distinguish emitting partial CLI results from displaying or publishing those results in downstream integrations.

2. Preserve partial findings in both IDE integrations

Both the VS Code and IntelliJ CliService implementations currently reject non-zero exits before parsing the captured stdout. With this change, a review that finds an issue in one file but times out on another will therefore stop displaying the completed findings, even though the CLI still emits them.

Please update both integrations to preserve and display a valid partial review result while clearly reporting that the review did not complete successfully. Execution status and available findings need to be handled separately; this should not turn arbitrary non-zero exits into success or hide errors when output is missing or invalid. Updating only the result-to-view status mapping is insufficient because the current exception occurs before result parsing.

Please add regression tests in both integrations for a non-zero exit with valid partial JSON containing at least one finding: the finding remains available, the incomplete status is surfaced, and ordinary CLI failures still follow the error path.

The intended CLI exit-code change should remain. These additions are needed to make its public contract consistent and avoid regressing existing IDE workflows when users upgrade.

AI assistance: OpenAI Codex was used for analysis and drafting this feedback.

@Qiyuanqiii

Copy link
Copy Markdown
Contributor Author

Thanks for addressing #1027. The core exit-code policy and the shared CLI/SARIF success check look right. From the maintainer side, please address both items below in this PR before merging, rather than deferring them to follow-ups.

1. Synchronize the public exit-code contract

The CLI reference and FAQ have been updated, but , the input description in , and the localized CI integration guides still contain the old partial-success wording. Please make these consistent:cmd/opencodereview/shared_flags.go``action.yml

  • Partial reviews with operational failures, such as timeouts or provider errors, exit non-zero even when other items completed.
  • Budget-only partial reviews with usable coverage continue to exit .0
  • Fully failed reviews remain non-zero, including when every selected item failed because of budget limits.

Please also distinguish emitting partial CLI results from displaying or publishing those results in downstream integrations.

2. Preserve partial findings in both IDE integrations

Both the VS Code and IntelliJ implementations currently reject non-zero exits before parsing the captured stdout. With this change, a review that finds an issue in one file but times out on another will therefore stop displaying the completed findings, even though the CLI still emits them.CliService

Please update both integrations to preserve and display a valid partial review result while clearly reporting that the review did not complete successfully. Execution status and available findings need to be handled separately; this should not turn arbitrary non-zero exits into success or hide errors when output is missing or invalid. Updating only the result-to-view status mapping is insufficient because the current exception occurs before result parsing.

Please add regression tests in both integrations for a non-zero exit with valid partial JSON containing at least one finding: the finding remains available, the incomplete status is surfaced, and ordinary CLI failures still follow the error path.

The intended CLI exit-code change should remain. These additions are needed to make its public contract consistent and avoid regressing existing IDE workflows when users upgrade.

AI assistance: OpenAI Codex was used for analysis and drafting this feedback.

Resolved

@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 b5e81a1 into alibaba:main Nov 17, 2026
19 checks passed
@Qiyuanqiii
Qiyuanqiii deleted the codex/fix-partial-failure-exit-code branch November 17, 2026 06:25
crestonepeaks added a commit to crestonepeaks/open-code-review that referenced this pull request Nov 26, 2026
- Classify provider budget/quota exhaustion as session.FailureProvider
  instead of session.FailureBudget so partially completed reviews still
  exit non-zero under the alibaba#1030 contract, and add a regression test for
  partial success followed by quota exhaustion.
- Preserve collected findings from applyResume() when grouping aborts on
  a provider quota error instead of returning nil comments.
- Emit a safe, stable diagnostic message in provider_budget_exceeded
  warnings instead of raw provider error text.
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.

ocr timed out and failed for some files, but status code=0

5 participants