Why is dfx canister delete failing to withdraw the leftover cycles to my wallet?

I have a number of old canisters that I want to stop and recycle the cycles into my cycle wallet.

However, I am seeing an error when I try to run dfx canister delete after dfx canister stop…

I have run dfxvm update and also tried dfx wallet upgrade which returned another error seeming to say I wasn’t a controller of the wallet when I clearly am…

Long story short the old way we withdraw cycles with doesn’t work anymore, although I’m not sure of the exact problem. I am working on a proper solution, but until that is ready I made a quick fix. For now you can dfxvm default 0.20.2-beta.0 to get the beta with the quick fix included and then dfx canister delete with --initial-margin <cycles to not withdraw> set to e.g. --initial-margin 50b and increase until it works

Add me to this camp. I’m going through the developer journey and need to delete the canisters and get my measly < 10T cycles back. Here’s my results if it helps:

dfx canister delete poll_backend --network ic
Beginning withdrawal of cycles; on failure try --no-wallet --no-withdrawal.
Setting the controller to identity principal.
Installing temporary wallet in canister poll_backend to enable transfer of cycles.
Attempting to transfer 2969251105624 cycles to canister 6tylh-uyaaa-aaaak-afpfq-cai.
Error: Failed to delete canister 'poll_backend'.
Caused by: Failed to delete canister 'poll_backend'.
  Failed to deposit 2969251105624 cycles into 6tylh-uyaaa-aaaak-afpfq-cai.
    Failed to call update function 'deposit_cycles' regarding canister '6tylh-uyaaa-aaaak-afpfq-cai'.
      Update call using wallet failed.
        The replica returned a rejection error: reject code CanisterError, reject message Error from Canister ygefb-eiaaa-aaaak-aku2a-cai: Canister ygefb-eiaaa-aaaak-aku2a-cai is out of cycles, error code None