Repository navigation
Surface recoverable saved reviews before retrying #1127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
db11fe5
1d269c2
7ed12b8
2398111
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -813,24 +813,10 @@ def cmd_review(args: argparse.Namespace, wt: Path, config: Config) -> int: | |
| kind, reviewed = _decide_kind( | ||
| _pr_markers(reviews, head, config.review_publishers, repo=config.repo, number=pr.number), head | ||
| ) | ||
| publication_context = {"repo": config.repo, "number": pr.number, "publisher": publisher} | ||
| if args.repost: | ||
| authors = runners.author_families(wt, head, _primary_base(wt, config)) | ||
| excluded = [family for family in config.reviewers if family in authors] | ||
| result = _load_review(wt, head, kind) | ||
| if result.fallback and result.family not in excluded: | ||
| raise CliError( | ||
| f"saved review claims a same-family fallback, but {result.family} is not a configured " | ||
| "reviewer family that contributed to this PR lineage; run without --repost" | ||
| ) | ||
| if not result.fallback and not any(family not in authors for family in config.reviewers): | ||
| raise IndependentReviewerUnavailable( | ||
| _independence_message(authors, excluded, []) | ||
| ) | ||
| if result.family in authors and not result.fallback: | ||
| raise IndependentReviewerUnavailable( | ||
| f"saved reviewer family {result.family} contributed to this PR lineage; " | ||
| "run without --repost to obtain an independent review" | ||
| ) | ||
| candidates, excluded = _repost_reviewer_families(wt, config, head, result) | ||
| publication = json.loads(_review_file(wt, head, kind).read_text()).get("publication") | ||
| if publication is not None: | ||
| if (not isinstance(publication, dict) or publication.get("repo") != config.repo | ||
|
|
@@ -845,7 +831,6 @@ def cmd_review(args: argparse.Namespace, wt: Path, config: Config) -> int: | |
| else: | ||
| reviews = _pr_reviews(config.repo, pr.number) | ||
| # Exact read-back above may confirm an older published note; a new post needs the current form. | ||
| candidates = [family for family in config.reviewers if family not in authors] | ||
| if result.fallback and not _published_fallback(result.fallback, candidates, excluded): | ||
| raise CliError("saved fallback note is not in the published form; run without --repost") | ||
| allowed, _ = _decide_kind( | ||
|
|
@@ -854,6 +839,10 @@ def cmd_review(args: argparse.Namespace, wt: Path, config: Config) -> int: | |
| if allowed != kind: | ||
| raise CliError("saved review kind differs from the remaining review budget") | ||
| else: | ||
| if args.model is None and args.effort is None and _has_recoverable_review( | ||
| wt, config, head, kind, publication_context, | ||
| ): | ||
| raise CliError(f"saved {kind} review for {head[:12]}; run `loopzero review --repost`") | ||
| try: | ||
| result = _run_review(wt, config, head, kind, reviewed, args.model, args.effort, | ||
| runtime_source=runtime_source, publication=(config.repo, pr.number, publisher)) | ||
|
|
@@ -876,7 +865,7 @@ def cmd_review(args: argparse.Namespace, wt: Path, config: Config) -> int: | |
| raise CliError("native publication context changed; HOLD") | ||
| if args.repost: | ||
| prefix = _repost_prefix(result) | ||
| _save_review(wt, result, {"repo": config.repo, "number": pr.number, "publisher": publisher}) | ||
| _save_review(wt, result, publication_context) | ||
| token = _refresh_publisher_token(token, publisher) | ||
| try: | ||
| github.post_review( | ||
|
|
@@ -922,6 +911,47 @@ def _review_verdict(result: ReviewResult) -> int: | |
| return 0 if result.verdict == "approve" else 5 # the exit code is the verdict, as for check | ||
|
|
||
|
|
||
| def _repost_reviewer_families( | ||
| wt: Path, config: Config, head: str, result: ReviewResult, | ||
| ) -> tuple[list[str], list[str]]: | ||
| authors = runners.author_families(wt, head, _primary_base(wt, config)) | ||
| excluded = [family for family in config.reviewers if family in authors] | ||
| if result.fallback and result.family not in excluded: | ||
| raise CliError( | ||
| f"saved review claims a same-family fallback, but {result.family} is not a configured " | ||
| "reviewer family that contributed to this PR lineage; run without --repost" | ||
| ) | ||
| if not result.fallback and not any(family not in authors for family in config.reviewers): | ||
| raise IndependentReviewerUnavailable( | ||
| _independence_message(authors, excluded, []) | ||
| ) | ||
| if result.family in authors and not result.fallback: | ||
| raise IndependentReviewerUnavailable( | ||
| f"saved reviewer family {result.family} contributed to this PR lineage; " | ||
| "run without --repost to obtain an independent review" | ||
| ) | ||
| return [family for family in config.reviewers if family not in authors], excluded | ||
|
|
||
|
|
||
| def _has_recoverable_review( | ||
| wt: Path, config: Config, head: str, kind: str, publication: dict, | ||
| ) -> bool: | ||
| other_kind = "delta" if kind == "primary" else "primary" | ||
| if not _review_file(wt, head, kind).exists() or _review_file(wt, head, other_kind).exists(): | ||
| return False | ||
| try: | ||
| result = _load_review(wt, head, kind, publication=publication) | ||
| candidates, excluded = _repost_reviewer_families(wt, config, head, result) | ||
| if result.fallback and not _published_fallback(result.fallback, candidates, excluded): | ||
| return False | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Recoverability check copies the repost path's fallback and evidence checks
|
||
| evidence = runners.codex_evidence(result) | ||
| except (CliError, runners.RunnerBadOutput): | ||
| return False | ||
| return evidence is None or (evidence["repo"], evidence["pr"], evidence["publisher"]) == ( | ||
| publication["repo"], publication["number"], publication["publisher"], | ||
| ) | ||
|
|
||
|
|
||
| def _repost_prefix(result: ReviewResult) -> str: | ||
| sessions = result.provenance["session_ids"] | ||
| return review_marker(result.head, result.kind, "repost") + "\n" + ( | ||
|
|
@@ -1153,22 +1183,24 @@ def _save_review(wt: Path, result: ReviewResult, publication: dict | None = None | |
| _write_json_atomically(directory, path.name, data) | ||
|
|
||
|
|
||
| def _load_review(wt: Path, head: str, kind: str) -> ReviewResult: | ||
| def _load_review( | ||
| wt: Path, head: str, kind: str, *, publication: dict | None = None, | ||
| ) -> ReviewResult: | ||
| path = _review_file(wt, head, kind) | ||
| if not path.exists(): | ||
| raise CliError(f"no saved {kind} review for {head[:12]} at {path}; run without --repost") | ||
| try: | ||
| data = json.loads(path.read_text()) | ||
| except (json.JSONDecodeError, OSError) as exc: | ||
| except (ValueError, OSError) as exc: | ||
| raise CliError(f"{path} is not runner-produced: invalid saved review") from exc | ||
| if not isinstance(data, dict): | ||
| raise CliError(f"{path} is not runner-produced: invalid saved review") | ||
| if data.get("head") != head: | ||
| raise CliError(f"{path} holds a review of {str(data.get('head'))[:12]}, not HEAD {head[:12]}") | ||
| try: | ||
| data.pop("publication", None) | ||
| if data.get("kind") != kind: | ||
| raise ValueError("saved review kind mismatch") | ||
| saved_publication = data.pop("publication", None) | ||
| if data.get("kind") != kind or (publication is not None and saved_publication != publication): | ||
| raise ValueError("saved review kind or publication mismatch") | ||
| findings = tuple(Finding(**f) for f in data["findings"]) | ||
| # Ordinary receipts written before pair retirement still carry these defaults. | ||
| for field, default in (("members", []), ("reconciliation", ""), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Refusal message doesn't say how to get a fresh review on purpose
When a valid receipt exists, a plain
loopzero reviewstops and only points to--repost. The only documented ways to get a fresh review are--modelor--effort, but the error doesn't mention them. Someone who wants to discard the saved result has to read the code to find out. Smallest fix: add to the message, e.g. "...; or pass --model/--effort to run a fresh review".