feat(review): add frozen staged snapshot reviews - #1511
Qiyuanqiii wants to merge 4 commits into
Conversation
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
|
|
@NanaseInori review |
NanaseInori
left a comment
There was a problem hiding this comment.
I re-reviewed the latest head (ad3bd56). The additional state-preservation and cancellation coverage is useful, and the earlier snapshot-rule diagnostic issue is fixed. The overall staged-snapshot design also looks coherent to me.
I found one gitlink case that still breaks the stated staged-mode boundary, though.
stagedDiffHasGitlink() detects mode/index headers containing 160000, but a pure rename of an unchanged gitlink does not necessarily emit any of those headers. Git can render it as only:
diff --git a/subold b/subnew
similarity index 100%
rename from subold
rename to subnewIn that case, stagedDiffHasGitlink() returns false and the change proceeds into ParseDiffText(). finalizeDiff() then attempts:
git show <snapshot-tree>:subnew
even though that tree entry is a gitlink/commit rather than a blob.
In the usual case this may fail because the submodule commit object is not present in the superproject. If that object is present, however, git show can render the commit as output and that content can enter the review path as though it were file content. That is exactly the situation the pre-parser gitlink guard is intended to prevent.
I think the gitlink check should use structural mode information rather than relying only on unified-diff headers. For example, a git diff --raw -z --find-renames ... preflight could reject any changed entry whose old or new mode is 160000, including a 100% gitlink rename.
A regression test for renaming an unchanged gitlink from one path to another would pin this case.
There are also two documentation follow-ups worth including with this feature:
- The localized
architecture.mdfiles still describe the diff provider as having only three modes:Workspace,Commit, andRange. - Both copies of
open-code-review/SKILL.mdstill say “Stage selectively if you want narrower scope”. That is no longer the right guidance once--stagedexists, because bareocr reviewstill includes staged, unstaged, and untracked changes. The skill should route requests such as “review my staged changes” toocr review --staged.
I don't currently see another implementation blocker beyond the gitlink-rename case. CI, CodeQL, Pages, translation-sync, and plugin-contract are all green.
|
@NanaseInori review |
Description
Adds
ocr review --stagedto review the content prepared for the next commit. OCR captures the complete Git index andHEADat the start of the run, then uses that snapshot for the diff and all built-in code-context tools.For example, a partially staged file can contain a defect while its working-tree version already contains the fix. Staged review examines the version that will be committed. The captured input stays stable throughout the review, including when files are edited or staged again.
Snapshot and selection
Capture copies the active index into a private temporary index and writes an immutable Git tree. It checks the original index and the resolved HEAD commit for changes during capture. The tree includes unchanged files used as context. In a repository with no commits, the comparison starts from an empty tree.
Before reading file content, OCR checks the old and new modes in a NUL-delimited raw diff between the captured trees. This rejects changed gitlinks, including pure renames. The review patch retains ordinary rename detection.
The snapshot supplies:
.gitattributes, including attributes used for binary classification..opencodereview/and their referenced documents.Each snapshot rule file, including
rule.json, has a 512 KiB limit. Referenced documents must be ordinary files in the snapshot, specified by repository-relative paths. Missing files, absolute paths, oversized files, and symlink references produce an error.Explicit
--rulefiles,--exclude, global configuration, Git configuration, global attributes, and.git/info/attributesretain their configured sources. Custom MCP servers and external tools use their own data sources and may access the live working tree.Staged paths remain eligible for review regardless of
.gitignorepatterns. OCR applies its directory and secret exclusions, supported-file allowlist, and review-rule exclusions to the paths tracked in the index. Preview shows the selected files, exclusion reasons, and input identity. Each invocation captures the current index.Capture preserves the user's index, working tree, and refs. The private index is removed after capture. Tree objects written to the repository follow Git's normal garbage-collection lifecycle.
Input identity
Staged results use
ocr.run-manifest/v2:input.modestagedinput.resolved_baseinput.snapshot_treeinput.resolved_headinput.exact_rangeJSON preview includes the same input identity. Other review modes keep their v1 format. Consumers of staged results need support for the v2 schema and its tree identity.
Usage and Git support
GIT_INDEX_FILEpaths, and SHA-256 repositories.--stagedis mutually exclusive with--from,--to,--commit, and--resume. Staged sessions currently have no resume support.git add -N), split indexes, and sparse indexes produce an error.The CLI reference and architecture pages are updated in English, Chinese, Japanese, Korean, and Russian. Both copies of the review skill route staged-change requests to
ocr review --stagedand document staged preview, flag conflicts, and resume behavior.Type of Change
How Has This Been Tested?
At
ad3bd56, all GitHub checks passed. The Linux/Windows CI run reports 91.5% Linux coverage and confirms successful execution of the POSIX cancellation and state-preservation regressions.At
fbe46d0, localmake check,make build, and the fullmake coveragesuite passed with 91.1% coverage. The diff package passed race tests. A pure gitlink-rename regression reproduced the prior failure and now passes; raw-diff tests cover special path bytes, SHA-256 object IDs, and malformed records. The compiled CLI rejects the same rename fixture while preserving index bytes, HEAD, and refs.Local validation used Windows/amd64, Go 1.26.5, and Git 2.54.0.windows.1, with implementation baseline
cf64e7080f600d507888a26785ad6a8b7a13ab6a:make license-add,make check, andmake buildpassed.make testsuite passed with the race detector.make coveragereported 91.1%, above the 90% threshold.Regression coverage includes:
file_read,file_find,code_search, andfile_read_diffcontinue to return the original snapshotThe during-capture mutation and cancellation tests use POSIX shell shims. A FIFO handshake triggers cancellation after
write-treecompletes. Linux CI executes these cases; Windows runs the remaining state-preservation cases. Functional tests use local model doubles for deterministic assertions.Pre-commit review
Ran the repository-required
ocr review --audience agent --background ...with OCR v1.11.9 and DeepSeekdeepseek-v4-flash. Both review runs completed all 19 selected production files without a failed review item. Their findings were checked against the code and focused regressions, not treated as automatically correct.Confirmed issues addressed before submission include Git submodule display settings bypassing the changed-gitlink guard; non-blob reads of unchanged gitlinks; implicit content-search recursion into unchanged submodules; lost errors/cancellation during unborn-HEAD probes; and a shared rule-loading deadline that did not scale with the number of documents. The final code also preserves Git diagnostics, uses explicit snapshot parameters, and documents the intentional rule-file restrictions. Focused tests cover the fixes, followed by the full final validation listed above.
The repeated claim that
--attr-sourcerequires Git 2.43 was rejected after checking the Git 2.41 source and documentation, which already implement and document the option. No claim of zero raw model findings is made, and this automated review does not replace contributor self-review.For the wrap-up changes, the configured provider rejected a further
ocr reviewrequest before review completed; that attempt is not counted as a successful review. OCR v1.12.7 delegation mode supplied file selection and Go rules, and Codex reviewed all three changed files (one selected production file plus both test files, which OCR excludes by default). This review found no blocking issues. Focused race tests cover the affected rules/tool packages and new capture-state tests;make checkalso passes.Checklist
AI/LLM disclosure
OpenAI Codex (GPT-6) assisted with implementation, tests, documentation, and preparation of this description. The repository-required pre-commit review uses the open-code-review CLI; its model and result are recorded in the validation section.
Related Issues
Closes #1510.