fix(toolkit-lib): finalizing deployment after refactor intermittently fails while stacks are still in UPDATE_IN_PROGRESS - #1805
Open
go-to-k wants to merge 5 commits into
Open
Conversation
…ctor with a deployment
auto-merge was automatically disabled
August 9, 2026 18:34
Head branch was pushed to by a user without write access
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1805 +/- ##
==========================================
- Coverage 90.32% 90.27% -0.05%
==========================================
Files 80 80
Lines 12124 12124
Branches 1716 1714 -2
==========================================
- Hits 10951 10945 -6
- Misses 1139 1145 +6
Partials 34 34
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…t polling interval
…refactor execution test
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 #1804
Problem
CloudFormation marks a stack refactor's
ExecutionStatusasEXECUTE_COMPLETEwhile the affected stacks may still be inUPDATE_IN_PROGRESSfor a few more seconds (observed: 0.5-3 seconds).RefactoringContext.execute()only waits for the refactor status (waitUntilStackRefactorExecuteComplete), andToolkit._refactor()then immediately starts the finalizing deployment. Since synthesis is done and the assets are already published at that point, the deployment reachesCreateChangeSetwithin ~1-2 seconds and frequently fails with:Whether it fails depends on where the waiter's 6-second polling of
DescribeStackRefactorlands relative to this window, so the failure is intermittent but frequent (2 out of 3 attempts in the reporter's environment).Fix
After
waitUntilStackRefactorExecuteComplete,RefactoringContext.execute()now waits for every stack involved in the mappings (source and destination) to stabilize, reusing the existingstabilizeStackhelper fromapi/deployments/cfn-api. The wait is placed insideexecute()rather than inToolkit._refactor()so that any caller ofexecute()is protected.Testing
test/api/refactoring/context-execute.test.ts(fake timers, same style ascfn-api-stabilization-polling-interval.test.ts):execute()does not resolve while the stack isUPDATE_IN_PROGRESSand resolves only after it reachesUPDATE_COMPLETE; in a cross-stack refactor both source and destination stacks are waited on.UPDATE_IN_PROGRESS (Refactor ... initiated)right after the refactor waiter returned, waited for it to stabilize, and the finalizing deployment then succeeded:This is exactly the timing where the current CLI fails.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license