From 87e735e077c956bae1c651cfdb1d35396d673163 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 31 Aug 2026 16:40:43 +0545 Subject: [PATCH 01/10] fix(usage): don't bill build compute when buildStartedAt is null buildDuration falls back to wall clock since the deployment was created when a build never stamped buildStartedAt, so queue wait was billed as build compute and flowed into builds.mbSeconds. Zero buildDuration and mbSeconds in that case. Both StatsUsage workers skip zero-valued metrics, so the compute rows drop out while the build counters and storage metrics still land. --- src/Appwrite/Usage/Build.php | 7 ++ tests/unit/Usage/BuildTest.php | 123 +++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 tests/unit/Usage/BuildTest.php diff --git a/src/Appwrite/Usage/Build.php b/src/Appwrite/Usage/Build.php index e2ab30893b..a961c49281 100644 --- a/src/Appwrite/Usage/Build.php +++ b/src/Appwrite/Usage/Build.php @@ -32,6 +32,13 @@ final class Build $buildDuration = (int) $deployment->getAttribute('buildDuration', 0) * 1000; $mbSeconds = (int) ($memory * $deployment->getAttribute('buildDuration', 0) * $cpus); + // Without a start stamp buildDuration falls back to wall clock since the + // deployment was created, which would bill queue wait as build compute. + if (empty($deployment->getAttribute('buildStartedAt'))) { + $buildDuration = 0; + $mbSeconds = 0; + } + // Per-resource breakdown now travels as resource dimensions on the // Context (resolved to resourceType + resourceId in the usage pipeline) // instead of per-{resourceInternalId} metric-name templates. diff --git a/tests/unit/Usage/BuildTest.php b/tests/unit/Usage/BuildTest.php new file mode 100644 index 0000000000..2e8652e478 --- /dev/null +++ b/tests/unit/Usage/BuildTest.php @@ -0,0 +1,123 @@ + $deployment + * @return array metric key => value + */ + private function publish(array $deployment): array + { + $publisher = new MockPublisher(); + + Build::publish( + new Context(), + new Document([ + '$id' => 'function', + '$sequence' => '1', + 'buildSpecification' => Specification::S_2VCPU_2GB, + ]), + new Document($deployment), + new Document(['$id' => 'project', '$sequence' => '1']), + new UsagePublisher($publisher, new Queue('usage')), + ); + + $events = $publisher->getEvents('usage'); + $this->assertCount(1, $events); + + $metrics = []; + foreach ($events[0]['metrics'] as $metric) { + $metrics[$metric['key']] = $metric['value']; + } + + return $metrics; + } + + /** + * @param array $overrides + * @return array + */ + private function deployment(array $overrides = []): array + { + return \array_merge([ + '$id' => 'deployment', + '$sequence' => '1', + '$createdAt' => '2026-08-31T10:00:00.000+00:00', + 'resourceType' => 'functions', + 'status' => 'ready', + 'buildDuration' => self::DURATION, + 'buildSize' => self::SIZE, + ], $overrides); + } + + public function testBuildStartedAtStampedBillsMemoryTimesDurationTimesCpus(): void + { + $metrics = $this->publish($this->deployment([ + 'buildStartedAt' => '2026-08-31T10:00:05.000+00:00', + ])); + + $expectedMbSeconds = self::MEMORY * self::DURATION * self::CPUS; + $expectedCompute = self::DURATION * 1000; + + $this->assertSame($expectedMbSeconds, $metrics[METRIC_BUILDS_MB_SECONDS]); + $this->assertSame($expectedMbSeconds, $metrics['functions.builds.mbSeconds']); + $this->assertSame($expectedCompute, $metrics[METRIC_BUILDS_COMPUTE]); + $this->assertSame($expectedCompute, $metrics[METRIC_BUILDS_COMPUTE_SUCCESS]); + $this->assertSame($expectedCompute, $metrics['functions.builds.compute']); + $this->assertSame(1, $metrics[METRIC_BUILDS]); + $this->assertSame(self::SIZE, $metrics[METRIC_BUILDS_STORAGE]); + } + + public function testMissingBuildStartedAtDropsComputeButKeepsCounts(): void + { + $metrics = $this->publish($this->deployment()); + + $this->assertSame(0, $metrics[METRIC_BUILDS_MB_SECONDS]); + $this->assertSame(0, $metrics['functions.builds.mbSeconds']); + $this->assertSame(0, $metrics[METRIC_BUILDS_COMPUTE]); + $this->assertSame(0, $metrics[METRIC_BUILDS_COMPUTE_SUCCESS]); + $this->assertSame(0, $metrics['functions.builds.compute']); + $this->assertSame(0, $metrics['functions.builds.compute.success']); + + $this->assertSame(1, $metrics[METRIC_BUILDS]); + $this->assertSame(1, $metrics[METRIC_BUILDS_SUCCESS]); + $this->assertSame(self::SIZE, $metrics[METRIC_BUILDS_STORAGE]); + } + + public function testNullBuildStartedAtDropsComputeOnFailedBuilds(): void + { + $metrics = $this->publish($this->deployment([ + 'status' => 'failed', + 'buildStartedAt' => null, + ])); + + $this->assertSame(0, $metrics[METRIC_BUILDS_MB_SECONDS]); + $this->assertSame(0, $metrics[METRIC_BUILDS_COMPUTE]); + $this->assertSame(0, $metrics[METRIC_BUILDS_COMPUTE_FAILED]); + $this->assertSame(0, $metrics['functions.builds.compute.failed']); + + $this->assertSame(1, $metrics[METRIC_BUILDS]); + $this->assertSame(1, $metrics[METRIC_BUILDS_FAILED]); + $this->assertSame(self::SIZE, $metrics[METRIC_BUILDS_STORAGE]); + } +} From bc9afc003196c40c8c119a180ac250b9d3e538b0 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 1 Sep 2026 11:23:35 +0530 Subject: [PATCH 02/10] feat: make the GitLab endpoint configurable Both GitLab surfaces hardcoded https://gitlab.com, so a self-hosted GitLab could not be used for either repository integration or console sign-in. _APP_VCS_GITLAB_ENDPOINT covers repository integration: the vcs registry entry Vcs\Factory hands to setEndpoint() and to the OAuth2 builder, plus the authorize and callback handlers that build their own client. _APP_CONSOLE_GITLAB_ENDPOINT covers console sign-in. Auth\OAuth2\Gitlab reads its endpoint out of a JSON-encoded secret, so gitlabSecret now carries {"clientSecret","endpoint"} rather than the raw secret string. That also fixes console sign-in outright, which threw "Invalid secret" on the undecodable plain string. The value stays empty when unconfigured so account.php keeps reporting the provider as disabled. Both default to https://gitlab.com. --- .env | 2 ++ app/config/console.php | 8 +++++++- app/config/variables.php | 18 ++++++++++++++++++ app/config/vcs.php | 5 +++-- docker-compose.yml | 4 ++++ src/Appwrite/Auth/OAuth2/Gitlab.php | 5 +++-- .../Modules/VCS/Http/Gitlab/Authorize/Get.php | 2 +- .../Modules/VCS/Http/Gitlab/Callback/Get.php | 2 +- 8 files changed, 39 insertions(+), 7 deletions(-) diff --git a/.env b/.env index 3ff3672e3d..7fe753006f 100644 --- a/.env +++ b/.env @@ -41,6 +41,7 @@ _APP_CONSOLE_GITHUB_APP_ID= _APP_CONSOLE_GITHUB_SECRET= _APP_CONSOLE_GITLAB_APP_ID= _APP_CONSOLE_GITLAB_SECRET= +_APP_CONSOLE_GITLAB_ENDPOINT=https://gitlab.com _APP_CONSOLE_BITBUCKET_APP_ID= _APP_CONSOLE_BITBUCKET_SECRET= _APP_CONSOLE_GOOGLE_APP_ID= @@ -181,6 +182,7 @@ _APP_VCS_GITEA_BROWSER_ENDPOINT=http://localhost:9515 _APP_VCS_GITEA_CLIENT_ID= _APP_VCS_GITEA_CLIENT_SECRET= _APP_VCS_GITEA_WEBHOOK_SECRET=gitea-webhook-secret +_APP_VCS_GITLAB_ENDPOINT=https://gitlab.com _APP_VCS_GITLAB_CLIENT_ID= _APP_VCS_GITLAB_CLIENT_SECRET= _APP_VCS_GITLAB_WEBHOOK_SECRET= diff --git a/app/config/console.php b/app/config/console.php index bc4c6f0b49..0d99ad71b5 100644 --- a/app/config/console.php +++ b/app/config/console.php @@ -59,7 +59,13 @@ $console = [ 'githubSecret' => System::getEnv('_APP_CONSOLE_GITHUB_SECRET', ''), 'githubAppid' => System::getEnv('_APP_CONSOLE_GITHUB_APP_ID', ''), 'gitlabEnabled' => true, - 'gitlabSecret' => System::getEnv('_APP_CONSOLE_GITLAB_SECRET', ''), + // Auth\OAuth2\Gitlab reads its endpoint out of a JSON-encoded secret, so + // _APP_CONSOLE_GITLAB_ENDPOINT travels with the credential. Stays empty when + // unconfigured so account.php keeps reporting the provider as disabled. + 'gitlabSecret' => empty(System::getEnv('_APP_CONSOLE_GITLAB_SECRET', '')) ? '' : \json_encode([ + 'clientSecret' => System::getEnv('_APP_CONSOLE_GITLAB_SECRET', ''), + 'endpoint' => System::getEnv('_APP_CONSOLE_GITLAB_ENDPOINT', 'https://gitlab.com'), + ]), 'gitlabAppid' => System::getEnv('_APP_CONSOLE_GITLAB_APP_ID', ''), 'bitbucketEnabled' => true, 'bitbucketSecret' => System::getEnv('_APP_CONSOLE_BITBUCKET_SECRET', ''), diff --git a/app/config/variables.php b/app/config/variables.php index e21b086f92..2580d0046c 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -295,6 +295,15 @@ return [ 'question' => '', 'filter' => '' ], + [ + 'name' => '_APP_CONSOLE_GITLAB_ENDPOINT', + 'description' => 'URL of the GitLab instance used for signing in to the Appwrite console, for self-hosted GitLab. This is separate from _APP_VCS_GITLAB_ENDPOINT, which powers repository integration rather than console sign-in.', + 'introduction' => '2.0.0', + 'default' => 'https://gitlab.com', + 'required' => false, + 'question' => '', + 'filter' => '' + ], [ 'name' => '_APP_CONSOLE_BITBUCKET_APP_ID', 'description' => 'Bitbucket OAuth consumer key used for signing in to the Appwrite console. You can find it in your Bitbucket workspace settings under OAuth consumers. This is separate from _APP_VCS_BITBUCKET_CLIENT_ID, which powers repository integration rather than console sign-in.', @@ -1572,6 +1581,15 @@ return [ 'question' => '', 'filter' => '' ], + [ + 'name' => '_APP_VCS_GITLAB_ENDPOINT', + 'description' => 'URL of your self-hosted GitLab instance, reachable from the Appwrite server and the browser.', + 'introduction' => '2.0.0', + 'default' => 'https://gitlab.com', + 'required' => false, + 'question' => '', + 'filter' => '' + ], [ 'name' => '_APP_VCS_GITLAB_CLIENT_ID', 'description' => 'GitLab OAuth2 application client ID. You can generate one in your GitLab instance under Settings > Applications.', diff --git a/app/config/vcs.php b/app/config/vcs.php index f21d54c803..c1c5f21deb 100644 --- a/app/config/vcs.php +++ b/app/config/vcs.php @@ -8,6 +8,7 @@ use Appwrite\Auth\OAuth2\Bitbucket as OAuth2Bitbucket; use Appwrite\Auth\OAuth2\Gitea as OAuth2Gitea; use Appwrite\Auth\OAuth2\Github as OAuth2Github; use Appwrite\Auth\OAuth2\Gitlab as OAuth2Gitlab; +use Utopia\System\System; use Utopia\VCS\Adapter\Git\Bitbucket; use Utopia\VCS\Adapter\Git\Gitea; use Utopia\VCS\Adapter\Git\GitHub; @@ -55,8 +56,8 @@ return [ 'clientSecret' => $clientSecret, 'endpoint' => $endpoint, ]), ''), - // Only official gitlab.com is supported -- fixed, not configurable. - 'endpoint' => 'https://gitlab.com', + // Defaults to gitlab.com; self-hosted installs point _APP_VCS_GITLAB_ENDPOINT at their own instance. + 'endpoint' => System::getEnv('_APP_VCS_GITLAB_ENDPOINT', 'https://gitlab.com'), 'variables' => [ 'clientId' => ['required' => true, 'envVariable' => '_APP_VCS_GITLAB_CLIENT_ID'], 'clientSecret' => ['required' => true, 'envVariable' => '_APP_VCS_GITLAB_CLIENT_SECRET'], diff --git a/docker-compose.yml b/docker-compose.yml index c709dc73e5..99a32c9628 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -103,6 +103,7 @@ services: - _APP_CONSOLE_GITHUB_SECRET - _APP_CONSOLE_GITLAB_APP_ID - _APP_CONSOLE_GITLAB_SECRET + - _APP_CONSOLE_GITLAB_ENDPOINT - _APP_CONSOLE_BITBUCKET_APP_ID - _APP_CONSOLE_BITBUCKET_SECRET - _APP_CONSOLE_GOOGLE_APP_ID @@ -229,6 +230,7 @@ services: - _APP_VCS_GITEA_CLIENT_ID - _APP_VCS_GITEA_CLIENT_SECRET - _APP_VCS_GITEA_WEBHOOK_SECRET + - _APP_VCS_GITLAB_ENDPOINT - _APP_VCS_GITLAB_CLIENT_ID - _APP_VCS_GITLAB_CLIENT_SECRET - _APP_VCS_GITLAB_WEBHOOK_SECRET @@ -482,6 +484,7 @@ services: - _APP_VCS_GITEA_CLIENT_ID - _APP_VCS_GITEA_CLIENT_SECRET - _APP_VCS_GITEA_WEBHOOK_SECRET + - _APP_VCS_GITLAB_ENDPOINT - _APP_VCS_GITLAB_CLIENT_ID - _APP_VCS_GITLAB_CLIENT_SECRET - _APP_VCS_GITLAB_WEBHOOK_SECRET @@ -824,6 +827,7 @@ services: - _APP_VCS_GITEA_CLIENT_ID - _APP_VCS_GITEA_CLIENT_SECRET - _APP_VCS_GITEA_WEBHOOK_SECRET + - _APP_VCS_GITLAB_ENDPOINT - _APP_VCS_GITLAB_CLIENT_ID - _APP_VCS_GITLAB_CLIENT_SECRET - _APP_VCS_GITLAB_WEBHOOK_SECRET diff --git a/src/Appwrite/Auth/OAuth2/Gitlab.php b/src/Appwrite/Auth/OAuth2/Gitlab.php index db72385a12..938926cf37 100644 --- a/src/Appwrite/Auth/OAuth2/Gitlab.php +++ b/src/Appwrite/Auth/OAuth2/Gitlab.php @@ -11,8 +11,9 @@ use Appwrite\Auth\OAuth2; * Shared with the "Sign in with GitLab" account-login OAuth2 provider, which * stores its secret as JSON ({"clientSecret": "...", "endpoint": "..."}) to * support self-hosted GitLab per-project. The VCS flow (see app/config/vcs.php) - * only supports official gitlab.com, but still encodes to that same JSON - * shape so getAppSecret()/getEndpoint() stay correct for both consumers. + * and the console project (see app/config/console.php) encode to that same JSON + * shape, taking their endpoint from _APP_VCS_GITLAB_ENDPOINT and + * _APP_CONSOLE_GITLAB_ENDPOINT respectively. */ class Gitlab extends OAuth2 { diff --git a/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Authorize/Get.php b/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Authorize/Get.php index 34e8dd71b0..0eca4c9906 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Authorize/Get.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Authorize/Get.php @@ -31,7 +31,7 @@ class Get extends Base System::getEnv('_APP_VCS_GITLAB_CLIENT_ID', ''), \json_encode([ 'clientSecret' => System::getEnv('_APP_VCS_GITLAB_CLIENT_SECRET', ''), - 'endpoint' => 'https://gitlab.com', + 'endpoint' => System::getEnv('_APP_VCS_GITLAB_ENDPOINT', 'https://gitlab.com'), ]), $callback, $state, diff --git a/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Callback/Get.php b/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Callback/Get.php index 6d86b25fa1..e48f488f5d 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Callback/Get.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Callback/Get.php @@ -30,7 +30,7 @@ class Get extends Base System::getEnv('_APP_VCS_GITLAB_CLIENT_ID', ''), \json_encode([ 'clientSecret' => System::getEnv('_APP_VCS_GITLAB_CLIENT_SECRET', ''), - 'endpoint' => 'https://gitlab.com', + 'endpoint' => System::getEnv('_APP_VCS_GITLAB_ENDPOINT', 'https://gitlab.com'), ]), $callback ); From 1bae8729749550de890c03970311bac1075dae8a Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 1 Sep 2026 12:07:52 +0530 Subject: [PATCH 03/10] fix(oauth2): stop GitLab rejecting a plain-string secret getAppSecret() decoded appSecret with JSON_THROW_ON_ERROR and turned any failure into "Invalid secret", so a secret that is not a JSON object took down every call that needed it. The legacy PATCH /v1/projects/:projectId/oauth2 writes the secret verbatim for any provider in the oAuthProviders config, gitlab included, so projects configured through it fail sign-in outright. A numeric secret decoded fine and then tripped the array return type instead. Fall back to treating the raw string as the client secret, matching Google, which grew the same fallback for the same reason. Also rtrim the endpoint, as Gitea's setEndpoint() does, so a configured endpoint with a trailing slash no longer builds //oauth/authorize. --- src/Appwrite/Auth/OAuth2/Gitlab.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Gitlab.php b/src/Appwrite/Auth/OAuth2/Gitlab.php index 938926cf37..fd2464b4ff 100644 --- a/src/Appwrite/Auth/OAuth2/Gitlab.php +++ b/src/Appwrite/Auth/OAuth2/Gitlab.php @@ -231,7 +231,8 @@ class Gitlab extends OAuth2 } /** - * Decode the JSON stored in appSecret + * Decode the JSON stored in appSecret. + * Falls back to treating the raw string as the client secret for backwards compatibility. * * @return array */ @@ -240,8 +241,13 @@ class Gitlab extends OAuth2 try { $secret = \json_decode($this->appSecret, true, 512, JSON_THROW_ON_ERROR); } catch (\Throwable $th) { - throw new \Exception('Invalid secret'); + return ['clientSecret' => $this->appSecret]; } + + if (!\is_array($secret)) { + return ['clientSecret' => $this->appSecret]; + } + return $secret; } @@ -256,6 +262,6 @@ class Gitlab extends OAuth2 $defaultEndpoint = 'https://gitlab.com'; $secret = $this->getAppSecret(); $endpoint = $secret['endpoint'] ?? $defaultEndpoint; - return empty($endpoint) ? $defaultEndpoint : $endpoint; + return empty($endpoint) ? $defaultEndpoint : \rtrim($endpoint, '/'); } } From 47d917dac6f686be408cff93524db15512fdf881 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 1 Sep 2026 11:22:49 +0300 Subject: [PATCH 04/10] Column boundaries for numeric attributes --- .../Collections/Attributes/Integer/Create.php | 5 +- .../Http/Databases/Collections/Create.php | 14 +- src/Appwrite/Utopia/Database/Attribute.php | 12 ++ .../Utopia/Database/Validator/Attributes.php | 17 ++ .../e2e/Services/Databases/DatabasesBase.php | 164 ++++++++++++++++++ .../Database/Validator/AttributesTest.php | 80 +++++++++ 6 files changed, 288 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php index 022efb2062..5647546661 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php @@ -94,7 +94,10 @@ class Create extends Action throw new Exception($this->getInvalidValueException(), $validator->getDescription()); } - $size = $max > 2147483647 ? 8 : 4; + // The 4 byte column only holds a range that fits INT32. min counts: a + // column bounded below -2147483648 has to be able to store that value, + // and with min left out the bound is PHP_INT_MIN. + $size = $min >= -2147483648 && $max <= 2147483647 ? 4 : 8; $attribute = $this->createAttribute($databaseId, $collectionId, new Document([ 'key' => $key, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index 0db84db7f3..0d0beb0003 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -297,16 +297,24 @@ class Create extends Action $formatOptions = ['elements' => $attribute['elements']]; } - if (isset($attribute['min']) || isset($attribute['max'])) { + // The dedicated endpoints store a range on every numeric attribute, falling + // back to the full width of the type, so omitting min/max here has to produce + // the same document rather than one with no range at all. + if (\in_array($type, [Database::VAR_INTEGER, Database::VAR_BIGINT, Database::VAR_FLOAT])) { + $isFloat = $type === Database::VAR_FLOAT; + $format = match($type) { Database::VAR_INTEGER => APP_DATABASE_ATTRIBUTE_INT_RANGE, Database::VAR_BIGINT => APP_DATABASE_ATTRIBUTE_BIGINT_RANGE, default => APP_DATABASE_ATTRIBUTE_FLOAT_RANGE, }; + $min = $attribute['min'] ?? ($isFloat ? -\PHP_FLOAT_MAX : \PHP_INT_MIN); + $max = $attribute['max'] ?? ($isFloat ? \PHP_FLOAT_MAX : \PHP_INT_MAX); + $formatOptions = [ - 'min' => $attribute['min'] ?? ($type === Database::VAR_INTEGER || $type === Database::VAR_BIGINT ? \PHP_INT_MIN : -\PHP_FLOAT_MAX), - 'max' => $attribute['max'] ?? ($type === Database::VAR_INTEGER || $type === Database::VAR_BIGINT ? \PHP_INT_MAX : \PHP_FLOAT_MAX), + 'min' => $isFloat ? \floatval($min) : $min, + 'max' => $isFloat ? \floatval($max) : $max, ]; } diff --git a/src/Appwrite/Utopia/Database/Attribute.php b/src/Appwrite/Utopia/Database/Attribute.php index b4dba3433c..010e27a7e5 100644 --- a/src/Appwrite/Utopia/Database/Attribute.php +++ b/src/Appwrite/Utopia/Database/Attribute.php @@ -22,6 +22,8 @@ class Attribute Database::VAR_TEXT => 65535, Database::VAR_MEDIUMTEXT => 16777215, Database::VAR_LONGTEXT => 2147483647, + // Bytes, the width createBigIntColumn hardcodes + Database::VAR_BIGINT => 8, ]; /** @@ -91,6 +93,16 @@ class Attribute $size = self::FORMAT_SIZES[$format] ?? $size; } + if ($type === Database::VAR_INTEGER && $size < 1) { + // Same width createIntegerColumn picks: the 4 byte column only holds a + // range that fits INT32, and a bound left out means the int64 edge, + // which does not. + $min = $attribute['min'] ?? \PHP_INT_MIN; + $max = $attribute['max'] ?? \PHP_INT_MAX; + $fitsInt32 = \is_int($min) && \is_int($max) && $min >= -2147483648 && $max <= 2147483647; + $size = $fitsInt32 ? 4 : 8; + } + return [ 'type' => $type, 'format' => $format, diff --git a/src/Appwrite/Utopia/Database/Validator/Attributes.php b/src/Appwrite/Utopia/Database/Validator/Attributes.php index 4eefb9ba2d..3b634d6989 100644 --- a/src/Appwrite/Utopia/Database/Validator/Attributes.php +++ b/src/Appwrite/Utopia/Database/Validator/Attributes.php @@ -8,6 +8,8 @@ use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Key; use Utopia\Emails\Validator\Email; use Utopia\Validator; +use Utopia\Validator\FloatValidator; +use Utopia\Validator\Integer; use Utopia\Validator\IP; use Utopia\Validator\Range; use Utopia\Validator\Text; @@ -204,6 +206,21 @@ class Attributes extends Validator return false; } + // The dedicated endpoints bound these with Integer(false, 64) / FloatValidator. + // Without the same check a JSON number past PHP_INT_MAX decodes to a float and is + // stored verbatim, so an int64 bound round-tripped through a client that cannot + // hold it lands in formatOptions as 9.223372036854776e+18. + $boundValidator = $type === Database::VAR_FLOAT + ? new FloatValidator() + : new Integer(false, 64); + + foreach (['min', 'max'] as $bound) { + if (isset($attribute[$bound]) && !$boundValidator->isValid($attribute[$bound])) { + $this->message = "Attribute '" . $attribute['key'] . "': " . $bound . ' is invalid. ' . $boundValidator->getDescription(); + return false; + } + } + // If both are set, validate ordering if (isset($attribute['min']) && isset($attribute['max']) && $attribute['min'] > $attribute['max']) { $this->message = "Attribute '" . $attribute['key'] . "': minimum value must be less than or equal to maximum value"; diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index bd0808fd69..4ba282050b 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -1223,6 +1223,170 @@ trait DatabasesBase } } + /** + * An inline numeric definition on create collection has to produce the same + * document the dedicated endpoints write: the full width of the type when no + * bounds are given, on a column wide enough to hold it. + */ + public function testCreateCollectionInlineNumericRange(): void + { + if (!$this->getSupportForAttributes()) { + $this->markTestSkipped('Attributes are not supported by this database adapter'); + } + + $data = $this->setupDatabase(); + $databaseId = $data['databaseId']; + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $schemaResource = $this->getSchemaResource(); + + $container = $this->client->call(Client::METHOD_POST, $this->getContainerUrl($databaseId), $headers, [ + $this->getContainerIdParam() => ID::unique(), + 'name' => 'Counters', + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + ], + $schemaResource => [ + ['key' => 'counter', 'type' => Database::VAR_INTEGER], + ['key' => 'total', 'type' => Database::VAR_BIGINT], + ['key' => 'ratio', 'type' => Database::VAR_FLOAT], + ['key' => 'bounded', 'type' => Database::VAR_INTEGER, 'min' => 0, 'max' => 100], + ], + ]); + + $this->assertEquals(201, $container['headers']['status-code']); + $containerId = $container['body']['$id']; + + $schema = $this->client->call(Client::METHOD_GET, $this->getSchemaUrl($databaseId, $containerId), $headers); + + $this->assertEquals(200, $schema['headers']['status-code']); + + $byKey = []; + foreach ($schema['body'][$schemaResource] as $attribute) { + $byKey[$attribute['key']] = $attribute; + } + + $this->assertSame(\PHP_INT_MIN, $byKey['counter']['min']); + $this->assertSame(\PHP_INT_MAX, $byKey['counter']['max']); + $this->assertSame(\PHP_INT_MIN, $byKey['total']['min']); + $this->assertSame(\PHP_INT_MAX, $byKey['total']['max']); + $this->assertSame(-\PHP_FLOAT_MAX, $byKey['ratio']['min']); + $this->assertSame(\PHP_FLOAT_MAX, $byKey['ratio']['max']); + + // A bound that was asked for is kept as asked for + $this->assertSame(0, $byKey['bounded']['min']); + $this->assertSame(100, $byKey['bounded']['max']); + + // The bounds are only honest if the column is that wide. 5e9 overflows the + // 4 byte column an implied INT32 range would have produced. + $record = $this->client->call(Client::METHOD_POST, $this->getRecordUrl($databaseId, $containerId), $headers, [ + $this->getRecordIdParam() => ID::unique(), + 'data' => [ + 'counter' => 5000000000, + 'total' => \PHP_INT_MAX, + ], + ]); + + $this->assertEquals(201, $record['headers']['status-code']); + $this->assertSame(5000000000, $record['body']['counter']); + $this->assertSame(\PHP_INT_MAX, $record['body']['total']); + + // A value outside a declared bound is still refused + $rejected = $this->client->call(Client::METHOD_POST, $this->getRecordUrl($databaseId, $containerId), $headers, [ + $this->getRecordIdParam() => ID::unique(), + 'data' => ['bounded' => 101], + ]); + + $this->assertEquals(400, $rejected['headers']['status-code']); + + // Same type, same collection, through the dedicated endpoint: the two paths + // have to agree on what "no bounds" means + $dedicated = $this->client->call(Client::METHOD_POST, $this->getSchemaUrl($databaseId, $containerId, 'integer'), $headers, [ + 'key' => 'dedicated', + 'required' => false, + ]); + + $this->assertEquals(202, $dedicated['headers']['status-code']); + $this->assertSame($byKey['counter']['min'], $dedicated['body']['min']); + $this->assertSame($byKey['counter']['max'], $dedicated['body']['max']); + } + + /** + * A JSON number past PHP_INT_MAX decodes to a float. The dedicated endpoints + * refuse it; an inline definition used to store it, leaving formatOptions + * holding 9.223372036854776e+18 on a column typed as an integer. + */ + public function testCreateCollectionInlineBoundBeyondInt64(): void + { + if (!$this->getSupportForAttributes()) { + $this->markTestSkipped('Attributes are not supported by this database adapter'); + } + + $data = $this->setupDatabase(); + $databaseId = $data['databaseId']; + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + $schemaResource = $this->getSchemaResource(); + $containerId = ID::unique(); + + $container = $this->client->call(Client::METHOD_POST, $this->getContainerUrl($databaseId), $headers, [ + $this->getContainerIdParam() => $containerId, + 'name' => 'Overflowing Bounds', + $schemaResource => [ + // What a client that cannot hold an int64 sends back after reading + // the default bounds off an existing column + ['key' => 'counter', 'type' => Database::VAR_INTEGER, 'min' => -9223372036854776000, 'max' => 9223372036854776000], + ], + ]); + + $this->assertEquals(400, $container['headers']['status-code']); + $this->assertStringContainsString("Attribute 'counter'", (string) $container['body']['message']); + + // The rejected definition must not leave a collection behind + $missing = $this->client->call(Client::METHOD_GET, $this->getContainerUrl($databaseId, $containerId), $headers); + $this->assertEquals(404, $missing['headers']['status-code']); + + // A bound sent as a string is not an integer either + $stringBound = $this->client->call(Client::METHOD_POST, $this->getContainerUrl($databaseId), $headers, [ + $this->getContainerIdParam() => ID::unique(), + 'name' => 'String Bounds', + $schemaResource => [ + ['key' => 'counter', 'type' => Database::VAR_INTEGER, 'max' => '9223372036854776000'], + ], + ]); + + $this->assertEquals(400, $stringBound['headers']['status-code']); + $this->assertStringContainsString("Attribute 'counter'", (string) $stringBound['body']['message']); + + // The dedicated endpoint is the reference: it refuses the same bound + $valid = $this->client->call(Client::METHOD_POST, $this->getContainerUrl($databaseId), $headers, [ + $this->getContainerIdParam() => ID::unique(), + 'name' => 'Dedicated Bounds', + ]); + + $this->assertEquals(201, $valid['headers']['status-code']); + + $attribute = $this->client->call(Client::METHOD_POST, $this->getSchemaUrl($databaseId, $valid['body']['$id'], 'integer'), $headers, [ + 'key' => 'counter', + 'required' => false, + 'max' => 9223372036854776000, + ]); + + $this->assertEquals(400, $attribute['headers']['status-code']); + + $schema = $this->client->call(Client::METHOD_GET, $this->getSchemaUrl($databaseId, $valid['body']['$id']), $headers); + + $this->assertEquals(200, $schema['headers']['status-code']); + $this->assertEquals(0, $schema['body']['total']); + } + public function testListAttributes(): void { if (!$this->getSupportForAttributes()) { diff --git a/tests/unit/Utopia/Database/Validator/AttributesTest.php b/tests/unit/Utopia/Database/Validator/AttributesTest.php index 6c02e5bbe7..34212a8b0c 100644 --- a/tests/unit/Utopia/Database/Validator/AttributesTest.php +++ b/tests/unit/Utopia/Database/Validator/AttributesTest.php @@ -120,6 +120,86 @@ final class AttributesTest extends TestCase ['type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_ENUM, 'size' => Database::LENGTH_KEY], Attribute::resolve(['key' => 'enum', 'type' => APP_DATABASE_ATTRIBUTE_ENUM]) ); + + // createIntegerColumn sizes the column off max, defaulting to the int64 + // range, and createBigIntColumn is always 8 bytes + $this->assertEquals( + ['type' => Database::VAR_INTEGER, 'format' => '', 'size' => 8], + Attribute::resolve(['key' => 'counter', 'type' => Database::VAR_INTEGER]) + ); + + $this->assertEquals( + ['type' => Database::VAR_INTEGER, 'format' => '', 'size' => 8], + Attribute::resolve(['key' => 'counter', 'type' => Database::VAR_INTEGER, 'max' => 3000000000]) + ); + + $this->assertEquals( + ['type' => Database::VAR_INTEGER, 'format' => '', 'size' => 4], + Attribute::resolve(['key' => 'counter', 'type' => Database::VAR_INTEGER, 'min' => 0, 'max' => 100]) + ); + + // Both edges of the declared range have to be storable. A max on its own + // leaves min at PHP_INT_MIN, and a min below INT32 needs the wide column + // however small max is. + $this->assertEquals( + ['type' => Database::VAR_INTEGER, 'format' => '', 'size' => 8], + Attribute::resolve(['key' => 'counter', 'type' => Database::VAR_INTEGER, 'max' => 100]) + ); + + $this->assertEquals( + ['type' => Database::VAR_INTEGER, 'format' => '', 'size' => 8], + Attribute::resolve(['key' => 'counter', 'type' => Database::VAR_INTEGER, 'min' => -5000000000, 'max' => 100]) + ); + + $this->assertEquals( + ['type' => Database::VAR_INTEGER, 'format' => '', 'size' => 4], + Attribute::resolve(['key' => 'counter', 'type' => Database::VAR_INTEGER, 'min' => -2147483648, 'max' => 2147483647]) + ); + + $this->assertEquals( + ['type' => Database::VAR_BIGINT, 'format' => '', 'size' => 8], + Attribute::resolve(['key' => 'total', 'type' => Database::VAR_BIGINT]) + ); + } + + public function testNumericBoundsMustFitTheType(): void + { + $this->assertTrue($this->object->isValid([ + ['key' => 'counter', 'type' => Database::VAR_INTEGER, 'min' => 0, 'max' => 100], + ['key' => 'total', 'type' => Database::VAR_BIGINT, 'min' => \PHP_INT_MIN, 'max' => \PHP_INT_MAX], + ['key' => 'ratio', 'type' => Database::VAR_FLOAT, 'min' => -1.5, 'max' => 1.5], + ]), $this->object->getDescription()); + + // 9223372036854776000 is what a client that rounds an int64 to a double + // sends back after reading the default bounds off an existing column. PHP + // decodes it as a float, and storing it leaves an integer column bounded + // by 9.223372036854776e+18. + $this->assertFalse($this->object->isValid([ + ['key' => 'counter', 'type' => Database::VAR_INTEGER, 'min' => -9223372036854776000, 'max' => 9223372036854776000], + ])); + $this->assertStringContainsString("Attribute 'counter': min is invalid", $this->object->getDescription()); + + $this->assertFalse($this->object->isValid([ + ['key' => 'counter', 'type' => Database::VAR_INTEGER, 'max' => 9223372036854776000], + ])); + $this->assertStringContainsString("Attribute 'counter': max is invalid", $this->object->getDescription()); + + $this->assertFalse($this->object->isValid([ + ['key' => 'total', 'type' => Database::VAR_BIGINT, 'max' => 9223372036854776000], + ])); + + $this->assertFalse($this->object->isValid([ + ['key' => 'counter', 'type' => Database::VAR_INTEGER, 'max' => 1.5], + ])); + + $this->assertFalse($this->object->isValid([ + ['key' => 'counter', 'type' => Database::VAR_INTEGER, 'max' => '100'], + ])); + + // A float column carries the same bound as a double, which is what it is + $this->assertTrue($this->object->isValid([ + ['key' => 'ratio', 'type' => Database::VAR_FLOAT, 'max' => 9223372036854776000], + ]), $this->object->getDescription()); } public function testResolveKeepsExplicitSize(): void From 40c61dc5cd2a4778dec77e140d0a1d7eaeacc39f Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 1 Sep 2026 15:21:30 +0300 Subject: [PATCH 05/10] Fix comments --- src/Appwrite/Utopia/Database/Attribute.php | 14 ++++++---- .../e2e/Services/Databases/DatabasesBase.php | 7 +++++ .../Database/Validator/AttributesTest.php | 27 +++++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Utopia/Database/Attribute.php b/src/Appwrite/Utopia/Database/Attribute.php index 010e27a7e5..61b3dc1895 100644 --- a/src/Appwrite/Utopia/Database/Attribute.php +++ b/src/Appwrite/Utopia/Database/Attribute.php @@ -22,8 +22,10 @@ class Attribute Database::VAR_TEXT => 65535, Database::VAR_MEDIUMTEXT => 16777215, Database::VAR_LONGTEXT => 2147483647, - // Bytes, the width createBigIntColumn hardcodes + // Bytes, the widths createBigIntColumn and createFloatColumn hardcode. + // Every adapter maps these two types without consulting the size. Database::VAR_BIGINT => 8, + Database::VAR_FLOAT => 0, ]; /** @@ -93,10 +95,12 @@ class Attribute $size = self::FORMAT_SIZES[$format] ?? $size; } - if ($type === Database::VAR_INTEGER && $size < 1) { - // Same width createIntegerColumn picks: the 4 byte column only holds a - // range that fits INT32, and a bound left out means the int64 edge, - // which does not. + if ($type === Database::VAR_INTEGER) { + // Same width createIntegerColumn picks. That endpoint takes no size at + // all, so a size sent inline is ignored rather than left to promise a + // range the column cannot hold: the 4 byte column only holds a range + // that fits INT32, and a bound left out means the int64 edge, which + // does not. $min = $attribute['min'] ?? \PHP_INT_MIN; $max = $attribute['max'] ?? \PHP_INT_MAX; $fitsInt32 = \is_int($min) && \is_int($max) && $min >= -2147483648 && $max <= 2147483647; diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 4ba282050b..39b2bb29ff 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -1255,6 +1255,9 @@ trait DatabasesBase ['key' => 'total', 'type' => Database::VAR_BIGINT], ['key' => 'ratio', 'type' => Database::VAR_FLOAT], ['key' => 'bounded', 'type' => Database::VAR_INTEGER, 'min' => 0, 'max' => 100], + // The numeric endpoints take no size, so this one cannot narrow the + // column below the int64 range the definition still declares + ['key' => 'sized', 'type' => Database::VAR_INTEGER, 'size' => 4], ], ]); @@ -1270,6 +1273,8 @@ trait DatabasesBase $byKey[$attribute['key']] = $attribute; } + $this->assertSame(\PHP_INT_MIN, $byKey['sized']['min']); + $this->assertSame(\PHP_INT_MAX, $byKey['sized']['max']); $this->assertSame(\PHP_INT_MIN, $byKey['counter']['min']); $this->assertSame(\PHP_INT_MAX, $byKey['counter']['max']); $this->assertSame(\PHP_INT_MIN, $byKey['total']['min']); @@ -1288,12 +1293,14 @@ trait DatabasesBase 'data' => [ 'counter' => 5000000000, 'total' => \PHP_INT_MAX, + 'sized' => 5000000000, ], ]); $this->assertEquals(201, $record['headers']['status-code']); $this->assertSame(5000000000, $record['body']['counter']); $this->assertSame(\PHP_INT_MAX, $record['body']['total']); + $this->assertSame(5000000000, $record['body']['sized']); // A value outside a declared bound is still refused $rejected = $this->client->call(Client::METHOD_POST, $this->getRecordUrl($databaseId, $containerId), $headers, [ diff --git a/tests/unit/Utopia/Database/Validator/AttributesTest.php b/tests/unit/Utopia/Database/Validator/AttributesTest.php index 34212a8b0c..7bb46d9fa6 100644 --- a/tests/unit/Utopia/Database/Validator/AttributesTest.php +++ b/tests/unit/Utopia/Database/Validator/AttributesTest.php @@ -160,6 +160,33 @@ final class AttributesTest extends TestCase ['type' => Database::VAR_BIGINT, 'format' => '', 'size' => 8], Attribute::resolve(['key' => 'total', 'type' => Database::VAR_BIGINT]) ); + + $this->assertEquals( + ['type' => Database::VAR_FLOAT, 'format' => '', 'size' => 0], + Attribute::resolve(['key' => 'ratio', 'type' => Database::VAR_FLOAT]) + ); + + // None of the numeric endpoints takes a size. A size sent inline must not + // narrow the column below the range the same definition declares. + $this->assertEquals( + ['type' => Database::VAR_INTEGER, 'format' => '', 'size' => 8], + Attribute::resolve(['key' => 'counter', 'type' => Database::VAR_INTEGER, 'size' => 4]) + ); + + $this->assertEquals( + ['type' => Database::VAR_INTEGER, 'format' => '', 'size' => 4], + Attribute::resolve(['key' => 'counter', 'type' => Database::VAR_INTEGER, 'size' => 8, 'min' => 0, 'max' => 100]) + ); + + $this->assertEquals( + ['type' => Database::VAR_BIGINT, 'format' => '', 'size' => 8], + Attribute::resolve(['key' => 'total', 'type' => Database::VAR_BIGINT, 'size' => 4]) + ); + + $this->assertEquals( + ['type' => Database::VAR_FLOAT, 'format' => '', 'size' => 0], + Attribute::resolve(['key' => 'ratio', 'type' => Database::VAR_FLOAT, 'size' => 4]) + ); } public function testNumericBoundsMustFitTheType(): void From 6f0601c7457b6d7300c46dd20f65cda9cece2daa Mon Sep 17 00:00:00 2001 From: "Luke B. Silver" <22452787+loks0n@users.noreply.github.com> Date: Tue, 1 Sep 2026 18:55:24 +0100 Subject: [PATCH 06/10] Drop the cp into /mnt/code from runtime entrypoints (#13440) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(builds): cap the billed build duration at the build timeout Jobs::duration() measures wall clock from buildStartedAt, which the first log callback stamps — so a build that never streamed a line falls back to the deployment's creation time and measures its whole queue wait. That value is what Usage\Build::publish() bills, at memory x duration x cpus, and it is billed for 'failed' exactly as for 'ready'. The executor backend could not produce this: it measured microtime() around the build's own execution, so queue wait was structurally unbillable. Since builds moved to the jobs-service the mean billed duration of a *failed* build has gone 111s (Jun) -> 157s (Jul) -> 491s (Aug) while successful builds held at ~52s, and failed builds are now 57% of all billed build compute fleet-wide. One production project shows the shape plainly: 2,286 of its 2,311 failed August builds have buildStartedAt NULL, empty buildLogs, "exit code -1", and durations at 904-912s. On s-2vcpu-2gb that is ~1.0 GB-hour billed per build that never ran — 1,869 of its 1,878 billed GB-hours for the month. Clamp to _APP_COMPUTE_BUILD_TIMEOUT, the same ceiling Deployments hands the jobs-service as timeoutSeconds: no job outlives it, so nothing past it can have been build time. Guarded so a 0 or negative value leaves the measurement alone rather than zeroing every build. This is a ceiling, not the whole fix — a starved build still bills the full timeout. Billing 0 when buildStartedAt is NULL, and the build fan-out that starves them, are follow-ups. Co-Authored-By: Claude Opus 5 (1M context) * test(builds): drop the build duration cap test Removed at request; the cap in Jobs::duration() is unchanged. Co-Authored-By: Claude Opus 5 (1M context) * chore(compute): drop the cp into /mnt/code from runtime entrypoints The executor now declares OPEN_RUNTIMES_CODE_PATH on runtime containers (open-runtimes/executor#253), so the start helper extracts the archive straight from the /tmp mount and the copy is dead weight on cold starts. Co-Authored-By: Claude Fable 5 * chore: bump openruntimes/executor to 0.29.0 Ships OPEN_RUNTIMES_CODE_PATH on runtime containers (open-runtimes/executor#253), which the entrypoints now rely on. Co-Authored-By: Claude Fable 5 --------- Co-authored-by: Claude Opus 5 (1M context) --- app/controllers/general.php | 2 +- docker-compose.yml | 2 +- .../Platform/Modules/Functions/Http/Executions/Create.php | 2 +- src/Appwrite/Platform/Workers/Functions.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 96b4b77894..b35b06eded 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -582,7 +582,7 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S $runtimeEntrypoint = match ($version) { 'v2' => '', - default => "cp /tmp/code.* /mnt/code/ && nohup helpers/start.sh \"$startCommand\"", + default => "nohup helpers/start.sh \"$startCommand\"", }; $entrypoint = match ($type) { diff --git a/docker-compose.yml b/docker-compose.yml index c709dc73e5..9d5793dd77 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1621,7 +1621,7 @@ services: max-file: "5" max-size: 10m stop_signal: SIGINT - image: openruntimes/executor:0.25.4 + image: openruntimes/executor:0.29.0 restart: unless-stopped networks: - appwrite diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index a51d5b54f8..6328792e5b 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -429,7 +429,7 @@ class Create extends Base $command = Deployments::startCommand($deployment, $runtime['startCommand']); $source = $deployment->getAttribute('buildPath', ''); - $command = $version === 'v2' ? '' : "cp /tmp/code.* /mnt/code/ && nohup helpers/start.sh \"$command\""; + $command = $version === 'v2' ? '' : "nohup helpers/start.sh \"$command\""; try { $executionResponse = $executor->createExecution( projectId: $project->getId(), diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 97851f2b91..409844ff8c 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -685,7 +685,7 @@ class Functions extends Action $command = Deployments::startCommand($deployment, $runtime['startCommand']); $source = $deployment->getAttribute('buildPath', ''); - $command = $version === 'v2' ? '' : "cp /tmp/code.* /mnt/code/ && nohup helpers/start.sh \"$command\""; + $command = $version === 'v2' ? '' : "nohup helpers/start.sh \"$command\""; try { $executionResponse = $executor->createExecution( projectId: $project->getId(), From ed02ca372a42f39ad522bd44c67bd6ad98adb9fd Mon Sep 17 00:00:00 2001 From: "Luke B. Silver" <22452787+loks0n@users.noreply.github.com> Date: Tue, 1 Sep 2026 22:57:53 +0100 Subject: [PATCH 07/10] chore: bump orchestrator to 1.9.2 (#13444) Co-authored-by: Claude Fable 5 --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9d5793dd77..9623a3eb08 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1667,7 +1667,7 @@ services: # One image carrying every orchestrator control plane. Appwrite drives the # jobs plane today; the per-plane images exist for Kubernetes, where each # scales, fails and gets RBAC on its own. - image: ghcr.io/open-runtimes/orchestrator/orchestrator:1.8.3 + image: ghcr.io/open-runtimes/orchestrator/orchestrator:1.9.2 restart: unless-stopped user: root networks: From fd8f8e41e54f6d97078fbfcc74a0b10b3460ec67 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 2 Sep 2026 06:22:34 +0545 Subject: [PATCH 08/10] test(usage): drop the Build usage unit test Requested in review; the guard is a two-line branch and the layer has no other unit coverage. --- tests/unit/Usage/BuildTest.php | 123 --------------------------------- 1 file changed, 123 deletions(-) delete mode 100644 tests/unit/Usage/BuildTest.php diff --git a/tests/unit/Usage/BuildTest.php b/tests/unit/Usage/BuildTest.php deleted file mode 100644 index 2e8652e478..0000000000 --- a/tests/unit/Usage/BuildTest.php +++ /dev/null @@ -1,123 +0,0 @@ - $deployment - * @return array metric key => value - */ - private function publish(array $deployment): array - { - $publisher = new MockPublisher(); - - Build::publish( - new Context(), - new Document([ - '$id' => 'function', - '$sequence' => '1', - 'buildSpecification' => Specification::S_2VCPU_2GB, - ]), - new Document($deployment), - new Document(['$id' => 'project', '$sequence' => '1']), - new UsagePublisher($publisher, new Queue('usage')), - ); - - $events = $publisher->getEvents('usage'); - $this->assertCount(1, $events); - - $metrics = []; - foreach ($events[0]['metrics'] as $metric) { - $metrics[$metric['key']] = $metric['value']; - } - - return $metrics; - } - - /** - * @param array $overrides - * @return array - */ - private function deployment(array $overrides = []): array - { - return \array_merge([ - '$id' => 'deployment', - '$sequence' => '1', - '$createdAt' => '2026-08-31T10:00:00.000+00:00', - 'resourceType' => 'functions', - 'status' => 'ready', - 'buildDuration' => self::DURATION, - 'buildSize' => self::SIZE, - ], $overrides); - } - - public function testBuildStartedAtStampedBillsMemoryTimesDurationTimesCpus(): void - { - $metrics = $this->publish($this->deployment([ - 'buildStartedAt' => '2026-08-31T10:00:05.000+00:00', - ])); - - $expectedMbSeconds = self::MEMORY * self::DURATION * self::CPUS; - $expectedCompute = self::DURATION * 1000; - - $this->assertSame($expectedMbSeconds, $metrics[METRIC_BUILDS_MB_SECONDS]); - $this->assertSame($expectedMbSeconds, $metrics['functions.builds.mbSeconds']); - $this->assertSame($expectedCompute, $metrics[METRIC_BUILDS_COMPUTE]); - $this->assertSame($expectedCompute, $metrics[METRIC_BUILDS_COMPUTE_SUCCESS]); - $this->assertSame($expectedCompute, $metrics['functions.builds.compute']); - $this->assertSame(1, $metrics[METRIC_BUILDS]); - $this->assertSame(self::SIZE, $metrics[METRIC_BUILDS_STORAGE]); - } - - public function testMissingBuildStartedAtDropsComputeButKeepsCounts(): void - { - $metrics = $this->publish($this->deployment()); - - $this->assertSame(0, $metrics[METRIC_BUILDS_MB_SECONDS]); - $this->assertSame(0, $metrics['functions.builds.mbSeconds']); - $this->assertSame(0, $metrics[METRIC_BUILDS_COMPUTE]); - $this->assertSame(0, $metrics[METRIC_BUILDS_COMPUTE_SUCCESS]); - $this->assertSame(0, $metrics['functions.builds.compute']); - $this->assertSame(0, $metrics['functions.builds.compute.success']); - - $this->assertSame(1, $metrics[METRIC_BUILDS]); - $this->assertSame(1, $metrics[METRIC_BUILDS_SUCCESS]); - $this->assertSame(self::SIZE, $metrics[METRIC_BUILDS_STORAGE]); - } - - public function testNullBuildStartedAtDropsComputeOnFailedBuilds(): void - { - $metrics = $this->publish($this->deployment([ - 'status' => 'failed', - 'buildStartedAt' => null, - ])); - - $this->assertSame(0, $metrics[METRIC_BUILDS_MB_SECONDS]); - $this->assertSame(0, $metrics[METRIC_BUILDS_COMPUTE]); - $this->assertSame(0, $metrics[METRIC_BUILDS_COMPUTE_FAILED]); - $this->assertSame(0, $metrics['functions.builds.compute.failed']); - - $this->assertSame(1, $metrics[METRIC_BUILDS]); - $this->assertSame(1, $metrics[METRIC_BUILDS_FAILED]); - $this->assertSame(self::SIZE, $metrics[METRIC_BUILDS_STORAGE]); - } -} From 65840c6c454d607435ed8fcbba9d38040ebf5069 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 2 Sep 2026 16:19:39 +1200 Subject: [PATCH 09/10] fix(databases): list indexes by database and collection sequence, not id The index list filtered the `indexes` metadata collection on the `databaseId` and `collectionId` strings while every sibling path (attribute list, the cursor lookup three lines below, the create-time limit count, and the worker's delete cascade) keys on `databaseInternalId`/`collectionInternalId`. A recreated database keeps its id but takes a new sequence, so whenever an earlier incarnation's index rows outlive it, the list returns them next to the live ones under the same key. The 109-point GA campaign hit this on r30 PR-95 (rv109a-vdb-ded, dedicated VectorsDB): r28 and r29 had left `idx_embeddings` rows at `processing` (the pool-identity denial fixed in cloud#5573 threw in the worker before createIndex could mark them `failed`, and the same denial stopped the delete-database job before its cascade reached them). r30 created the index cleanly (worker createIndex 0.43s, `available`), the similarity query ranked correctly, yet the list kept reporting the stale `processing` rows and the row failed on "index never left processing" for a third round. PR-93 on the same prefix passed because the attribute list already filters on the sequences. Both metadata collections carry `_key_db_collection` on the sequence pair, so the corrected filter is the indexed one. Co-Authored-By: Claude Fable 5 --- .../Databases/Collections/Indexes/XList.php | 4 +- .../Databases/Http/IndexesListTest.php | 121 ++++++++++++++++++ 2 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 tests/unit/Platform/Modules/Databases/Http/IndexesListTest.php diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php index bf926f158f..fb10254c67 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php @@ -95,8 +95,8 @@ class XList extends Action \array_push( $queries, - Query::equal('databaseId', [$databaseId]), - Query::equal('collectionId', [$collectionId]), + Query::equal('databaseInternalId', [$database->getSequence()]), + Query::equal('collectionInternalId', [$collection->getSequence()]), ); $cursor = Query::getCursorQueries($queries, false); diff --git a/tests/unit/Platform/Modules/Databases/Http/IndexesListTest.php b/tests/unit/Platform/Modules/Databases/Http/IndexesListTest.php new file mode 100644 index 0000000000..d19b742b31 --- /dev/null +++ b/tests/unit/Platform/Modules/Databases/Http/IndexesListTest.php @@ -0,0 +1,121 @@ + self::DATABASE_ID, + '$sequence' => '148569', + 'type' => DATABASE_TYPE_VECTORSDB, + ]); + $collection = new Document([ + '$id' => self::COLLECTION_ID, + '$sequence' => '1', + 'attributes' => [], + 'indexes' => [], + ]); + $records = [ + $this->index('148001', 'processing'), + $this->index('148569', 'available'), + ]; + + $matching = static fn (array $queries): array => \array_values(\array_filter( + $records, + static fn (Document $record): bool => self::satisfies($record, $queries), + )); + + $dbForProject = $this->createStub(Database::class); + $dbForProject->method('getDocument')->willReturnCallback( + static fn (string $collectionId, string $id): Document => match ($collectionId) { + 'databases' => $database, + 'database_148569' => $collection, + default => new Document(), + } + ); + $dbForProject->method('find')->willReturnCallback( + static fn (string $collectionId, array $queries): array => $matching($queries) + ); + $dbForProject->method('count')->willReturnCallback( + static fn (string $collectionId, array $queries): int => \count($matching($queries)) + ); + + $authorization = $this->createStub(Authorization::class); + $authorization->method('skip')->willReturnCallback(static fn (callable $callback): mixed => $callback()); + + $listed = null; + $response = $this->createMock(Response::class); + $response->expects($this->once()) + ->method('dynamic') + ->willReturnCallback(static function (Document $document) use (&$listed): void { + $listed = $document; + }); + + (new XList())->action(self::DATABASE_ID, self::COLLECTION_ID, [], true, $response, $dbForProject, $authorization); + + $this->assertInstanceOf(Document::class, $listed); + $this->assertSame(1, $listed->getAttribute('total'), 'total must count only the live incarnation'); + $this->assertSame( + ['148569_1_idx_embeddings'], + \array_map(static fn (Document $index): string => $index->getId(), $listed->getAttribute('indexes')), + 'a torn-down incarnation of the same database id must not be listed' + ); + } + + private function index(string $databaseSequence, string $status): Document + { + return new Document([ + '$id' => $databaseSequence . '_1_idx_embeddings', + 'key' => 'idx_embeddings', + 'status' => $status, + 'databaseInternalId' => $databaseSequence, + 'databaseId' => self::DATABASE_ID, + 'collectionInternalId' => '1', + 'collectionId' => self::COLLECTION_ID, + 'type' => 'hnsw_cosine', + 'attributes' => ['embeddings'], + ]); + } + + /** + * @param array $queries + */ + private static function satisfies(Document $record, array $queries): bool + { + foreach ($queries as $query) { + if ($query->getMethod() !== Query::TYPE_EQUAL) { + continue; + } + if (!\in_array($record->getAttribute($query->getAttribute()), $query->getValues(), true)) { + return false; + } + } + + return true; + } +} From a38e90dcf4266a5a5c6e342e52c2dd00ba2d79e8 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Wed, 2 Sep 2026 13:50:44 +0530 Subject: [PATCH 10/10] chore: ship the GitLab endpoint variables empty System::getEnv is getenv($name) ?: $default, so a set-but-empty variable falls through to the https://gitlab.com default the config already carries. Shipping the value blank keeps the sample env and a generated install free of a URL that only self-hosted GitLab needs to change, matching the Gitea endpoint entry. The effective default moves into the descriptions. --- .env | 4 ++-- app/config/variables.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.env b/.env index 7fe753006f..6fcb35a315 100644 --- a/.env +++ b/.env @@ -41,7 +41,7 @@ _APP_CONSOLE_GITHUB_APP_ID= _APP_CONSOLE_GITHUB_SECRET= _APP_CONSOLE_GITLAB_APP_ID= _APP_CONSOLE_GITLAB_SECRET= -_APP_CONSOLE_GITLAB_ENDPOINT=https://gitlab.com +_APP_CONSOLE_GITLAB_ENDPOINT= _APP_CONSOLE_BITBUCKET_APP_ID= _APP_CONSOLE_BITBUCKET_SECRET= _APP_CONSOLE_GOOGLE_APP_ID= @@ -182,7 +182,7 @@ _APP_VCS_GITEA_BROWSER_ENDPOINT=http://localhost:9515 _APP_VCS_GITEA_CLIENT_ID= _APP_VCS_GITEA_CLIENT_SECRET= _APP_VCS_GITEA_WEBHOOK_SECRET=gitea-webhook-secret -_APP_VCS_GITLAB_ENDPOINT=https://gitlab.com +_APP_VCS_GITLAB_ENDPOINT= _APP_VCS_GITLAB_CLIENT_ID= _APP_VCS_GITLAB_CLIENT_SECRET= _APP_VCS_GITLAB_WEBHOOK_SECRET= diff --git a/app/config/variables.php b/app/config/variables.php index 2580d0046c..4b69212e75 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -297,9 +297,9 @@ return [ ], [ 'name' => '_APP_CONSOLE_GITLAB_ENDPOINT', - 'description' => 'URL of the GitLab instance used for signing in to the Appwrite console, for self-hosted GitLab. This is separate from _APP_VCS_GITLAB_ENDPOINT, which powers repository integration rather than console sign-in.', + 'description' => 'URL of the GitLab instance used for signing in to the Appwrite console, for self-hosted GitLab. Defaults to https://gitlab.com when unset. This is separate from _APP_VCS_GITLAB_ENDPOINT, which powers repository integration rather than console sign-in.', 'introduction' => '2.0.0', - 'default' => 'https://gitlab.com', + 'default' => '', 'required' => false, 'question' => '', 'filter' => '' @@ -1583,9 +1583,9 @@ return [ ], [ 'name' => '_APP_VCS_GITLAB_ENDPOINT', - 'description' => 'URL of your self-hosted GitLab instance, reachable from the Appwrite server and the browser.', + 'description' => 'URL of your self-hosted GitLab instance, reachable from the Appwrite server and the browser. Defaults to https://gitlab.com when unset.', 'introduction' => '2.0.0', - 'default' => 'https://gitlab.com', + 'default' => '', 'required' => false, 'question' => '', 'filter' => ''