Skip to content

Commit 123a42c

Browse files
committed
Fix rounds checkpoint on a WIP branch and land as one commit on the PR
Every push to a pull request branch re-runs CI and, on repositories that dismiss stale approvals, dismisses them. A fix round now pushes to the pull request exactly once. - CI fix, review fix and feedback rounds write their checkpoint commits to coderhelm-wip/<pr branch>, opened at the PR head when the round starts (a continuing round reuses its own). - When the round is done, everything it changed since it started lands on the PR as ONE commit in the team's commit style (round::land: removals and renames included), and the WIP branch is deleted. If the PR changed the same files meanwhile, nothing lands and the round is left unfinished. - A round that times out, errors or is cancelled keeps its WIP branch; the run records it (round / round_incomplete.wip_branch and base_sha, also written by the stuck-run sweep), Resume continues from it, and nothing partial reaches the PR. The status note says the PR is unchanged. - API: RoundIncomplete.wip_branch (OpenAPI). The pre-PR stop copy is now coderhelm-wip/<branch> too.
1 parent e917ead commit 123a42c

9 files changed

Lines changed: 499 additions & 70 deletions

File tree

‎docs/api/openapi.json‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@
20162016
"type": "object"
20172017
},
20182018
"PushedCommit": {
2019-
"description": "A commit a fix round pushed before it stopped.",
2019+
"description": "A checkpoint commit a fix round saved on its WIP branch before it stopped.",
20202020
"properties": {
20212021
"message": {
20222022
"description": "Its subject line.",
@@ -2768,7 +2768,7 @@
27682768
"type": "integer"
27692769
},
27702770
"pushed": {
2771-
"description": "The commits the round pushed to the pull request's branch before it\nstopped, oldest first.",
2771+
"description": "The checkpoint commits the round saved on `wip_branch` before it\nstopped, oldest first (never on the pull request).",
27722772
"items": {
27732773
"$ref": "#/components/schemas/PushedCommit"
27742774
},
@@ -2787,6 +2787,13 @@
27872787
"Pull request open; the last fix round didn't finish: the review fix round ran out of its time budget 3 times in a row."
27882788
],
27892789
"type": "string"
2790+
},
2791+
"wip_branch": {
2792+
"description": "The branch the round's work so far is saved on. A round that didn't\nfinish never pushes to the pull request; Resume continues from here.",
2793+
"examples": [
2794+
"coderhelm-wip/web-42-gallery"
2795+
],
2796+
"type": "string"
27902797
}
27912798
},
27922799
"required": [
@@ -2795,6 +2802,7 @@
27952802
"summary",
27962803
"pushed",
27972804
"files",
2805+
"wip_branch",
27982806
"at",
27992807
"can_resume"
28002808
],

‎lambda/stuck-run-cleanup/handler.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ def incomplete_record(run, pass_name, now_iso):
166166
"at": now_iso,
167167
"feedback": rnd.get("feedback", ""),
168168
"scoped": rnd.get("scoped", True),
169+
# The round's work so far stays on its WIP branch, never the PR's.
170+
"wip_branch": rnd.get("wip_branch", ""),
171+
"base_sha": rnd.get("base_sha", ""),
169172
}
170173

171174

‎lambda/tests/test_stuck_run_cleanup.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,21 @@ def test_a_stuck_run_with_an_open_pr_is_not_failed(self):
8686
run = {
8787
"pr_number": 41,
8888
"current_pass": "implement",
89-
"round": {"kind": "review_fix", "number": 3, "feedback": "Add the tabs"},
89+
"round": {
90+
"kind": "review_fix",
91+
"number": 3,
92+
"feedback": "Add the tabs",
93+
"wip_branch": "coderhelm-wip/feature/x",
94+
"base_sha": "abc",
95+
},
9096
}
9197
self.assertTrue(sweep.has_pull_request(run))
9298
rec = sweep.incomplete_record(run, "implement", "2026-10-26T15:00:00+00:00")
9399
self.assertEqual(rec["kind"], "review_fix")
94100
self.assertEqual(rec["number"], 3)
95101
self.assertEqual(rec["feedback"], "Add the tabs")
102+
self.assertEqual(rec["wip_branch"], "coderhelm-wip/feature/x")
103+
self.assertEqual(rec["base_sha"], "abc")
96104
line = sweep.status_line(rec["reason"])
97105
self.assertTrue(line.startswith("Pull request open; the last fix round didn't finish:"))
98106
self.assertNotIn("failed", line.lower())

