Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/incidents.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ pipeline still calls it there.
| bs. `bs_cut_plan_revision` | A ticket with a long history was planned, and the plan check sent the plan back with two open items. The revision reached the output limit partway through its last block. The planner was told the coder's note ("make a change in small edit_file calls"), wrote only its decision block again, and the worker read only that last turn: no tasks, no design. The run failed with "empty or malformed plan ... retry the run" and the first plan was thrown away. | A planner's cut answer is continued where it stopped and read together with what came before the cut, file by file (`plan_sections`). A cut turn's note fits its loop: the coder's edit note only where there are edit tools, the planner's "continue the document" note, a shorter answer for everyone else. A revision that comes back empty, cut off or malformed never replaces a valid file, and a send-back asks for only the files that change. Files still missing are asked for alone, twice at most, the second with a larger output budget. A plan still not usable is planned again in a fresh step, then reported as CoderHelm's own failure, saying what it lacked. No run tells a person to retry it. |
| bt. `bt_proof_answer_closes` | A security update's own review asked for proof of the build and unit tests on the head. The fix rounds changed no code: the second ran every check on the head, all passing, and one runtime check it started was cut short by the step's time. The ledger counted that as a block, the round pushed nothing so no review read the head again, and the draft was held for a person ("Fix them on the branch, or remove a finding") while the merge standing said no person was needed. | A round that pushed nothing is read by a review of the same head, with the round's account in the reviewer's context, and a finding answered with proof closes there. A command, check or codegen a step is too short to start is owed: the pass continues in a fresh step that runs it first, and a round cut short by time is never a block. Nothing on CoderHelm's side holds a draft for a person: what is left after every approach is listed as CoderHelm's note and the pull request goes ready, with CoderHelm's verdict kept so nothing merges over it. A stuck run is sent back to its review on the next look of the ready sweep or the pull request's watch. |
| bu. `bu_held_draft_after_release` | A release fixed how a held draft is finished, and the run it was for never got there. Its hold had been decided 22 minutes before the release and the draft sweep re-decides a hold only once it is an hour old: the first sweep after the release came six seconds early and only peeked. The next skipped the installation for GitHub's budget, logging "it looks again in about 1 min", though nothing ran until the next scheduled sweep. The pull request watch spent its hourly cap on merged pull requests and looked at the held draft in none of three sweeps. A person reset the run 67 minutes after the release. | A hold carries the version of the code that decided it, and the sweep decides a hold other code wrote on its first pass after a release, decisions before peeks. A sweep GitHub's budget skipped runs again once the budget refills (one follow-up per gap, claimed). The pull request watch looks at held drafts first. |
| bv. `bv_no_limit_hands_to_a_person` | Four paths still ended a pull request "for a person" over CoderHelm's own limits: a security fix whose CI stayed red after its fix rounds stayed a draft with "Fix the failing checks on this branch" and the run waited or failed; a wait unchanged for two hours on one head became "Look at why it didn't happen ... or mark it ready yourself"; description lines (security items, planned work not finished, a check the change didn't pass, review findings) each held the draft with a person's to-do; and GitHub refusing to mark a pull request ready counted as a person's. | Only a reason on the human-only list keeps a draft for a person, made only by `Reason::person`; everything else, once CoderHelm's attempts are spent, is its note on a pull request that goes ready. A stalled wait is CoderHelm's next action (its checks run on the head again), twice, then its note. A security fix whose CI stays red after every set of bumps that could come out did is completed and ready with the failing checks as its note. The run guard waits on a person only with a human-only reason. |
| bw. `bw_dependency_pr_review` | A product owner's review of a dependency pull request asked for the type check on the changed package when CI runs none, for sibling packages of one scope to move together, and for each major override to say which package pulls it in and why the bump is safe. The family check found siblings only from a registry record naming their source repository. | The verification set adds the type check to steps that lack one, and a failing type check takes the set out. When no registry record names a source repository, the scope's packages the base lockfile installs on one minor line are a family (never `@types/`), held together, and a head that splits them fails the set. Each major's section is built from its lockfile dependency paths, its route and the parents an override moves outside their range. |

## Adding a case

Expand Down
52 changes: 48 additions & 4 deletions services/common/src/draft_hold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
//! - a wait CoderHelm settles by itself ([`Kind::Waiting`]) leaves the
//! status alone and says what it waits for;
//! - once the pull request is ready (or closed), the hold is removed and
//! `draft_settled` says how it ended, so the sweep stops looking at it.
//! `draft_settled` says how it ended, so the sweep stops looking at it;
//! - only a reason on the human-only list (`crate::handback::HumanOnly`)
//! makes a hold a person's ([`Reason::person`], [`DraftHold::needs_person`]).
//! Every other reason is CoderHelm's own to finish, or to list as its note
//! on a pull request that goes ready: a red check, a stalled wait, a
//! finding its rounds left, planned work it deferred.

use std::collections::HashMap;

Expand Down Expand Up @@ -59,6 +64,10 @@ pub struct Reason {
/// What to do about it, in plain words.
#[serde(default, skip_serializing_if = "String::is_empty")]
pub todo: String,
/// The human-only reason a person is needed for it (`HumanOnly::code`);
/// empty for everything CoderHelm finishes or notes itself.
#[serde(default, skip_serializing_if = "String::is_empty")]
pub human: String,
}

