Repository navigation
feat: skip a plan or apply that's already running for the commit - #2758
Open
dannysauer wants to merge 1 commit into
Open
dannysauer wants to merge 1 commit into
dannysauer wants to merge 1 commit into
Conversation
A second `digger plan` or `digger apply` on a commit that's still being planned or applied started a second batch. Two applies of the same project then raced for its state. The backend now skips such a comment, or a check-run Apply, and replies with the projects it found running and how to force it. A plan is skipped when every requested project is being planned; an apply when any is. `--force` runs it anyway. A job downstream of a failed job doesn't count, since it never starts. DIGGER_DUPLICATE_COMMAND_WINDOW bounds how far back the check looks (default 2h, the job token's lifetime); 0 disables it. A new index on digger_batches (repo_full_name, pr_number, commit_sha) keeps the lookup cheap. Requests that arrive together would both pass the check before either created its batch. A transaction-scoped Postgres advisory lock per PR serializes them from the check until the batch exists, for at most 5 minutes. A request that can't get the lock within a minute, or can't run the check, is skipped with a note to retry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2755. A repeated
digger planordigger applycomment no longer starts a second run of a commit that's still being planned or applied. Digger replies to the comment instead, naming the projects it found running and pointing to--force.This is a little wider than the issue, for the reasons in this comment: it covers applies too, and it closes the race between comments that arrive together.
Behavior
DIGGER_DUPLICATE_COMMAND_WINDOWchanges the window, and0turns the check off.--forceskips the check. It's a new flag inParseDiggerCommentFlags, which rejected unknown flags until now, so it can't collide with existing comments.digger_batches (repo_full_name, pr_number, commit_sha)anddigger_job_parent_links (parent_digger_job_id)keep the lookup cheap. The second was already named on the model, but a,in its gorm tag where;belongs meant it was never created.--forceand ignore it.The race
Two comments a few seconds apart could both pass the check before either had created its batch. On our deployment, a pair of
digger applycomments did exactly that while GitHub was slow. So each plan or apply comment takes a transaction-scoped Postgres advisory lock for its PR, from the check until its batch exists, for at most 5 minutes.Known gap
A run that was cancelled in CI, or that failed to dispatch, still counts as running until the window ends, because the backend doesn't hear that it stopped. The reply and the docs point to
--forcefor that.Testing
--forceparsing and the query, including jobs downstream of a failure.TestLockPullRequestCommandsPostgresneeds a real Postgres and skips unlessDIGGER_TEST_POSTGRES_URLis set. I ran it, and the query test, against Postgres 17. Happy to wire a Postgres service intobackend_test.ymlif you'd like it in CI.comment-args,commentops,plan-preview(which also gets a broken CommentOps link fixed), and the self-hosting configuration table.We run this on our self-hosted backend. We're happy to adjust it based on your feedback.