From 7a1290e3bf96a49b62d395ee59c4e60f32ebddbd Mon Sep 17 00:00:00 2001 From: kellyaa Date: Thu, 19 Nov 2026 16:28:26 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Lift=20delegated=20park=20labels?= =?UTF-8?q?=20on=20a=20detached=20bounded=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The park-label lift runs after the decision's own writes, so the caller's context was often spent and every removal failed with 'context deadline exceeded', leaving the PR parked in 085. Run the lift on its own bounded context detached from the caller's cancellation. Fixes #19256 Hive-Run: hivecommons/hive#19256 Hive-Plan: selfreport-fix Hive-Spec: delegated-decision#park-lift Co-Authored-By: Claude Opus 5.5 Signed-off-by: kellyaa --- changelog.d/fixed-delegated-park-lift-context.md | 1 + .../dashboard/api_repo_item_decide_delegated.go | 12 ++++++++++++ .../api_repo_item_decide_delegated_test.go | 16 ++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 changelog.d/fixed-delegated-park-lift-context.md diff --git a/changelog.d/fixed-delegated-park-lift-context.md b/changelog.d/fixed-delegated-park-lift-context.md new file mode 100644 index 0000000000..418911de7c --- /dev/null +++ b/changelog.d/fixed-delegated-park-lift-context.md @@ -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). diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated.go b/src/pkg/dashboard/api_repo_item_decide_delegated.go index 7e7ed8550c..0b25de9f39 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated.go @@ -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) { @@ -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) }) { diff --git a/src/pkg/dashboard/api_repo_item_decide_delegated_test.go b/src/pkg/dashboard/api_repo_item_decide_delegated_test.go index 6cccf92765..9dccb1b180 100644 --- a/src/pkg/dashboard/api_repo_item_decide_delegated_test.go +++ b/src/pkg/dashboard/api_repo_item_decide_delegated_test.go @@ -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