From 487249c41329257458230146504118a7f48b4351 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 10 Jun 2026 00:59:01 +0400 Subject: [PATCH 01/17] Add node modules cache key for builds --- docker-compose.yml | 7 +- .../Modules/Functions/Workers/Builds.php | 71 ++++++++++++++++++- src/Executor/Executor.php | 6 +- 3 files changed, 77 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 7d3f6bdc5f..0e61c9b8b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1218,11 +1218,11 @@ services: - appwrite openruntimes-executor: - container_name: openruntimes-executor + container_name: exc1 hostname: exc1 <<: *x-logging stop_signal: SIGINT - image: openruntimes/executor:0.11.4 + image: openruntimes/executor:0.24.0 restart: unless-stopped networks: - appwrite @@ -1236,6 +1236,8 @@ services: # It's not possible to share mount file between 2 containers without host mount (copying is too slow) - /tmp:/tmp:rw environment: + - OPR_EXECUTOR_CONNECTION_STORAGE=local://localhost + - OPR_EXECUTOR_CONNECTION_BUILD_CACHE_STORAGE= - OPR_EXECUTOR_IMAGE_PULL=enabled - OPR_EXECUTOR_INACTIVE_TRESHOLD=$_APP_COMPUTE_INACTIVE_THRESHOLD - OPR_EXECUTOR_MAINTENANCE_INTERVAL=$_APP_COMPUTE_MAINTENANCE_INTERVAL @@ -1494,3 +1496,4 @@ volumes: appwrite-builds: appwrite-config: appwrite-models: + openruntimes-node-modules-cache: diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 92e00cd4e6..760e926a21 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -679,6 +679,14 @@ class Builds extends Action deployment: $deployment ); + $cacheKey = $this->getNodeModulesCacheKey($project, $resource, $runtime, $version, $command); + + Span::add('build.node_modules_cache.enabled', $cacheKey !== ''); + Span::add('build.node_modules_cache.key', $cacheKey); + + $cacheDebugLogs = $this->getNodeModulesCacheDebugLog($cacheKey, $runtime, $version, $command, $source); + $deployment = $this->appendBuildLog($dbForProject, $queueForRealtime, $deployment, $cacheDebugLogs); + $response = null; $err = null; @@ -692,7 +700,7 @@ class Builds extends Action $span = Span::current(); Co::join([ - Co\go(function () use ($executor, &$response, $project, $deployment, $source, $resource, $runtime, $vars, $command, $cpus, $memory, $timeout, &$err, $version, $span) { + Co\go(function () use ($executor, &$response, $project, $deployment, $source, $resource, $runtime, $vars, $command, $cacheKey, $cpus, $memory, $timeout, &$err, $version, $span) { try { if ($version === 'v2') { $command = 'tar -zxf /tmp/code.tar.gz -C /usr/code && cd /usr/local/src/ && ./build.sh'; @@ -737,7 +745,8 @@ class Builds extends Action destination: APP_STORAGE_BUILDS . "/app-{$project->getId()}", variables: $vars, command: $command, - outputDirectory: $outputDirectory ?? '' + outputDirectory: $outputDirectory ?? '', + cacheKey: $cacheKey ); } catch (ExecutorTimeout $error) { @@ -888,7 +897,7 @@ class Builds extends Action $logs = $logsBefore . $logsAfter; } - $deployment->setAttribute('buildLogs', $logs); + $deployment->setAttribute('buildLogs', $cacheDebugLogs . $logs); $adapter = null; if ($resource->getCollection() === 'sites' && ! empty($detectionLogs)) { @@ -1342,6 +1351,62 @@ class Builds extends Action return ''; } + protected function getNodeModulesCacheKey(Document $project, Document $resource, array $runtime, string $version, string $command): string + { + if ($version !== 'v5' || $command === '' || $command === '0') { + return ''; + } + + $hashContext = [ + 'version' => 'v1', + 'projectId' => $project->getId(), + 'resourceType' => $resource->getCollection(), + 'resourceId' => $resource->getId(), + 'runtime' => $runtime['image'] ?? '', + ]; + + return \substr(\hash('sha256', \json_encode($hashContext, JSON_THROW_ON_ERROR)), 0, 48); + } + + protected function getNodeModulesCacheDebugLog(string $cacheKey, array $runtime, string $version, string $command, string $source): string + { + $date = \date('H:i:s'); + $runtimeKey = $runtime['key'] ?? ''; + $prefix = "\033[90m[$date] \033[90m[\033[0mappwrite\033[90m]\033[36m"; + + if ($cacheKey !== '') { + return $prefix . " build cache requested. key={$cacheKey} source={$source} \033[0m\n"; + } + + $reason = match (true) { + $version !== 'v5' => 'runtime version is not v5', + $command === '' || $command === '0' => 'build command is empty', + default => 'cache key unavailable', + }; + + return $prefix . " build cache not requested. reason={$reason} runtime={$runtimeKey} version={$version} source={$source} \033[0m\n"; + } + + protected function appendBuildLog(Database $dbForProject, Realtime $queueForRealtime, Document $deployment, string $log): Document + { + if ($log === '') { + return $deployment; + } + + $logs = $deployment->getAttribute('buildLogs', '') . $log; + $deployment->setAttribute('buildLogs', $logs); + + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), new Document([ + 'buildLogs' => $logs, + ])); + + $queueForRealtime + ->setPayload($deployment->getArrayCopy()) + ->trigger(); + + return $deployment; + } + /** * @throws Structure * @throws \Utopia\Database\Exception diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index c570970732..53c86f1287 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -71,7 +71,8 @@ class Executor array $variables = [], ?string $command = null, string $outputDirectory = '', - string $runtimeEntrypoint = '' + string $runtimeEntrypoint = '', + string $cacheKey = '' ) { $runtimeId = "$projectId-$deploymentId-build"; $route = "/runtimes"; @@ -95,7 +96,8 @@ class Executor 'version' => $version, 'timeout' => $timeout, 'outputDirectory' => $outputDirectory, - 'runtimeEntrypoint' => $runtimeEntrypoint + 'runtimeEntrypoint' => $runtimeEntrypoint, + 'cacheKey' => $cacheKey ]; From 241602d9e1edad71d89c89337dd66fa7c01a8a84 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 10 Jun 2026 02:16:10 +0400 Subject: [PATCH 02/17] Update E2E SitesBase to use exc1 container --- tests/e2e/Services/Sites/SitesBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 7ce6772c90..21d3a4ff66 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -72,7 +72,7 @@ trait SitesBase throw new Critical('Deployment failed: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); } - Console::execute("docker inspect openruntimes-executor --format='{{.State.ExitCode}}'", '', $this->stdout, $this->stderr); + Console::execute("docker inspect exc1 --format='{{.State.ExitCode}}'", '', $this->stdout, $this->stderr); if (\trim($this->stdout) !== '0') { $msg = 'Executor has a problem: ' . $this->stderr . ' (' . $this->stdout . '), current status: '; From 1af1da01e203aadb152b76f1b08aaa972ec3bf68 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 10 Jun 2026 02:18:02 +0400 Subject: [PATCH 03/17] Update E2E SitesBase executor logs lookup --- tests/e2e/Services/Sites/SitesBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 21d3a4ff66..f93a534bc4 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -76,7 +76,7 @@ trait SitesBase if (\trim($this->stdout) !== '0') { $msg = 'Executor has a problem: ' . $this->stderr . ' (' . $this->stdout . '), current status: '; - Console::execute("docker compose logs openruntimes-executor", '', $this->stdout, $this->stderr); + Console::execute("docker logs exc1", '', $this->stdout, $this->stderr); $msg .= $this->stdout . ' (' . $this->stderr . ')'; throw new Critical($msg . json_encode($deployment['body'], JSON_PRETTY_PRINT)); From 57269867daf25cf49e2836f6111619dff9445ff5 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 10 Jun 2026 02:36:06 +0400 Subject: [PATCH 04/17] Update install compose executor config --- app/views/install/compose.phtml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 6ce1fb5cea..d401db9ce0 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -983,12 +983,12 @@ $hostPath = rtrim($this->getParam('hostPath', ''), '/'); - appwrite openruntimes-executor: - container_name: openruntimes-executor + container_name: exc1 hostname: exc1 <<: *x-logging restart: unless-stopped stop_signal: SIGINT - image: openruntimes/executor:0.11.4 + image: openruntimes/executor:0.24.0 networks: - appwrite - runtimes @@ -1001,6 +1001,8 @@ $hostPath = rtrim($this->getParam('hostPath', ''), '/'); # It's not possible to share mount file between 2 containers without host mount (copying is too slow) - /tmp:/tmp:rw environment: + - OPR_EXECUTOR_CONNECTION_STORAGE=local://localhost + - OPR_EXECUTOR_CONNECTION_BUILD_CACHE_STORAGE= - OPR_EXECUTOR_INACTIVE_TRESHOLD=$_APP_COMPUTE_INACTIVE_THRESHOLD - OPR_EXECUTOR_MAINTENANCE_INTERVAL=$_APP_COMPUTE_MAINTENANCE_INTERVAL - OPR_EXECUTOR_NETWORK=$_APP_COMPUTE_RUNTIMES_NETWORK @@ -1209,3 +1211,4 @@ volumes: appwrite-sites: appwrite-builds: appwrite-config: + openruntimes-node-modules-cache: From 25aa717712aaaf6a9ba0970116cec7f42203e24a Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 11 Jun 2026 14:33:11 +0530 Subject: [PATCH 05/17] added null checks --- app/realtime.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/realtime.php b/app/realtime.php index 4d638818f5..1061cd6b0d 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -1281,7 +1281,12 @@ $server->onClose(function (int $connection) use ($realtime, $stats, $register, $ try { if (array_key_exists($connection, $realtime->connections)) { - $stats->decr($realtime->connections[$connection]['projectId'], 'connectionsTotal'); + // A connection can exist without a stored projectId (e.g. it was torn down + // before subscribing, or only carries an authorization entry), so guard every + // project-scoped bookkeeping call. $projectId is read defensively above. + if (!empty($projectId)) { + $stats->decr($projectId, 'connectionsTotal'); + } $register->get('telemetry.connectionCounter')->add(-1); $register->get('telemetry.workerClientCounter')->add(-1, $register->get('telemetry.workerAttributes')); $subscriptionsBeforeClose = \count($realtime->getSubscriptionMetadata($connection)); @@ -1289,12 +1294,12 @@ $server->onClose(function (int $connection) use ($realtime, $stats, $register, $ $register->get('telemetry.workerSubscriptionCounter')->add(-$subscriptionsBeforeClose, $register->get('telemetry.workerAttributes')); } - $projectId = $realtime->connections[$connection]['projectId']; /** @var array $presencesById */ $presencesById = $realtime->connections[$connection]['presences'] ?? []; if ( !empty($presencesById) + && !empty($projectId) && $projectId !== 'console' ) { go(function () use ($presencesById, $projectId, $userId, $container, $presenceState): void { @@ -1385,9 +1390,11 @@ $server->onClose(function (int $connection) use ($realtime, $stats, $register, $ }); } - triggerStats([ - METRIC_REALTIME_CONNECTIONS => -1, - ], $projectId); + if (!empty($projectId)) { + triggerStats([ + METRIC_REALTIME_CONNECTIONS => -1, + ], $projectId); + } } $success = true; } catch (\Throwable $th) { From 3e5e3b6c628218b8053264f63b1dd18d0c61fbbf Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 11 Jun 2026 16:19:08 +0530 Subject: [PATCH 06/17] Refactor realtime connection handling to sanitize user data and improve telemetry metrics --- app/realtime.php | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/app/realtime.php b/app/realtime.php index 1061cd6b0d..191d2419b5 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -915,7 +915,7 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, $channels = Realtime::convertChannels($request->getQuery('channels', []), $user->getId()); $channelCount = \count($channels); - $updateStats = static function (string $projectId, ?string $teamId, string $payloadJson) use ($register, $stats): void { + $updateStats = static function (string $projectId, ?string $teamId) use ($register, $stats): void { $register->get('telemetry.connectionCounter')->add(1); $register->get('telemetry.workerClientCounter')->add(1, $register->get('telemetry.workerAttributes')); $register->get('telemetry.connectionCreatedCounter')->add(1); @@ -929,7 +929,6 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, triggerStats([ METRIC_REALTIME_CONNECTIONS => 1, - METRIC_REALTIME_OUTBOUND => \strlen($payloadJson), ], $projectId); }; @@ -950,9 +949,12 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, $realtime->subscribe($project->getId(), $connection, '', $roles, [], [], $user->getId()); $realtime->connections[$connection]['authorization'] = $authorization; + $updateStats($project->getId(), $project->getAttribute('teamId')); $server->send([$connection], $connectedPayloadJson); $outboundBytes += \strlen($connectedPayloadJson); - $updateStats($project->getId(), $project->getAttribute('teamId'), $connectedPayloadJson); + triggerStats([ + METRIC_REALTIME_OUTBOUND => \strlen($connectedPayloadJson), + ], $project->getId()); $subscriptionMode = 'message'; $success = true; return; @@ -970,6 +972,8 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, throw new Exception(Exception::REALTIME_POLICY_VIOLATION, $e->getMessage()); } + $sanitizedUser = empty($user->getId()) ? null : $response->output($user, Response::MODEL_ACCOUNT); + $mapping = []; foreach ($subscriptions as $index => $subscription) { $subscriptionId = ID::unique(); @@ -986,27 +990,29 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, $mapping[$index] = $subscriptionId; } + + $realtime->connections[$connection]['authorization'] = $authorization; + $updateStats($project->getId(), $project->getAttribute('teamId')); + $subscriptionCount = \count($subscriptions); if (!empty($subscriptions)) { $register->get('telemetry.workerSubscriptionCounter')->add(\count($subscriptions), $register->get('telemetry.workerAttributes')); } - $realtime->connections[$connection]['authorization'] = $authorization; - - $user = empty($user->getId()) ? null : $response->output($user, Response::MODEL_ACCOUNT); - $connectedPayloadJson = json_encode([ 'type' => 'connected', 'data' => [ 'channels' => $names, 'subscriptions' => $mapping, - 'user' => $user + 'user' => $sanitizedUser ] ]); $server->send([$connection], $connectedPayloadJson); $outboundBytes += \strlen($connectedPayloadJson); - $updateStats($project->getId(), $project->getAttribute('teamId'), $connectedPayloadJson); + triggerStats([ + METRIC_REALTIME_OUTBOUND => \strlen($connectedPayloadJson), + ], $project->getId()); $success = true; } catch (Throwable $th) { @@ -1281,14 +1287,16 @@ $server->onClose(function (int $connection) use ($realtime, $stats, $register, $ try { if (array_key_exists($connection, $realtime->connections)) { - // A connection can exist without a stored projectId (e.g. it was torn down - // before subscribing, or only carries an authorization entry), so guard every - // project-scoped bookkeeping call. $projectId is read defensively above. + // These decrements are symmetric with the increments in updateStats (onOpen), + // which run when the connection enters $realtime->connections — the same gate as the + // array_key_exists check above. The connectionsTotal stat is keyed by project, so it's + // additionally guarded: a connection can exist without a stored projectId (e.g. only an + // authorization entry left after an orphaning re-subscribe). + $register->get('telemetry.connectionCounter')->add(-1); + $register->get('telemetry.workerClientCounter')->add(-1, $register->get('telemetry.workerAttributes')); if (!empty($projectId)) { $stats->decr($projectId, 'connectionsTotal'); } - $register->get('telemetry.connectionCounter')->add(-1); - $register->get('telemetry.workerClientCounter')->add(-1, $register->get('telemetry.workerAttributes')); $subscriptionsBeforeClose = \count($realtime->getSubscriptionMetadata($connection)); if ($subscriptionsBeforeClose > 0) { $register->get('telemetry.workerSubscriptionCounter')->add(-$subscriptionsBeforeClose, $register->get('telemetry.workerAttributes')); From 53b09dc51686d0900eb06a80566aee9e61804ab2 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 11 Jun 2026 17:00:35 +0530 Subject: [PATCH 07/17] Enhance subscription logic to handle empty meta and improve connection management --- app/realtime.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/realtime.php b/app/realtime.php index 191d2419b5..8fb33723a4 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -699,8 +699,15 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, ); } + // Restore authorization after subscribe - if ($authorization !== null) { + // meta can be empty as well as the channels are not required query param to connect + // channels and queries can be sent via message later on + // so if meta is empty we are not subscribing above to the projectId + if (!isset($realtime->connections[$connection])) { + $realtime->subscribe($projectId, $connection, '', $roles, [], [], $userId); + } + if ($authorization !== null && isset($realtime->connections[$connection])) { $realtime->connections[$connection]['authorization'] = $authorization; } From 8791964e2b83ca234f2c5eeb86efcaaed5ff530b Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 11 Jun 2026 18:10:29 +0400 Subject: [PATCH 08/17] Remove node modules cache debug build logs --- .../Modules/Functions/Workers/Builds.php | 44 +------------------ 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index c945fedb6a..69c64e4df9 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -673,9 +673,6 @@ class Builds extends Action Span::add('build.node_modules_cache.enabled', $cacheKey !== ''); Span::add('build.node_modules_cache.key', $cacheKey); - $cacheDebugLogs = $this->getNodeModulesCacheDebugLog($cacheKey, $runtime, $version, $command, $source); - $deployment = $this->appendBuildLog($dbForProject, $queueForRealtime, $deployment, $cacheDebugLogs); - $response = null; $err = null; @@ -866,7 +863,7 @@ class Builds extends Action ['logs' => $logs, 'detectionLogs' => $detectionLogs] = $this->splitSiteDetectionLogs($logs); - $deployment->setAttribute('buildLogs', $cacheDebugLogs . $logs); + $deployment->setAttribute('buildLogs', $logs); $adapter = null; if ($resource->getCollection() === 'sites' && ! empty($detectionLogs)) { @@ -1323,45 +1320,6 @@ class Builds extends Action return \substr(\hash('sha256', \json_encode($hashContext, JSON_THROW_ON_ERROR)), 0, 48); } - protected function getNodeModulesCacheDebugLog(string $cacheKey, array $runtime, string $version, string $command, string $source): string - { - $date = \date('H:i:s'); - $runtimeKey = $runtime['key'] ?? ''; - $prefix = "\033[90m[$date] \033[90m[\033[0mappwrite\033[90m]\033[36m"; - - if ($cacheKey !== '') { - return $prefix . " build cache requested. key={$cacheKey} source={$source} \033[0m\n"; - } - - $reason = match (true) { - $version !== 'v5' => 'runtime version is not v5', - $command === '' || $command === '0' => 'build command is empty', - default => 'cache key unavailable', - }; - - return $prefix . " build cache not requested. reason={$reason} runtime={$runtimeKey} version={$version} source={$source} \033[0m\n"; - } - - protected function appendBuildLog(Database $dbForProject, Realtime $queueForRealtime, Document $deployment, string $log): Document - { - if ($log === '') { - return $deployment; - } - - $logs = $deployment->getAttribute('buildLogs', '') . $log; - $deployment->setAttribute('buildLogs', $logs); - - $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), new Document([ - 'buildLogs' => $logs, - ])); - - $queueForRealtime - ->setPayload($deployment->getArrayCopy()) - ->trigger(); - - return $deployment; - } - protected function prepareSiteBuildCommand(string $command, string $outputDirectory): string { $listFilesCommand = 'echo "{APPWRITE_DETECTION_SEPARATOR_START}" && cd /usr/local/build'; From 0197f4576df6c29fd3fa0e2e6e4f4b7269bd9d5b Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 12 Jun 2026 13:08:05 +0530 Subject: [PATCH 09/17] bug: added the message increment in the message path as well --- app/realtime.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/realtime.php b/app/realtime.php index 8fb33723a4..39bdf103fe 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -1222,7 +1222,10 @@ $server->onMessage(function (int $connection, string $message) use ($container, $outboundBytes += $bytes; if ($project !== null && !$project->isEmpty()) { - triggerStats([METRIC_REALTIME_OUTBOUND => $bytes], $project->getId()); + triggerStats([ + METRIC_REALTIME_OUTBOUND => $bytes, + METRIC_REALTIME_CONNECTIONS_MESSAGES_SENT => 1, + ], $project->getId()); } } From a553db94b55839659000eeb2160a249c97362f78 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 12 Jun 2026 15:14:34 +0530 Subject: [PATCH 10/17] fix: preserve VCS repository record when providerRepositoryId is omitted in updateFunction/updateSite --- .../Functions/Http/Functions/Update.php | 10 ++++ .../Modules/Sites/Http/Sites/Update.php | 10 ++++ .../Functions/FunctionsCustomServerTest.php | 55 +++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index 5fbe010f05..7b8e16d083 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -182,6 +182,16 @@ class Update extends Base $isConnected = !empty($function->getAttribute('providerRepositoryId', '')); + // If providerRepositoryId is omitted (null) and function is already connected, preserve existing VCS values + if ($isConnected && $providerRepositoryId === null) { + $providerRepositoryId = $function->getAttribute('providerRepositoryId', ''); + $installationId = $function->getAttribute('installationId', ''); + $providerBranch = $providerBranch ?: $function->getAttribute('providerBranch', ''); + $providerRootDirectory = $providerRootDirectory ?: $function->getAttribute('providerRootDirectory', ''); + $repositoryId = $function->getAttribute('repositoryId', ''); + $repositoryInternalId = $function->getAttribute('repositoryInternalId', ''); + } + // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 6cb1905550..38374f036b 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -182,6 +182,16 @@ class Update extends Base $isConnected = !empty($site->getAttribute('providerRepositoryId', '')); + // If providerRepositoryId is omitted (null) and site is already connected, preserve existing VCS values + if ($isConnected && $providerRepositoryId === null) { + $providerRepositoryId = $site->getAttribute('providerRepositoryId', ''); + $installationId = $site->getAttribute('installationId', ''); + $providerBranch = $providerBranch ?: $site->getAttribute('providerBranch', ''); + $providerRootDirectory = $providerRootDirectory ?: $site->getAttribute('providerRootDirectory', ''); + $repositoryId = $site->getAttribute('repositoryId', ''); + $repositoryInternalId = $site->getAttribute('repositoryInternalId', ''); + } + // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 726e73931c..0b6691ba7c 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -3311,4 +3311,59 @@ final class FunctionsCustomServerTest extends Scope $this->cleanupFunction($functionId); } } + + /** + * Regression test for: omitting providerRepositoryId in updateFunction must not silently + * clear the VCS connection while leaving the platform repository record intact. + * + * Before the fix, calling updateFunction without providerRepositoryId on a connected + * function would write null/empty to the function document (making it look disconnected + * in the console) but would NOT delete the repositories record in the platform DB, so + * GitHub webhooks would keep finding the record and keep triggering builds. + * + * This test covers the API-observable side: + * 1. Omitting providerRepositoryId on a non-connected function keeps the field empty. + * 2. Passing providerRepositoryId="" (explicit disconnect) on a non-connected function + * is a no-op and does not cause errors. + * + * The full scenario (connected function + omit providerRepositoryId) requires a live + * VCS installation and is validated in VCSCustomServerTest. + */ + public function testUpdateFunctionPreservesVcsOnOmittedProviderRepositoryId(): void + { + $functionId = $this->setupFunction([ + 'functionId' => ID::unique(), + 'name' => 'VCS Preserve Test', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', + 'commands' => '', + ]); + + // 1. Update without providerRepositoryId — field should stay empty, no error + $response = $this->updateFunction($functionId, [ + 'name' => 'VCS Preserve Test', + 'runtime' => 'node-22', + ]); + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame('', $response['body']['providerRepositoryId']); + $this->assertSame('', $response['body']['installationId']); + $this->assertSame('', $response['body']['providerBranch']); + + // 2. Update with providerRepositoryId="" explicit on non-connected function — no-op, no error + $response = $this->updateFunction($functionId, [ + 'name' => 'VCS Preserve Test', + 'runtime' => 'node-22', + 'providerRepositoryId' => '', + ]); + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame('', $response['body']['providerRepositoryId']); + + // 3. Verify GET also reflects the unchanged state + $response = $this->getFunction($functionId); + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame('', $response['body']['providerRepositoryId']); + $this->assertSame('', $response['body']['installationId']); + + $this->cleanupFunction($functionId); + } } From 6e581014054103b94a043aae7849dcbdd34fe0e8 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 12 Jun 2026 15:15:25 +0530 Subject: [PATCH 11/17] chore: trim comments --- .../Modules/Functions/Http/Functions/Update.php | 2 +- .../Modules/Sites/Http/Sites/Update.php | 2 +- .../Functions/FunctionsCustomServerTest.php | 17 ++--------------- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index 7b8e16d083..d1b5d21728 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -182,7 +182,7 @@ class Update extends Base $isConnected = !empty($function->getAttribute('providerRepositoryId', '')); - // If providerRepositoryId is omitted (null) and function is already connected, preserve existing VCS values + // Omitted providerRepositoryId (null) on a connected function — preserve existing VCS values if ($isConnected && $providerRepositoryId === null) { $providerRepositoryId = $function->getAttribute('providerRepositoryId', ''); $installationId = $function->getAttribute('installationId', ''); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 38374f036b..0e22fe8343 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -182,7 +182,7 @@ class Update extends Base $isConnected = !empty($site->getAttribute('providerRepositoryId', '')); - // If providerRepositoryId is omitted (null) and site is already connected, preserve existing VCS values + // Omitted providerRepositoryId (null) on a connected site — preserve existing VCS values if ($isConnected && $providerRepositoryId === null) { $providerRepositoryId = $site->getAttribute('providerRepositoryId', ''); $installationId = $site->getAttribute('installationId', ''); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 0b6691ba7c..bfa8396615 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -3313,21 +3313,8 @@ final class FunctionsCustomServerTest extends Scope } /** - * Regression test for: omitting providerRepositoryId in updateFunction must not silently - * clear the VCS connection while leaving the platform repository record intact. - * - * Before the fix, calling updateFunction without providerRepositoryId on a connected - * function would write null/empty to the function document (making it look disconnected - * in the console) but would NOT delete the repositories record in the platform DB, so - * GitHub webhooks would keep finding the record and keep triggering builds. - * - * This test covers the API-observable side: - * 1. Omitting providerRepositoryId on a non-connected function keeps the field empty. - * 2. Passing providerRepositoryId="" (explicit disconnect) on a non-connected function - * is a no-op and does not cause errors. - * - * The full scenario (connected function + omit providerRepositoryId) requires a live - * VCS installation and is validated in VCSCustomServerTest. + * Regression: omitting providerRepositoryId must not clear VCS fields or leave + * the platform repository record orphaned (causing ghost GitHub builds). */ public function testUpdateFunctionPreservesVcsOnOmittedProviderRepositoryId(): void { From 7bff6e98825c573f2f944c7978cce7d141914832 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 12 Jun 2026 15:19:52 +0530 Subject: [PATCH 12/17] fix: re-fetch installation document after preserving VCS values, remove untestable test --- .../Functions/Http/Functions/Update.php | 1 + .../Modules/Sites/Http/Sites/Update.php | 1 + .../Functions/FunctionsCustomServerTest.php | 41 ------------------- 3 files changed, 2 insertions(+), 41 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index d1b5d21728..fd89651800 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -190,6 +190,7 @@ class Update extends Base $providerRootDirectory = $providerRootDirectory ?: $function->getAttribute('providerRootDirectory', ''); $repositoryId = $function->getAttribute('repositoryId', ''); $repositoryInternalId = $function->getAttribute('repositoryInternalId', ''); + $installation = $dbForPlatform->getDocument('installations', $installationId); } // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 0e22fe8343..be585ffdab 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -190,6 +190,7 @@ class Update extends Base $providerRootDirectory = $providerRootDirectory ?: $site->getAttribute('providerRootDirectory', ''); $repositoryId = $site->getAttribute('repositoryId', ''); $repositoryInternalId = $site->getAttribute('repositoryInternalId', ''); + $installation = $dbForPlatform->getDocument('installations', $installationId); } // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index bfa8396615..1aba466944 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -3312,45 +3312,4 @@ final class FunctionsCustomServerTest extends Scope } } - /** - * Regression: omitting providerRepositoryId must not clear VCS fields or leave - * the platform repository record orphaned (causing ghost GitHub builds). - */ - public function testUpdateFunctionPreservesVcsOnOmittedProviderRepositoryId(): void - { - $functionId = $this->setupFunction([ - 'functionId' => ID::unique(), - 'name' => 'VCS Preserve Test', - 'runtime' => 'node-22', - 'entrypoint' => 'index.js', - 'commands' => '', - ]); - - // 1. Update without providerRepositoryId — field should stay empty, no error - $response = $this->updateFunction($functionId, [ - 'name' => 'VCS Preserve Test', - 'runtime' => 'node-22', - ]); - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('', $response['body']['providerRepositoryId']); - $this->assertSame('', $response['body']['installationId']); - $this->assertSame('', $response['body']['providerBranch']); - - // 2. Update with providerRepositoryId="" explicit on non-connected function — no-op, no error - $response = $this->updateFunction($functionId, [ - 'name' => 'VCS Preserve Test', - 'runtime' => 'node-22', - 'providerRepositoryId' => '', - ]); - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('', $response['body']['providerRepositoryId']); - - // 3. Verify GET also reflects the unchanged state - $response = $this->getFunction($functionId); - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('', $response['body']['providerRepositoryId']); - $this->assertSame('', $response['body']['installationId']); - - $this->cleanupFunction($functionId); - } } From fb336e2c04128fc7a988aab95cf00479433bbb42 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 12 Jun 2026 15:22:30 +0530 Subject: [PATCH 13/17] test: add real VCS e2e test for omitted providerRepositoryId preserving connection --- .../e2e/Services/VCS/VCSConsoleClientTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index 513d2c1824..2d7e71ab28 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -653,6 +653,27 @@ final class VCSConsoleClientTest extends Scope $this->assertEquals('main', $function['body']['providerBranch']); } + public function testUpdateFunctionOmitProviderRepositoryIdPreservesVcs(): void + { + $data = $this->setupFunctionUsingVCS(); + + // Omit providerRepositoryId entirely — should preserve VCS connection, not clear it + $function = $this->client->call(Client::METHOD_PUT, '/functions/' . $data['functionId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'name' => 'Test', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'timeout' => 10, + ]); + + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertNotEmpty($function['body']['providerRepositoryId']); + $this->assertNotEmpty($function['body']['installationId']); + $this->assertNotEmpty($function['body']['providerBranch']); + } + public function testCreateRepository(): void { $installationId = $this->setupInstallation(); From 802c47c0e7945152317b1c52b3d73d68053fa30f Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 12 Jun 2026 15:24:25 +0530 Subject: [PATCH 14/17] test: add real VCS e2e test for sites omitted providerRepositoryId preserving connection --- .../e2e/Services/VCS/VCSConsoleClientTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index 2d7e71ab28..041f825cee 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -674,6 +674,47 @@ final class VCSConsoleClientTest extends Scope $this->assertNotEmpty($function['body']['providerBranch']); } + public function testUpdateSiteOmitProviderRepositoryIdPreservesVcs(): void + { + $installationId = $this->setupInstallation(); + + $site = $this->client->call(Client::METHOD_POST, '/sites', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'siteId' => ID::unique(), + 'name' => 'Test Site VCS', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId3, + 'providerBranch' => 'main', + ]); + + $this->assertEquals(201, $site['headers']['status-code']); + $siteId = $site['body']['$id']; + + // Omit providerRepositoryId — should preserve VCS connection, not clear it + $updated = $this->client->call(Client::METHOD_PUT, '/sites/' . $siteId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'name' => 'Test Site VCS', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + ]); + + $this->assertEquals(200, $updated['headers']['status-code']); + $this->assertNotEmpty($updated['body']['providerRepositoryId']); + $this->assertNotEmpty($updated['body']['installationId']); + $this->assertNotEmpty($updated['body']['providerBranch']); + + $this->client->call(Client::METHOD_DELETE, '/sites/' . $siteId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + } + public function testCreateRepository(): void { $installationId = $this->setupInstallation(); From 81a20a514578ffa8eb7c691592718c62f232938e Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 12 Jun 2026 15:49:56 +0530 Subject: [PATCH 15/17] Update utopia-php/database to 5.9.2 (#12587) * (test): use utopia-php/database write-conflict retry branch for CI validation * (chore): update utopia-php/database to 5.9.2 * (test): fix flaky executor health check in Sites deployment polling The docker inspect health check in waitDeploymentReady treated empty stdout as an executor crash. When proc_open transiently fails under paratest load, Console::execute returns empty stdout/stderr, which threw a Critical and aborted the retry loop while the deployment was still building. Only throw when the inspect command itself succeeded and reported a non-zero exit code. --- composer.lock | 12 ++++++------ tests/e2e/Services/Sites/SitesBase.php | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index d886034bd3..703189e5f9 100644 --- a/composer.lock +++ b/composer.lock @@ -3682,16 +3682,16 @@ }, { "name": "utopia-php/database", - "version": "5.9.0", + "version": "5.9.2", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "477bae83e27631f78c159f45b0441c0c7dc69050" + "reference": "698952455dd645ff41057621c90a4cea977fb1bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/477bae83e27631f78c159f45b0441c0c7dc69050", - "reference": "477bae83e27631f78c159f45b0441c0c7dc69050", + "url": "https://api.github.com/repos/utopia-php/database/zipball/698952455dd645ff41057621c90a4cea977fb1bf", + "reference": "698952455dd645ff41057621c90a4cea977fb1bf", "shasum": "" }, "require": { @@ -3736,9 +3736,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/5.9.0" + "source": "https://github.com/utopia-php/database/tree/5.9.2" }, - "time": "2026-05-17T15:57:21+00:00" + "time": "2026-06-12T08:33:14+00:00" }, { "name": "utopia-php/detector", diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 7ce6772c90..1f27ff45de 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -72,8 +72,8 @@ trait SitesBase throw new Critical('Deployment failed: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); } - Console::execute("docker inspect openruntimes-executor --format='{{.State.ExitCode}}'", '', $this->stdout, $this->stderr); - if (\trim($this->stdout) !== '0') { + $code = Console::execute("docker inspect openruntimes-executor --format='{{.State.ExitCode}}'", '', $this->stdout, $this->stderr); + if ($code === 0 && \trim($this->stdout) !== '' && \trim($this->stdout) !== '0') { $msg = 'Executor has a problem: ' . $this->stderr . ' (' . $this->stdout . '), current status: '; Console::execute("docker compose logs openruntimes-executor", '', $this->stdout, $this->stderr); From c6314d52a6d3637f99dfe3e8310ea491bce30b18 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 12 Jun 2026 14:41:09 +0400 Subject: [PATCH 16/17] Update executor to 0.24.1 --- .github/workflows/ci.yml | 6 +++--- app/views/install/compose.phtml | 2 +- docker-compose.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78e1ea5255..96b579c006 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -429,7 +429,7 @@ jobs: - name: Wait for Open Runtimes timeout-minutes: 3 run: | - while ! docker compose logs openruntimes-executor | grep -q "Executor is ready."; do + while ! docker logs exc1 | grep -q "Executor is ready."; do echo "Waiting for Executor to come online" sleep 1 done @@ -525,7 +525,7 @@ jobs: - name: Wait for Open Runtimes timeout-minutes: 3 run: | - while ! docker compose logs openruntimes-executor | grep -q "Executor is ready."; do + while ! docker logs exc1 | grep -q "Executor is ready."; do echo "Waiting for Executor to come online" sleep 1 done @@ -678,7 +678,7 @@ jobs: - name: Wait for Open Runtimes timeout-minutes: 3 run: | - while ! docker compose logs openruntimes-executor | grep -q "Executor is ready."; do + while ! docker logs exc1 | grep -q "Executor is ready."; do echo "Waiting for Executor to come online" sleep 1 done diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index d401db9ce0..d71ccff0b4 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -988,7 +988,7 @@ $hostPath = rtrim($this->getParam('hostPath', ''), '/'); <<: *x-logging restart: unless-stopped stop_signal: SIGINT - image: openruntimes/executor:0.24.0 + image: openruntimes/executor:0.24.1 networks: - appwrite - runtimes diff --git a/docker-compose.yml b/docker-compose.yml index 3e05c90104..d4b2aacd03 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1249,7 +1249,7 @@ services: hostname: exc1 <<: *x-logging stop_signal: SIGINT - image: openruntimes/executor:0.24.0 + image: openruntimes/executor:0.24.1 restart: unless-stopped networks: - appwrite From 5f23b0e8049f5239a079483ee7784dd7c4523b22 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 12 Jun 2026 23:22:02 +1200 Subject: [PATCH 17/17] fix: resolve data-plane database before writing collection metadata For a dedicated product database (documentsdb/vectorsdb on Cloud), the data-plane resolver throws while the database is still provisioning (the DSN is not published yet). Both collection create paths wrote the control-plane metadata row before resolving the data plane, so every create attempted against a provisioning database returned 409 but still persisted a collection row with no backing collection. The orphan lists fine in the API and console, but every document operation against it fails with 'Invalid document structure: Missing collection attribute $collection'. Resolve the data-plane database first so a provisioning (or otherwise unreachable) backend rejects the request before any metadata is written. Co-Authored-By: Claude Fable 5 --- .../Http/Databases/Collections/Create.php | 14 +++++++++----- .../Http/VectorsDB/Collections/Create.php | 9 +++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) 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 a0ee24db87..b2e783bccd 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -103,6 +103,15 @@ class Create extends Action // Map aggregate permissions into the multiple permissions they represent. $permissions = Permission::aggregate($permissions) ?? []; + // Resolve the data-plane database BEFORE writing the metadata row. For a + // dedicated product database this throws while provisioning (no DSN yet); + // writing the row first would leave an orphaned collection with no backing + // collection, which lists fine but fails every document operation. + /** + * @var Database $dbForDatabases + */ + $dbForDatabases = $getDatabasesDB($database); + try { $collection = $dbForProject->createDocument('database_' . $database->getSequence(), new Document([ '$id' => $collectionId, @@ -122,11 +131,6 @@ class Create extends Action throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } - /** - * @var Database $dbForDatabases - */ - $dbForDatabases = $getDatabasesDB($database); - $collectionKey = 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(); $databaseKey = 'database_' . $database->getSequence(); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php index 58433c7deb..3b346bb7c0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php @@ -94,6 +94,13 @@ class Create extends CollectionAction // Map aggregate permissions into the multiple permissions they represent. $permissions = Permission::aggregate($permissions) ?? []; + // Resolve the data-plane database BEFORE writing the metadata row. For a + // dedicated product database this throws while provisioning (no DSN yet); + // writing the row first would leave an orphaned collection with no backing + // collection, which lists fine but fails every document operation. + /** @var Database $dbForDatabases */ + $dbForDatabases = $getDatabasesDB($database); + try { $collection = $dbForProject->createDocument('database_' . $database->getSequence(), new Document([ '$id' => $collectionId, @@ -114,8 +121,6 @@ class Create extends CollectionAction } catch (NotFoundException) { throw new Exception(Exception::DATABASE_NOT_FOUND); } - /** @var Database $dbForDatabases */ - $dbForDatabases = $getDatabasesDB($database); $attributes = []; $indexes = [];