fix(#2469): supersede stale config-PR approval on PR update instead of skipping
This commit is contained in:
parent
d8567fc546
commit
152d54dcdc
3 changed files with 54 additions and 39 deletions
|
|
@ -157,6 +157,31 @@ pub(crate) async fn submit_merge_config_pr(
|
|||
let sha = crate::forge::pr_head_sha(&repo, pr_number)
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("fetch PR head sha for {agent} PR #{pr_number}: {e}"))?;
|
||||
// Both the webhook (`synchronize`) and the poll fallback call this on
|
||||
// every PR update. If an approval for this PR is already pending, reconcile
|
||||
// it against the live head sha rather than blindly queuing another:
|
||||
// - same sha → the PR hasn't moved, so this is a duplicate signal — no-op.
|
||||
// - drifted sha → the reviewed head is stale. Don't mutate the
|
||||
// pending row in place (that races a concurrent approve); cancel it and
|
||||
// fall through to queue a FRESH approval pinned to the new head.
|
||||
if let Some((old_id, old_sha)) = coord.approvals.pending_merge_config_pr(agent, pr_number)? {
|
||||
if old_sha.as_deref() == Some(sha.as_str()) {
|
||||
return Ok(old_id);
|
||||
}
|
||||
let cancelled = coord
|
||||
.approvals
|
||||
.mark_cancelled(old_id, "config PR updated — superseded by a fresh approval")
|
||||
.map_err(|e| anyhow::anyhow!("cancel superseded merge_config_pr approval: {e:#}"))?;
|
||||
coord.emit_approval_resolved(crate::coordinator::ApprovalResolved {
|
||||
id: old_id,
|
||||
agent,
|
||||
approval_kind: "merge_config_pr",
|
||||
sha_short: old_sha.map(|s| s[..s.len().min(12)].to_owned()),
|
||||
status: "cancelled",
|
||||
note: Some("PR head moved; superseded by a fresh approval".to_owned()),
|
||||
description: cancelled.description,
|
||||
});
|
||||
}
|
||||
let id = coord
|
||||
.approvals
|
||||
.submit_kind(
|
||||
|
|
|
|||
Loading…
Reference in a new issue