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
4 changes: 2 additions & 2 deletions docs/incidents/xu_every_repo_gets_its_ci_rounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
**The guarantee (invariants, enforced in code):**

- **Each pull request has its own CI ledger.** Every pull request of the run is an entry of `common::repo_ci::RepoCi` on the run record: its rounds, how many in a row met the same failure, and whether its rounds stopped or wait on a person.
- **A red pull request gets the same round a single repository gets.** The mode diagnosis first (`mode_cause`, `mode_repair::on_red`): a mode CoderHelm's own commits dropped is put back and CI decides again. Then the CI fix round every fix takes (`run_fix_round`, a `run_round` round with its own budget, parked for a fresh step when it needs one), on that pull request's branch, with its failing checks, their logs and the run's other pull requests named. A parked round runs again for the pull request it belongs to. The run waits for CI on what the round pushed.
- **A red pull request gets the same round a single repository gets.** The mode diagnosis first (`read_modes`, `mode_repair::on_red`, the same one the single repository loop's `mode_cause` uses): a mode CoderHelm's own commits dropped is put back and CI decides again. Its stuck record is that pull request's own, and a repair that is retried or stops making progress marks only that pull request: the step goes on to the others, and a stopped repair settles it as CoderHelm's own problem. Then the CI fix round every fix takes (`run_fix_round`, a `run_round` round with its own budget, parked for a fresh step when it needs one), on that pull request's branch, with its failing checks, their logs and the run's other pull requests named. A parked round runs again for the pull request it belongs to. The run waits for CI on what the round pushed.
- **Repositories go independently; providers first.** A pull request whose change builds on another repository's (the plan's order, which is also the merge order) waits while that one is red or its CI runs. Every other red pull request takes its round; the one with the fewest rounds goes first. A provider whose rounds stopped never holds the rest.
- **Rounds go on while they make progress.** The bound is the single repository loop's own rule (`run_round::ci_cycle_goes_on`): a round followed by the same failure it was asked to fix made no progress. Two such rounds in a row stop that pull request's rounds. The stop is CoderHelm's own problem: an internal alert and the run page's line (`own_problems::record`), the pull request says what fails and what was tried, and the run ends with its typed stop with the checks named (`stop_red`). Never a person's to-do.
- **The run ends only when every pull request is settled.** All green or merged: each goes through the ready decision in the plan's order and the run completes. A person is named only for a typed person-only reason (`common::person_only::admit`): a round that changed no code and found the fix needs a GitHub permission only an admin grants holds that pull request, and the run's note says exactly that, beside every other pull request having gone green.

**Where it's enforced:** `common::repo_ci::{RepoCi::of, next, begin, after_round, hold_for_person, brief}`, the worker's `resume::{resume_multi_repo, run_repo_round, repo_red, stop_repo_rounds, ready_in_merge_order, restore_primary, claim_for_round, CI_FIX_RULES}`, and `run_fix_round`, which keeps a CI round's account for the reading after it.
**Where it's enforced:** `common::repo_ci::{RepoCi::of, next, begin, stop, keep_mode, after_round, hold_for_person, brief}`, the worker's `resume::{resume_multi_repo, read_modes, repo_red, stop_repo_rounds, ready_in_merge_order, restore_primary, claim_for_round, CI_FIX_RULES}`, and `run_fix_round`, which keeps a CI round's account for the reading after it.
25 changes: 22 additions & 3 deletions services/common/src/repo_ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ pub struct PrCi {
/// That reason's code ([`crate::person_only::PersonOnly::code`]).
#[serde(default, skip_serializing_if = "String::is_empty")]
pub person_code: String,
/// The mode repair's stuck record for this pull request (the worker's
/// `mode_repair::StuckState`, as JSON): its tries count for it alone.
/// Empty when nothing is stuck.
#[serde(default, skip_serializing_if = "String::is_empty")]
pub mode_stuck: String,
}

impl PrCi {
Expand Down Expand Up @@ -272,9 +277,7 @@ impl RepoCi {
)
};
let why = p.stopped.clone();
if self.fixing == url {
self.fixing.clear();
}
self.after_round(url);
return Begin::Stop(why);
}
p.rounds += 1;
Expand All @@ -284,6 +287,22 @@ impl RepoCi {
Begin::Go(n)
}

/// `url`'s work stops as CoderHelm's own problem, in these words: no
/// more rounds go to it, and the others go on.
pub fn stop(&mut self, url: &str, why: &str) {
if let Some(e) = self.entry_mut(url) {
e.stopped = why.to_string();
}
self.after_round(url);
}

/// Keeps `url`'s mode repair record (`stuck`, empty to clear it).
pub fn keep_mode(&mut self, url: &str, stuck: &str) {
if let Some(e) = self.entry_mut(url) {
e.mode_stuck = stuck.to_string();
}
}

/// The round on `url` ended (whatever it pushed: CI on its head says
/// next whether it made progress).
pub fn after_round(&mut self, url: &str) {
Expand Down
14 changes: 10 additions & 4 deletions services/worker/src/passes/incidents/xq_own_modes_never_red_ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ fn a_red_check_from_dropped_modes_is_fixed_by_a_mode_commit_not_handed_off() {
);
// What the diagnosis does: a commit and a wait on CI, or CoderHelm's
// own problem tried again; never a failed run.
let cause = fn_src(RESUME, "async fn mode_cause(");
// `mode_cause` acts on the diagnosis `read_modes` makes (the one
// the multi-repository loop shares).
let cause = format!(
"{}{}",
fn_src(RESUME, "async fn mode_cause("),
fn_src(RESUME, "async fn read_modes(")
);
for part in [
"mr::on_red(",
"own_problems::record(",
Expand Down Expand Up @@ -395,9 +401,9 @@ fn a_stuck_repair_retries_while_it_makes_progress_then_stops() {
other => panic!("{other:?}"),
}

let cause = fn_src(RESUME, "async fn mode_cause(");
assert!(cause.contains("mr::stuck_step("));
assert!(cause.contains("if retry && matches!(waiting, Ok(true))"));
assert!(fn_src(RESUME, "async fn read_modes(").contains("mr::stuck_step("));
assert!(fn_src(RESUME, "async fn mode_cause(")
.contains("if read == ModeRead::Retry && matches!(waiting, Ok(true))"));
let sweep = fn_src(REPAIR, "pub async fn sweep(");
let raced = sweep.find("if r.raced {").expect("a raced repair");
assert!(sweep[raced..].find("release(state, &c)").unwrap() < 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,10 @@ fn no_pr_work_is_limited_to_one_repository() {
}
let text = std::fs::read_to_string(&f).unwrap_or_default();
let low = text.to_lowercase();
// No exception: a run spanning several repositories fixes CI on each
// of its pull requests (`xu`), so nothing says otherwise.
for l in LIMITS {
// The one place that says how a run spanning several
// repositories ends when CI fails: it says so to people, true
// and named, rather than fixing them one by one.
let told = p.ends_with("/passes/resume.rs")
&& low.contains(
"coderhelm fixes ci one repository at a time and this run spans several",
);
if low.contains(l) && !(told && *l == "one repository at a time") {
if low.contains(l) {
found.push(format!("{p}: {l}"));
}
}
Expand Down
Loading