Skip to content

fix: keep successful plans applyable when automerge blocks on a sibling project error#6698

Open
azotamiota wants to merge 3 commits into
runatlantis:mainfrom
azotamiota:fix/keep-successful-plans-on-partial-automerge-failure
Open

fix: keep successful plans applyable when automerge blocks on a sibling project error#6698
azotamiota wants to merge 3 commits into
runatlantis:mainfrom
azotamiota:fix/keep-successful-plans-on-partial-automerge-failure

Conversation

@azotamiota

@azotamiota azotamiota commented Jul 24, 2026

Copy link
Copy Markdown

What

Stops Atlantis from deleting a project's saved plan and lock when automerge is enabled and a different project's atlantis plan errors. A project whose plan succeeded can now be applied on its own (atlantis apply -p <path>) while a sibling project's plan is fixed and replanned, instead of both being wiped.

  • server/events/plan_command_runner.go: removed the post-run deletePlansAndPlanLocks + result.PlansDeleted = true step in both runAutoplan() and run() that ran whenever automerge was enabled and the batch had any error. No replacement gate is added — a successful project's plan/lock is simply left alone.
  • server/events/command_runner_test.go: updated TestRunAutoplanCommandWithError_DeletePlansTestRunAutoplanCommandWithError_KeepsSuccessfulPlans, asserting DeletePlans is now called once (the pre-run stale-plan discard) instead of twice.

Automerge itself is unaffected by this change: AutoMerger.automerge() in server/events/automerger.go already refuses to merge until every project tracked on the pull request has an Applied status, so the extra plan-wiping under automerge+error was blocking a valid recovery workflow without adding any real safety.

Why / relation to #3002 and #6613

This closes #3002 ("Only delete the plan that failed when automerge is enabled").

#6613 also targets #3002 and independently arrives at "keep successful plans on disk," plus adds atlantis plan --failed to re-plan just the broken projects — a genuinely useful, complementary addition this PR does not attempt to duplicate.

However, testing against #6613 shows it doesn't unblock the specific workflow this PR is for. #6613 adds an unconditional gate at the top of ApplyCommandRunner.Run():

if failedProjects := ctx.ErroredPlanProjects(); len(failedProjects) > 0 {
    ...
    a.pullUpdater.updatePull(ctx, cmd, command.Result{Failure: failedPlansApplyBlockFailure(failedProjects)})
    return
}

ctx.ErroredPlanProjects() inspects every project tracked on the whole pull request, not just the one(s) targeted by the current command. So even a scoped atlantis apply -p <successful-project-path> is rejected as long as any other project in the PR has an errored plan — which reintroduces the "can't touch anything until everything is fixed" problem for targeted applies, just via a hard block instead of file deletion.

This PR takes the narrower approach of not adding any new apply-time gate: a project's plan is either there (because it planned successfully) or it isn't, and -p/-d/-w-scoped applies behave exactly as they already do for any other single-project apply. It can coexist with atlantis plan --failed from #6613 if that lands separately, or the apply-blocking behavior there could be re-scoped to the command's targeted project(s) — happy to help with either depending on maintainer preference.

Scenario this enables

  1. Push a change touching two projects. Atlantis auto-plans both; project 1 errors, project 2 succeeds.
  2. atlantis apply -p <project-2-path> works immediately instead of failing with "plan was not saved" (or, under feat: keep plans on partial failure, add 'atlantis plan --failed' #6613 as currently written, a hard apply-block).
  3. Fix project 1 and push again; only project 1 gets replanned (project 2 shows "No changes").
  4. Apply project 1 — automerge then proceeds since every tracked project is Applied.

Test plan

  • go build ./...
  • go test ./server/events/... (full package passes, including the updated test)
  • Manual verification against a live Atlantis instance with automerge enabled and a two-project PR

Assisted-by: Claude noreply@anthropic.com

… error

When automerge is enabled and a multi-project plan run has one project
error out, Atlantis was deleting the plan and lock for every project in
the run, including ones that planned successfully. This made it
impossible to apply a project that planned cleanly until the failing
project was fixed and everything was replanned from scratch.

Automerge itself already refuses to merge until every project tracked
on the pull request shows an Applied status, so gating on this specific
failure by wiping successful plans was unnecessary. Stop deleting plans
and locks after a partial failure so a successful project can still be
applied on its own while a sibling project is fixed and replanned.

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Norbert Majer <norbert.majer@getchip.uk>
@dosubot dosubot Bot added bug Something isn't working go Pull requests that update Go code labels Jul 24, 2026
Norbert Majer added 2 commits July 24, 2026 23:02
…-plans-on-partial-automerge-failure

Signed-off-by: Norbert Majer <norbert.majer@getchip.uk>

# Conflicts:
#	server/events/command_runner_test.go
#	server/events/plan_command_runner.go
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Only delete the plan that failed when automerge is enabled

1 participant