fn one_line(s: &str, max: usize) -> String {
Expand All @@ -71,9 +80,28 @@ impl Reason {
Reason {
what: one_line(what.as_ref(), MAX_WHAT),
todo: one_line(todo.as_ref(), MAX_TODO),
human: String::new(),
}
}

/// A reason only a person can settle, for `why` on the human-only list:
/// the one way a hold becomes a person's.
pub fn person(
why: crate::handback::HumanOnly,
what: impl AsRef<str>,
todo: impl AsRef<str>,
) -> Self {
Reason {
human: why.code().to_string(),
..Reason::new(what, todo)
}
}

/// The human-only reason it needs a person for, if any.
pub fn human_only(&self) -> Option<crate::handback::HumanOnly> {
crate::handback::HumanOnly::from_code(&self.human)
}

/// `what. todo`, one sentence each.
pub fn line(&self) -> String {
let what = self.what.trim().trim_end_matches('.');
Expand Down Expand Up @@ -116,6 +144,14 @@ pub struct DraftHold {
/// every held draft at once, never an hour later.
#[serde(default, skip_serializing_if = "String::is_empty")]
pub version: String,
/// Times CoderHelm took its own next action on a wait that stalled on
/// this head (`ready::MAX_STALL_RETRIES`).
#[serde(default, skip_serializing_if = "is_zero")]
pub retried: u32,
}

fn is_zero(n: &u32) -> bool {
*n == 0
}

/// A wait whose reason hasn't changed on the same head for this long is a
Expand Down Expand Up @@ -145,6 +181,7 @@ impl DraftHold {
checked_at: now,
head: String::new(),
ready: false,
retried: 0,
version: String::new(),
})
}
Expand Down Expand Up @@ -191,9 +228,12 @@ impl DraftHold {
self.version != version
}

/// Whether a person must act (the run waits on them).
/// Whether a person must act (the run waits on them): only a held
/// pull request with a reason on the human-only list. A hold for
/// anything else, and GitHub refusing to mark it ready, are CoderHelm's
/// to finish.
pub fn needs_person(&self) -> bool {
matches!(self.kind, Kind::Held | Kind::Failed)
self.kind == Kind::Held && self.reasons.iter().any(|r| r.human_only().is_some())
}

fn pr_words(&self) -> String {
Expand Down Expand Up @@ -296,7 +336,8 @@ mod tests {
);
let h = DraftHold::new(
Kind::Held,
vec![Reason::new(
vec![Reason::person(
crate::handback::HumanOnly::MissingAccess,
"Security items are open in the description",
"Fix them on this branch, or delete each line once it is checked.",
)],
Expand All @@ -310,6 +351,9 @@ mod tests {
description. Fix them on this branch, or delete each line once it is checked."
);
assert!(h.needs_person());
// The same reason without a human-only one is CoderHelm's to finish.
let own = DraftHold::new(Kind::Held, vec![Reason::new("x", "y")], 583, "").unwrap();
assert!(!own.needs_person());
let w = h.waiting_on();
assert_eq!(w.action, "Deal with what keeps pull request #583 a draft");
assert!(w.detail.contains("Security items"));
Expand Down
60 changes: 60 additions & 0 deletions services/common/src/upgrade_quality/family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ pub enum Evidence {
},
/// The members share a scope or a name stem. Supporting only.
NamePattern { pattern: String },
/// No registry record named a source repository, and the base branch's
/// lockfile installs every member of the scope on one minor line
/// ([`scope_siblings`]).
ScopeAndLine { scope: String, line: String },
}

impl Evidence {
Expand All @@ -75,6 +79,9 @@ impl Evidence {
format!("`{from}` declares the peer range `{range}` for `{on}`")
}
Evidence::NamePattern { pattern } => format!("the names share `{pattern}`"),
Evidence::ScopeAndLine { scope, line } => format!(
"the base branch's lockfile installs each package of `{scope}/` it has on {line}"
),
}
}
}
Expand Down Expand Up @@ -298,9 +305,28 @@ pub fn detect(
range: range.clone(),
});
}
// No registry record named a source repository: the lockfile alone.
// Packages of the bumped one's scope the base branch installs on its
// minor line are released together (`@scope/common`, `@scope/core`,
// `@scope/platform-x`). A dependency pull request once raised one of
// them and left its siblings a minor behind.
let mut scope_line: Option<(String, String)> = None;
if source.is_none() && members.is_empty() {
let siblings = scope_siblings(package, from, base);
if !siblings.is_empty() {
scope_line = Some((stem(package).to_string(), minor_line(from).to_string()));
members.extend(siblings);
}
}
if members.is_empty() && independent.is_empty() {
return None;
}
if let Some((scope, line)) = &scope_line {
evidence.push(Evidence::ScopeAndLine {
scope: scope.clone(),
line: line.clone(),
});
}
let mut patterns: Vec<String> = members
.iter()
.filter_map(|m| name_pattern(package, m))
Expand All @@ -312,6 +338,7 @@ pub fn detect(
}
let key = match (&source, evidence.first()) {
(Some(repo), Some(Evidence::SameSource { .. })) | (Some(repo), None) => repo.clone(),
(_, Some(Evidence::ScopeAndLine { scope, line })) => format!("{scope}/ on {line}"),
_ => format!("peers of {package}"),
};
members.insert(package.to_string());
Expand All @@ -327,6 +354,39 @@ pub fn detect(
})
}

