From cc43455191bb7434055bb68e463c944aeb9fc2d0 Mon Sep 17 00:00:00 2001 From: codex Date: Wed, 28 Oct 2026 07:11:25 +0800 Subject: [PATCH] fix: preserve prepare progress during rollback retry --- .../Cloud/CloudInstanceMigrationWorkflow.php | 8 +++++--- web/tests/CloudInstanceMigrationWorkflowTest.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/web/app/Services/Cloud/CloudInstanceMigrationWorkflow.php b/web/app/Services/Cloud/CloudInstanceMigrationWorkflow.php index b2ece235..2185aa8f 100644 --- a/web/app/Services/Cloud/CloudInstanceMigrationWorkflow.php +++ b/web/app/Services/Cloud/CloudInstanceMigrationWorkflow.php @@ -314,9 +314,11 @@ final class CloudInstanceMigrationWorkflow $stepStatus = 'pending'; if ($onRollbackPath) { if ($key === 'prepare') { - $stepStatus = (string) $migration->error_code - === 'migration_transfer_aborted' - ? 'completed' : 'interrupted'; + // A transfer job can only be queued after source prepare + // succeeds. Unlike error_code, this durable link is not + // rewritten when rollback itself fails and is retried. + $stepStatus = $migration->target_receive_job_id === null + ? 'interrupted' : 'completed'; } elseif ($key === 'transfer') { $stepStatus = $migration->target_receive_job_id === null ? 'skipped' : 'interrupted'; diff --git a/web/tests/CloudInstanceMigrationWorkflowTest.php b/web/tests/CloudInstanceMigrationWorkflowTest.php index d5ad0ad3..bf21ed1f 100644 --- a/web/tests/CloudInstanceMigrationWorkflowTest.php +++ b/web/tests/CloudInstanceMigrationWorkflowTest.php @@ -151,6 +151,20 @@ $assert(($rollbackProjection['status'] ?? null) === 'rolled_back' === 'completed', 'Rollback progress hid the interrupted migration stage.'); +$retryingRollback = $migration('rollback_running'); +$retryingRollback->error_code = 'migration_source_rollback_failed'; +$retryingRollback->target_receive_job_id = 2; +$retryProjection = CloudInstanceMigrationWorkflow::progress( + $retryingRollback +); +$assert(($step($retryProjection, 'prepare')['status'] ?? null) + === 'completed' + && ($step($retryProjection, 'transfer')['status'] ?? null) + === 'interrupted' + && ($step($retryProjection, 'rollback')['status'] ?? null) + === 'running', + 'Retrying rollback rewrote completed source preparation as interrupted.'); + $completed = $migration('completed'); $completed->target_receive_job_id = 2; $completed->activate_job_id = 3;