Skip to content

feat: add opt-in gate for saved review results - #1457

Closed
Qiyuanqiii wants to merge 2 commits into
alibaba:mainfrom
Qiyuanqiii:codex/result-gate
Closed

Qiyuanqiii wants to merge 2 commits into
alibaba:mainfrom
Qiyuanqiii:codex/result-gate

Conversation

@Qiyuanqiii

@Qiyuanqiii Qiyuanqiii commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Summary

  • Add an opt-in ocr gate command that evaluates a saved review JSON result without running another review or calling a model.
  • Require complete, internally consistent coverage of the selected items and check recorded comment-submission failures.
  • Support optional severity thresholds and exact expected base/head object IDs.
  • Emit a separate ocr.gate/v1 decision with pass, fail, or inconclusive, ordered checks, and stable reason codes. Only pass exits 0.
  • Add evaluator and CLI regression tests, including results emitted by the existing review-output producer, and synchronize the CLI reference in English, Chinese, Japanese, Korean, and Russian.

Motivation and Scope

A review process finishing successfully does not necessarily mean its result meets a team's merge requirements. For example, a budget-limited partial review can leave selected files unreviewed, while a complete review can report high-severity findings. CI needs a separate, explicit policy decision without spending model tokens again or embedding different interpretations in each platform integration.

This PR implements that decision as a standalone command over an existing artifact. Running ocr gate opts into the policy; existing ocr review behavior is unchanged.

This complements #1030, which addresses process exit status and SARIF execution metadata for operational partial failures. The gate has a different responsibility: budget-only partial coverage is also insufficient to pass, and findings can block an otherwise complete run when a severity threshold is enabled. This change does not depend on #1030 being merged and does not change its scope.

Usage

ocr gate --input ocr-result.json --fail-on-severity high --format json

# Optionally require the exact immutable input reviewed by the producer.
ocr gate --input ocr-result.json \
  --expected-base <resolved-base-sha> \
  --expected-head <reviewed-head-sha>

# Read an artifact from stdin.
ocr gate --input - --fail-on-severity high --format json < ocr-result.json

--input is required. Text output is the default; severity and revision checks are disabled until their corresponding flags are supplied. Revision flags accept full lowercase 40- or 64-character object IDs, not mutable branch names. For a range review, the expected base is the resolved merge base, not the requested branch tip.

Implementation

  • internal/gate evaluates the artifact through an io.Reader; it does not resolve Git refs, read a checkout, or call a model or hosting API.
  • Validate the supported review-manifest version, operation, input mode, run identity, all five coverage arrays, item identity, and agreement between coverage outcomes and the reported terminal status. Outcomes must form an exact, disjoint partition of the selected set.
  • Require the findings field while accepting the producer's legitimate comments: null for an empty slice. Additional metadata fields are tolerated; missing evidence and unknown manifest versions cannot pass.
  • Check delivery evidence using tool failure counts and names, without echoing raw tool arguments or error payloads. A recorded code_comment failure remains inconclusive even after a later success because the artifact does not establish that the same findings were resubmitted.
  • Apply severity thresholds to all original findings, including findings not published inline. Matching is case-insensitive and ignores surrounding whitespace.
  • Register the CLI without a Git prerequisite. Read the input without modifying it, emit the decision, and use the existing command-error path for a non-zero exit.

Decision Rules

The following outcomes assume the other applicable checks pass:

Evidence or condition Gate result Exit
Every selected item completed or was reused under the existing resume contract pass 0
A finding meets or exceeds the configured severity threshold fail 1
Failed items, including budget stops; waived items; or a run-level failure inconclusive 1
Zero selected items inconclusive 1
Missing/inconsistent evidence, legacy output, unknown manifest version, or malformed JSON inconclusive 1
Any recorded code_comment failure inconclusive 1
Exploratory search/read failures alone, with consistent failure accounting pass 0
Missing/unknown finding severity when the severity check is enabled inconclusive 1
An expected revision does not match, is absent, or the artifact describes a workspace review inconclusive 1

A confirmed severity violation takes precedence over inconclusive coverage or delivery checks, but all evaluated checks remain in the output. Invalid arguments, input-file errors, and output-write errors also exit 1; these may produce only a stderr diagnostic rather than a complete decision document.

Compatibility and CI Integration Boundary

  • No existing review flags, exit codes, manifest fields, scheduling, retry behavior, resume semantics, or SARIF output change.
  • Coverage and delivery checks are mandatory once the gate is invoked. Severity and revision checks are explicitly optional.
  • A pass applies to the selected set. Manifest v1 cannot prove that selection included every intended file, or distinguish an empty change from changes entirely excluded by selection; zero selected items therefore remain inconclusive.
  • CI must retain the original review exit status. A gate pass must not mask a process or publishing failure.
  • Use a fresh result path for each review because a failed review may leave an earlier output file untouched. Preserve the artifact even on failure, evaluate the gate, and fail CI if either execution or policy failed.

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?

Validation Environment

  • OS: Windows/amd64, build 26200.9457
  • Go: go1.26.5 windows/amd64
  • Baseline: a003b9341a65130b024829101ea35494b56569e1