/// `major.minor` of a version (`1.4.2` is `1.4`); the version itself when
/// it has fewer parts.
pub fn minor_line(v: &str) -> &str {
let v = v.trim().trim_start_matches(['v', '=', '^', '~']);
match v.match_indices('.').nth(1) {
Some((i, _)) => &v[..i],
None => v,
}
}

/// The packages of `package`'s scope the base branch's lockfile installs
/// on the minor line of `from`: its siblings when no registry record names
/// a source repository. Only scoped names (`@scope/x`); the scope of type
/// declarations, whose packages are versioned one by one, is never a
/// family.
pub fn scope_siblings(package: &str, from: &str, base: &[(String, String)]) -> Vec<String> {
let scope = stem(package);
if !scope.starts_with('@') || scope.eq_ignore_ascii_case("@types") {
return vec![];
}
let line = minor_line(from);
let mut out: Vec<String> = base
.iter()
.filter(|(n, _)| !n.eq_ignore_ascii_case(package))
.filter(|(n, _)| stem(n).eq_ignore_ascii_case(scope))
.filter(|(_, v)| minor_line(v) == line)
.map(|(n, _)| n.clone())
.collect();
out.sort();
out.dedup();
out
}

/// The version a family moves to: the lowest of `wanted` (the versions
/// that fix the advisory, lowest first) every member publishes.
/// `published`: per member, which of `wanted` its registry has; a member
Expand Down
22 changes: 13 additions & 9 deletions services/worker/src/passes/incidents/aa_promised_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,19 @@ fn says_coderhelm_works(text: &str) -> bool {
}

#[test]
fn with_no_round_left_the_hold_is_a_persons_and_promises_nothing() {
fn with_no_round_left_the_findings_are_coderhelms_note_and_promise_nothing() {
// The run's budget as its record shows it: no round may be queued.
let budget = resume::own_round_budget(&record("needs_input", 8), 0);
let why = own_review::round_left(&budget, HEAD, 8, 10).unwrap_err();
assert!(why.contains("fix budget is spent"), "{why}");

let d = ready::decide(&facts(false));
// CoderHelm's limit: its note on a ready pull request, never a
// person's hold (incident bv).
assert!(
matches!(ready::decide(&facts(false)), Decision::Ready { open }
if open.iter().any(|o| o.starts_with(ready::NOTE_PREFIX)))
);
let d = ready::found(&facts(false));
let Decision::Held { reasons } = &d else {
panic!("{d:?}")
};
Expand Down Expand Up @@ -203,13 +209,11 @@ fn the_wait_for_a_round_is_bounded_like_every_wait() {
f.now = Some(t("2026-11-10T04:31:00Z"));
assert!(matches!(ready::decide(&f), Decision::Wait { .. }));
f.now = Some(t("2026-11-10T05:32:00Z"));
let d = ready::decide(&f);
let Decision::Held { reasons } = &d else {
panic!("{d:?}")
};
assert!(reasons[0]
.what
.contains("hasn't changed in 2 hours on this head"));
// Stalled: CoderHelm's own next action, never a person's hold.
assert!(matches!(
ready::decide(&f),
Decision::Retry { attempt: 1, .. }
));
}

#[test]
Expand Down
16 changes: 12 additions & 4 deletions services/worker/src/passes/incidents/ac_partial_and_red_ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ fn a_draft_with_failing_ci_is_held_with_the_check_named() {
..Default::default()
};
assert!(ready::reads_ci(&f));
match ready::decide(&f) {
match ready::found(&f) {
Decision::Held { reasons } => {
assert!(
reasons[0]
Expand Down Expand Up @@ -392,9 +392,17 @@ fn the_ready_decision_keeps_the_rules_across_combinations() {
};
let d = ready::decide(&f);
let ci_state = CiState::of(&f.ci, f.red_on_base);
if matches!(d, Decision::Ready { .. } | Decision::Proving { .. }) {
assert!(ci_state.allows_done(), "ready with {ci_state:?}: {f:?}");
assert!(!body_unfinished, "ready with planned work left");
// Ready over red CI or planned work left only
// with it listed as CoderHelm's note (incident bv).
if let Decision::Ready { open } = &d {
let noted = open.iter().any(|o| o.starts_with(ready::NOTE_PREFIX));
if !ci_state.allows_done() || body_unfinished {
assert!(noted, "ready without a note: {f:?}");
}
}
if matches!(d, Decision::Proving { .. }) {
assert!(ci_state.allows_done(), "proving with {ci_state:?}: {f:?}");
assert!(!body_unfinished, "proving with planned work left");
}
n += 1;
}
Expand Down
Loading
Loading