diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 20b73319..a18c4994 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -220,7 +220,7 @@ def _pr_markers(reviews: list[dict], head: str, if not eligibility.review_projection(review, head, repo, number)[0] and any( runners.codex_fatal_startup(item) for item in eligibility.review_envelopes(body)[1]): continue - match = REVIEW_MARKER_RE.search(body) + match = eligibility.leading_marker(body) if not match or review.get("commit_id") != match.group(1): continue if not trusted: @@ -894,8 +894,9 @@ def _confirm_review(wt: Path, config: Config, pr: github.PR, result: ReviewResul publisher: str, reviews: list[dict]) -> bool: """Confirm an exact live publication; absence authorizes no automatic write.""" trusted = config.review_publishers or (publisher,) - evidence = [r for r in reviews if "loopzero:review" in (r.get("body") or "") and (r.get("commit_id") == result.head or any( - m.group(1) == result.head for m in REVIEW_MARKER_RE.finditer(r["body"])))] + evidence = [r for r in reviews if "loopzero:review" in (r.get("body") or "") and ( + r.get("commit_id") == result.head + or ((marker := eligibility.leading_marker(r["body"])) and marker.group(1) == result.head))] fresh = github.pr_view(config.repo, pr.number) if fresh.head_sha != result.head or fresh.state != "OPEN" or fresh.base_ref != pr.base_ref: raise CliError("PR changed during publication recovery") diff --git a/src/loopzero/eligibility.py b/src/loopzero/eligibility.py index 981c0bed..4de8fb3d 100644 --- a/src/loopzero/eligibility.py +++ b/src/loopzero/eligibility.py @@ -18,6 +18,14 @@ CONTEXT = "Loop-zero Eligibility" +def leading_marker(body: str) -> re.Match[str] | None: + """The review marker opening the publisher's leading machine block; prose never counts.""" + block, span = runners.leading_review_block(body if isinstance(body, str) else "") + if not block or len(REVIEW_MARKER_RE.findall(span)) != 1: + return None + return REVIEW_MARKER_RE.fullmatch(block[0]) + + def review_envelopes(body: str) -> tuple[str, list[dict]]: """Decode only the publisher's raw-output block, not quoted findings/prose.""" if not isinstance(body, str): @@ -40,7 +48,7 @@ def review_projection(review: dict, head: str, repo: str, number: int): block, span = runners.leading_review_block(body) positions = [i for i, line in enumerate(block) if line.lstrip().startswith("