From 9c370329a3339a7a82258f6f8ed677ba1526e1c5 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 24 May 2026 12:17:32 +0300 Subject: fix(manager): only delete state file when VM deletion is confirmed Ensure Manager#delete does not wipe the state file on generic/transient API failures. The rescue now checks whether the error message indicates the VM is already gone (404, not_found, does not exist) before removing state. This prevents orphaned billable VMs after exhausted retries or transient network errors. --- lib/hyperstack/manager.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/hyperstack/manager.rb b/lib/hyperstack/manager.rb index 2134c92..39b8767 100644 --- a/lib/hyperstack/manager.rb +++ b/lib/hyperstack/manager.rb @@ -117,10 +117,14 @@ module HyperstackVM delete_ssh_known_hosts_file @state_store.delete unless preserve_state_on_failure info "VM #{target_vm_id} deleted." - rescue Error + rescue Error => e raise if preserve_state_on_failure - @state_store.delete + gone = e.message.include?('not_found') || + e.message.include?('does not exist') || + e.message.include?('does not exists') || + e.message.include?('404') + @state_store.delete if gone raise end -- cgit v1.2.3