Skip to content
Open
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 changelog.d/fixed-delegated-park-lift-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- A delegated decision ("Let hive decide") on a PR now takes the `needs-human` and `stage/085-needs-decision` labels off even when the decision itself used up its time budget. Before, the label lift ran on the already-expired request context, failed with `context deadline exceeded`, and the next pass parked the PR in 085 again (#19256).
12 changes: 12 additions & 0 deletions src/pkg/dashboard/api_repo_item_decide_delegated.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,10 @@ func delegatedLowRiskPath(path string) bool {

const delegatedApprovalReportingTimeout = 15 * time.Second

// delegatedParkLiftTimeout bounds the park-label lift, which runs on a
// context detached from the decision's own (hivecommons/hive#19256).
const delegatedParkLiftTimeout = 15 * time.Second

// executeDelegatedDecision runs the allowed actions through the existing
// GitHub helpers. It stops at the first failure and reports what landed.
func (s *Server) executeDelegatedDecision(ctx context.Context, in delegatedecision.Input, d delegatedecision.Decision, user string, mergerRole bool) (notes []string, execErr error) {
Expand Down Expand Up @@ -1194,10 +1198,18 @@ func delegatedDecisionResolves(v delegatedecision.Verdict) bool {
// the row in 085 and the popover re-asked). Returns the labels removed; a
// failed removal is logged, not returned — the decision record stands and
// the tracker projection ranks it above the stale label.
//
// The lift runs last, after the decision's own writes, so the caller's
// context (the request, or the bounded post-approval reporting window) is
// often spent by then; hivecommons/hive#19256 saw every lift fail with
// `context deadline exceeded` and the row re-park in 085. It therefore runs
// on its own bounded context detached from the caller's cancellation.
func (s *Server) liftDelegatedParkLabels(ctx context.Context, in delegatedecision.Input, d delegatedecision.Decision) []string {
if in.Kind != delegatedecision.KindPR || !delegatedDecisionResolves(d.Verdict) {
return nil
}
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), delegatedParkLiftTimeout)
defer cancel()
var lifted []string
for _, label := range delegatedParkLabels {
if !slices.ContainsFunc(in.Labels, func(l string) bool { return strings.EqualFold(l, label) }) {
Expand Down
16 changes: 16 additions & 0 deletions src/pkg/dashboard/api_repo_item_decide_delegated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,22 @@ func TestDelegatedDecisionLiftsStaleNeedsHuman(t *testing.T) {
}
}

// hivecommons/hive#19256: the lift runs after the decision's own writes,
// when the caller's context is often already spent; it still takes the
// park labels off instead of failing with `context deadline exceeded`.
func TestDelegatedParkLiftSurvivesSpentContext(t *testing.T) {
mock := &repoItemDecisionMock{prForeign: true, prLabels: []string{"needs-human", stagelabels.NeedsDecision.Label()}}
srv := newDelegatedServer(t, mock)
in := delegatedecision.Input{Repo: "testorg/testrepo", Number: 8, Kind: delegatedecision.KindPR, Labels: mock.prLabels}
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
defer cancel()
<-ctx.Done()
lifted := srv.liftDelegatedParkLabels(ctx, in, delegatedecision.Decision{Verdict: delegatedecision.VerdictApprove})
if len(lifted) != 2 {
t.Fatalf("lifted = %v, removed = %v", lifted, mock.removed)
}
}

// hivecommons/hive#15289: the #15219 scenario end to end. A conflicting,
// offline clanker PR whose issue a merged PR already closed is closed as
// superseded with a note naming that PR — not adopted — and the job
Expand Down
Loading