‎services/common/src/run_round.rs‎

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
//! - The round being worked is on the run record ([`FIELD`]) with its
2222
//! deadline, so the stuck-run sweep waits for that deadline (plus
2323
//! [`SWEEP_GRACE_SECS`]) before it calls the worker gone.
24+
//! - A round works on its own branch, [`wip_branch`] (`coderhelm-wip/<pr
25+
//! branch>`), never the pull request's: every write is a checkpoint
26+
//! commit there. When the round finishes, its changes land on the pull
27+
//! request as ONE commit in the repository's commit style, so a round is
28+
//! one push (one CI run; a repository that dismisses stale approvals
29+
//! dismisses them once). A round that stops keeps its WIP branch, and
30+
//! Resume continues from it; partial work never reaches the pull request.
2431
//! - A round that doesn't finish while the pull request is open never fails
2532
//! the run. The run is `completed` with [`INCOMPLETE_FIELD`] saying which
2633
//! round, why, and the commits it pushed; [`status_line`] is how a person
@@ -144,6 +151,15 @@ pub struct Round {
144151
/// Whether the round may only change the files the pull request already
145152
/// changes (a bot-driven fix).
146153
pub scoped: bool,
154+
/// The branch the round writes its checkpoints to (empty until it
155+
/// starts working).
156+
pub wip_branch: String,
157+
}
158+
159+
/// The branch a round on `pr_branch` keeps its checkpoints on: a branch of
160+
/// its own, never the pull request's head.
161+
pub fn wip_branch(pr_branch: &str) -> String {
162+
format!("coderhelm-wip/{pr_branch}")
147163
}
148164

149165
fn s(v: &str) -> AttributeValue {
@@ -193,6 +209,7 @@ impl Round {
193209
base_sha: base_sha.to_string(),
194210
feedback: cut(feedback, MAX_FEEDBACK_CHARS),
195211
scoped,
212+
wip_branch: String::new(),
196213
}
197214
}
198215

@@ -232,6 +249,7 @@ impl Round {
232249
("base_sha".to_string(), s(&self.base_sha)),
233250
("feedback".to_string(), s(&self.feedback)),
234251
("scoped".to_string(), AttributeValue::Bool(self.scoped)),
252+
("wip_branch".to_string(), s(&self.wip_branch)),
235253
]))
236254
}
237255

@@ -255,6 +273,7 @@ impl Round {
255273
.and_then(|v| v.as_bool().ok())
256274
.copied()
257275
.unwrap_or(true),
276+
wip_branch: get_s(m, "wip_branch"),
258277
})
259278
}
260279

@@ -289,6 +308,10 @@ pub struct Incomplete {
289308
pub feedback: String,
290309
/// Whether the round was a bot-driven fix scoped to the PR's files.
291310
pub scoped: bool,
311+
/// The branch holding the round's work so far (not the pull request's).
312+
pub wip_branch: String,
313+
/// The pull request's head when the round started.
314+
pub base_sha: String,
292315
}
293316

294317
impl Incomplete {
@@ -303,6 +326,8 @@ impl Incomplete {
303326
at: now.to_string(),
304327
feedback: round.feedback.clone(),
305328
scoped: round.scoped,
329+
wip_branch: round.wip_branch.clone(),
330+
base_sha: round.base_sha.clone(),
306331
}
307332
}
308333

@@ -339,6 +364,8 @@ impl Incomplete {
339364
s(&cut(&self.feedback, MAX_FEEDBACK_CHARS)),
340365
),
341366
("scoped".to_string(), AttributeValue::Bool(self.scoped)),
367+
("wip_branch".to_string(), s(&self.wip_branch)),
368+
("base_sha".to_string(), s(&self.base_sha)),
342369
]))
343370
}
344371

