Skip to content

fix: restore plans from the external store when the pull dir has none - #6813

Open
SaiPisey2 wants to merge 1 commit into
runatlantis:mainfrom
SaiPisey2:fix/restore-plans-when-pull-dir-has-no-plans
Open

fix: restore plans from the external store when the pull dir has none#6813
SaiPisey2 wants to merge 1 commit into
runatlantis:mainfrom
SaiPisey2:fix/restore-plans-when-pull-dir-has-no-plans

Conversation

@SaiPisey2

Copy link
Copy Markdown

what

  • buildAllProjectCommandsByPlan now also tries the external plan store when the pull directory exists but PendingPlanFinder finds no plans in it, not only when the directory is missing entirely.
  • The restore path (capability probe, workspace listing, cloning each workspace, RestorePlans) moves into restorePlansFromStore and is shared by both cases.

why

  • Restore was reachable only from the os.IsNotExist branch. If the directory was present but empty of plans, apply failed with plan file is missing for dir "..." workspace "..." with status "planned"; run atlantis plan, even though the plan was in the store and PullStatus said planned.
  • With more than one replica the apply can land on a replica that never held the plan but does have a working dir for that PR, created by an earlier event. It also happens after deletePlansAndPlanLocks removes the .tfplan of an autoplan that failed for an unrelated reason, leaving the directory behind.
  • When the store genuinely has nothing (os.ErrNotExist), the empty plan list is kept so the existing "plan file is missing" error is still what the user sees. Stores that cannot restore, such as LocalPlanStore, are skipped by the capability probe as before, so this is a no-op without --enable-external-stores.

tests

  • Added TestDefaultProjectCommandBuilder_ExternalPlanStoreRecoveryPullDirWithoutPlans: the pull dir exists as a git repo with no .tfplan, and RestorePlans writes the plan back. Without the change the test fails with the exact error from the issue — plan file is missing for dir "project1" workspace "default" project "" with status "planned" — and passes with it.
  • go build ./... and go test ./server/events/... pass on darwin/arm64. The existing recovery tests, including the ones covering clone-before-restore ordering for non-default workspaces, are unchanged and still pass.

references

buildAllProjectCommandsByPlan only restored plans from the external store
when the pull directory was absent. If the directory existed but held no
plan files, the apply failed with "plan file is missing ... run atlantis
plan" even though the plan was in the store.

That happens whenever an earlier event created the directory on this
replica, including after deletePlansAndPlanLocks removes the .tfplan of a
failed autoplan, and it is the normal case with more than one replica,
where an apply can land on a replica that never held the plan.

Attempt the restore when the plan finder comes back empty as well, and
share the restore path between both cases.

Signed-off-by: SaiPisey2 <piseysai0202@gmail.com>
@dosubot dosubot Bot added bug Something isn't working go Pull requests that update Go code labels Aug 27, 2026
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

1 participant