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
1 change: 1 addition & 0 deletions docs/incidents.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pipeline still calls it there.
| ad. `ad_hand_back_reply` | A coder ended its step with "I couldn't finish, please complete the remaining tasks manually". Nothing it lacked was a credential, access, a product decision, an ambiguous ticket or an approval; its words alone handed the work to a person. | A model reply that hands the work back for a reason not on the human-only list is not an ending: the implement pass tells the coder to change its approach and runs it again, and a reply that still changes nothing is a step without progress, which climbs the supervisor's ladder (one task, other tools, a re-split, the strongest model, then the stuck task deferred with its reason) until the run finishes with what is done. Only a reply naming something on the list makes a hand-back. Every coder's system prompt carries the same stance (`ownership::coder_stance`), and a source scan fails on a hand-off phrase in any prompt or message (`ownership`). |
| ae. `ae_budget_rounds` | Two loops of fix rounds still stopped on their own budget after the supervisor took every other ending. At eight automatic pushes the CI-only rounds on a finished run's pull request marked it ready, completed the run with its checks red and said a comment naming a change would start the next round, even while each round turned another red check green; at two rounds the self-review on CoderHelm's own pull request said the same and left its findings holding the draft, even while each round closed one. | Both loops follow `supervisor::next_round`: rounds go on while they make progress (checks that were red turn green, findings close), past the cap up to twice it and below the spend ceiling; a round without progress changes approach (one item, a fresh context with small edits, a re-split, the strongest model). When the rounds end, the findings left move to "Deferred" with the reason and stop holding the draft, and the run finishes; red checks are reverted to the last green head and deferred, or, when nothing can come out, the run fails with what fails and why. No message asks for a comment to go on: the phrases are on the `ownership` hand-off list. |
| af. `af_lockfiles_out_of_sync` | A security update's pull request changed three `package.json` files (a pnpm workspace root and two npm packages with their own lockfiles) and none of the lockfiles, so every CI job failed at its frozen install. A retry planned its bumps by rule, then handed the red pull request to a model instead of building the plan. The model changed nothing; landing "nothing" removed the round's work branch, so the next attempt wrote to a branch that was gone (every write a 404, a hand edit of a lockfile among them). The round was called unfinished and the run ended failed after one attempt of three, with the same vague sentence twice. | A lockfile out of sync with its manifest is repaired by code before any model round, for any ticket and every package manager CoderHelm writes lockfiles for: each manager writes its own lockfile in the sandbox (with another mode and the LTS Node as fallbacks), one commit, and one that can't be written never hides the others. Any run that changes a manifest gets its lockfile written before the pull request opens. A retry of a dependency fix rebuilds its change from its plan on the same branch. A model's write to a lockfile is refused and pointed to the regenerate tool. Every attempt of a CI fix round opens its work branch first; a fault inside the round (no work branch, a compare or push GitHub refuses, a sandbox failure, anything else) is classified and has a way around it, and the catch-all runs the round again from a clean state, then once in a fresh step, before the supervisor's ending is asked. An attempt that changed nothing is followed by the repairs by code, then fresh evidence, then the strongest model. A run about to complete with red checks goes back to its CI fix round first, and an ending for red checks names the recorded cause, once. |
| ag. `ag_red_ci_ships_what_passes` | Three ways were left for a run to end badly over red checks or a refused landing. A dependency fix whose CI stayed red was taken apart by planned task (one task per lockfile, so a lockfile went back without its manifest), and after three reverts the run ended failed with bumps left in that passed on their own. A run stopped after its work opened its pull request with manifests changed and lockfiles unwritten, and waited for CI to fail first. A review fix or feedback round whose finished work GitHub refused to land was recorded as unfinished at once. | Red checks after every fix take out only what breaks them. A dependency fix takes out its newest commit of verified bumps, defers those bumps with what CI printed, holds their findings out of later bundles and keeps the commits before it, again while CI stays red, never emptying the pull request. Any other run is taken apart task by task (up to eight reverts) down to the part that passes; what ships is green with the rest under "Deferred". A stopped run's lockfiles are written by their package managers before its pull request opens, and one that can't be written is named without stopping it. Every kind of fix round takes one classified decision about a fault (`round::plan_for_fault`): while it may continue it runs again in a fresh step, keeping its work when only the landing failed and starting from the pull request's head otherwise. |

## Adding a case

