From 0a7f0e35b557628b32f1c144f9163f08c5234a68 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Sat, 5 Dec 2026 19:07:40 -0500 Subject: [PATCH 1/3] Name the single-reviewer path tally type --- services/common/src/pr_overview.rs | 5 +++-- services/common/src/pr_settings.rs | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/services/common/src/pr_overview.rs b/services/common/src/pr_overview.rs index 6d4bcfec..06963be4 100644 --- a/services/common/src/pr_overview.rs +++ b/services/common/src/pr_overview.rs @@ -1159,8 +1159,9 @@ pub fn build(i: &Input) -> Value { // levels), the busiest reviewer's share of human reviews on 10 or more // pull requests. The path is shown, never the person. let single_paths: Vec = { - let mut per: BTreeMap<(String, String), (BTreeSet, BTreeMap)> = - BTreeMap::new(); + // (repo, directory): the pull requests, and human reviews per reviewer. + type PathReviews = (BTreeSet, BTreeMap); + let mut per: BTreeMap<(String, String), PathReviews> = BTreeMap::new(); for h in hist .iter() .filter(|h| h.merged && h.merged_at > now - 90 * DAY) diff --git a/services/common/src/pr_settings.rs b/services/common/src/pr_settings.rs index eaad2e08..038b8afe 100644 --- a/services/common/src/pr_settings.rs +++ b/services/common/src/pr_settings.rs @@ -136,7 +136,9 @@ impl PrSettings { if self.digest.channel == "email" && (self.digest.to.is_empty() || self.digest.to.len() > 20) { - return Err("an email digest needs between 1 and 20 team members' addresses".into()); + return Err( + "an email digest needs between 1 and 20 team members' addresses".into(), + ); } } Ok(self) @@ -263,12 +265,18 @@ mod tests { s.digest.enabled = true; assert!(s.clone().validated().is_err(), "a digest needs a channel"); s.digest.channel = "email".into(); - assert!(s.clone().validated().is_err(), "an email digest needs someone"); + assert!( + s.clone().validated().is_err(), + "an email digest needs someone" + ); s.digest.to = vec!["octocat@example.com".into()]; assert!(s.clone().validated().is_ok()); s.digest.channel = "slack".into(); s.digest.to.clear(); - assert!(s.clone().validated().is_ok(), "Slack uses the team's channels"); + assert!( + s.clone().validated().is_ok(), + "Slack uses the team's channels" + ); s.sla.critical = 0; assert!(s.validated().is_err()); } From 48c383a7af0b74a5ba69097ffa9218687bf578d7 Mon Sep 17 00:00:00 2001 From: Nam Bok Rodriguez Date: Sat, 5 Dec 2026 20:18:31 -0500 Subject: [PATCH 2/3] Retry a refused merge and ask a person only the contested hunk (#989) * Retry a refused merge and ask a person only the contested hunk A conflict round whose merge was refused no longer asks a person to resolve the conflict. It runs again in a fresh step against the base's newest head while the base moves between tries and under the round's step ceiling. Out of tries, a person is asked only when both sides changed the same lines with incompatible intent and the model's merge was refused on both tries: a typed product decision showing the two versions (keep A, keep B, or combine). Anything else stops as CoderHelm's own problem. * Keep hand-off text out of the conflict round tests and Debug The tests asserted on the typed question and the PR comment with the values in their failure messages, and AfterRefused derived Debug over a PersonOnly. The messages no longer carry those values, and AfterRefused prints only its variant and the reason code. --- .../xy_merge_keeps_both_sides_and_parses.md | 1 + .../xy_merge_keeps_both_sides_and_parses.rs | 22 +- services/worker/src/passes/merge3.rs | 116 ++++++- services/worker/src/passes/pr.rs | 5 +- services/worker/src/passes/resume.rs | 306 ++++++++++++++++-- 5 files changed, 408 insertions(+), 42 deletions(-) diff --git a/docs/incidents/xy_merge_keeps_both_sides_and_parses.md b/docs/incidents/xy_merge_keeps_both_sides_and_parses.md index fea37af6..92742a65 100644 --- a/docs/incidents/xy_merge_keeps_both_sides_and_parses.md +++ b/docs/incidents/xy_merge_keeps_both_sides_and_parses.md @@ -10,5 +10,6 @@ - Only a hunk both sides changed differently goes to the model, alone with its ancestor, ours and theirs and a few unchanged lines around it. Its reply must be that hunk's lines: prose, markdown fences and conflict markers are stripped where they wrap it and refused inside it, it can't be longer than both sides together, and every identifier either side added must still be there. - The merged file is checked before anything is committed (`merge3::check_merged`): no conflict markers or prose, a line count within both sides' changes together, both sides' added identifiers present, and it parses for its language as well as the sides do (TypeScript, TSX, JavaScript, Python and Rust by their parsers; JSON, YAML and TOML must parse; other code by the bracket scan). - A merge that fails is tried once more with smaller hunks. Failing again, nothing is pushed and the branch stays as it was. The failure is CoderHelm's own problem: an internal alert, a line on the run page, and the reason as the stop reason. +- A conflict round on CoderHelm's own pull request that meets a refused merge runs again in a fresh step against the base's newest head, while the base moves between tries and under the round's step ceiling. Out of tries, a person is asked only when both sides changed the same lines with incompatible intent and the model's merge of them was refused on both tries. That is a typed product decision with one question showing the two versions: keep A, keep B, or combine them. Anything else stops as CoderHelm's own problem, and no person is asked to "resolve the conflict". The case replays it with invented content: a TSX file where the base changed many lines and the branch added two merges mechanically without asking the model, the result that was pushed fails every check, and a model reply of prose plus a rewritten file for a real overlapping hunk pushes nothing. diff --git a/services/worker/src/passes/incidents/xy_merge_keeps_both_sides_and_parses.rs b/services/worker/src/passes/incidents/xy_merge_keeps_both_sides_and_parses.rs index 7e1ddf15..1629d738 100644 --- a/services/worker/src/passes/incidents/xy_merge_keeps_both_sides_and_parses.rs +++ b/services/worker/src/passes/incidents/xy_merge_keeps_both_sides_and_parses.rs @@ -26,7 +26,12 @@ //! language as well as the sides do. A failed merge is tried once more with //! smaller hunks; failing again, nothing is pushed, the branch stays as it //! was, and the failure is CoderHelm's own problem (an internal alert) with -//! the reason as the stop reason. +//! the reason as the stop reason. A conflict round on CoderHelm's own pull +//! request tries again in a fresh step against the base's newest head while +//! that makes progress; only a hunk both sides changed with incompatible +//! intent, refused on both tries, becomes one question to a person, with +//! the two versions (keep A, keep B, or combine). Never "resolve the +//! conflict". use crate::passes::merge3::{self, HunkAsk, HunkModel}; @@ -282,8 +287,8 @@ fn an_overlapping_hunk_reaches_the_model_alone_and_a_prose_reply_pushes_nothing( &mut model, )) .unwrap_err(); - assert!(err.0.contains("merging each conflicting hunk"), "{err}"); - assert!(err.0.contains("smaller pieces"), "{err}"); + assert!(err.why.contains("merging each conflicting hunk"), "{err}"); + assert!(err.why.contains("smaller pieces"), "{err}"); // It saw the hunk, never the whole file. assert!(!model.asked.is_empty()); for ask in &model.asked { @@ -338,6 +343,17 @@ fn the_conflicted_merge_goes_through_the_three_way_merge() { assert!(!pr.contains("Produce the correctly merged file")); // The rebuilt stack merges through the same path. assert!(include_str!("../restack.rs").contains("super::pr::merge_file(")); + // The conflict round retries a refused merge and asks only the typed + // question; it never hands a person a generic conflict. + let resume = include_str!("../resume.rs"); + let round = super::fixture::fn_src(resume, "async fn run_conflict_round("); + assert!(round.contains("after_refused(round, refused, &base_head, &base)")); + assert!(!round.contains("Please resolve")); + let after = super::fixture::fn_src(resume, "pub(crate) fn after_refused("); + assert!(after.contains(".stepped(base_head).parked(true)")); + assert!(after.contains("may_continue()")); + let ask = super::fixture::fn_src(resume, "pub(crate) fn contested_question("); + assert!(ask.contains("person_only::Want::ProductDecision")); // A refused merge leaves the conflict standing where it was reported. for src in [ include_str!("../await_merge.rs"), diff --git a/services/worker/src/passes/merge3.rs b/services/worker/src/passes/merge3.rs index 165b555d..2801e285 100644 --- a/services/worker/src/passes/merge3.rs +++ b/services/worker/src/passes/merge3.rs @@ -31,11 +31,37 @@ const DP_CELLS: usize = 4_000_000; /// A merge CoderHelm refused to commit, with why. The branch is left as it /// was. #[derive(Debug, Clone, PartialEq, Eq)] -pub struct Refused(pub String); +pub struct Refused { + pub why: String, + /// The hunk both sides changed with incompatible intent, when the + /// model's merge of it was refused on both tries (`None` for any other + /// failure, which is CoderHelm's own). + pub contested: Option, +} + +impl Refused { + /// A refusal that is CoderHelm's own, with no contested hunk. + pub fn own(why: impl Into) -> Refused { + Refused { + why: why.into(), + contested: None, + } + } +} + +/// The two competing versions of one hunk. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Contested { + pub path: String, + /// The branch's lines. + pub ours: String, + /// The other side's lines. + pub theirs: String, +} impl std::fmt::Display for Refused { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) + write!(f, "{}", self.why) } } @@ -810,6 +836,23 @@ fn context_after(pieces: &[Piece<'_>], k: usize) -> String { } } +/// Why one try at the conflicts failed: the whole hunk whose reply was +/// refused (its ours and theirs), when the model replied and the reply was +/// refused. +struct Failed { + why: String, + refused_hunk: Option<(String, String)>, +} + +impl From for Failed { + fn from(why: String) -> Failed { + Failed { + why, + refused_hunk: None, + } + } +} + /// Every conflict of `pieces` resolved by the model at `scope`. async fn resolve_all( path: &str, @@ -817,7 +860,7 @@ async fn resolve_all( pieces: &[Piece<'_>], scope: Scope, model: &mut M, -) -> Result<(String, usize), String> { +) -> Result<(String, usize), Failed> { let mut text = String::new(); let mut asked = 0; for (k, piece) in pieces.iter().enumerate() { @@ -858,9 +901,18 @@ async fn resolve_all( .resolve(&ask) .await .map_err(|e| format!("the model couldn't merge a hunk ({e})"))?; - let out = hunk_reply(path, &raw, small)?; - echoed(&out, &before, &after, small)?; - text.push_str(&out); + let checked = hunk_reply(path, &raw, small) + .and_then(|out| echoed(&out, &before, &after, small).map(|()| out)); + match checked { + Ok(out) => text.push_str(&out), + // The whole hunk is what a person would be asked about. + Err(why) => { + return Err(Failed { + why, + refused_hunk: Some((join(&h.ours), join(&h.theirs))), + }) + } + } } } Ok((text, asked)) @@ -914,22 +966,41 @@ pub async fn merge_text( .collect(); return check_merged(path, &base, ours, theirs, &text) .map(|()| Merged { text, by_model: 0 }) - .map_err(|e| Refused(format!("the mechanical merge failed its checks: {e}"))); + .map_err(|e| Refused::own(format!("the mechanical merge failed its checks: {e}"))); } let mut why = Vec::new(); + // The hunk each try's reply was refused on (`None`: the try failed some + // other way, which is CoderHelm's own). + let mut refused_on = Vec::new(); for scope in [Scope::Hunk, Scope::Split] { let tried = match resolve_all(path, their_label, &pieces, scope, model).await { - Ok((text, by_model)) => { - check_merged(path, &base, ours, theirs, &text).map(|()| Merged { text, by_model }) - } + Ok((text, by_model)) => check_merged(path, &base, ours, theirs, &text) + .map(|()| Merged { text, by_model }) + .map_err(Failed::from), Err(e) => Err(e), }; match tried { Ok(m) => return Ok(m), - Err(e) => why.push(format!("{}: {e}", scope.words())), + Err(f) => { + why.push(format!("{}: {}", scope.words(), f.why)); + refused_on.push(f.refused_hunk); + } } } - Err(Refused(why.join("; then "))) + // Both tries had the model's reply refused, on the same hunk: its two + // sides changed the same lines with incompatible intent. + let contested = match (&refused_on[0], &refused_on[1]) { + (Some(a), Some(b)) if a == b => Some(Contested { + path: path.to_string(), + ours: a.0.clone(), + theirs: a.1.clone(), + }), + _ => None, + }; + Err(Refused { + why: why.join("; then "), + contested, + }) } #[cfg(test)] @@ -1101,8 +1172,25 @@ mod tests { &mut m, )) .unwrap_err(); - assert!(err.0.contains("merging each conflicting hunk")); - assert!(err.0.contains("smaller pieces")); + assert!(err.why.contains("merging each conflicting hunk")); + assert!(err.why.contains("smaller pieces")); + // Both replies were refused on the same hunk: its two sides are + // contested. + let c = err.contested.expect("contested"); + assert_eq!(c.ours, "b1\nkeep\nc1\n"); + assert_eq!(c.theirs, "b2\nkeep\nc2\n"); + // A model that never answered is CoderHelm's own problem. + let mut m = scripted(&[]); + let err = run(merge_text( + "x.txt", + Some(base), + theirs, + ours, + "main branch", + &mut m, + )) + .unwrap_err(); + assert_eq!(err.contested, None); } #[test] diff --git a/services/worker/src/passes/pr.rs b/services/worker/src/passes/pr.rs index 7e04f1c5..cca451d3 100644 --- a/services/worker/src/passes/pr.rs +++ b/services/worker/src/passes/pr.rs @@ -1426,7 +1426,10 @@ async fn refuse_merge( super::own_problems::alert(state, &msg.team_id, "", own.subject.code(), &own.text).await } } - merge3::Refused(text) + merge3::Refused { + why: text, + contested: why.contested.clone(), + } } /// A path both sides changed whose two versions are text files: merged diff --git a/services/worker/src/passes/resume.rs b/services/worker/src/passes/resume.rs index 5f41ad5c..0537b546 100644 --- a/services/worker/src/passes/resume.rs +++ b/services/worker/src/passes/resume.rs @@ -5645,7 +5645,7 @@ async fn run_pending_round( let planned = (kind == run_round::Kind::PlannedWork).then(|| round.clone()); let mut refused = Vec::new(); let end = if kind == run_round::Kind::Conflict { - run_conflict_round(state, msg, &mut ctx, &pr, &round).await + run_conflict_round(state, msg, &mut ctx, &pr, &round, created_at, start).await } else { run_fix_round( state, @@ -5876,27 +5876,37 @@ pub(crate) async fn start_conflict_round( } /// The conflict round: the base branch merged into the pull request's -/// branch, the conflicting files resolved, one commit. A conflict that -/// can't be resolved that way is handed to a person with one comment. +/// branch, the conflicting files resolved, one commit. A merge that fails +/// its checks pushes nothing and is CoderHelm's own problem: the round runs +/// again in a fresh step against the base's newest head while that makes +/// progress (`after_refused`). Only when both sides changed the same lines +/// with incompatible intent, and the model's merge of them was refused on +/// both tries, is a person asked: one question with the two versions. +#[allow(clippy::too_many_arguments)] async fn run_conflict_round( state: &WorkerState, msg: &ResumeMessage, ctx: &mut FixContext, pr: &PrRef<'_>, round: &run_round::Round, + created_at: Option>, + start: &std::time::Instant, ) -> RoundEnd { let _ = super::update_pass(state, &msg.team_id, &msg.run_id, "conflict_fix").await; let base = ctx.ticket_msg.base_branch.clone(); - match super::pr::resolve_conflicts( + // The run's id rides along, so a refused merge is recorded on this run. + let mut ticket = ctx.ticket_msg.clone(); + ticket.continuation_run_id = Some(msg.run_id.clone()); + let merged = super::pr::resolve_conflicts( state, - &ctx.ticket_msg, + &ticket, &ctx.github, pr.branch, &ctx.provider, &mut ctx.usage, ) - .await - { + .await; + let e = match merged { Ok(resolved) => { super::round::clear(state, &msg.team_id, &msg.run_id).await; super::add_progress_note( @@ -5913,31 +5923,81 @@ async fn run_conflict_round( ) .await; // A new head: CI runs, the review of that commit re-arms auto-merge. - RoundEnd::Done { files: 1 } + return RoundEnd::Done { files: 1 }; } - Err(e) => { - let why = common::run_fail::error_text(&*e); - let gh = super::round::Pr { - github: &ctx.github, - owner: pr.owner, - repo: pr.repo, - branch: pr.branch, - }; + Err(e) => e, + }; + let gh = super::round::Pr { + github: &ctx.github, + owner: pr.owner, + repo: pr.repo, + branch: pr.branch, + }; + let Some(refused) = e.downcast_ref::() else { + // Any other failure is CoderHelm's own: recorded, never a person's. + let why = format!( + "merging `{base}` into the branch failed: {}", + common::run_fail::error_text(&*e) + ); + let own = common::person_only::OwnProblem { + subject: common::person_only::OwnSubject::Tooling, + text: why.clone(), + }; + super::own_problems::record(state, &msg.team_id, &msg.run_id, &own).await; + super::round::finish_incomplete(state, &msg.team_id, &msg.run_id, &gh, round, &why).await; + return RoundEnd::Incomplete; + }; + let base_head = ctx + .github + .get_ref(pr.owner, pr.repo, &base) + .await + .unwrap_or_default(); + match after_refused(round, refused, &base_head, &base) { + AfterRefused::Retry(next) => { + super::round::record(state, &msg.team_id, &msg.run_id, &next).await; + super::add_progress_note( + state, + &msg.team_id, + &msg.run_id, + &format!( + "The merge of `{base}` failed its checks, so nothing was pushed; CoderHelm \ + merges again in a fresh step against `{base}`'s newest head (step {} of at \ + most {}).", + next.attempt, + run_round::MAX_STEPS + ), + ) + .await; + let still_active = set_run_awaiting_ci( + state, + &ctx.ticket_msg, + &msg.run_id, + pr.url, + pr.number, + pr.branch, + &ctx.usage, + wall_clock_secs(created_at, start), + ) + .await + .unwrap_or_else(|e| { + warn!(run_id = msg.run_id, error = %e, "Could not park the conflict round"); + false + }); + if still_active { + send_delayed_resume(state, msg, CONFLICT_RETRY_SECS).await; + } + RoundEnd::Parked + } + AfterRefused::Ask { question, comment } => { super::round::finish_incomplete( state, &msg.team_id, &msg.run_id, &gh, round, - &format!("the conflict with `{base}` couldn't be resolved automatically ({why})"), + &question.line(), ) .await; - let comment = format!( - "This pull request conflicts with `{base}` and CoderHelm couldn't resolve it on its \ - own ({}). Please resolve the conflict on this branch; auto-merge starts again with \ - the review of the new commit.", - common::truncate_str(&why, 300) - ); if let Err(e) = crate::passes::conversation::github( &ctx.github, pr.owner, @@ -5947,10 +6007,208 @@ async fn run_conflict_round( ) .await { - warn!(run_id = msg.run_id, error = %e, "Could not hand the conflict off on the PR"); + warn!(run_id = msg.run_id, error = %e, "Could not ask the conflict's question on the PR"); } RoundEnd::Incomplete } + AfterRefused::Stop(why) => { + let own = common::person_only::OwnProblem { + subject: common::person_only::OwnSubject::Tooling, + text: why.clone(), + }; + super::own_problems::record(state, &msg.team_id, &msg.run_id, &own).await; + super::round::finish_incomplete(state, &msg.team_id, &msg.run_id, &gh, round, &why) + .await; + RoundEnd::Incomplete + } + } +} + +/// The wait before a refused merge is tried again: time for the base to +/// move on. +const CONFLICT_RETRY_SECS: i32 = 60; + +/// What a conflict round does after its merge was refused. +#[derive(Clone, PartialEq, Eq)] +pub(crate) enum AfterRefused { + /// Tried again in a fresh step, against the base's newest head. + Retry(run_round::Round), + /// Both sides changed the same lines with incompatible intent and the + /// model's merge was refused on both tries: one question, with the two + /// versions in the pull request's comment. + Ask { + question: common::person_only::PersonOnly, + comment: String, + }, + /// CoderHelm's own problem, out of tries: the round ends unfinished with + /// the reason, and nobody is handed anything. + Stop(String), +} + +/// Only the variant and the question's reason code: a hand-off's named +/// thing (a credential's name, say) never reaches a log. +impl std::fmt::Debug for AfterRefused { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AfterRefused::Retry(r) => write!(f, "Retry(attempt {})", r.attempt), + AfterRefused::Ask { question, .. } => write!(f, "Ask({})", question.code()), + AfterRefused::Stop(_) => write!(f, "Stop"), + } + } +} + +/// After a refused merge: tried again while the tries make progress (the +/// base's head moved since the last try, `Round::stepped`) and under the +/// round's ceiling (`Round::may_continue`). Out of tries, a contested hunk +/// is one question to a person (a typed `PersonOnly`); anything else stops +/// as CoderHelm's own problem. +pub(crate) fn after_refused( + round: &run_round::Round, + refused: &super::merge3::Refused, + base_head: &str, + base: &str, +) -> AfterRefused { + let next = round.stepped(base_head).parked(true); + if next.may_continue() { + return AfterRefused::Retry(next); + } + let tries = next.attempt - 1; + let own = format!( + "the merge of `{base}` failed its checks on all {tries} tries, so nothing was pushed and \ + the branch is unchanged ({})", + common::truncate_str(&refused.why, 400) + ); + let Some(c) = &refused.contested else { + return AfterRefused::Stop(own); + }; + match contested_question(c, base) { + Ok((question, comment)) => AfterRefused::Ask { question, comment }, + Err(p) => AfterRefused::Stop(format!("{own}; {}", p.text)), + } +} + +/// The one question for a contested hunk (a product decision only a person +/// makes: which intent stands), and the comment that shows both versions. +pub(crate) fn contested_question( + c: &super::merge3::Contested, + base: &str, +) -> Result<(common::person_only::PersonOnly, String), common::person_only::OwnProblem> { + let path = &c.path; + let ask = format!( + "In `{path}`, this branch and `{base}` changed the same lines in different ways: keep \ + this branch's version (A), keep `{base}`'s version (B), or combine them?" + ); + let question = common::person_only::admit(common::person_only::Want::ProductDecision, &ask)?; + let block = |text: &str| { + let fence = if text.contains("```") { "~~~~" } else { "```" }; + format!("{fence}\n{}\n{fence}", text.trim_end_matches('\n')) + }; + let comment = format!( + "This pull request conflicts with `{base}` in `{path}`. CoderHelm merged everything \ + else, but here both sides changed the same lines with different intent, and its merge \ + of them failed its checks on every try, so nothing was pushed and the branch is \ + unchanged.\n\n**A, this branch:**\n\n{}\n\n**B, `{base}`:**\n\n{}\n\n{} Reply \ + with A, B, or how to combine them, and CoderHelm makes the merge.", + block(&c.ours), + block(&c.theirs), + question.line() + ); + Ok((question, comment)) +} + +#[cfg(test)] +mod conflict_retry_tests { + use super::*; + use crate::passes::merge3::{Contested, Refused}; + + fn round() -> run_round::Round { + run_round::Round::start( + run_round::Kind::Conflict, + 1, + "", + "Merge the base branch.", + true, + chrono::Utc::now(), + ) + } + + fn contested() -> Refused { + Refused { + why: "merging each conflicting hunk: the reply drops what the other side added".into(), + contested: Some(Contested { + path: "web/src/app-frame.tsx".into(), + ours: " Reviews\n".into(), + theirs: " Queue\n".into(), + }), + } + } + + /// Steps of the round until it stops retrying, the base's head moving + /// (or not) between tries. + fn until_done(refused: &Refused, heads: &[&str]) -> (u32, AfterRefused) { + let mut r = round(); + let mut tries = 0; + for head in heads.iter().cycle() { + tries += 1; + match after_refused(&r, refused, head, "main") { + AfterRefused::Retry(next) => r = next, + end => return (tries, end), + } + } + unreachable!() + } + + #[test] + fn a_refused_merge_is_retried_against_a_fresh_base_while_that_makes_progress() { + let refused = Refused::own("the merged file doesn't parse"); + // The first refusal always retries. + assert!(matches!( + after_refused(&round(), &refused, "base-1", "main"), + AfterRefused::Retry(_) + )); + // A base that stays put: two tries without progress stop it. + let (tries, end) = until_done(&refused, &["base-1"]); + assert_eq!(tries, 3); + // CoderHelm's own problem: no person is handed anything. + let AfterRefused::Stop(why) = end else { + panic!("expected a stop") + }; + assert!(why.contains("nothing was pushed")); + // A base that keeps moving retries up to the round's ceiling, never + // past it. + let heads: Vec = (0..40).map(|i| format!("base-{i}")).collect(); + let heads: Vec<&str> = heads.iter().map(String::as_str).collect(); + let (tries, end) = until_done(&refused, &heads); + assert!(tries > 3 && tries < run_round::MAX_STEPS + 1); + assert!(matches!(end, AfterRefused::Stop(_))); + // A contested hunk is retried first too. + assert!(matches!( + after_refused(&round(), &contested(), "base-1", "main"), + AfterRefused::Retry(_) + )); + } + + #[test] + fn a_contested_hunk_out_of_tries_is_one_question_with_both_versions() { + let (_, end) = until_done(&contested(), &["base-1"]); + let AfterRefused::Ask { question, comment } = end else { + panic!("expected one question") + }; + assert_eq!(question.code(), "product_decision"); + let line = question.line(); + assert!(line.contains("keep this branch's version (A)")); + assert!(line.contains("keep `main`'s version (B), or combine them?")); + assert!(line.contains("web/src/app-frame.tsx")); + // The comment shows the two competing versions. + assert!(comment.contains("**A, this branch:**\n\n```\n ")); + assert!(comment.contains("**B, `main`:**\n\n```\n ")); + // Never a generic ask, never a hand-off phrase. + let lower = comment.to_lowercase(); + assert!(!lower.contains("resolve the conflict")); + assert!(!lower.contains("please")); + for phrase in crate::passes::ownership::HAND_OFF_PHRASES { + assert!(!lower.contains(phrase), "a hand-off phrase"); + } } } From ae72fe824314d45c18647aa1939d31972c8246ff Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Sat, 5 Dec 2026 20:24:53 -0500 Subject: [PATCH 3/3] Name what hasn't reported yet instead of a zero; the run join's team check lives in the shared reader Blocked by main is unknown, not 0, until a default-branch check reports; the findings funnel and cost per merged pull request are named in missing while nothing is recorded in the window. xw checks the team filter where the run join now lives. --- services/common/src/pr_overview.rs | 24 ++++++++++++++++++- .../xw_every_open_pr_has_one_state.rs | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/services/common/src/pr_overview.rs b/services/common/src/pr_overview.rs index 06963be4..7a6c089c 100644 --- a/services/common/src/pr_overview.rs +++ b/services/common/src/pr_overview.rs @@ -729,8 +729,15 @@ pub fn build(i: &Input) -> Value { "abandoned": abandoned.len(), "zombie": zombie, "high_drift": drift_p85.map(|_| drifting.len()), - "blocked_by_main": blocked_main.len(), + "blocked_by_main": (!i.main_ci.is_empty()).then_some(blocked_main.len()), }); + if i.main_ci.is_empty() { + miss( + "conditions.blocked_by_main", + "history", + "No default-branch checks have reported since CoderHelm began recording them.", + ); + } let drafts_ages: Vec = open .iter() .filter(|o| o.rec.draft) @@ -1239,6 +1246,13 @@ pub fn build(i: &Input) -> Value { "incorrect": funnel.dismissed, })), }); + if funnel.raised == 0 { + miss( + "review.funnel", + "history", + "CoderHelm's reviewer hasn't raised a finding in this window since findings began being recorded.", + ); + } if merged_w.is_empty() { miss( "review.coverage", @@ -1694,6 +1708,14 @@ pub fn build(i: &Input) -> Value { } }); + if !ch_merged_w.iter().any(|h| h.cost_micro_usd > 0) { + miss( + "coderhelm.exceptions.cost_per_merged", + "history", + "No pull request CoderHelm worked on has merged with its runs' cost recorded in this window.", + ); + } + // ── Summary ── let ctx = SummaryCtx { red_now: mains diff --git a/services/worker/src/passes/incidents/xw_every_open_pr_has_one_state.rs b/services/worker/src/passes/incidents/xw_every_open_pr_has_one_state.rs index c4d857d6..6ae050ae 100644 --- a/services/worker/src/passes/incidents/xw_every_open_pr_has_one_state.rs +++ b/services/worker/src/passes/incidents/xw_every_open_pr_has_one_state.rs @@ -355,7 +355,8 @@ fn no_pull_request_of_another_team_reaches_a_row() { assert!(prs.contains("read_all(&state, &claims.team_id)")); assert!(prs.contains("pr_view::rows(&claims.team_id, items, joins, viewer")); assert!(prs.contains("read_key(installation_id, &format!(\"prs#{team_id}\"))")); - assert!(prs.contains("if s(item, \"team_id\") != team_id {")); + // The run join (shared with the overview) skips another team's run. + assert!(src("common/src/pr_overview_read.rs").contains("if s(item, \"team_id\") != team_id {")); assert!(!prs.contains("q.team")); let perms = src("gateway/src/permissions.rs"); assert!(perms.contains("\"prs::list_prs\"") && perms.contains("\"prs::get_pr\""));