From 5a2b1a3b567b57ff299c9e8921e7453a67293388 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Wed, 18 Nov 2026 17:18:29 -0500 Subject: [PATCH] A carried approval carries the review it rests on, and that review stays in sight After a person merged the base branch into an approved pull request, CoderHelm posted a new approval whose whole body was one line ("the new commits only bring in the base branch; the PR's own change is the same as the approved "). Posting it rewrote the earlier full review to "Outdated", and the tidy between reviews cuts a review of an older commit to one line, so the pull request's only visible approval had no review in it. - The carried approval now carries the stored review of the approved commit as it was posted (the posted body is now kept on every review record), stated against the new head; a carry of a carry keeps the one review without nesting. - With no stored review to carry (or only an old one-line carry), the pull request is reviewed in full instead. - review_supersede::plan and tidy never rewrite, cut or hide the review the latest carried approval rests on, nor its comments and threads; the old one-line wording is read the same way. - Incident case kr_carried_approval_keeps_its_review with its page. --- .../kr_carried_approval_keeps_its_review.md | 7 + services/common/src/review_supersede.rs | 79 ++++- .../kr_carried_approval_keeps_its_review.rs | 273 ++++++++++++++++++ services/worker/src/passes/review_eval.rs | 2 + services/worker/src/passes/review_policy.rs | 1 + .../worker/src/passes/review_policy_eval.rs | 1 + services/worker/src/passes/review_pr.rs | 229 ++++++++++++--- services/worker/src/passes/review_scope.rs | 1 + services/worker/src/passes/review_sweep.rs | 5 + 9 files changed, 551 insertions(+), 47 deletions(-) create mode 100644 docs/incidents/kr_carried_approval_keeps_its_review.md create mode 100644 services/worker/src/passes/incidents/kr_carried_approval_keeps_its_review.rs diff --git a/docs/incidents/kr_carried_approval_keeps_its_review.md b/docs/incidents/kr_carried_approval_keeps_its_review.md new file mode 100644 index 000000000..e3ff9b8bb --- /dev/null +++ b/docs/incidents/kr_carried_approval_keeps_its_review.md @@ -0,0 +1,7 @@ +# kr. `kr_carried_approval_keeps_its_review` + +**What happened:** CoderHelm approved a pull request on a web app after a full review. A week later a person merged the base branch into it. CoderHelm saw that the PR's own change was the one it had approved, so it did not review again. Instead it posted a new approval on the new head whose whole body was one line: "Approved: the new commits only bring in the base branch; the PR's own change is the same as the approved `dab6dae`." plus the rating footer. Posting it rewrote CoderHelm's earlier reviews to "Outdated: see CoderHelm's latest review", and the tidy between reviews cuts a review of an older commit to one line, so the full review the approval rested on was gone from sight. The pull request's only visible approval had no review in it. A person said: "if this happens we have no review to check". + +**The guarantee:** A carried approval stands on its own. Its body gives the verdict and why the earlier review still holds for the new head ("the PR's own change is unchanged since ``; the new commits only bring in ``"), then that review as it was posted: what was checked, the criteria, the verification, the tests, the notes and findings. The content comes from the stored record of the approved commit's review (the posted body is now kept on every review record); the model is not run again. A carry of a carry keeps the one review and names the commit it was written for, with no nesting. While a carried approval is CoderHelm's latest review, the review it rests on is never rewritten, cut to one line or hidden, its comments stay in sight and its threads stay open; an approval posted the old one-line way is read the same way. A later real review, a merge or a close cuts both as before. With no stored review of the approved commit to carry, or only an old one-line carry with no review in it, the pull request is reviewed in full instead of approved with nothing in sight. + +**Where it's enforced:** `worker::passes::review_pr` (`carried_review`, `carried_approval_body`, `carry_approval`, the `posted_body` on `store_review_record`, and the full review when nothing can be carried), `worker::passes::review_sweep::ReviewRecord::posted_body`, and `common::review_supersede` (`carried_from`, `live_carried_sha`, `kept_for_carry`, used by `plan` and `tidy`). diff --git a/services/common/src/review_supersede.rs b/services/common/src/review_supersede.rs index 85c1fd401..d63a700c2 100644 --- a/services/common/src/review_supersede.rs +++ b/services/common/src/review_supersede.rs @@ -116,9 +116,16 @@ pub fn finding_key(path: &str, body: &str) -> String { /// The plan once review `new_id` is posted, raising the findings `raised` /// ([`finding_key`] of each of its inline comments). pub fn plan(reviews: &[Review], threads: &[Thread], new_id: u64, raised: &[String]) -> Plan { + // A carried approval rests on the review it carries: that one, its + // comments and its threads stay as they are. + let carried = reviews + .iter() + .find(|r| r.id == new_id) + .and_then(|r| carried_from(&r.body)); let earlier: Vec<&Review> = reviews .iter() .filter(|r| r.own && r.id != new_id && r.state != "PENDING") + .filter(|r| !rests_on(r, carried.as_deref())) .collect(); let earlier_ids: Vec = earlier.iter().map(|r| r.id).collect(); let mut out = Plan { @@ -145,7 +152,12 @@ pub fn plan(reviews: &[Review], threads: &[Thread], new_id: u64, raised: &[Strin out.minimize.push(c.node_id.clone()); } } - if !t.resolved && !raised.contains(&finding_key(&t.path, &t.first_body)) { + let kept = t.comments.first().is_some_and(|c| { + reviews + .iter() + .any(|r| r.id == c.review_id && rests_on(r, carried.as_deref())) + }); + if !kept && !t.resolved && !raised.contains(&finding_key(&t.path, &t.first_body)) { out.resolve.push(t.id.clone()); } } @@ -263,6 +275,62 @@ fn is_head(sha: &str, head: &str) -> bool { sha.len() >= 7 && head.len() >= 7 && (head.starts_with(sha) || sha.starts_with(head)) } +// ── Carried approvals ──────────────────────────────────────────────────── +// +// A push that only brings in the base branch is not reviewed again: the +// approval of the earlier commit is posted again on the new head. That +// review's verdict rests on the earlier one, so the earlier one is never cut +// or hidden while the carried approval is CoderHelm's latest word, and the +// carried approval itself carries the earlier review's content. + +/// The mark a carried approval starts with, followed by the commit whose +/// review it carries and ` -->`. +pub const CARRIES_MARK: &str = "`. +pub const CARRIED_REVIEW_MARK: &str = "").unwrap_or(0); + let origin = rest[..end].trim(); + let body = rest.get(end + 3..).unwrap_or(""); + let origin = if origin.is_empty() { + c.approved + } else { + origin + }; + (origin.to_string(), body) + } + None => (c.approved.to_string(), c.review), + }; + // The carried review's own content: no marks of CoderHelm's (a cut or + // brought-up-to-date body), no rating footer. + let review = review + .split("\n\n---\n**Was this review right?**") + .next() + .unwrap_or(""); + let review: String = review + .lines() + .filter(|l| !l.trim_start().starts_with("\n{verdict} on `{head}`: {why}. The review of `{origin_short}` \ + below holds for this commit: what it checked, its notes and its findings.\n\n\ + {CARRIED_REVIEW_MARK}{origin} -->\n{}", + c.approved, + review.trim(), + ) } -/// Posts the approval of `approved` again on `head` (a COMMENT on -/// CoderHelm's own PR, where GitHub refuses a verdict) and records it, so -/// the head carries a visible verdict and later pushes are reviewed from it. -/// Best-effort: a failure is logged and the auto-merge gate still runs. +/// Posts the approval of `carry.approved` again on `head` (a COMMENT on +/// CoderHelm's own PR, where GitHub refuses a verdict), carrying the review +/// it rests on, and records it, so the head carries a visible verdict with +/// what was checked and later pushes are reviewed from it. Best-effort: a +/// failure is logged and the auto-merge gate still runs. #[allow(clippy::too_many_arguments)] async fn carry_approval( state: &WorkerState, @@ -4864,8 +4970,7 @@ async fn carry_approval( msg: &ReviewMessage, job: &LiveJob, head: &str, - approved: &str, - only_base_merged: bool, + carry: &CarriedApproval<'_>, standing: Option, self_authored: bool, ) { @@ -4882,9 +4987,9 @@ async fn carry_approval( else { return; }; - let heading = carried_approval_body(approved, only_base_merged); + let carried = carried_approval_body(carry, head); let body = format!( - "{heading}{}", + "{carried}{}", rating_footer( common::public_urls::app_url(&state.config.stage), &msg.repo_owner, @@ -4915,7 +5020,8 @@ async fn carry_approval( head, "APPROVE", "N/A", - &heading, + &carried, + &carried, event, "", &common::review_stats::ReviewCounts { @@ -4924,7 +5030,7 @@ async fn carry_approval( }, ) .await; - info!(pr = msg.pr_number, head = %head, approved = %approved, event, "Approval carried to the new head"); + info!(pr = msg.pr_number, head = %head, approved = %carry.approved, event, "Approval carried to the new head with the review it rests on"); } /// The PR reviewer's verdict on a run's own PR, for the run. @@ -6029,6 +6135,9 @@ struct ReviewRecord<'a> { verdict: &'a str, risk: &'a str, body: &'a str, + /// The review as posted, without the rating footer: what a carried + /// approval carries to a later head (`carried_review`). + posted_body: &'a str, posted_as: &'a str, action_summary: &'a str, /// RFC 3339; also the end of the sort key. @@ -6068,6 +6177,12 @@ fn review_record_item( .into_iter() .map(|(k, v)| (k.to_string(), v)) .collect(); + if !r.posted_body.is_empty() { + item.insert( + "posted_body".to_string(), + attr_s(&common::head_tail_str(r.posted_body, 30_000)), + ); + } if !r.action_summary.is_empty() { item.insert( "action_summary".to_string(), @@ -6098,6 +6213,7 @@ async fn store_review_record( verdict: &str, risk: &str, body: &str, + posted_body: &str, posted_as: &str, action_summary: &str, counts: &common::review_stats::ReviewCounts, @@ -6112,6 +6228,7 @@ async fn store_review_record( verdict, risk, body, + posted_body, posted_as, action_summary, created_at: &created_at, @@ -7122,21 +7239,42 @@ mod verdict_tests { assert_eq!(super::findings_record(&[]), "[]"); } - /// A carried approval says it is one, and why, in its one line. + /// A carried approval says it is one, why, and carries the review it + /// rests on (its own marks and rating footer left out); a carry of a + /// carry still names the review's own commit and nests nothing. #[test] - fn a_carried_approval_names_the_approved_commit_and_why() { - let merged = super::carried_approval_body("abc1234def", true); + fn a_carried_approval_names_the_approved_commit_and_carries_its_review() { + let review = "\n✅ **Approved with notes**: nothing \ + blocks.\n\n#### Verification\n- typecheck passed\n\n---\n**Was this \ + review right?** Rate it"; + let carry = |approved, only_base_merged, review| super::CarriedApproval { + approved, + only_base_merged, + base_branch: "main", + review, + }; + let merged = super::carried_approval_body(&carry("abc1234def", true, review), "fed9876"); + assert!( + merged.starts_with("\n"), + "{merged}" + ); + assert!(merged.contains( + "✅ **Approved with notes** on `fed9876`: the PR's own change is unchanged since \ + `abc1234`; the new commits only bring in `main`. The review of `abc1234` below" + )); + assert!(merged.contains("#### Verification\n- typecheck passed")); + assert!(!merged.contains("review-updated") && !merged.contains("Was this review right")); assert_eq!( - merged, - "✅ **Approved**: the new commits only bring in the base branch; the PR's own \ - change is the same as the approved `abc1234`." + common::review_supersede::carried_from(&merged).as_deref(), + Some("abc1234def") ); - let docs = super::carried_approval_body("abc1234def", false); - assert!(docs.starts_with("✅ **Approved**: "), "{docs}"); - assert!(docs.contains("only docs, comments or whitespace")); - for b in [merged, docs] { - assert_eq!(b.lines().count(), 1); - } + let docs = super::carried_approval_body(&carry("abc1234def", false, review), "fed9876"); + assert!(docs.contains("only docs, comments or whitespace"), "{docs}"); + let again = super::carried_approval_body(&carry("fed9876aaa", true, &merged), "0a1b2c3"); + assert!(again.contains("unchanged since `fed9876`"), "{again}"); + assert!(again.contains("The review of `abc1234` below"), "{again}"); + assert_eq!(again.matches("coderhelm:carries").count(), 1); + assert_eq!(again.matches("#### Verification").count(), 1); } #[test] @@ -7390,6 +7528,7 @@ mod failure_tests { verdict: "APPROVE", risk: "LOW", body: "Looks right.", + posted_body: "", posted_as: "APPROVE", action_summary: "", created_at: "2026-11-10T12:00:00+00:00", diff --git a/services/worker/src/passes/review_scope.rs b/services/worker/src/passes/review_scope.rs index dc3430a41..4ce1c760b 100644 --- a/services/worker/src/passes/review_scope.rs +++ b/services/worker/src/passes/review_scope.rs @@ -461,6 +461,7 @@ mod tests { body: "Looks good.".into(), fingerprint: None, holding: Vec::new(), + posted_body: String::new(), } } diff --git a/services/worker/src/passes/review_sweep.rs b/services/worker/src/passes/review_sweep.rs index 9cebc43d2..38a20e050 100644 --- a/services/worker/src/passes/review_sweep.rs +++ b/services/worker/src/passes/review_sweep.rs @@ -41,6 +41,9 @@ pub struct ReviewRecord { pub fingerprint: Option, /// What held the merge, by name. pub holding: Vec, + /// The review as posted, without the rating footer (empty on a record + /// older than it): a carried approval carries it to a new head. + pub posted_body: String, } impl ReviewRecord { @@ -126,6 +129,7 @@ fn record_from_item(i: &HashMap) -> ReviewRecord { body: s_of(i, "body"), fingerprint: serde_json::from_str(&s_of(i, "fingerprint")).ok(), holding: serde_json::from_str(&s_of(i, "holding")).unwrap_or_default(), + posted_body: s_of(i, "posted_body"), } } @@ -476,6 +480,7 @@ mod tests { body: body.into(), fingerprint: None, holding: Vec::new(), + posted_body: String::new(), } }