Skip to content

fix(toolkit-lib): dispose temporary outdir by default in fromAssemblyBuilder - #2194

Open
mayankcodes-dev wants to merge 1 commit into
aws:mainfrom
mayankcodes-dev:fix/dispose-temp-outdir-by-default
Open

mayankcodes-dev wants to merge 1 commit into
aws:mainfrom
mayankcodes-dev:fix/dispose-temp-outdir-by-default

Conversation

@mayankcodes-dev

Copy link
Copy Markdown

Fixes #2189

Root cause

When fromAssemblyBuilder is called without an outdir, ExecutionEnvironment.create() creates a temporary $TMPDIR/cdk.outXXXXXX directory with outDirIsTemporary = true and initializes shouldClean = true. In CloudAssemblySourceBuilder.makeContextAwareCloudAssemblySource(), execution.markSuccessful() is awaited first so ExecutionEnvironment converts the write lock to a read lock and clears this.shouldClean = false (preventing ExecutionEnvironment[Symbol.asyncDispose]() from deleting the assembly while returning it). Because execution.shouldDisposeOutDir returned this.shouldClean, the subsequent options.disposeOutdir ?? execution.shouldDisposeOutDir check always evaluated to false when disposeOutdir was omitted.

Changes

  • packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/prepare-source.ts:
    • Expose public readonly outDirIsTemporary: boolean on ExecutionEnvironment (immutable fact of whether ExecutionEnvironment.create() allocated a temporary directory), separate from the internal shouldClean flag used by [Symbol.asyncDispose]().
    • Update [Symbol.asyncDispose]() to check this.shouldClean and clarify the ExecutionEnvironment.create doc comment.
    • Because prepare-source.ts lives under private/ and is not exported from lib/index.ts, the public API of @aws-cdk/toolkit-lib is unchanged.
  • packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/source-builder.ts:
    • Read options.disposeOutdir ?? execution.outDirIsTemporary so temporary output directories default to deleteOnDispose = true while explicit disposeOutdir: false and explicit outdir values keep their documented behavior.
  • packages/@aws-cdk/toolkit-lib/test/api/cloud-assembly/source-builder.test.ts:
    • Add unit tests under describe('fromAssemblyBuilder') covering default cleanup of omitted temporary outdirs (fails before the fix), disposeOutdir: false preservation of temporary outdirs, preservation of explicit outdirs when disposeOutdir is omitted, and cleanup of temporary outdirs when a builder fails.

Testing

  • yarn compile and api-extractor run in packages/@aws-cdk/toolkit-lib completed without errors.
  • eslint on 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 (all fromAssemblyBuilder, fromAssemblyDirectory, fromCdkAppDirectory, and non-signal fromCdkApp tests pass on Windows; fromCdkApp abort tests expect POSIX termination signal wording).
  • npx jest across context-store, environment, exec, stack-selection-*, stack-selectors, list, and diff suites: 8 of 9 suites passed (120 passed; 1 pre-existing Windows cmd.exe echo quoting failure in exec.test.ts).

Checklist

  • This change contains a major version upgrade for a dependency and I confirm all breaking changes are addressed
    • Release notes for the new version:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@mayankcodes-dev
mayankcodes-dev requested review from a team and a balanced review from Copilot December 2, 2026 14:22
@github-actions github-actions Bot added the p2 label Dec 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch is waiting to be deployed

1 active and 1 waiting deployments
integ-approval — 719ed0b1 Waiting Dec 2, 2026 by mayankcodes-dev via prepare #7829
automation — 719ed0b1 Deployed Dec 2, 2026 by mayankcodes-dev via Set AutoQueue on PR #2194 #4069
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(toolkit-lib): fromAssemblyBuilder never deletes its temporary outdir on dispose (deleteOnDispose read after markSuccessful clears it)

2 participants