@@ -373,9 +400,27 @@ impl Incomplete {
373400
.and_then(|v| v.as_bool().ok())
374401
.copied()
375402
.unwrap_or(true),
403+
wip_branch: get_s(m, "wip_branch"),
404+
base_sha: get_s(m, "base_sha"),
376405
})
377406
}
378407

408+
/// The round to run again on Resume: parked, continuing from its WIP
409+
/// branch and its starting point, with a fresh budget.
410+
pub fn resume_round(&self, now: chrono::DateTime<chrono::Utc>) -> Option<Round> {
411+
let kind = self.kind?;
412+
let mut r = Round::start(
413+
kind,
414+
self.number,
415+
&self.base_sha,
416+
&self.feedback,
417+
self.scoped,
418+
now,
419+
);
420+
r.wip_branch = self.wip_branch.clone();
421+
Some(r.parked(false))
422+
}
423+
379424
/// The unfinished round on a run record, if any.
380425
pub fn from_item(item: &HashMap<String, AttributeValue>) -> Option<Incomplete> {
381426
item.get(INCOMPLETE_FIELD).and_then(Incomplete::from_attr)
@@ -450,18 +495,19 @@ pub fn pushed_from_compare(compare: &serde_json::Value) -> (Vec<Pushed>, Vec<Str
450495
(pushed.into_iter().skip(skip).collect(), files)
451496
}
452497

453-
/// One line for a progress note: what an unfinished round left on the
454-
/// branch.
455-
pub fn pushed_note(pushed: &[Pushed], files: &[String]) -> String {
498+
/// One line for a progress note: what an unfinished round left, and where.
499+
/// The pull request itself is never changed by a round that didn't finish.
500+
pub fn pushed_note(pushed: &[Pushed], files: &[String], wip: &str) -> String {
456501
if pushed.is_empty() {
457-
return "It pushed no commits before it stopped.".to_string();
502+
return "It saved no work before it stopped; the pull request is unchanged.".to_string();
458503
}
459504
let shas: Vec<String> = pushed
460505
.iter()
461506
.map(|p| p.sha.chars().take(7).collect())
462507
.collect();
463508
format!(
464-
"It pushed {} commit(s) to the pull request branch before it stopped ({}), changing {} file(s).",
509+
"Its work so far ({} checkpoint commit(s): {}, {} file(s)) is saved on branch `{wip}`; \
510+
the pull request is unchanged, and Resume continues from there.",
465511
pushed.len(),
466512
shas.join(", "),
467513
files.len()
@@ -537,6 +583,24 @@ mod tests {
537583
assert_eq!(back, inc);
538584
}
539585

586+
#[test]
587+
fn a_round_writes_to_its_own_branch_and_resume_continues_from_it() {
588+
assert_eq!(wip_branch("feature/abc-7"), "coderhelm-wip/feature/abc-7");
589+
assert_ne!(wip_branch("x"), "x");
590+
let mut r = Round::start(Kind::ReviewFix, 2, "base1", "Add the tabs", true, now());
591+
r.wip_branch = wip_branch("feature/abc-7");
592+
let inc = Incomplete::of(&r, "out of time", "t");
593+
assert_eq!(inc.wip_branch, "coderhelm-wip/feature/abc-7");
594+
assert_eq!(inc.base_sha, "base1");
595+
let back = Incomplete::from_attr(&inc.to_attr()).unwrap();
596+
let again = back.resume_round(now()).unwrap();
597+
assert_eq!(again.state, State::Pending);
598+
assert_eq!(again.wip_branch, "coderhelm-wip/feature/abc-7");
599+
assert_eq!(again.base_sha, "base1");
600+
assert_eq!(again.feedback, "Add the tabs");
601+
assert!(Incomplete::default().resume_round(now()).is_none());
602+
}
603+
540604
#[test]
541605
fn the_long_feedback_of_a_parked_round_is_cut() {
542606
let big = "x".repeat(MAX_FEEDBACK_CHARS * 2);
@@ -584,14 +648,11 @@ mod tests {
584648
assert_eq!(pushed.len(), 2);
585649
assert_eq!(pushed[0].message, "Add the tabs");
586650
assert_eq!(files, vec!["src/tabs.ts", "src/tabs.test.ts"]);
587-
assert_eq!(
588-
pushed_note(&pushed, &files),
589-
"It pushed 2 commit(s) to the pull request branch before it stopped (aaaaaaa, bbbbbbb), changing 2 file(s)."
590-
);
591-
assert_eq!(
592-
pushed_note(&[], &[]),
593-
"It pushed no commits before it stopped."
594-
);
651+
let note = pushed_note(&pushed, &files, "coderhelm-wip/feature/x");
652+
assert!(note.contains("2 checkpoint commit(s): aaaaaaa, bbbbbbb, 2 file(s)"));
653+
assert!(note.contains("`coderhelm-wip/feature/x`"));
654+
assert!(note.contains("the pull request is unchanged"));
655+
assert!(pushed_note(&[], &[], "w").contains("the pull request is unchanged"));
595656
}
596657

597658
#[test]

‎services/gateway/src/routes/api.rs‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ pub struct CodegenEnvMissing {
914914
pub vars: Vec<String>,
915915
}
916916

917-
/// A commit a fix round pushed before it stopped.
917+
/// A checkpoint commit a fix round saved on its WIP branch before it stopped.
918918
#[derive(serde::Serialize, utoipa::ToSchema)]
919919
pub struct PushedCommit {
920920
/// The commit's SHA.
@@ -946,12 +946,16 @@ pub struct RoundIncomplete {
946946
example = "Pull request open; the last fix round didn't finish: the review fix round ran out of its time budget 3 times in a row."
947947
)]
948948
pub summary: String,
949-
/// The commits the round pushed to the pull request's branch before it
950-
/// stopped, oldest first.
949+
/// The checkpoint commits the round saved on `wip_branch` before it
950+
/// stopped, oldest first (never on the pull request).
951951
pub pushed: Vec<PushedCommit>,
952952
/// The files those commits changed.
953953
#[schema(example = json!(["src/blocks/gallery/tabs.tsx"]))]
954954
pub files: Vec<String>,
955+
/// The branch the round's work so far is saved on. A round that didn't
956+
/// finish never pushes to the pull request; Resume continues from here.
957+
#[schema(example = "coderhelm-wip/web-42-gallery")]
958+
pub wip_branch: String,
955959
/// When it stopped (RFC 3339).
956960
#[schema(example = "2026-10-22T15:40:02Z")]
957961
pub at: String,
@@ -1154,6 +1158,7 @@ fn round_incomplete_of(item: &run_search::Item) -> Option<RoundIncomplete> {
11541158
})
11551159
.collect(),
11561160
files: inc.files,
1161+
wip_branch: inc.wip_branch,
11571162
at: inc.at,
11581163
can_resume: common::run_round::may_resume(status, pr_number, true),
11591164
})
@@ -2000,12 +2005,13 @@ fn resume_route(
20002005
inc: &common::run_round::Incomplete,
20012006
now: chrono::DateTime<chrono::Utc>,
20022007
) -> ResumeRoute {
2003-
use common::run_round::{Kind, Round};
2008+
use common::run_round::Kind;
20042009
match inc.kind {
20052010
Some(Kind::Feedback) => ResumeRoute::Feedback,
2006-
Some(kind) if !inc.feedback.trim().is_empty() => ResumeRoute::Parked(
2007-
Round::start(kind, inc.number, "", &inc.feedback, inc.scoped, now).parked(false),
2008-
),
2011+
Some(_) if !inc.feedback.trim().is_empty() => match inc.resume_round(now) {
2012+
Some(r) => ResumeRoute::Parked(r),
2013+
None => ResumeRoute::Recheck,
2014+
},
20092015
_ => ResumeRoute::Recheck,
20102016
}
20112017
}

0 commit comments

Comments
 (0)