Expand Down
82 changes: 82 additions & 0 deletions services/common/src/dep_fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,45 @@ pub struct DepRun {
pub budget_stop: bool,
pub uses: Vec<BatchUse>,
pub done: bool,
/// Each commit of verified bumps on the branch, oldest first: what the
/// pull request's own CI can take out again, one at a time
/// ([`DepRun::take_out_last_commit`]).
pub commits: Vec<BatchCommit>,
}

/// One commit of verified bumps.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct BatchCommit {
/// The head the commit was made on: its files are the branch without
/// this commit and everything after it.
pub before: String,
pub head: String,
pub bumps: Vec<usize>,
}

/// What [`DepRun::take_out_last_commit`] took out.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TakenOut {
/// The head whose files the branch goes back to.
pub restore_to: String,
/// Each bump taken out, as its deferral line.
pub lines: Vec<String>,
}

/// Why a bump the sandbox verified is deferred after all: the pull
/// request's own CI failed with it applied. `failure` is what CI printed.
pub fn ci_deferral_reason(failure: &str) -> String {
let failure = failure.trim();
if failure.is_empty() {
"the pull request's CI failed with it applied; taken out so the bumps before it ship"
.to_string()
} else {
format!(
"the pull request's CI failed with it applied ({}); taken out so the bumps before it ship",
crate::truncate_str(failure, 300)
)
}
}

