fix: prevent JIT source TTL from wiping varfiles/backend mid-execution#2253
Draft
fix: prevent JIT source TTL from wiping varfiles/backend mid-execution#2253
Conversation
…process execution When AutoProvisionSource is called twice within the same command invocation (once from resolveAndProvisionComponentPath and once via the before.terraform.init hook in prepareInitExecution), a zero TTL would cause VendorSource to call os.RemoveAll on the workdir, deleting varfiles and backend configs written between the two calls. Fix: add an invocationDoneKey guard that marks componentConfig after the first call completes. Any subsequent call with the same componentConfig returns immediately without re-provisioning, preserving the workdir contents for the subprocess. The defer-based marker ensures the guard is set for both the "provisioned" and "skipped" paths without duplicating code. Co-authored-by: osterman <52489+osterman@users.noreply.github.com> Agent-Logs-Url: https://github.com/cloudposse/atmos/sessions/2c2dec41-5920-40f9-9420-137f7970ff42
Copilot
AI
changed the title
[WIP] Fix JIT source provisioning TTL expiry causing varfile deletion
fix: prevent JIT source TTL from wiping varfiles/backend mid-execution
Mar 26, 2026
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.
AutoProvisionSourceis called twice per command invocation — once directly fromresolveAndProvisionComponentPath, and again via thebefore.terraform.inithook inprepareInitExecution. Withttl: "0s", the second call treats the workdir as always-expired, invokesos.RemoveAll(targetDir), and wipes the varfiles and backend configs written between the two calls. The subprocess then fails with"file does not exist".Changes
pkg/provisioner/source/provision_hook.go— adds an in-memory idempotency guard (invocationDoneKey = "_atmos_source_provisioned") toAutoProvisionSource. A named-returndefersets the marker incomponentConfigon successful return. Any subsequent call with the same map (same in-memory invocation) short-circuits immediately. The guard is scoped to the per-invocationcomponentConfig; separateatmosruns are unaffected.pkg/provisioner/source/provision_hook_test.go— two regression tests:TestAutoProvisionSource_InvocationGuard_PreventsDoubleProvisioning: asserts the guard short-circuits a second call even withttl: "0s"TestAutoProvisionSource_InvocationGuard_SetAfterProvisioning: asserts the marker is written tocomponentConfigafter a skipped provision (TTL not expired), ensuring the hook path is a no-opOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.