Skip to content

Fix merge queue state and event handling issues - #41

Merged
FranciscoKurpiel merged 8 commits into
mainfrom
fix-mergequeue-issues
Oct 27, 2026
Merged

FranciscoKurpiel merged 8 commits into
mainfrom
fix-mergequeue-issues

Conversation

@FranciscoKurpiel

@FranciscoKurpiel FranciscoKurpiel commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

This PR addresses several issues identified in directorius production logs:

  • A. Dequeue closed/merged PRs instead of suspending them: When processPR evaluates a PR that is already closed or merged (for example, when a push event on the base branch arrives before or without the pull_request closed webhook), it previously suspended the PR instead of removing it from the queue. This overwrote the merged commit's directorius status back to pending and caused the closed PR to be moved back into the active queue on subsequent pushes to the base branch.
  • B. Fix inverted error check and nil-pointer dereference in processCheckRunEvent: In processCheckRunEvent, SetPRStaleSinceIfNewer is only called inside the if err != nil branch when NewBaseBranch fails (passing a nil base branch and dereferencing it), and is skipped when NewBaseBranch succeeds. Also avoid mutating the outer logger across loop iterations.
  • C. Downgrade empty-branches check_run/status logs to Debug and fix SetPRStaleSinceIfNewerByBranch: Non-PR check_run and status events (such as pushes to master, scheduled workflows, or already-closed PRs) have an empty pull_requests/branches list and were logged at Info level, flooding production logs. Also fix SetPRStaleSinceIfNewerByBranch overwriting missing when a repository has queues for multiple base branches.
  • D. Fix logger field accumulation in Coordinator.sync: During initial synchronization, logger = logger.With(pr.LogFields...) is reassigned in a loop over all open PRs, causing every subsequent log line in sync to accumulate duplicate github.pull_request and git.branch fields for all processed PRs.
  • E. Avoid redundant AddLabel calls and misleading success logs: prAddQueueHeadLabel is called on every periodic processPR run even when the head PR already has the label, and both prAddQueueHeadLabel and prRemoveQueueHeadLabel log that the label was added/removed even when the GitHub API call failed.
  • F. Preserve queue head position during startup sync: On startup, sync removes the mergequeue-first label from the previously active head PR and re-enqueues all PRs sorted only by EnqueuedAt, losing the head position of the PR whose CI was already running before the restart.
  • G. Log canceled processPR evaluation at Debug instead of Error: When an in-flight processPR run is intentionally canceled (e.g., via cancelActionForPR when the PR is dequeued after merging), evalPRAction returns context.Canceled. Checking errors.Is(err, context.Canceled) before logger.Error avoids emitting a false-positive error and stacktrace.

@FranciscoKurpiel FranciscoKurpiel self-assigned this Oct 27, 2026
@FranciscoKurpiel FranciscoKurpiel added bug Something isn't working go Pull requests that update Go code labels Oct 27, 2026
@FranciscoKurpiel
FranciscoKurpiel marked this pull request as ready for review October 27, 2026 19:23
@FranciscoKurpiel
FranciscoKurpiel merged commit a8be1a1 into main Oct 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update Go code

Development

Successfully merging this pull request may close these issues.

1 participant