From f0be2d9bb31e6ac89d8143b6a2450782133d483f Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 28 Jul 2026 17:50:41 +0100 Subject: [PATCH] fix: hand activation back when a queued deployment is canceled deactivateOthers() clears `activate` on the other pending deployments so the one being dispatched wins when it finishes. A cancel landing between the queued transition and that call left the resource with nothing able to go live: the replacement was canceled, and the deployments it displaced could no longer activate when their own builds finished. Return the ids deactivateOthers() cleared, and hand the claim back to exactly those deployments when the dispatch turns out to have been canceled. No job is submitted in that case either. Co-Authored-By: Claude Opus 5 (1M context) --- src/Appwrite/Deployment/Deployments.php | 31 ++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Deployment/Deployments.php b/src/Appwrite/Deployment/Deployments.php index 82707f05bb..336a71c6ca 100644 --- a/src/Appwrite/Deployment/Deployments.php +++ b/src/Appwrite/Deployment/Deployments.php @@ -152,7 +152,20 @@ readonly class Deployments return $deployment; } - $this->deactivateOthers($resource, $deployment); + // Claiming activation takes it away from the other pending deployments, + // so a cancel landing while we do it would leave nothing able to go + // live. Hand the claim back to exactly the deployments it was taken + // from, and stop before submitting a job for a canceled deployment. + $deactivated = $this->deactivateOthers($resource, $deployment); + if ($deactivated !== [] && $this->status($deployment->getId()) === 'canceled') { + foreach ($deactivated as $other) { + $this->dbForProject->updateDocument('deployments', $other, new Document([ + 'activate' => true, + ])); + } + + return $this->dbForProject->getDocument('deployments', $deployment->getId()); + } try { $this->jobs->create(...static::payload($this->project, $resource, $deployment, $this->platform, $source)); @@ -187,11 +200,14 @@ readonly class Deployments /** * Deactivates any other active deployment for $resource before this one * goes live, called once the deployment is queued for building. + * + * @return array The ids it deactivated, so the caller can hand the + * claim back if this deployment never gets to build. */ - protected function deactivateOthers(Document $resource, Document $deployment): void + protected function deactivateOthers(Document $resource, Document $deployment): array { if (!$deployment->getAttribute('activate', false)) { - return; + return []; } $others = $this->dbForProject->find('deployments', [ @@ -201,11 +217,20 @@ readonly class Deployments Query::notEqual('$id', $deployment->getId()), ]); + $deactivated = []; foreach ($others as $other) { $this->dbForProject->updateDocument('deployments', $other->getId(), new Document([ 'activate' => false, ])); + $deactivated[] = $other->getId(); } + + return $deactivated; + } + + private function status(string $deploymentId): string + { + return $this->dbForProject->getDocument('deployments', $deploymentId)->getAttribute('status', ''); } /**