From 6797986574fd0a17749cbd339a73fd7eca41c121 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 2 Jun 2026 17:31:58 +0400 Subject: [PATCH 01/20] Update default site build specification --- app/config/collections/projects.php | 2 +- app/init/constants.php | 1 + .../Platform/Modules/Compute/Base.php | 15 ++++++++----- .../Compute/Validator/Specification.php | 9 +++++--- .../Modules/Sites/Http/Sites/Create.php | 5 +++-- .../Modules/Sites/Http/Sites/Update.php | 5 +++-- .../Services/Sites/SitesCustomServerTest.php | 1 + .../Compute/Validator/SpecificationTest.php | 22 +++++++++++++++++++ 8 files changed, 47 insertions(+), 13 deletions(-) diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index 9ac5c562e3..95f78bcb12 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -1306,7 +1306,7 @@ return [ 'size' => 128, 'signed' => false, 'required' => false, - 'default' => APP_COMPUTE_SPECIFICATION_DEFAULT, + 'default' => APP_SITES_BUILD_SPECIFICATION_DEFAULT, 'filters' => [], ], [ diff --git a/app/init/constants.php b/app/init/constants.php index d426e51fb6..545f3acafa 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -98,6 +98,7 @@ const APP_SOCIAL_YOUTUBE = 'https://www.youtube.com/c/appwrite?sub_confirmation= const APP_COMPUTE_CPUS_DEFAULT = 0.5; const APP_COMPUTE_MEMORY_DEFAULT = 512; const APP_COMPUTE_SPECIFICATION_DEFAULT = Specification::S_1VCPU_512MB; +const APP_SITES_BUILD_SPECIFICATION_DEFAULT = Specification::S_2VCPU_2GB; const APP_COMPUTE_DEPLOYMENT_MAX_RETENTION = 100 * 365; // 100 years const APP_SDK_PLATFORM_SERVER = 'server'; const APP_SDK_PLATFORM_CLIENT = 'client'; diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index b0efac3829..f7bc954bd7 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -33,29 +33,34 @@ class Base extends Action * @param array $plan The billing plan configuration * @return string The appropriate default specification */ - protected function getDefaultSpecification(array $plan): string + protected function getDefaultSpecification(array $plan, string $planKey = 'runtimeSpecifications', string $fallback = APP_COMPUTE_SPECIFICATION_DEFAULT, bool $preferFallback = false): string { $specifications = Config::getParam('specifications', []); if (empty($specifications)) { - return APP_COMPUTE_SPECIFICATION_DEFAULT; + return $fallback; } $specificationValidator = new SpecificationValidator( $plan, $specifications, System::getEnv('_APP_COMPUTE_CPUS', 0), - System::getEnv('_APP_COMPUTE_MEMORY', 0) + System::getEnv('_APP_COMPUTE_MEMORY', 0), + $planKey ); $allowedSpecifications = $specificationValidator->getAllowedSpecifications(); + if ($preferFallback && !array_key_exists($planKey, $plan) && \in_array($fallback, $allowedSpecifications)) { + return $fallback; + } + // If there is no plan use the highest specification if (empty($plan)) { - return end($allowedSpecifications) ?? APP_COMPUTE_SPECIFICATION_DEFAULT; + return end($allowedSpecifications) ?? $fallback; } // Otherwise, use the lowest specification available in the plan - return $allowedSpecifications[0] ?? APP_COMPUTE_SPECIFICATION_DEFAULT; + return $allowedSpecifications[0] ?? $fallback; } public function redeployVcsFunction(Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, BuildPublisher $publisherForBuilds, Document $template, GitHub $github, bool $activate, array $platform = [], string $referenceType = 'branch', string $reference = ''): Document diff --git a/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php b/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php index 5c6cf9ce1f..5f1337c97f 100644 --- a/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php +++ b/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php @@ -14,12 +14,15 @@ class Specification extends Validator private int $maxMemory; - public function __construct(array $plan, array $specifications, float $maxCpus, int $maxMemory) + private string $planKey; + + public function __construct(array $plan, array $specifications, float $maxCpus, int $maxMemory, string $planKey = 'runtimeSpecifications') { $this->plan = $plan; $this->specifications = $specifications; $this->maxCpus = $maxCpus; $this->maxMemory = $maxMemory; + $this->planKey = $planKey; } /** @@ -35,8 +38,8 @@ class Specification extends Validator foreach ($this->specifications as $size => $values) { if ((empty($this->maxCpus) || $values['cpus'] <= $this->maxCpus) && (empty($this->maxMemory) || $values['memory'] <= $this->maxMemory)) { - if (!empty($this->plan) && array_key_exists('runtimeSpecifications', $this->plan)) { - if (!\in_array($size, $this->plan['runtimeSpecifications'])) { + if (!empty($this->plan) && array_key_exists($this->planKey, $this->plan)) { + if (!\in_array($size, $this->plan[$this->planKey])) { continue; } } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php index e167c88af2..3662bb4d35 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php @@ -82,11 +82,12 @@ class Create extends Base ->param('providerRootDirectory', '', new Text(128, 0), 'Path to site code in the linked repo.', true) ->param('providerBranches', [], new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of branch name patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all branches.', true) ->param('providerPaths', [], new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of file path patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all file changes.', true) - ->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification( + ->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan, 'buildSpecifications', APP_SITES_BUILD_SPECIFICATION_DEFAULT, true), fn (array $plan) => new Specification( $plan, Config::getParam('specifications', []), System::getEnv('_APP_COMPUTE_CPUS', 0), - System::getEnv('_APP_COMPUTE_MEMORY', 0) + System::getEnv('_APP_COMPUTE_MEMORY', 0), + 'buildSpecifications' ), 'Build specification for the site deployments.', true, ['plan']) ->param('runtimeSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification( $plan, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 6cb1905550..0a2f5cdd71 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -86,11 +86,12 @@ class Update extends Base ->param('providerRootDirectory', '', new Text(128, 0), 'Path to site code in the linked repo.', true) ->param('providerBranches', null, new Nullable(new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'List of branch name patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all branches.', true) ->param('providerPaths', null, new Nullable(new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'List of file path patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all file changes.', true) - ->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification( + ->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan, 'buildSpecifications', APP_SITES_BUILD_SPECIFICATION_DEFAULT, true), fn (array $plan) => new Specification( $plan, Config::getParam('specifications', []), System::getEnv('_APP_COMPUTE_CPUS', 0), - System::getEnv('_APP_COMPUTE_MEMORY', 0) + System::getEnv('_APP_COMPUTE_MEMORY', 0), + 'buildSpecifications' ), 'Build specification for the site deployments.', true, ['plan']) ->param('runtimeSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification( $plan, diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 9cca689780..914390c354 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -100,6 +100,7 @@ class SitesCustomServerTest extends Scope $this->assertEquals(true, $dateValidator->isValid($site['body']['$createdAt'])); $this->assertEquals(true, $dateValidator->isValid($site['body']['$updatedAt'])); $this->assertEquals('node-22', $site['body']['buildRuntime']); + $this->assertEquals(Specification::S_2VCPU_2GB, $site['body']['buildSpecification']); $this->assertEquals(null, $site['body']['fallbackFile']); $this->assertEquals('./', $site['body']['outputDirectory']); diff --git a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php index 0505494e17..7977212885 100644 --- a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php +++ b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php @@ -72,4 +72,26 @@ class SpecificationTest extends TestCase $this->assertContains(SpecificationConstants::S_05VCPU_512MB, $allowed); $this->assertContains(SpecificationConstants::S_1VCPU_512MB, $allowed); } + + public function testGetAllowedSpecificationsWithBuildPlanLimits(): void + { + $plan = [ + 'buildSpecifications' => [ + SpecificationConstants::S_1VCPU_1GB, + SpecificationConstants::S_2VCPU_2GB, + ] + ]; + $validator = new Specification( + plan: $plan, + specifications: $this->specifications, + maxCpus: 0, + maxMemory: 0, + planKey: 'buildSpecifications' + ); + + $allowed = $validator->getAllowedSpecifications(); + $this->assertCount(2, $allowed); + $this->assertContains(SpecificationConstants::S_1VCPU_1GB, $allowed); + $this->assertContains(SpecificationConstants::S_2VCPU_2GB, $allowed); + } } From aae23cf5a1a74084ccb34849b8ff7a2605112bb3 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 22 Jun 2026 18:35:02 +0400 Subject: [PATCH 02/20] Fix site build specification defaults --- src/Appwrite/Platform/Modules/Compute/Base.php | 4 ++-- src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php | 5 +++++ tests/e2e/Services/Sites/SitesCustomServerTest.php | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index 5e1aba372c..8efa6d8843 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -56,11 +56,11 @@ class Base extends Action // If there is no plan use the highest specification if (empty($plan)) { - return end($allowedSpecifications) ?? $fallback; + return end($allowedSpecifications) ?: ''; } // Otherwise, use the lowest specification available in the plan - return $allowedSpecifications[0] ?? $fallback; + return $allowedSpecifications[0] ?? ''; } public function redeployVcsFunction(Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, BuildPublisher $publisherForBuilds, Document $template, GitHub $github, bool $activate, array $platform = [], string $referenceType = 'branch', string $reference = ''): Document diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 474024fc76..1f6d7cd215 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -178,6 +178,11 @@ class Update extends Base $framework = $site->getAttribute('framework'); } + $missingParam = new \stdClass(); + if ($request->getPayload('buildSpecification', $missingParam) === $missingParam) { + $buildSpecification = $site->getAttribute('buildSpecification', APP_COMPUTE_SPECIFICATION_DEFAULT); + } + $repositoryId = $site->getAttribute('repositoryId', ''); $repositoryInternalId = $site->getAttribute('repositoryInternalId', ''); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index c2d69f8cc6..1eee0ecbc8 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1680,6 +1680,7 @@ final class SitesCustomServerTest extends Scope $this->assertEquals(200, $site['headers']['status-code']); $this->assertNotEmpty($site['body']['$id']); + $this->assertEquals(Specification::S_2VCPU_2GB, $site['body']['buildSpecification']); $this->assertEquals(Specification::S_1VCPU_1GB, $site['body']['runtimeSpecification']); // Change the specs to 1vcpu 512mb @@ -1697,6 +1698,7 @@ final class SitesCustomServerTest extends Scope $this->assertEquals(200, $site['headers']['status-code']); $this->assertNotEmpty($site['body']['$id']); + $this->assertEquals(Specification::S_2VCPU_2GB, $site['body']['buildSpecification']); $this->assertEquals(Specification::S_1VCPU_512MB, $site['body']['runtimeSpecification']); /** From 419cd2e35638d1d2561343939d613d106a277cf6 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 22 Jun 2026 19:10:28 +0400 Subject: [PATCH 03/20] Expose build enabled specifications --- .../Modules/Functions/Http/Specifications/XList.php | 4 ++++ .../Platform/Modules/Sites/Http/Specifications/XList.php | 4 ++++ src/Appwrite/Utopia/Response/Model/Specification.php | 8 +++++++- .../e2e/Services/Functions/FunctionsCustomServerTest.php | 2 ++ tests/e2e/Services/Sites/SitesCustomServerTest.php | 2 ++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php index d76584534d..498a274280 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php @@ -58,10 +58,14 @@ class XList extends Base $specs = []; foreach ($allSpecs as $spec) { $spec['enabled'] = true; + $spec['buildEnabled'] = true; if (array_key_exists('runtimeSpecifications', $plan)) { $spec['enabled'] = in_array($spec['slug'], $plan['runtimeSpecifications']); } + if (array_key_exists('buildSpecifications', $plan)) { + $spec['buildEnabled'] = in_array($spec['slug'], $plan['buildSpecifications']); + } $maxCpus = System::getEnv('_APP_COMPUTE_CPUS', 0); $maxMemory = System::getEnv('_APP_COMPUTE_MEMORY', 0); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php index 4bda37df73..d5b6515de7 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php @@ -58,10 +58,14 @@ class XList extends Base $specs = []; foreach ($allSpecs as $spec) { $spec['enabled'] = true; + $spec['buildEnabled'] = true; if (array_key_exists('runtimeSpecifications', $plan)) { $spec['enabled'] = in_array($spec['slug'], $plan['runtimeSpecifications']); } + if (array_key_exists('buildSpecifications', $plan)) { + $spec['buildEnabled'] = in_array($spec['slug'], $plan['buildSpecifications']); + } $maxCpus = System::getEnv('_APP_COMPUTE_CPUS', 0); $maxMemory = System::getEnv('_APP_COMPUTE_MEMORY', 0); diff --git a/src/Appwrite/Utopia/Response/Model/Specification.php b/src/Appwrite/Utopia/Response/Model/Specification.php index 4fa7fb9bc7..034d399a75 100644 --- a/src/Appwrite/Utopia/Response/Model/Specification.php +++ b/src/Appwrite/Utopia/Response/Model/Specification.php @@ -24,7 +24,13 @@ class Specification extends Model ]); $this->addRule('enabled', [ 'type' => self::TYPE_BOOLEAN, - 'description' => 'Is size enabled.', + 'description' => 'Is size enabled for runtime.', + 'default' => false, + 'example' => true + ]); + $this->addRule('buildEnabled', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Is size enabled for builds.', 'default' => false, 'example' => true ]); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 1aba466944..86aa67df32 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -208,10 +208,12 @@ final class FunctionsCustomServerTest extends Scope $this->assertArrayHasKey('memory', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][0]); + $this->assertArrayHasKey('buildEnabled', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('memory', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][1]); + $this->assertArrayHasKey('buildEnabled', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][1]); $function = $this->createFunction([ diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 1eee0ecbc8..8a326d1023 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -34,10 +34,12 @@ final class SitesCustomServerTest extends Scope $this->assertArrayHasKey('memory', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][0]); + $this->assertArrayHasKey('buildEnabled', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('memory', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][1]); + $this->assertArrayHasKey('buildEnabled', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][1]); $site = $this->createSite([ From 7f536750b4ea92799515cd3ae368a1baed06eba6 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 22 Jun 2026 19:18:53 +0400 Subject: [PATCH 04/20] Rename build specification availability field --- .../Platform/Modules/Functions/Http/Specifications/XList.php | 4 ++-- .../Platform/Modules/Sites/Http/Specifications/XList.php | 4 ++-- src/Appwrite/Utopia/Response/Model/Specification.php | 2 +- tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 4 ++-- tests/e2e/Services/Sites/SitesCustomServerTest.php | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php index 498a274280..53d52cccb5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php @@ -58,13 +58,13 @@ class XList extends Base $specs = []; foreach ($allSpecs as $spec) { $spec['enabled'] = true; - $spec['buildEnabled'] = true; + $spec['enabledForBuilds'] = true; if (array_key_exists('runtimeSpecifications', $plan)) { $spec['enabled'] = in_array($spec['slug'], $plan['runtimeSpecifications']); } if (array_key_exists('buildSpecifications', $plan)) { - $spec['buildEnabled'] = in_array($spec['slug'], $plan['buildSpecifications']); + $spec['enabledForBuilds'] = in_array($spec['slug'], $plan['buildSpecifications']); } $maxCpus = System::getEnv('_APP_COMPUTE_CPUS', 0); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php index d5b6515de7..86904e8f67 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php @@ -58,13 +58,13 @@ class XList extends Base $specs = []; foreach ($allSpecs as $spec) { $spec['enabled'] = true; - $spec['buildEnabled'] = true; + $spec['enabledForBuilds'] = true; if (array_key_exists('runtimeSpecifications', $plan)) { $spec['enabled'] = in_array($spec['slug'], $plan['runtimeSpecifications']); } if (array_key_exists('buildSpecifications', $plan)) { - $spec['buildEnabled'] = in_array($spec['slug'], $plan['buildSpecifications']); + $spec['enabledForBuilds'] = in_array($spec['slug'], $plan['buildSpecifications']); } $maxCpus = System::getEnv('_APP_COMPUTE_CPUS', 0); diff --git a/src/Appwrite/Utopia/Response/Model/Specification.php b/src/Appwrite/Utopia/Response/Model/Specification.php index 034d399a75..74188a533a 100644 --- a/src/Appwrite/Utopia/Response/Model/Specification.php +++ b/src/Appwrite/Utopia/Response/Model/Specification.php @@ -28,7 +28,7 @@ class Specification extends Model 'default' => false, 'example' => true ]); - $this->addRule('buildEnabled', [ + $this->addRule('enabledForBuilds', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Is size enabled for builds.', 'default' => false, diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 86aa67df32..aba9ec2104 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -208,12 +208,12 @@ final class FunctionsCustomServerTest extends Scope $this->assertArrayHasKey('memory', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][0]); - $this->assertArrayHasKey('buildEnabled', $specifications['body']['specifications'][0]); + $this->assertArrayHasKey('enabledForBuilds', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('memory', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][1]); - $this->assertArrayHasKey('buildEnabled', $specifications['body']['specifications'][1]); + $this->assertArrayHasKey('enabledForBuilds', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][1]); $function = $this->createFunction([ diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 8a326d1023..c5e27cd324 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -34,12 +34,12 @@ final class SitesCustomServerTest extends Scope $this->assertArrayHasKey('memory', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][0]); - $this->assertArrayHasKey('buildEnabled', $specifications['body']['specifications'][0]); + $this->assertArrayHasKey('enabledForBuilds', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('memory', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][1]); - $this->assertArrayHasKey('buildEnabled', $specifications['body']['specifications'][1]); + $this->assertArrayHasKey('enabledForBuilds', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][1]); $site = $this->createSite([ From 23be75a87fd4679d83a0a35d5dd7bff5ac597f93 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 22 Jun 2026 19:51:26 +0400 Subject: [PATCH 05/20] Add specification type parameter --- .../Modules/Functions/Http/Specifications/XList.php | 13 ++++++------- .../Modules/Sites/Http/Specifications/XList.php | 13 ++++++------- .../Utopia/Response/Model/Specification.php | 8 +------- tests/e2e/Services/Functions/FunctionsBase.php | 4 ++-- .../Functions/FunctionsCustomServerTest.php | 12 +++++++----- tests/e2e/Services/Sites/SitesBase.php | 4 ++-- tests/e2e/Services/Sites/SitesCustomServerTest.php | 12 +++++++----- 7 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php index 53d52cccb5..8cbff906fa 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php @@ -12,6 +12,7 @@ use Utopia\Database\Document; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\System\System; +use Utopia\Validator\WhiteList; class XList extends Base { @@ -46,25 +47,23 @@ class XList extends Base ) ] )) + ->param('type', 'runtimes', new WhiteList(['runtimes', 'builds']), 'Specification type to list. Can be one of: runtimes, builds.', true) ->inject('response') ->inject('plan') ->callback($this->action(...)); } - public function action(Response $response, array $plan) + public function action(string $type, Response $response, array $plan) { $allSpecs = Config::getParam('specifications', []); + $planKey = $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'; $specs = []; foreach ($allSpecs as $spec) { $spec['enabled'] = true; - $spec['enabledForBuilds'] = true; - if (array_key_exists('runtimeSpecifications', $plan)) { - $spec['enabled'] = in_array($spec['slug'], $plan['runtimeSpecifications']); - } - if (array_key_exists('buildSpecifications', $plan)) { - $spec['enabledForBuilds'] = in_array($spec['slug'], $plan['buildSpecifications']); + if (array_key_exists($planKey, $plan)) { + $spec['enabled'] = in_array($spec['slug'], $plan[$planKey]); } $maxCpus = System::getEnv('_APP_COMPUTE_CPUS', 0); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php index 86904e8f67..a4f865d859 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php @@ -12,6 +12,7 @@ use Utopia\Database\Document; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\System\System; +use Utopia\Validator\WhiteList; class XList extends Base { @@ -46,25 +47,23 @@ class XList extends Base ) ] )) + ->param('type', 'runtimes', new WhiteList(['runtimes', 'builds']), 'Specification type to list. Can be one of: runtimes, builds.', true) ->inject('response') ->inject('plan') ->callback($this->action(...)); } - public function action(Response $response, array $plan) + public function action(string $type, Response $response, array $plan) { $allSpecs = Config::getParam('specifications', []); + $planKey = $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'; $specs = []; foreach ($allSpecs as $spec) { $spec['enabled'] = true; - $spec['enabledForBuilds'] = true; - if (array_key_exists('runtimeSpecifications', $plan)) { - $spec['enabled'] = in_array($spec['slug'], $plan['runtimeSpecifications']); - } - if (array_key_exists('buildSpecifications', $plan)) { - $spec['enabledForBuilds'] = in_array($spec['slug'], $plan['buildSpecifications']); + if (array_key_exists($planKey, $plan)) { + $spec['enabled'] = in_array($spec['slug'], $plan[$planKey]); } $maxCpus = System::getEnv('_APP_COMPUTE_CPUS', 0); diff --git a/src/Appwrite/Utopia/Response/Model/Specification.php b/src/Appwrite/Utopia/Response/Model/Specification.php index 74188a533a..4fa7fb9bc7 100644 --- a/src/Appwrite/Utopia/Response/Model/Specification.php +++ b/src/Appwrite/Utopia/Response/Model/Specification.php @@ -24,13 +24,7 @@ class Specification extends Model ]); $this->addRule('enabled', [ 'type' => self::TYPE_BOOLEAN, - 'description' => 'Is size enabled for runtime.', - 'default' => false, - 'example' => true - ]); - $this->addRule('enabledForBuilds', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Is size enabled for builds.', + 'description' => 'Is size enabled.', 'default' => false, 'example' => true ]); diff --git a/tests/e2e/Services/Functions/FunctionsBase.php b/tests/e2e/Services/Functions/FunctionsBase.php index 458359bbe9..05f2e52c1a 100644 --- a/tests/e2e/Services/Functions/FunctionsBase.php +++ b/tests/e2e/Services/Functions/FunctionsBase.php @@ -494,11 +494,11 @@ trait FunctionsBase return $deployment; } - protected function listSpecifications(): mixed + protected function listSpecifications(array $params = []): mixed { $specifications = $this->client->call(Client::METHOD_GET, '/functions/specifications', array_merge([ 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); + ], $this->getHeaders()), $params); return $specifications; } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index aba9ec2104..80578d443b 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -208,28 +208,30 @@ final class FunctionsCustomServerTest extends Scope $this->assertArrayHasKey('memory', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][0]); - $this->assertArrayHasKey('enabledForBuilds', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('memory', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][1]); - $this->assertArrayHasKey('enabledForBuilds', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][1]); + $buildSpecifications = $this->listSpecifications(['type' => 'builds']); + $this->assertEquals(200, $buildSpecifications['headers']['status-code']); + $this->assertEquals($specifications['body']['total'], $buildSpecifications['body']['total']); + $function = $this->createFunction([ 'functionId' => ID::unique(), 'name' => 'Specs function', 'runtime' => 'node-22', - 'buildSpecification' => $specifications['body']['specifications'][0]['slug'], + 'buildSpecification' => $buildSpecifications['body']['specifications'][0]['slug'], 'runtimeSpecification' => $specifications['body']['specifications'][1]['slug'], ]); $this->assertEquals(201, $function['headers']['status-code']); - $this->assertEquals($specifications['body']['specifications'][0]['slug'], $function['body']['buildSpecification']); + $this->assertEquals($buildSpecifications['body']['specifications'][0]['slug'], $function['body']['buildSpecification']); $this->assertEquals($specifications['body']['specifications'][1]['slug'], $function['body']['runtimeSpecification']); $function = $this->getFunction($function['body']['$id']); $this->assertEquals(200, $function['headers']['status-code']); - $this->assertEquals($specifications['body']['specifications'][0]['slug'], $function['body']['buildSpecification']); + $this->assertEquals($buildSpecifications['body']['specifications'][0]['slug'], $function['body']['buildSpecification']); $this->assertEquals($specifications['body']['specifications'][1]['slug'], $function['body']['runtimeSpecification']); $this->cleanupFunction($function['body']['$id']); diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 54344f649a..f6a29f82ab 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -489,11 +489,11 @@ trait SitesBase return $deployment; } - protected function listSpecifications(): mixed + protected function listSpecifications(array $params = []): mixed { $specifications = $this->client->call(Client::METHOD_GET, '/sites/specifications', array_merge([ 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); + ], $this->getHeaders()), $params); return $specifications; } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index c5e27cd324..102f828441 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -34,29 +34,31 @@ final class SitesCustomServerTest extends Scope $this->assertArrayHasKey('memory', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][0]); - $this->assertArrayHasKey('enabledForBuilds', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][0]); $this->assertArrayHasKey('memory', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('cpus', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('enabled', $specifications['body']['specifications'][1]); - $this->assertArrayHasKey('enabledForBuilds', $specifications['body']['specifications'][1]); $this->assertArrayHasKey('slug', $specifications['body']['specifications'][1]); + $buildSpecifications = $this->listSpecifications(['type' => 'builds']); + $this->assertEquals(200, $buildSpecifications['headers']['status-code']); + $this->assertEquals($specifications['body']['total'], $buildSpecifications['body']['total']); + $site = $this->createSite([ 'buildRuntime' => 'node-22', 'framework' => 'other', 'name' => 'Specs site', 'siteId' => ID::unique(), - 'buildSpecification' => $specifications['body']['specifications'][0]['slug'], + 'buildSpecification' => $buildSpecifications['body']['specifications'][0]['slug'], 'runtimeSpecification' => $specifications['body']['specifications'][1]['slug'], ]); $this->assertEquals(201, $site['headers']['status-code']); - $this->assertEquals($specifications['body']['specifications'][0]['slug'], $site['body']['buildSpecification']); + $this->assertEquals($buildSpecifications['body']['specifications'][0]['slug'], $site['body']['buildSpecification']); $this->assertEquals($specifications['body']['specifications'][1]['slug'], $site['body']['runtimeSpecification']); $site = $this->getSite($site['body']['$id']); $this->assertEquals(200, $site['headers']['status-code']); - $this->assertEquals($specifications['body']['specifications'][0]['slug'], $site['body']['buildSpecification']); + $this->assertEquals($buildSpecifications['body']['specifications'][0]['slug'], $site['body']['buildSpecification']); $this->assertEquals($specifications['body']['specifications'][1]['slug'], $site['body']['runtimeSpecification']); $this->cleanupSite($site['body']['$id']); From bd9855587628b4c53bf5efec57b4086227e00547 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 22 Jun 2026 22:06:56 +0400 Subject: [PATCH 06/20] Make specification tests explicit --- src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php | 5 ----- tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 2 +- tests/e2e/Services/Sites/SitesCustomServerTest.php | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 1f6d7cd215..474024fc76 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -178,11 +178,6 @@ class Update extends Base $framework = $site->getAttribute('framework'); } - $missingParam = new \stdClass(); - if ($request->getPayload('buildSpecification', $missingParam) === $missingParam) { - $buildSpecification = $site->getAttribute('buildSpecification', APP_COMPUTE_SPECIFICATION_DEFAULT); - } - $repositoryId = $site->getAttribute('repositoryId', ''); $repositoryInternalId = $site->getAttribute('repositoryInternalId', ''); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 80578d443b..87635d55c3 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -200,7 +200,7 @@ final class FunctionsCustomServerTest extends Scope public function testListSpecs(): void { - $specifications = $this->listSpecifications(); + $specifications = $this->listSpecifications(['type' => 'runtimes']); $this->assertEquals(200, $specifications['headers']['status-code']); $this->assertGreaterThanOrEqual(2, $specifications['body']['total']); $this->assertArrayHasKey(0, $specifications['body']['specifications']); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 102f828441..5b09b4b45c 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -26,7 +26,7 @@ final class SitesCustomServerTest extends Scope public function testListSpecs(): void { - $specifications = $this->listSpecifications(); + $specifications = $this->listSpecifications(['type' => 'runtimes']); $this->assertEquals(200, $specifications['headers']['status-code']); $this->assertGreaterThanOrEqual(2, $specifications['body']['total']); $this->assertArrayHasKey(0, $specifications['body']['specifications']); From a7fc66ef3e47dc1214973acfa6e2963dab39b647 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 22 Jun 2026 22:34:04 +0400 Subject: [PATCH 07/20] Use listed build specs in tests --- .../Functions/FunctionsCustomServerTest.php | 7 ++--- .../Services/Sites/SitesCustomServerTest.php | 27 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 87635d55c3..0e98be1d25 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -217,21 +217,22 @@ final class FunctionsCustomServerTest extends Scope $buildSpecifications = $this->listSpecifications(['type' => 'builds']); $this->assertEquals(200, $buildSpecifications['headers']['status-code']); $this->assertEquals($specifications['body']['total'], $buildSpecifications['body']['total']); + $buildSpecification = $buildSpecifications['body']['specifications'][0]['slug']; $function = $this->createFunction([ 'functionId' => ID::unique(), 'name' => 'Specs function', 'runtime' => 'node-22', - 'buildSpecification' => $buildSpecifications['body']['specifications'][0]['slug'], + 'buildSpecification' => $buildSpecification, 'runtimeSpecification' => $specifications['body']['specifications'][1]['slug'], ]); $this->assertEquals(201, $function['headers']['status-code']); - $this->assertEquals($buildSpecifications['body']['specifications'][0]['slug'], $function['body']['buildSpecification']); + $this->assertEquals($buildSpecification, $function['body']['buildSpecification']); $this->assertEquals($specifications['body']['specifications'][1]['slug'], $function['body']['runtimeSpecification']); $function = $this->getFunction($function['body']['$id']); $this->assertEquals(200, $function['headers']['status-code']); - $this->assertEquals($buildSpecifications['body']['specifications'][0]['slug'], $function['body']['buildSpecification']); + $this->assertEquals($buildSpecification, $function['body']['buildSpecification']); $this->assertEquals($specifications['body']['specifications'][1]['slug'], $function['body']['runtimeSpecification']); $this->cleanupFunction($function['body']['$id']); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 5b09b4b45c..a2bf0771ca 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -43,22 +43,23 @@ final class SitesCustomServerTest extends Scope $buildSpecifications = $this->listSpecifications(['type' => 'builds']); $this->assertEquals(200, $buildSpecifications['headers']['status-code']); $this->assertEquals($specifications['body']['total'], $buildSpecifications['body']['total']); + $buildSpecification = $buildSpecifications['body']['specifications'][0]['slug']; $site = $this->createSite([ 'buildRuntime' => 'node-22', 'framework' => 'other', 'name' => 'Specs site', 'siteId' => ID::unique(), - 'buildSpecification' => $buildSpecifications['body']['specifications'][0]['slug'], + 'buildSpecification' => $buildSpecification, 'runtimeSpecification' => $specifications['body']['specifications'][1]['slug'], ]); $this->assertEquals(201, $site['headers']['status-code']); - $this->assertEquals($buildSpecifications['body']['specifications'][0]['slug'], $site['body']['buildSpecification']); + $this->assertEquals($buildSpecification, $site['body']['buildSpecification']); $this->assertEquals($specifications['body']['specifications'][1]['slug'], $site['body']['runtimeSpecification']); $site = $this->getSite($site['body']['$id']); $this->assertEquals(200, $site['headers']['status-code']); - $this->assertEquals($buildSpecifications['body']['specifications'][0]['slug'], $site['body']['buildSpecification']); + $this->assertEquals($buildSpecification, $site['body']['buildSpecification']); $this->assertEquals($specifications['body']['specifications'][1]['slug'], $site['body']['runtimeSpecification']); $this->cleanupSite($site['body']['$id']); @@ -84,11 +85,15 @@ final class SitesCustomServerTest extends Scope public function testCreateSite(): void { + $buildSpecifications = $this->listSpecifications(['type' => 'builds']); + $buildSpecification = $buildSpecifications['body']['specifications'][0]['slug']; + /** * Test for SUCCESS */ $site = $this->createSite([ 'buildRuntime' => 'node-22', + 'buildSpecification' => $buildSpecification, 'fallbackFile' => '', 'framework' => 'other', 'name' => 'Test Site', @@ -106,7 +111,7 @@ final class SitesCustomServerTest extends Scope $this->assertEquals(true, $dateValidator->isValid($site['body']['$createdAt'])); $this->assertEquals(true, $dateValidator->isValid($site['body']['$updatedAt'])); $this->assertEquals('node-22', $site['body']['buildRuntime']); - $this->assertEquals(Specification::S_2VCPU_2GB, $site['body']['buildSpecification']); + $this->assertEquals($buildSpecification, $site['body']['buildSpecification']); $this->assertEquals(null, $site['body']['fallbackFile']); $this->assertEquals('./', $site['body']['outputDirectory']); @@ -721,11 +726,14 @@ final class SitesCustomServerTest extends Scope public function testListSites(): void { + $buildSpecifications = $this->listSpecifications(['type' => 'builds']); + /** * Test for SUCCESS */ $siteId = $this->setupSite([ 'buildRuntime' => 'node-22', + 'buildSpecification' => $buildSpecifications['body']['specifications'][0]['slug'], 'fallbackFile' => '', 'framework' => 'analog', 'name' => 'Test List Sites', @@ -867,8 +875,11 @@ final class SitesCustomServerTest extends Scope public function testGetSite(): void { + $buildSpecifications = $this->listSpecifications(['type' => 'builds']); + $siteId = $this->setupSite([ 'buildRuntime' => 'node-22', + 'buildSpecification' => $buildSpecifications['body']['specifications'][0]['slug'], 'fallbackFile' => '', 'framework' => 'other', 'name' => 'Test Site', @@ -1655,8 +1666,12 @@ final class SitesCustomServerTest extends Scope public function testUpdateSpecs(): void { + $buildSpecifications = $this->listSpecifications(['type' => 'builds']); + $buildSpecification = $buildSpecifications['body']['specifications'][0]['slug']; + $siteId = $this->setupSite([ 'buildRuntime' => 'node-22', + 'buildSpecification' => $buildSpecification, 'fallbackFile' => '', 'framework' => 'other', 'name' => 'Test Site', @@ -1684,7 +1699,7 @@ final class SitesCustomServerTest extends Scope $this->assertEquals(200, $site['headers']['status-code']); $this->assertNotEmpty($site['body']['$id']); - $this->assertEquals(Specification::S_2VCPU_2GB, $site['body']['buildSpecification']); + $this->assertEquals($buildSpecification, $site['body']['buildSpecification']); $this->assertEquals(Specification::S_1VCPU_1GB, $site['body']['runtimeSpecification']); // Change the specs to 1vcpu 512mb @@ -1702,7 +1717,7 @@ final class SitesCustomServerTest extends Scope $this->assertEquals(200, $site['headers']['status-code']); $this->assertNotEmpty($site['body']['$id']); - $this->assertEquals(Specification::S_2VCPU_2GB, $site['body']['buildSpecification']); + $this->assertEquals($buildSpecification, $site['body']['buildSpecification']); $this->assertEquals(Specification::S_1VCPU_512MB, $site['body']['runtimeSpecification']); /** From ea574f9909380b049a7bfe2b48330cc150197e99 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 22 Jun 2026 22:44:22 +0400 Subject: [PATCH 08/20] Pass build spec explicitly in site update test --- tests/e2e/Services/Sites/SitesCustomServerTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index a2bf0771ca..436afea1bd 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1687,6 +1687,7 @@ final class SitesCustomServerTest extends Scope // Change the function specs $site = $this->updateSite([ 'buildRuntime' => 'node-22', + 'buildSpecification' => $buildSpecification, 'fallbackFile' => '', 'framework' => 'other', 'name' => 'Test Site', @@ -1705,6 +1706,7 @@ final class SitesCustomServerTest extends Scope // Change the specs to 1vcpu 512mb $site = $this->updateSite([ 'buildRuntime' => 'node-22', + 'buildSpecification' => $buildSpecification, 'fallbackFile' => '', 'framework' => 'other', 'name' => 'Test Site', From 7b88334981eae3eb9911282d504966db89852d78 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 18 Jun 2026 04:18:02 +0000 Subject: [PATCH 09/20] fix(storage): return 404 instead of 500 on concurrent file deletion When two requests delete the same file concurrently, both pass the existence check and remove the device file. The first request's deleteDocument() succeeds; the second sees the document already gone (Database::deleteDocument() returns false when the document is empty) and threw GENERAL_SERVER_ERROR ("Failed to remove file from DB"), surfacing a 500 for a file that no longer exists. When deleteDocument() returns false, re-check the document. If it is gone, throw STORAGE_FILE_NOT_FOUND (404), consistent with the not-found check at the start of the request. Only throw the server error when the document genuinely still exists (real DB failure). --- .../Platform/Modules/Storage/Http/Buckets/Files/Delete.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php index c16b374c78..51a175b4c0 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Delete.php @@ -145,7 +145,11 @@ class Delete extends Action } if (!$deleted) { - throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove file from DB'); + $exists = $authorization->skip(fn () => $dbForProject->getDocument('bucket_' . $bucket->getSequence(), $fileId)); + if (!$exists->isEmpty()) { + throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove file from DB'); + } + throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); } } else { throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to delete file from device'); From 76e2baf3aa1f23780f3bbc260fb04bf249a7d686 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 23 Jun 2026 14:36:11 +0530 Subject: [PATCH 10/20] fix: purge project cache after config updates (#12654) --- .../Modules/Project/Http/Project/AuthMethods/Update.php | 1 + .../Platform/Modules/Project/Http/Project/OAuth2/Base.php | 5 ++++- .../Http/Project/Policies/MembershipPrivacy/Update.php | 1 + .../Http/Project/Policies/PasswordDictionary/Update.php | 1 + .../Project/Http/Project/Policies/PasswordHistory/Update.php | 1 + .../Http/Project/Policies/PasswordPersonalData/Update.php | 1 + .../Http/Project/Policies/PasswordStrength/Update.php | 1 + .../Project/Http/Project/Policies/SessionAlert/Update.php | 1 + .../Project/Http/Project/Policies/SessionDuration/Update.php | 1 + .../Http/Project/Policies/SessionInvalidation/Update.php | 1 + .../Project/Http/Project/Policies/SessionLimit/Update.php | 1 + .../Project/Http/Project/Policies/UserLimit/Update.php | 1 + .../Modules/Project/Http/Project/Protocols/Update.php | 1 + .../Platform/Modules/Project/Http/Project/SMTP/Update.php | 1 + .../Modules/Project/Http/Project/Services/Update.php | 1 + 15 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php index e98d3141f6..f5f0ae0a32 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/AuthMethods/Update.php @@ -82,6 +82,7 @@ class Update extends Action $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ 'auths' => $auths, ]))); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents->setParam('methodId', $methodId); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php index b5b8cacb73..b439e7fdf7 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/OAuth2/Base.php @@ -425,7 +425,10 @@ abstract class Base extends Action 'oAuthProviders' => $oAuthProviders ]); - return $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); + + return $project; } public function action( diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php index 5d7043fedf..b167aba794 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php @@ -103,6 +103,7 @@ class Update extends Action ]); $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents ->setParam('projectId', $project->getId()) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php index d7ee99fbfe..d0f8882e99 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordDictionary/Update.php @@ -75,6 +75,7 @@ class Update extends Action ]); $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents ->setParam('projectId', $project->getId()) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php index 84861a19e1..be611e299f 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php @@ -83,6 +83,7 @@ class Update extends Action ]); $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents ->setParam('projectId', $project->getId()) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php index 435f00fc39..ff7819f192 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPersonalData/Update.php @@ -76,6 +76,7 @@ class Update extends Action ]); $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents ->setParam('projectId', $project->getId()) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php index 3fbcbe8b30..0f8c566511 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php @@ -103,6 +103,7 @@ class Update extends Action $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ 'auths' => $auths, ]))); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents ->setParam('projectId', $project->getId()) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php index 79653d46ad..d930fd89e7 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionAlert/Update.php @@ -75,6 +75,7 @@ class Update extends Action ]); $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents ->setParam('projectId', $project->getId()) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php index 0a7f33218a..10eabb57cd 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php @@ -75,6 +75,7 @@ class Update extends Action ]); $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents ->setParam('projectId', $project->getId()) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php index a1feb67346..d4d87edbba 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionInvalidation/Update.php @@ -75,6 +75,7 @@ class Update extends Action ]); $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents ->setParam('projectId', $project->getId()) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php index 936a541249..93ae339b79 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php @@ -81,6 +81,7 @@ class Update extends Action ]); $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents ->setParam('projectId', $project->getId()) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php index 2b7e704853..b3f430b779 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php @@ -81,6 +81,7 @@ class Update extends Action ]); $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents ->setParam('projectId', $project->getId()) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php index bfc73802c8..e0e4477a3c 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Protocols/Update.php @@ -79,6 +79,7 @@ class Update extends Action $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ 'apis' => $protocols, ]))); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents->setParam('protocolId', $protocolId); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php index bf513f5dac..dd8a469d26 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php @@ -170,6 +170,7 @@ class Update extends Action ]); $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $response->dynamic($project, Response::MODEL_PROJECT); } diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php index 518eeb4c36..86ef67bb01 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Services/Update.php @@ -79,6 +79,7 @@ class Update extends Action $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ 'services' => $services, ]))); + $authorization->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); $queueForEvents->setParam('serviceId', $serviceId); From dc50f940bf1436860d96d3ea5f5e262fe1c3fe02 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 23 Jun 2026 14:47:06 +0400 Subject: [PATCH 11/20] Fix compute build specification defaults --- src/Appwrite/Platform/Modules/Compute/Base.php | 8 ++++++-- .../Modules/Functions/Http/Functions/Create.php | 5 +++-- .../Modules/Functions/Http/Functions/Update.php | 11 +++++++---- .../Modules/Sites/Http/Sites/Update.php | 8 +++++--- .../Services/Sites/SitesCustomServerTest.php | 17 +++++++++++++++++ 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index 8efa6d8843..b3740787b3 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -50,17 +50,21 @@ class Base extends Action ); $allowedSpecifications = $specificationValidator->getAllowedSpecifications(); + if (empty($allowedSpecifications)) { + return $fallback; + } + if ($preferFallback && !array_key_exists($planKey, $plan) && \in_array($fallback, $allowedSpecifications)) { return $fallback; } // If there is no plan use the highest specification if (empty($plan)) { - return end($allowedSpecifications) ?: ''; + return end($allowedSpecifications); } // Otherwise, use the lowest specification available in the plan - return $allowedSpecifications[0] ?? ''; + return $allowedSpecifications[0]; } public function redeployVcsFunction(Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, BuildPublisher $publisherForBuilds, Document $template, GitHub $github, bool $activate, array $platform = [], string $referenceType = 'branch', string $reference = ''): Document diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php index 2692eaf630..48818dd3ec 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php @@ -98,11 +98,12 @@ class Create extends Base ->param('providerRootDirectory', '', new Text(128, 0), 'Path to function code in the linked repo.', true) ->param('providerBranches', [], new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of branch name patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all branches.', true) ->param('providerPaths', [], new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of file path patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all file changes.', true) - ->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification( + ->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan, 'buildSpecifications'), fn (array $plan) => new Specification( $plan, Config::getParam('specifications', []), System::getEnv('_APP_COMPUTE_CPUS', 0), - System::getEnv('_APP_COMPUTE_MEMORY', 0) + System::getEnv('_APP_COMPUTE_MEMORY', 0), + 'buildSpecifications' ), 'Build specification for the function deployments.', true, ['plan']) ->param('runtimeSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification( $plan, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index e9e14a6e22..f23f4bd678 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -90,12 +90,13 @@ class Update extends Base ->param('providerRootDirectory', '', new Text(128, 0), 'Path to function code in the linked repo.', true) ->param('providerBranches', null, new Nullable(new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'List of branch name patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all branches.', true) ->param('providerPaths', null, new Nullable(new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'List of file path patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all file changes.', true) - ->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification( + ->param('buildSpecification', null, fn (array $plan) => new Nullable(new Specification( $plan, Config::getParam('specifications', []), System::getEnv('_APP_COMPUTE_CPUS', 0), - System::getEnv('_APP_COMPUTE_MEMORY', 0) - ), 'Build specification for the function deployments.', true, ['plan']) + System::getEnv('_APP_COMPUTE_MEMORY', 0), + 'buildSpecifications' + )), 'Build specification for the function deployments.', true, ['plan']) ->param('runtimeSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification( $plan, Config::getParam('specifications', []), @@ -137,7 +138,7 @@ class Update extends Base string $providerRootDirectory, ?array $providerBranches, ?array $providerPaths, - string $buildSpecification, + ?string $buildSpecification, string $runtimeSpecification, int $deploymentRetention, Request $request, @@ -173,6 +174,8 @@ class Update extends Base $runtime = $function->getAttribute('runtime'); } + $buildSpecification ??= $function->getAttribute('buildSpecification', APP_COMPUTE_SPECIFICATION_DEFAULT); + $repositoryId = $function->getAttribute('repositoryId', ''); $repositoryInternalId = $function->getAttribute('repositoryInternalId', ''); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 474024fc76..18b38d45af 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -86,13 +86,13 @@ class Update extends Base ->param('providerRootDirectory', '', new Text(128, 0), 'Path to site code in the linked repo.', true) ->param('providerBranches', null, new Nullable(new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'List of branch name patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all branches.', true) ->param('providerPaths', null, new Nullable(new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'List of file path patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all file changes.', true) - ->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan, 'buildSpecifications', APP_SITES_BUILD_SPECIFICATION_DEFAULT, true), fn (array $plan) => new Specification( + ->param('buildSpecification', null, fn (array $plan) => new Nullable(new Specification( $plan, Config::getParam('specifications', []), System::getEnv('_APP_COMPUTE_CPUS', 0), System::getEnv('_APP_COMPUTE_MEMORY', 0), 'buildSpecifications' - ), 'Build specification for the site deployments.', true, ['plan']) + )), 'Build specification for the site deployments.', true, ['plan']) ->param('runtimeSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification( $plan, Config::getParam('specifications', []), @@ -134,7 +134,7 @@ class Update extends Base string $providerRootDirectory, ?array $providerBranches, ?array $providerPaths, - string $buildSpecification, + ?string $buildSpecification, string $runtimeSpecification, int $deploymentRetention, Request $request, @@ -178,6 +178,8 @@ class Update extends Base $framework = $site->getAttribute('framework'); } + $buildSpecification ??= $site->getAttribute('buildSpecification', APP_SITES_BUILD_SPECIFICATION_DEFAULT); + $repositoryId = $site->getAttribute('repositoryId', ''); $repositoryInternalId = $site->getAttribute('repositoryInternalId', ''); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 436afea1bd..7a5f578492 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1703,6 +1703,23 @@ final class SitesCustomServerTest extends Scope $this->assertEquals($buildSpecification, $site['body']['buildSpecification']); $this->assertEquals(Specification::S_1VCPU_1GB, $site['body']['runtimeSpecification']); + $site = $this->updateSite([ + 'buildRuntime' => 'node-22', + 'fallbackFile' => '', + 'framework' => 'other', + 'name' => 'Test Site', + 'outputDirectory' => './', + 'providerBranch' => 'main', + 'providerRootDirectory' => './', + '$id' => $siteId, + 'runtimeSpecification' => Specification::S_1VCPU_1GB, + ]); + + $this->assertEquals(200, $site['headers']['status-code']); + $this->assertNotEmpty($site['body']['$id']); + $this->assertEquals($buildSpecification, $site['body']['buildSpecification']); + $this->assertEquals(Specification::S_1VCPU_1GB, $site['body']['runtimeSpecification']); + // Change the specs to 1vcpu 512mb $site = $this->updateSite([ 'buildRuntime' => 'node-22', From bcb0cb014fe1165faa6f71e0ecce49693d324f22 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 23 Jun 2026 15:04:59 +0400 Subject: [PATCH 12/20] Preserve legacy build specification limits --- .../Platform/Modules/Compute/Base.php | 1 + .../Compute/Validator/Specification.php | 14 +++++++++-- .../Functions/Http/Specifications/XList.php | 3 ++- .../Sites/Http/Specifications/XList.php | 3 ++- .../Compute/Validator/SpecificationTest.php | 23 +++++++++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index b3740787b3..07e09a3b89 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -49,6 +49,7 @@ class Base extends Action $planKey ); $allowedSpecifications = $specificationValidator->getAllowedSpecifications(); + $planKey = $specificationValidator->getPlanKey(); if (empty($allowedSpecifications)) { return $fallback; diff --git a/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php b/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php index 5f1337c97f..8a77afef24 100644 --- a/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php +++ b/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php @@ -25,6 +25,15 @@ class Specification extends Validator $this->planKey = $planKey; } + public function getPlanKey(): string + { + if ($this->planKey === 'buildSpecifications' && !array_key_exists('buildSpecifications', $this->plan) && array_key_exists('runtimeSpecifications', $this->plan)) { + return 'runtimeSpecifications'; + } + + return $this->planKey; + } + /** * Get Allowed Specifications. * @@ -35,11 +44,12 @@ class Specification extends Validator public function getAllowedSpecifications(): array { $allowedSpecifications = []; + $planKey = $this->getPlanKey(); foreach ($this->specifications as $size => $values) { if ((empty($this->maxCpus) || $values['cpus'] <= $this->maxCpus) && (empty($this->maxMemory) || $values['memory'] <= $this->maxMemory)) { - if (!empty($this->plan) && array_key_exists($this->planKey, $this->plan)) { - if (!\in_array($size, $this->plan[$this->planKey])) { + if (!empty($this->plan) && array_key_exists($planKey, $this->plan)) { + if (!\in_array($size, $this->plan[$planKey])) { continue; } } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php index 8cbff906fa..e8177abdbd 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Modules\Functions\Http\Specifications; use Appwrite\Platform\Modules\Compute\Base; +use Appwrite\Platform\Modules\Compute\Validator\Specification; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; @@ -56,7 +57,7 @@ class XList extends Base public function action(string $type, Response $response, array $plan) { $allSpecs = Config::getParam('specifications', []); - $planKey = $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'; + $planKey = (new Specification($plan, [], 0, 0, $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'))->getPlanKey(); $specs = []; foreach ($allSpecs as $spec) { diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php index a4f865d859..735e45bcdc 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Modules\Sites\Http\Specifications; use Appwrite\Platform\Modules\Compute\Base; +use Appwrite\Platform\Modules\Compute\Validator\Specification; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; @@ -56,7 +57,7 @@ class XList extends Base public function action(string $type, Response $response, array $plan) { $allSpecs = Config::getParam('specifications', []); - $planKey = $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'; + $planKey = (new Specification($plan, [], 0, 0, $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'))->getPlanKey(); $specs = []; foreach ($allSpecs as $spec) { diff --git a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php index abc6296d0a..15d9961aa8 100644 --- a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php +++ b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php @@ -96,4 +96,27 @@ final class SpecificationTest extends TestCase $this->assertContains(SpecificationConstants::S_1VCPU_1GB, $allowed); $this->assertContains(SpecificationConstants::S_2VCPU_2GB, $allowed); } + + public function testGetAllowedSpecificationsWithLegacyBuildPlanLimits(): void + { + $plan = [ + 'runtimeSpecifications' => [ + SpecificationConstants::S_05VCPU_512MB, + SpecificationConstants::S_1VCPU_512MB, + ] + ]; + $validator = new Specification( + plan: $plan, + specifications: $this->specifications, + maxCpus: 0, + maxMemory: 0, + planKey: 'buildSpecifications' + ); + + $allowed = $validator->getAllowedSpecifications(); + $this->assertEquals('runtimeSpecifications', $validator->getPlanKey()); + $this->assertCount(2, $allowed); + $this->assertContains(SpecificationConstants::S_05VCPU_512MB, $allowed); + $this->assertContains(SpecificationConstants::S_1VCPU_512MB, $allowed); + } } From c44c5e6733792b6988c663d32340fdb6ad65a87c Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 23 Jun 2026 15:18:32 +0400 Subject: [PATCH 13/20] Apply specification test rector fix --- .../Platform/Modules/Compute/Validator/SpecificationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php index 15d9961aa8..5b9c8b4310 100644 --- a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php +++ b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php @@ -114,7 +114,7 @@ final class SpecificationTest extends TestCase ); $allowed = $validator->getAllowedSpecifications(); - $this->assertEquals('runtimeSpecifications', $validator->getPlanKey()); + $this->assertSame('runtimeSpecifications', $validator->getPlanKey()); $this->assertCount(2, $allowed); $this->assertContains(SpecificationConstants::S_05VCPU_512MB, $allowed); $this->assertContains(SpecificationConstants::S_1VCPU_512MB, $allowed); From 38467157db2c175cfbc2b00de587736f18b3d0c9 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 23 Jun 2026 15:26:58 +0400 Subject: [PATCH 14/20] Revert "Apply specification test rector fix" This reverts commit c44c5e6733792b6988c663d32340fdb6ad65a87c. --- .../Platform/Modules/Compute/Validator/SpecificationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php index 5b9c8b4310..15d9961aa8 100644 --- a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php +++ b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php @@ -114,7 +114,7 @@ final class SpecificationTest extends TestCase ); $allowed = $validator->getAllowedSpecifications(); - $this->assertSame('runtimeSpecifications', $validator->getPlanKey()); + $this->assertEquals('runtimeSpecifications', $validator->getPlanKey()); $this->assertCount(2, $allowed); $this->assertContains(SpecificationConstants::S_05VCPU_512MB, $allowed); $this->assertContains(SpecificationConstants::S_1VCPU_512MB, $allowed); From e9baaddfaddedda7072c9651d12f3f2f49d2c5b7 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 23 Jun 2026 15:26:58 +0400 Subject: [PATCH 15/20] Revert "Preserve legacy build specification limits" This reverts commit bcb0cb014fe1165faa6f71e0ecce49693d324f22. --- .../Platform/Modules/Compute/Base.php | 1 - .../Compute/Validator/Specification.php | 14 ++--------- .../Functions/Http/Specifications/XList.php | 3 +-- .../Sites/Http/Specifications/XList.php | 3 +-- .../Compute/Validator/SpecificationTest.php | 23 ------------------- 5 files changed, 4 insertions(+), 40 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index 07e09a3b89..b3740787b3 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -49,7 +49,6 @@ class Base extends Action $planKey ); $allowedSpecifications = $specificationValidator->getAllowedSpecifications(); - $planKey = $specificationValidator->getPlanKey(); if (empty($allowedSpecifications)) { return $fallback; diff --git a/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php b/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php index 8a77afef24..5f1337c97f 100644 --- a/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php +++ b/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php @@ -25,15 +25,6 @@ class Specification extends Validator $this->planKey = $planKey; } - public function getPlanKey(): string - { - if ($this->planKey === 'buildSpecifications' && !array_key_exists('buildSpecifications', $this->plan) && array_key_exists('runtimeSpecifications', $this->plan)) { - return 'runtimeSpecifications'; - } - - return $this->planKey; - } - /** * Get Allowed Specifications. * @@ -44,12 +35,11 @@ class Specification extends Validator public function getAllowedSpecifications(): array { $allowedSpecifications = []; - $planKey = $this->getPlanKey(); foreach ($this->specifications as $size => $values) { if ((empty($this->maxCpus) || $values['cpus'] <= $this->maxCpus) && (empty($this->maxMemory) || $values['memory'] <= $this->maxMemory)) { - if (!empty($this->plan) && array_key_exists($planKey, $this->plan)) { - if (!\in_array($size, $this->plan[$planKey])) { + if (!empty($this->plan) && array_key_exists($this->planKey, $this->plan)) { + if (!\in_array($size, $this->plan[$this->planKey])) { continue; } } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php index e8177abdbd..8cbff906fa 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Functions\Http\Specifications; use Appwrite\Platform\Modules\Compute\Base; -use Appwrite\Platform\Modules\Compute\Validator\Specification; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; @@ -57,7 +56,7 @@ class XList extends Base public function action(string $type, Response $response, array $plan) { $allSpecs = Config::getParam('specifications', []); - $planKey = (new Specification($plan, [], 0, 0, $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'))->getPlanKey(); + $planKey = $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'; $specs = []; foreach ($allSpecs as $spec) { diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php index 735e45bcdc..a4f865d859 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Sites\Http\Specifications; use Appwrite\Platform\Modules\Compute\Base; -use Appwrite\Platform\Modules\Compute\Validator\Specification; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; @@ -57,7 +56,7 @@ class XList extends Base public function action(string $type, Response $response, array $plan) { $allSpecs = Config::getParam('specifications', []); - $planKey = (new Specification($plan, [], 0, 0, $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'))->getPlanKey(); + $planKey = $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'; $specs = []; foreach ($allSpecs as $spec) { diff --git a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php index 15d9961aa8..abc6296d0a 100644 --- a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php +++ b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php @@ -96,27 +96,4 @@ final class SpecificationTest extends TestCase $this->assertContains(SpecificationConstants::S_1VCPU_1GB, $allowed); $this->assertContains(SpecificationConstants::S_2VCPU_2GB, $allowed); } - - public function testGetAllowedSpecificationsWithLegacyBuildPlanLimits(): void - { - $plan = [ - 'runtimeSpecifications' => [ - SpecificationConstants::S_05VCPU_512MB, - SpecificationConstants::S_1VCPU_512MB, - ] - ]; - $validator = new Specification( - plan: $plan, - specifications: $this->specifications, - maxCpus: 0, - maxMemory: 0, - planKey: 'buildSpecifications' - ); - - $allowed = $validator->getAllowedSpecifications(); - $this->assertEquals('runtimeSpecifications', $validator->getPlanKey()); - $this->assertCount(2, $allowed); - $this->assertContains(SpecificationConstants::S_05VCPU_512MB, $allowed); - $this->assertContains(SpecificationConstants::S_1VCPU_512MB, $allowed); - } } From 2d1d290c9bd58bf61a88e3e5c698f7fd758f641b Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 23 Jun 2026 17:58:25 +0530 Subject: [PATCH 16/20] fix: prevent VCS webhook 500s on inaccessible commits and failed comment updates - Wrap getCommit() in try/catch so force-pushed/deleted commits fall back to empty author/message instead of throwing a 500 - Catch updateComment() failures at all 3 call sites so a cosmetic PR comment update failure no longer fails the entire deployment --- .../Platform/Modules/VCS/Http/GitHub/Deployment.php | 6 ++++++ .../Platform/Modules/VCS/Http/GitHub/Events/Create.php | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php index d172fdc688..d312cc3a56 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Deployment.php @@ -237,6 +237,8 @@ trait Deployment $comment->addBuild($project, $resource, $resourceType, $commentStatus, $deploymentId, $action, $commentPreviewUrl); $latestCommentId = \strval($github->updateComment($owner, $repositoryName, $latestCommentId, $comment->generateComment())); + } catch (\Throwable $e) { + Console::warning("Failed to update PR comment '{$latestCommentId}': " . $e->getMessage()); } finally { $authorization->skip(fn () => $dbForPlatform->deleteDocument('vcsCommentLocks', $latestCommentId)); } @@ -308,6 +310,8 @@ trait Deployment $comment->addBuild($project, $resource, $resourceType, $commentStatus, $deploymentId, $action, ''); $latestCommentId = \strval($github->updateComment($owner, $repositoryName, $latestCommentId, $comment->generateComment())); + } catch (\Throwable $e) { + Console::warning("Failed to update PR comment '{$latestCommentId}': " . $e->getMessage()); } finally { $authorization->skip(fn () => $dbForPlatform->deleteDocument('vcsCommentLocks', $latestCommentId)); } @@ -526,6 +530,8 @@ trait Deployment $comment->addBuild($project, $resource, $resourceType, $commentStatus, $deploymentId, $action, $previewUrl); $github->updateComment($owner, $repositoryName, $latestCommentId, $comment->generateComment()); } + } catch (\Throwable $e) { + Console::warning("Failed to update PR comment '{$latestCommentId}': " . $e->getMessage()); } finally { $authorization->skip(fn () => $dbForPlatform->deleteDocument('vcsCommentLocks', $latestCommentId)); } diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php index 420715ddc6..5ace6d72df 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php @@ -12,6 +12,7 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; +use Utopia\Console; use Utopia\Platform\Scope\HTTP; use Utopia\Span\Span; use Utopia\System\System; @@ -207,7 +208,12 @@ class Create extends Action $github->initializeVariables($providerInstallationId, $privateKey, $githubAppId); - $commitDetails = $github->getCommit($providerRepositoryOwner, $providerRepositoryName, $providerCommitHash); + try { + $commitDetails = $github->getCommit($providerRepositoryOwner, $providerRepositoryName, $providerCommitHash); + } catch (\Throwable $e) { + Console::warning("Failed to fetch commit '{$providerCommitHash}': " . $e->getMessage()); + $commitDetails = []; + } $providerCommitAuthor = $commitDetails["commitAuthor"] ?? ''; $providerCommitMessage = $commitDetails["commitMessage"] ?? ''; From de1951996e84bfe9bf1a876b0a2d432699953ca6 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 23 Jun 2026 18:43:05 +0530 Subject: [PATCH 17/20] fix: order use imports --- src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php index 5ace6d72df..e40e447ed5 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php @@ -8,11 +8,11 @@ use Appwrite\Platform\Action; use Appwrite\Platform\Modules\VCS\Http\GitHub\Deployment; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; +use Utopia\Console; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; -use Utopia\Console; use Utopia\Platform\Scope\HTTP; use Utopia\Span\Span; use Utopia\System\System; From 82df418820da32f070ae23056ec8572435994c2f Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 17 Jun 2026 18:01:16 +0100 Subject: [PATCH 18/20] fix(builds): mask internal errors from user-visible build logs The builds worker wrote the message of any caught throwable straight into the user-visible buildLogs, leaking internal errors (e.g. database or executor failures) to users. Introduce a BuildException (a typed Appwrite\Extend\Exception defaulting to BUILD_FAILED) for every build error we raise intentionally, and only surface its message in the failure handler. Any other throwable is masked behind a generic message; the real error is still recorded on the span. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Functions/Workers/BuildException.php | 23 ++++++++++++++ .../Modules/Functions/Workers/Builds.php | 31 ++++++++++--------- 2 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Functions/Workers/BuildException.php diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/BuildException.php b/src/Appwrite/Platform/Modules/Functions/Workers/BuildException.php new file mode 100644 index 0000000000..1496fd7b72 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Functions/Workers/BuildException.php @@ -0,0 +1,23 @@ +getCollection() === 'functions' ? RESOURCE_TYPE_FUNCTIONS : RESOURCE_TYPE_SITES, $resource->getId())) { - throw new \Exception('Resource is blocked'); + throw new BuildException('Resource is blocked'); } $log->addTag('deploymentId', $deployment->getId()); @@ -226,7 +226,7 @@ class Builds extends Action } if ($resource->getCollection() === 'functions' && empty($deployment->getAttribute('entrypoint', ''))) { - throw new \Exception('Entrypoint for your Appwrite Function is missing. Please specify it when making deployment or update the entrypoint under your function\'s "Settings" > "Configuration" > "Entrypoint".'); + throw new BuildException('Entrypoint for your Appwrite Function is missing. Please specify it when making deployment or update the entrypoint under your function\'s "Settings" > "Configuration" > "Entrypoint".'); } $version = $this->getVersion($resource); @@ -406,7 +406,7 @@ class Builds extends Action $exit = Console::execute($gitCloneCommand, '', $stdout, $stderr); if ($exit !== 0) { - throw new \Exception('Unable to clone code repository: ' . $stderr); + throw new BuildException('Unable to clone code repository: ' . $stderr); } // Local refactoring for function folder with spaces @@ -501,7 +501,7 @@ class Builds extends Action } if ($directorySize > $sizeLimit && $sizeLimit !== 0) { - throw new \Exception('Repository directory size should be less than ' . number_format($sizeLimit / (1000 * 1000), 2) . ' MBs.'); + throw new BuildException('Repository directory size should be less than ' . number_format($sizeLimit / (1000 * 1000), 2) . ' MBs.'); } Console::execute('find ' . \escapeshellarg($tmpDirectory) . ' -type d -name ".git" -exec rm -rf {} +', '', $stdout, $stderr); @@ -739,7 +739,7 @@ class Builds extends Action $span?->set('build.runtime.timed_out', true); $span?->set('build.runtime.error_type', $error::class); $span?->set('build.runtime.error_message', $error->getMessage()); - $err = new AppwriteException(AppwriteException::BUILD_TIMEOUT, previous: $error); + $err = new BuildException(type: AppwriteException::BUILD_TIMEOUT, previous: $error); } catch (\Throwable $error) { $span?->set('build.runtime.error_type', $error::class); $span?->set('build.runtime.error_message', $error->getMessage()); @@ -865,7 +865,7 @@ class Builds extends Action $buildSizeLimit = $plan['buildSize'] * 1000 * 1000; } if ($response['size'] > $buildSizeLimit && $buildSizeLimit !== 0) { - throw new \Exception('Build size should be less than ' . number_format($buildSizeLimit / (1000 * 1000), 2) . ' MBs.'); + throw new BuildException('Build size should be less than ' . number_format($buildSizeLimit / (1000 * 1000), 2) . ' MBs.'); } $deployment->setAttribute('buildPath', $response['path']); @@ -896,7 +896,7 @@ class Builds extends Action Span::add('build.adapter', $deployment->getAttribute('adapter')); Span::add('build.fallback_file', $deployment->getAttribute('fallbackFile')); } elseif ($adapter === 'ssr' && $detection->getName() === 'static') { - throw new \Exception('Adapter mismatch. Detected: ' . $detection->getName() . ' does not match with the set adapter: ' . $adapter); + throw new BuildException('Adapter mismatch. Detected: ' . $detection->getName() . ' does not match with the set adapter: ' . $adapter); } } @@ -1134,14 +1134,12 @@ class Builds extends Action return; } - Span::add('build.error.stage', 'deployment'); - Span::add('build.error.type', $th::class); - Span::add('build.error.message', $th->getMessage()); - Span::add('build.error.file', $th->getFile()); - Span::add('build.error.line', $th->getLine()); + $isUserFacing = $th instanceof BuildException; + $message = $isUserFacing + ? $th->getMessage() + : 'An internal error occurred while building. Please try again, and contact support if the problem persists.'; // Color message red - $message = $th->getMessage(); if (! \str_contains($message, '')) { $message = '' . $message; } @@ -1181,6 +1179,11 @@ class Builds extends Action if ($isVcsEnabled) { $this->runGitAction('failed', $github, $providerCommitHash, $owner, $repositoryName, $project, $resource, $deployment->getId(), $dbForProject, $dbForPlatform, $queueForRealtime, $platform, true); } + + // Let the worker harness record internal errors via the span and logger. + if (! $isUserFacing) { + throw $th; + } } finally { $queueForRealtime ->setPayload($deployment->getArrayCopy()) @@ -1277,7 +1280,7 @@ class Builds extends Action default => null }; if (\is_null($runtime)) { - throw new \Exception('Runtime "' . $resource->getAttribute('runtime', '') . '" is not supported'); + throw new BuildException('Runtime "' . $resource->getAttribute('runtime', '') . '" is not supported'); } return $runtime; From b881a4ed641a175e39b4e836fea85ed96c2dda53 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 23 Jun 2026 14:38:24 +0100 Subject: [PATCH 19/20] feat(builds): record per-phase timings on the build span Emit timings.{setup,source,build,finalize} so each distinct phase of a build (preparation, source packaging, executor build, finalization) can be profiled independently of the overall build.duration. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Platform/Modules/Functions/Workers/Builds.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 392f37bc02..e1e7375cb5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -195,6 +195,7 @@ class Builds extends Action $startTime = DateTime::now(); $durationStart = \microtime(true); + $phaseStart = $durationStart; $resourceKey = match ($resource->getCollection()) { 'functions' => 'functionId', @@ -297,6 +298,9 @@ class Builds extends Action $github->initializeVariables($providerInstallationId, $privateKey, $githubAppId); } + Span::add('timings.setup', \round(\microtime(true) - $phaseStart, 3)); + $phaseStart = \microtime(true); + try { if (! $isVcsEnabled) { // Non-VCS + Template @@ -539,6 +543,9 @@ class Builds extends Action $this->runGitAction('processing', $github, $providerCommitHash, $owner, $repositoryName, $project, $resource, $deployment->getId(), $dbForProject, $dbForPlatform, $queueForRealtime, $platform); } + Span::add('timings.source', \round(\microtime(true) - $phaseStart, 3)); + $phaseStart = \microtime(true); + /** Request the executor to build the code... */ $updated = $dbForProject->updateDocuments('deployments', new Document([ 'status' => 'building', @@ -849,6 +856,9 @@ class Builds extends Action }), ]); + Span::add('timings.build', \round(\microtime(true) - $phaseStart, 3)); + $phaseStart = \microtime(true); + $latestDeployment = $dbForProject->getDocument('deployments', $deploymentId); if ($latestDeployment->getAttribute('status') === 'canceled') { $this->finalizeCanceledDeployment($deployment->getId(), $dbForProject, $queueForRealtime); @@ -1127,6 +1137,8 @@ class Builds extends Action Span::add('build.screenshot_queued', true); } + + Span::add('timings.finalize', \round(\microtime(true) - $phaseStart, 3)); } catch (\Throwable $th) { if ($dbForProject->getDocument('deployments', $deploymentId)->getAttribute('status') === 'canceled') { $this->finalizeCanceledDeployment($deployment->getId(), $dbForProject, $queueForRealtime); From 65b863b44345d09adca5f2971c9590c179d51327 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 23 Jun 2026 14:55:24 +0100 Subject: [PATCH 20/20] fix(builds): record user-facing build failures on the span A swallowed BuildException is never re-raised to the worker harness, so without this its failure reason was absent from the trace. Record build.error.type/message on the span for user-facing failures; internal errors still get full detail via the harness setError on rethrow. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index e1e7375cb5..c2b8837c13 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1151,6 +1151,13 @@ class Builds extends Action ? $th->getMessage() : 'An internal error occurred while building. Please try again, and contact support if the problem persists.'; + // Record user-facing failures on the span here, since they're not + // re-raised to the harness (which records internal errors via setError). + if ($isUserFacing) { + Span::add('build.exception.type', $th->getType()); + Span::add('build.exception.message', $th->getMessage()); + } + // Color message red if (! \str_contains($message, '')) { $message = '' . $message;