Automated Validation

  • make license-add
  • Project make check target through mingw32-make with Git Bash: license headers, English-only source check, module tidying, formatting, and go vet
  • Project make test target: complete Go test suite with the race detector
  • Project make coverage target: 91.4% total statement coverage, above the required 90%; 100.0% for internal/gate
  • Project make build target with a local executable name
  • git diff --check and LF-only verification of changed files

Regression Coverage

  • Complete, reused, waived, skipped, run-level failure, and partial budget/timeout/provider outcomes.
  • Missing/null coverage arrays, duplicate or unknown item IDs, mismatched paths/fingerprints, unaccounted items, and contradictory terminal states.
  • Missing findings, producer-emitted null findings, unknown severities, threshold boundaries, and independent blocking findings retained alongside incomplete coverage.
  • Missing or inconsistent tool failure evidence, comment-submission failures, and exploratory failures that do not independently block.
  • Exact revision matches/mismatches, missing reviewed revisions, and workspace artifacts that cannot attest immutable inputs.
  • Malformed and trailing JSON, input/output errors, file and stdin input, deterministic output, unchanged input files, and command registration without a Git prerequisite.
  • CLI contract tests consume the real emitRunResult output rather than relying only on handcrafted JSON fixtures.

Manual Validation and Review

  • Executed the built CLI from a directory outside any repository with an empty PATH: pass exited 0; threshold failure and malformed-input inconclusive decisions exited 1; stdout remained parseable JSON.
  • Verified stdin input and an exact expected-head match using the built executable.
  • Completed an OCR delegation self-review of all 3 reviewable production files (3 reviewed, 0 skipped); separately inspected the 2 test files and 5 documentation pages.

The repository-required pre-commit review also completed successfully using ocr review --audience agent --background ...:

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

Known Limitations and Follow-up Scope

  • The artifact, policy, and expected revisions must be trusted. The gate does not authenticate JSON, query the live PR head, attest publication success, or certify that code has no defects.
  • Missing expected-revision flags leave revision matching unchecked. Reused items rely on OCR's existing resume contract.
  • Platform-specific CI adapters, live-head freshness enforcement, selection/exclusion evidence, and waiver policy are follow-up work. This PR supplies the shared offline command they can consume.
  • Local validation was performed on Windows/amd64; remote CI remains responsible for the other supported environments.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have added tests that prove my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly
  • I have performed a personal self-review of all generated code and text before requesting maintainer review
  • I have confirmed CLA coverage for this contribution
  • I disclosed AI/LLM use, personally reviewed its output, and will answer maintainer questions and review comments from my own understanding

AI/LLM Disclosure

Codex (GPT-6-Astra Max) was used for tests, documentation
The required pre-commit model review used open-code-review CLI v1.11.9 with the configured deepseek-v4-flash model.

Related Issues

Related to #1027 and #1030. This PR adds a separate opt-in policy layer and does not change the timeout exit-code behavior tracked in #1027.

@CLAassistant

CLAassistant commented Sep 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Qiyuanqiii

Copy link
Copy Markdown
Contributor Author

666,cla过期的来

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

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

  • ✅ Successfully posted inline: 2 comment(s)

Comment thread internal/gate/gate.go Resolved
Comment thread internal/gate/gate.go Resolved

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

Reviewed the current head (06312c5). I don't see a blocking issue in the implementation.

The opt-in boundary is clear: ocr gate evaluates an existing JSON artifact without changing ocr review behavior, rerunning the model, consulting Git, or pretending to attest the live PR head. The evaluator is conservative about evidence: unsupported/legacy manifests, malformed or inconsistent coverage, zero selected items, run/coverage failures, missing delivery evidence, failed code_comment calls, revision mismatches, and unknown severities all avoid a false pass. Established severity violations correctly take precedence over inconclusive checks while retaining the independent reasons.

The result contract is deterministic and machine-readable, policy validation happens before consuming input, the command keeps stdout suitable for CI decisions, and the integration tests exercise the actual emitRunResult output rather than only synthetic internal structs. I also appreciate that the documentation explicitly states the trust boundary: the artifact is assumed trusted, live-head freshness is opt-in via expected immutable revisions, and callers must preserve the original review exit status rather than using a gate pass to mask an execution failure.

Given those constraints are explicit and the feature is opt-in, this adds a useful deterministic CI layer without silently changing review semantics.

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

@Qiyuanqiii
Qiyuanqiii marked this pull request as ready for review September 19, 2026 14:44
@lizhengfeng101

Copy link
Copy Markdown
Contributor

Thanks for the contribution. The CI workflow you describe is useful, but I think the decision to block a build belongs outside OCR. One team may want a high-severity finding to fail CI and require the author to fix it; another may want the same finding to trigger a notification. Both should be able to use the same review report. A team that switches review tools should also be able to keep its policy and change only how its CI script reads the findings.

I'd like OCR to focus on producing a stable, machine-readable account of what it reviewed and what it found, and leave the pass/fail decision to an external script or CI integration. I'm closing this PR on that scope decision, not because the use case is invalid. If the report is missing information an external integration needs, that would be a useful issue to discuss separately.

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.

4 participants