As described in the PR1586481 , Software versions 21.1 and lower are running FreeBSD version 11 whereas from version 21.2 onward, the FreeBSD version is 12. Software upgrade to 21.2 (or later) from 21.1 (or earlier) will need CLI mandatory knob 'no-validate' to be used during software image upgrade process.
However, as described in the PR1730442 on all Junos platforms, if there are incompatible configuration present in the box and if no-validate option is used while upgrading then it is expected for the box to go into the amnesiac mode because of incompatible configuration after upgrade. However due to software issue it is seen that even without addressing the configuration errors when the device is rebooted manually the SSH connection is getting restored but the box still has those bad or incompatible configurations and causes unexpected behavior.
In the scenario where you are upgrading from code 20 to code 21.4R3, you have to add no-validate, but if incompatible configuration exists, once the device boots up in the code 21.4R3 you will be unable to SSH or device will be showing as amnesiac after booting up.
Examples of incompatible configuration:
set interfaces ae0 aggregated-ether-options minimum-links 1, but no physical links associate it to ae0. Commit will succeed in code 20, but in code 21 it will fail.
IP assigned to management port me0 or em0, and family dhcp configured in port vme (virtual management port). Commit will succeed in code 20, but in code 21 it will fail.
The steps suggested are listed as below:
Open a JTAC case and request to check the configuration against the target code, loading the configuration in a device running the target code to make sure no commit errors will be seen.
Save the running configuration with the commands >show configuration | display set | no-more or > show configuration | no-more, paste it on a notepad and save it. You can then remove the unnecessary configuration from the switch and leave only the root password if you have console access, this will avoid the chance of having incompatible configuration so once the device is upgraded, paste the configuration and if any commit error is seen just correct it as required.