Repository navigation
fix(toolkit-lib): dispose temporary outdir by default in fromAssemblyBuilder - #2194
Open
mayankcodes-dev wants to merge 1 commit into
Open
mayankcodes-dev wants to merge 1 commit into
mayankcodes-dev wants to merge 1 commit into
Conversation
mayankcodes-dev
requested review from
a team
and
a balanced review from Copilot
December 2, 2026 14:22
mayankcodes-dev
requested a deployment
to
integ-approval
December 2, 2026 14:22 — with
GitHub Actions
Waiting
aws-cdk-automation
enabled auto-merge
December 2, 2026 14:22
This branch is waiting to be 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.
Fixes #2189
Root cause
When
fromAssemblyBuilderis called without anoutdir,ExecutionEnvironment.create()creates a temporary$TMPDIR/cdk.outXXXXXXdirectory withoutDirIsTemporary = trueand initializesshouldClean = true. InCloudAssemblySourceBuilder.makeContextAwareCloudAssemblySource(),execution.markSuccessful()is awaited first soExecutionEnvironmentconverts the write lock to a read lock and clearsthis.shouldClean = false(preventingExecutionEnvironment[Symbol.asyncDispose]()from deleting the assembly while returning it). Becauseexecution.shouldDisposeOutDirreturnedthis.shouldClean, the subsequentoptions.disposeOutdir ?? execution.shouldDisposeOutDircheck always evaluated tofalsewhendisposeOutdirwas omitted.Changes
packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/prepare-source.ts:public readonly outDirIsTemporary: booleanonExecutionEnvironment(immutable fact of whetherExecutionEnvironment.create()allocated a temporary directory), separate from the internalshouldCleanflag used by[Symbol.asyncDispose]().[Symbol.asyncDispose]()to checkthis.shouldCleanand clarify theExecutionEnvironment.createdoc comment.prepare-source.tslives underprivate/and is not exported fromlib/index.ts, the public API of@aws-cdk/toolkit-libis unchanged.packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/source-builder.ts:options.disposeOutdir ?? execution.outDirIsTemporaryso temporary output directories default todeleteOnDispose = truewhile explicitdisposeOutdir: falseand explicitoutdirvalues keep their documented behavior.packages/@aws-cdk/toolkit-lib/test/api/cloud-assembly/source-builder.test.ts:describe('fromAssemblyBuilder')covering default cleanup of omitted temporary outdirs (fails before the fix),disposeOutdir: falsepreservation of temporary outdirs, preservation of explicit outdirs whendisposeOutdiris omitted, and cleanup of temporary outdirs when a builder fails.Testing
yarn compileandapi-extractor runinpackages/@aws-cdk/toolkit-libcompleted without errors.eslinton the 3 modified files passed with 0 errors and 0 warnings.npx jest test/api/cloud-assembly/prepare-source.test.ts test/actions/synth.test.ts test/toolkit/toolkit.test.ts --collectCoverage=false: 3 suites passed (23 passed).npx jest test/api/cloud-assembly/source-builder.test.ts -t "^(?!fromCdkApp abort)" --collectCoverage=false: 50 passed, 5 skipped (allfromAssemblyBuilder,fromAssemblyDirectory,fromCdkAppDirectory, and non-signalfromCdkApptests pass on Windows;fromCdkApp aborttests expect POSIX termination signal wording).npx jestacrosscontext-store,environment,exec,stack-selection-*,stack-selectors,list, anddiffsuites: 8 of 9 suites passed (120 passed; 1 pre-existing Windowscmd.exeechoquoting failure inexec.test.ts).Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license