impl DepRun {
Expand Down Expand Up @@ -1421,6 +1460,13 @@ impl DepRun {
if let Some(u) = self.uses.get_mut(self.batch) {
u.applied += g.bumps.len();
}
if head != self.head {
self.commits.push(BatchCommit {
before: self.head.clone(),
head: head.to_string(),
bumps: g.bumps.clone(),
});
}
self.applied.extend(g.bumps);
self.head = head.to_string();
// A green probe of the rest was on the old head: probed again. A red
Expand Down Expand Up @@ -1531,6 +1577,42 @@ impl DepRun {

/// Ends the run where it stands (no step left): what is committed
/// ships, everything not yet verified is deferred `later`.
/// The pull request's CI is red after every fix: the newest commit of
/// verified bumps comes out, its bumps deferred with `why` (not to come
/// back by themselves: they broke the checks), and the commits before
/// it stay. `None` when one commit or none is left: the pull request is
/// never emptied. Called again while CI stays red, it takes out the one
/// before, so only what breaks CI is deferred.
pub fn take_out_last_commit(&mut self, why: &str) -> Option<TakenOut> {
if self.commits.len() < 2 {
return None;
}
let c = self.commits.pop()?;
let mut lines = Vec::new();
for &i in &c.bumps {
let Some(b) = self.plan.bumps.get(i).cloned() else {
continue;
};
let d = Deferral {
package: b.package,
from: b.from,
to: b.to,
manifest: b.manifest,
finding_ids: b.finding_ids,
reason: why.to_string(),
later: false,
};
lines.push(d.line());
self.deferred.push(d);
}
self.applied.retain(|i| !c.bumps.contains(i));
self.head = c.before.clone();
Some(TakenOut {
restore_to: c.before,
lines,
})
}

pub fn finish_now(&mut self, why: &str) {
self.give_up_unverified(why);
self.done = true;
Expand Down
55 changes: 55 additions & 0 deletions services/common/src/dep_fix/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,3 +1251,58 @@ fn proof_a_fix_ticket_never_asks_for_documentation() {
let body = crate::security_fixes::ticket_body(&units[0], &members, &cfg);
assert!(body.contains("Never edit documentation"), "{body}");
}

/// The pull request's own CI stays red after the fixes: the newest commit
/// of verified bumps comes out and the earlier ones stay, one at a time,
/// and the pull request is never emptied.
#[test]
fn red_ci_takes_out_the_newest_commit_of_bumps_and_keeps_the_rest() {
let mut run = DepRun::new(ten_bumps(), "base", 3.0);
for (bumps, head) in [(vec![0, 1, 2], "h1"), (vec![3, 4], "h2"), (vec![5], "h3")] {
run.groups = vec![Group {
bumps,
green: true,
..Default::default()
}];
run.on_commit(0, head);
}
assert_eq!(run.commits.len(), 3);
assert_eq!(run.applied, vec![0, 1, 2, 3, 4, 5]);
// A green set with nothing to write is no commit of its own.
run.groups = vec![Group {
bumps: vec![6],
green: true,
..Default::default()
}];
run.on_commit(0, "h3");
assert_eq!(run.commits.len(), 3);

let why = ci_deferral_reason("npm error ETARGET No matching version found for lib-05@2.1.5");
let out = run.take_out_last_commit(&why).expect("three commits");
assert_eq!(out.restore_to, "h2");
assert_eq!(out.lines.len(), 1);
assert!(out.lines[0].starts_with("`lib-05` 2.1.0 to 2.1.5 deferred: the pull request's CI failed with it applied (npm error ETARGET"), "{}", out.lines[0]);
assert_eq!(run.applied, vec![0, 1, 2, 3, 4, 6]);
assert_eq!(run.head, "h2");
// It broke the checks: it doesn't come back by itself.
let d = run.deferred.last().unwrap();
assert_eq!(d.package, "lib-05");
assert!(!d.later);
assert!(run.report_md().contains("lib-05"), "{}", run.report_md());

// Still red: the one before it. Then one commit is left, and it stays.
let out = run.take_out_last_commit(&why).expect("two commits");
assert_eq!(out.restore_to, "h1");
assert_eq!(out.lines.len(), 2);
assert_eq!(run.applied, vec![0, 1, 2, 6]);
assert_eq!(run.take_out_last_commit(&why), None);
assert_eq!(run.commits.len(), 1);
assert_eq!(run.applied, vec![0, 1, 2, 6]);

// A saved run from before commits were kept reads with none, and
// nothing is taken out of it.
let mut old: DepRun = serde_json::from_str("{\"applied\":[0,1]}").unwrap();
assert!(old.commits.is_empty());
assert_eq!(old.take_out_last_commit(&why), None);
assert!(ci_deferral_reason(" ").contains("CI failed with it applied;"));
}
32 changes: 32 additions & 0 deletions services/worker/src/passes/feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,38 @@ Rules:
}
super::round::Landed::Nothing => {}
super::round::Landed::Refused(why) => {
// The same classified decision as every fix round's
// (`round::plan_for_fault`): while the round may
// continue it runs again in a fresh step, on its work
// branch when only the landing failed, from the pull
// request's head otherwise.
let plan = super::round::plan_for_fault(
feedback_round.kind,
&why,
super::round::after_fault_parked(feedback_round.may_continue()),
);
warn!(
run_id = %msg.run_id,
fault = ?plan.class,
way_around = ?super::round::way_around(plan.class),
next = ?plan.next,
error = %why,
"Feedback round met a fault"
);
if plan.next != super::round::AfterFault::Supervisor {
let mut again = feedback_round.clone();
if plan.clean {
super::round::start_clean(&land_pr, &mut again).await;
}
super::round::record(state, &msg.team_id, &msg.run_id, &again).await;
let mut next = msg.clone();
next.round_attempt = feedback_round.attempt;
if send_delayed_feedback(state, &next, 5).await {
super::add_progress_note(state, &msg.team_id, &msg.run_id, &plan.note)
.await;
return Ok(());
}
}
super::round::finish_incomplete(
state,
&msg.team_id,
Expand Down
29 changes: 29 additions & 0 deletions services/worker/src/passes/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,35 @@ pub(crate) async fn run_lock_repair(
/// package manager in the sandbox and committed on `w.branch`. Says why
/// when nothing could run; never an error.
pub(crate) async fn repair_lockfiles(w: &Work<'_>, nonce: usize) -> LockRepair {
repair_lockfiles_with(
&LockWork {
state: w.state,
msg: w.msg,
github: w.github,
branch: w.branch,
run_id: w.run_id,
deadline: w.deadline,
provider: w.provider,
},
nonce,
)
.await
}

/// What a lockfile repair needs of a run: less than a whole [`Work`], so
/// a path with no plan in hand (a stopped run's pull request) can call it.
pub(crate) struct LockWork<'a> {
pub state: &'a crate::WorkerState,
pub msg: &'a crate::models::TicketMessage,
pub github: &'a GitHubClient,
pub branch: &'a str,
pub run_id: &'a str,
pub deadline: Option<std::time::Instant>,
pub provider: &'a crate::agent::provider::ModelProvider,
}

/// [`repair_lockfiles`], from the pieces it needs.
pub(crate) async fn repair_lockfiles_with(w: &LockWork<'_>, nonce: usize) -> LockRepair {
let state = w.state;
if state.config.sandbox_bucket_name.is_empty() || state.config.sandbox_project_name.is_empty() {
return LockRepair::not_run("no sandbox is set up");
Expand Down
Loading
Loading