From b21730dea6be7cc60d16a697b3c980019040d39d Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 11:47:51 +0530 Subject: [PATCH 01/25] Move execution log persistence to cloud --- Dockerfile | 1 - app/init/resources.php | 6 --- app/listeners.php | 2 - app/views/install/compose.phtml | 29 ----------- bin/worker-executions | 3 -- docker-compose.yml | 31 ----------- src/Appwrite/Bus/Events/ExecutionLogged.php | 18 +++++++ src/Appwrite/Bus/Listeners/Log.php | 50 ------------------ .../Functions/Http/Executions/Create.php | 18 +++++-- src/Appwrite/Platform/Services/Workers.php | 2 - src/Appwrite/Platform/Tasks/ScheduleBase.php | 10 +++- src/Appwrite/Platform/Workers/Executions.php | 51 ------------------- tests/resources/docker/docker-compose.yml | 21 -------- 13 files changed, 41 insertions(+), 201 deletions(-) delete mode 100755 bin/worker-executions create mode 100644 src/Appwrite/Bus/Events/ExecutionLogged.php delete mode 100644 src/Appwrite/Bus/Listeners/Log.php delete mode 100644 src/Appwrite/Platform/Workers/Executions.php diff --git a/Dockerfile b/Dockerfile index 9a61635415..58150321d6 100755 --- a/Dockerfile +++ b/Dockerfile @@ -89,7 +89,6 @@ RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/worker-certificates && \ chmod +x /usr/local/bin/worker-databases && \ chmod +x /usr/local/bin/worker-deletes && \ - chmod +x /usr/local/bin/worker-executions && \ chmod +x /usr/local/bin/worker-functions && \ chmod +x /usr/local/bin/worker-mails && \ chmod +x /usr/local/bin/worker-messaging && \ diff --git a/app/init/resources.php b/app/init/resources.php index 34f66d3de7..b9f2e90a15 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -7,7 +7,6 @@ use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Event\Publisher\Certificate as CertificatePublisher; use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Event\Publisher\Delete as DeletePublisher; -use Appwrite\Event\Publisher\Execution as ExecutionPublisher; use Appwrite\Event\Publisher\Func as FunctionPublisher; use Appwrite\Event\Publisher\Mail as MailPublisher; use Appwrite\Event\Publisher\Messaging as MessagingPublisher; @@ -105,11 +104,6 @@ $container->set('publisherForUsage', fn (Publisher $publisher) => new UsagePubli new Queue(System::getEnv('_APP_STATS_USAGE_QUEUE_NAME', Event::STATS_USAGE_QUEUE_NAME)) ), ['publisher']); -$container->set('publisherForExecutions', fn (Publisher $publisher) => new ExecutionPublisher( - $publisher, - new Queue(System::getEnv('_APP_EXECUTIONS_QUEUE_NAME', Event::EXECUTIONS_QUEUE_NAME)) -), ['publisher']); - $container->set('publisherForFunctions', fn (Publisher $publisher) => new FunctionPublisher( $publisher, new Queue(System::getEnv('_APP_FUNCTIONS_QUEUE_NAME', Event::FUNCTIONS_QUEUE_NAME), 'utopia-queue', Event::FUNCTIONS_QUEUE_TTL) diff --git a/app/listeners.php b/app/listeners.php index 240225dc45..9f959ac6ab 100644 --- a/app/listeners.php +++ b/app/listeners.php @@ -1,11 +1,9 @@ getParam('hostPath', ''), '/'); - _APP_DB_PASS - _APP_LOGGING_CONFIG - appwrite-worker-executions: - image: /: - entrypoint: worker-executions - <<: *x-logging - container_name: appwrite-worker-executions - restart: unless-stopped - networks: - - appwrite - depends_on: - redis: - condition: service_healthy - : - condition: service_healthy - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_ENV - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_LOGGING_CONFIG - appwrite-worker-functions: image: /: entrypoint: worker-functions diff --git a/bin/worker-executions b/bin/worker-executions deleted file mode 100755 index 6789fb8da8..0000000000 --- a/bin/worker-executions +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -exec php /usr/src/code/app/worker.php executions "$@" diff --git a/docker-compose.yml b/docker-compose.yml index 7d3f6bdc5f..e2a5a7161e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -690,37 +690,6 @@ services: - _APP_LOGGING_CONFIG - _APP_DATABASE_SHARED_TABLES - appwrite-worker-executions: - entrypoint: worker-executions - <<: [*x-logging, *x-build] - container_name: appwrite-worker-executions - image: appwrite-dev - networks: - - appwrite - volumes: - - ./app:/usr/src/code/app - - ./src:/usr/src/code/src - depends_on: - - redis - - ${_APP_DB_HOST:-mongodb} - environment: - - _APP_ENV - - _APP_WORKER_PER_CORE - - _APP_POOL_ADAPTER - - _APP_OPENSSL_KEY_V1 - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_ADAPTER - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - - _APP_LOGGING_CONFIG - - _APP_DATABASE_SHARED_TABLES - appwrite-worker-functions: entrypoint: worker-functions <<: [*x-logging, *x-build] diff --git a/src/Appwrite/Bus/Events/ExecutionLogged.php b/src/Appwrite/Bus/Events/ExecutionLogged.php new file mode 100644 index 0000000000..eabdc618e8 --- /dev/null +++ b/src/Appwrite/Bus/Events/ExecutionLogged.php @@ -0,0 +1,18 @@ + $execution + * @param array $project + */ + public function __construct( + public readonly array $execution, + public readonly array $project, + ) { + } +} diff --git a/src/Appwrite/Bus/Listeners/Log.php b/src/Appwrite/Bus/Listeners/Log.php deleted file mode 100644 index e0376a4f81..0000000000 --- a/src/Appwrite/Bus/Listeners/Log.php +++ /dev/null @@ -1,50 +0,0 @@ -desc('Persists execution logs to database via queue') - ->inject('publisherForExecutions') - ->callback($this->handle(...)); - } - - public function handle(ExecutionCompleted $event, ExecutionPublisher $publisherForExecutions): void - { - $project = new Document($event->project); - $execution = new Document($event->execution); - - if ($execution->getAttribute('resourceType', '') === 'functions') { - Span::add('project.id', $project->getId()); - Span::add('function.id', $execution->getAttribute('resourceId', '')); - Span::add('execution.id', $execution->getId()); - Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); - Span::add('execution.status', $execution->getAttribute('status', '')); - } - - $publisherForExecutions->enqueue(new ExecutionMessage( - project: $project, - execution: $execution, - )); - } -} diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index ba36b47884..b866e7b579 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Modules\Functions\Http\Executions; use Ahc\Jwt\JWT; +use Appwrite\Bus\Events\ExecutionLogged; use Appwrite\Event\Event; use Appwrite\Event\Message\Delete as DeleteMessage; use Appwrite\Event\Message\Func as FunctionMessage; @@ -24,6 +25,7 @@ use Executor\Executor; use MaxMind\Db\Reader; use Utopia\Auth\Proofs\Token; use Utopia\Auth\Store; +use Utopia\Bus\Bus; use Utopia\Config\Config; use Utopia\Console; use Utopia\Database\Database; @@ -107,6 +109,7 @@ class Create extends Base ->inject('authorization') ->inject('publisherForDeletes') ->inject('executionsRetentionCount') + ->inject('bus') ->callback($this->action(...)); } @@ -135,6 +138,7 @@ class Create extends Base Authorization $authorization, DeletePublisher $publisherForDeletes, int $executionsRetentionCount, + Bus $bus, ) { $async = \strval($async) === 'true' || \strval($async) === '1'; @@ -296,7 +300,6 @@ class Create extends Base if ($async) { if (is_null($scheduledAt)) { - $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); $publisherForFunctions->enqueue(new FunctionMessage( project: $project, user: $user, @@ -316,7 +319,8 @@ class Create extends Base 'path' => $path, 'method' => $method, 'body' => $body, - 'userId' => $user->getId() + 'userId' => $user->getId(), + 'execution' => $execution->getArrayCopy(), ]; $schedule = $dbForPlatform->createDocument('schedules', new Document([ @@ -336,7 +340,10 @@ class Create extends Base ->setAttribute('scheduleInternalId', $schedule->getSequence()) ->setAttribute('scheduledAt', $scheduledAt); - $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); + $bus->dispatch(new ExecutionLogged( + execution: $execution->getArrayCopy(), + project: $project->getArrayCopy(), + )); } if ($executionsRetentionCount > 0 && ENABLE_EXECUTIONS_LIMIT_ON_ROUTE) { @@ -506,7 +513,10 @@ class Create extends Base ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ; - $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); + $bus->dispatch(new ExecutionLogged( + execution: $execution->getArrayCopy(), + project: $project->getArrayCopy(), + )); } $executionResponse['headers']['x-appwrite-execution-id'] = $execution->getId(); diff --git a/src/Appwrite/Platform/Services/Workers.php b/src/Appwrite/Platform/Services/Workers.php index fa77725f7a..f2cbeb390a 100644 --- a/src/Appwrite/Platform/Services/Workers.php +++ b/src/Appwrite/Platform/Services/Workers.php @@ -5,7 +5,6 @@ namespace Appwrite\Platform\Services; use Appwrite\Platform\Workers\Audits; use Appwrite\Platform\Workers\Certificates; use Appwrite\Platform\Workers\Deletes; -use Appwrite\Platform\Workers\Executions; use Appwrite\Platform\Workers\Functions; use Appwrite\Platform\Workers\Mails; use Appwrite\Platform\Workers\Messaging; @@ -24,7 +23,6 @@ class Workers extends Service ->addAction(Audits::getName(), new Audits()) ->addAction(Certificates::getName(), new Certificates()) ->addAction(Deletes::getName(), new Deletes()) - ->addAction(Executions::getName(), new Executions()) ->addAction(Functions::getName(), new Functions()) ->addAction(Mails::getName(), new Mails()) ->addAction(Messaging::getName(), new Messaging()) diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index 1213f78924..2662369cf3 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -173,6 +173,7 @@ abstract class ScheduleBase extends Action 'schedule' => $schedule->getAttribute('schedule'), 'active' => $schedule->getAttribute('active'), 'resourceUpdatedAt' => $schedule->getAttribute('resourceUpdatedAt'), + 'data' => $schedule->getAttribute('data', []), ]; } catch (\Throwable $th) { Console::error("Failed to load schedule for project {$schedule->getAttribute('projectId')} {$collectionId} {$schedule->getAttribute('resourceId')}"); @@ -269,7 +270,14 @@ abstract class ScheduleBase extends Action // In case the resource is not found (project deleted). try { - $resource = $getProjectDB($project)->getDocument(static::getCollectionId(), $schedule['resourceId']); + $data = \is_array($schedule['data']) ? $schedule['data'] : []; + $resource = static::getSupportedResource() === SCHEDULE_RESOURCE_TYPE_EXECUTION + ? new Document($data['execution'] ?? []) + : new Document(); + + if ($resource->isEmpty()) { + $resource = $getProjectDB($project)->getDocument(static::getCollectionId(), $schedule['resourceId']); + } } catch (\Throwable $th) { Console::error("Failed to load resource: projectId::{$schedule['projectId']} resourceId::{$schedule['resourceId']}"); Console::error($th->getMessage()); diff --git a/src/Appwrite/Platform/Workers/Executions.php b/src/Appwrite/Platform/Workers/Executions.php deleted file mode 100644 index 8dbf10cae6..0000000000 --- a/src/Appwrite/Platform/Workers/Executions.php +++ /dev/null @@ -1,51 +0,0 @@ -desc('Executions worker') - ->groups(['executions']) - ->inject('message') - ->inject('dbForProject') - ->callback($this->action(...)); - } - - public function action( - Message $message, - Database $dbForProject, - ): void { - $executionMessage = Execution::fromArray($message->getPayload()); - $execution = $executionMessage->execution; - - if ($execution->isEmpty()) { - throw new Exception('Missing execution'); - } - - Span::add('project.id', $executionMessage->project->getId()); - Span::add('function.id', $execution->getAttribute('resourceId', '')); - Span::add('execution.id', $execution->getId()); - Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); - Span::add('resource.type', $execution->getAttribute('resourceType', '')); - - $dbForProject->upsertDocument('executions', $execution); - } -} diff --git a/tests/resources/docker/docker-compose.yml b/tests/resources/docker/docker-compose.yml index 47a69f077b..735e88525e 100644 --- a/tests/resources/docker/docker-compose.yml +++ b/tests/resources/docker/docker-compose.yml @@ -216,27 +216,6 @@ services: - _APP_DB_USER - _APP_DB_PASS - appwrite-worker-executions: - entrypoint: worker-executions - container_name: appwrite-worker-executions - build: - context: . - restart: unless-stopped - networks: - - appwrite - depends_on: - - redis - - mariadb - environment: - - _APP_ENV - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - appwrite-worker-functions: entrypoint: worker-functions container_name: appwrite-worker-functions From 56dce499c0dcc9a84515102e8ef3dabc1b22b58f Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 13:02:09 +0530 Subject: [PATCH 02/25] Keep execution documents without logs --- .../Functions/Http/Executions/Create.php | 13 ++++++++++ src/Appwrite/Platform/Workers/Functions.php | 26 +++++++++++++++---- .../Functions/FunctionsCustomClientTest.php | 3 ++- .../Functions/FunctionsCustomServerTest.php | 14 +++++----- .../FunctionsScheduleTest.php | 12 +++------ tests/unit/Docker/ComposeTest.php | 2 +- 6 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index b866e7b579..5d2c6c1d0e 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -300,6 +300,8 @@ class Create extends Base if ($async) { if (is_null($scheduledAt)) { + $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); + $publisherForFunctions->enqueue(new FunctionMessage( project: $project, user: $user, @@ -340,6 +342,8 @@ class Create extends Base ->setAttribute('scheduleInternalId', $schedule->getSequence()) ->setAttribute('scheduledAt', $scheduledAt); + $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); + $bus->dispatch(new ExecutionLogged( execution: $execution->getArrayCopy(), project: $project->getArrayCopy(), @@ -360,6 +364,8 @@ class Create extends Base return; } + $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); + $durationStart = \microtime(true); $vars = []; @@ -513,6 +519,13 @@ class Create extends Base ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ; + $authorization->skip(fn () => $dbForProject->updateDocument('executions', $execution->getId(), new Document([ + 'status' => $execution->getAttribute('status'), + 'responseStatusCode' => $execution->getAttribute('responseStatusCode'), + 'responseHeaders' => $execution->getAttribute('responseHeaders'), + 'duration' => $execution->getAttribute('duration'), + ]))); + $bus->dispatch(new ExecutionLogged( execution: $execution->getArrayCopy(), project: $project->getArrayCopy(), diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 73c1db9444..75bda7aa18 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -263,6 +263,7 @@ class Functions extends Action /** * @param string $message + * @param Database $dbForProject * @param Document $function * @param string $trigger * @param string $path @@ -274,6 +275,7 @@ class Functions extends Action */ private function fail( string $message, + Database $dbForProject, Document $project, Bus $bus, Document $function, @@ -313,19 +315,24 @@ class Functions extends Action 'requestPath' => $path, 'requestMethod' => $method, 'requestHeaders' => $headersFiltered, - 'errors' => $message, + 'errors' => '', 'logs' => '', 'duration' => 0.0, ]); + $executionForEvent = new Document($execution->getArrayCopy()) + ->setAttribute('errors', $message); + Span::add('function.id', $function->getId()); Span::add('execution.id', $execution->getId()); Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); Span::add('execution.trigger', $trigger); Span::add('execution.status', $execution->getAttribute('status', '')); + $dbForProject->upsertDocument('executions', $execution); + $bus->dispatch(new ExecutionCompleted( - execution: $execution->getArrayCopy(), + execution: $executionForEvent->getArrayCopy(), project: $project->getArrayCopy(), )); } @@ -390,19 +397,19 @@ class Functions extends Action if ($deployment->getAttribute('resourceId') !== $functionId) { $errorMessage = 'The execution could not be completed because a corresponding deployment was not found. A function deployment needs to be created before it can be executed. Please create a deployment for your function and try again.'; - $this->fail($errorMessage, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); + $this->fail($errorMessage, $dbForProject, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); return; } if ($deployment->isEmpty()) { $errorMessage = 'The execution could not be completed because a corresponding deployment was not found. A function deployment needs to be created before it can be executed. Please create a deployment for your function and try again.'; - $this->fail($errorMessage, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); + $this->fail($errorMessage, $dbForProject, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); return; } if ($deployment->getAttribute('status') !== 'ready') { $errorMessage = 'The execution could not be completed because the build is not ready. Please wait for the build to complete and try again.'; - $this->fail($errorMessage, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); + $this->fail($errorMessage, $dbForProject, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); return; } @@ -471,6 +478,8 @@ class Functions extends Action 'duration' => 0.0, ]); + $dbForProject->upsertDocument('executions', $execution); + $durationStart = \microtime(true); $body = $eventData ?? ''; @@ -626,6 +635,13 @@ class Functions extends Action /** Persist final execution status and record usage */ Span::add('execution.status', $execution->getAttribute('status', '')); + $dbForProject->updateDocument('executions', $execution->getId(), new Document([ + 'status' => $execution->getAttribute('status'), + 'responseStatusCode' => $execution->getAttribute('responseStatusCode'), + 'responseHeaders' => $execution->getAttribute('responseHeaders'), + 'duration' => $execution->getAttribute('duration'), + ])); + $bus->dispatch(new ExecutionCompleted( execution: $execution->getArrayCopy(), project: $project->getArrayCopy(), diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 1208121077..032307a723 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -605,7 +605,8 @@ class FunctionsCustomClientTest extends Scope $lastExecution = $executions['body']['executions'][0]; $this->assertEquals('completed', $lastExecution['status']); $this->assertEquals(204, $lastExecution['responseStatusCode']); - $this->assertStringContainsString($documentId, $lastExecution['logs']); + $this->assertEmpty($lastExecution['logs']); + $this->assertEmpty($lastExecution['errors']); }, 20000, 500); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, [ diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 44d5d274da..8527a90d40 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -745,7 +745,7 @@ class FunctionsCustomServerTest extends Scope $executionId = $execution['body']['$id'] ?? ''; - $this->assertEventually(function () use ($functionId, $executionId, $totalUsers) { + $this->assertEventually(function () use ($functionId, $executionId) { $execution = $this->getExecution($functionId, $executionId); $this->assertEquals(200, $execution['headers']['status-code']); @@ -753,7 +753,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEmpty($execution['body']['responseBody']); $this->assertEmpty($execution['body']['errors']); - $this->assertStringContainsString("Total users: " . $totalUsers, $execution['body']['logs']); + $this->assertEmpty($execution['body']['logs']); }, 10000, 500); $deployment = $this->getDeployment($functionId, $deployment['body']['$id']); @@ -2124,7 +2124,7 @@ class FunctionsCustomServerTest extends Scope $this->assertLessThan(20, $execution['body']['duration']); $this->assertEquals('', $execution['body']['responseBody']); $this->assertEquals('', $execution['body']['logs']); - $this->assertStringContainsString('timed out', $execution['body']['errors']); + $this->assertEquals('', $execution['body']['errors']); }, 10000, 500); $this->cleanupFunction($functionId); @@ -2357,8 +2357,8 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $lastExecution['status']); $this->assertEquals(204, $lastExecution['responseStatusCode']); - $this->assertStringContainsString($userId, $lastExecution['logs']); - $this->assertStringContainsString('Event User', $lastExecution['logs']); + $this->assertEmpty($lastExecution['logs']); + $this->assertEmpty($lastExecution['errors']); $this->assertNotEmpty($lastExecution['$id']); $headers = array_column($lastExecution['requestHeaders'] ?? [], 'value', 'name'); $this->assertEmpty($headers['x-appwrite-client-ip'] ?? ''); @@ -2426,8 +2426,8 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertGreaterThan(0, $execution['body']['duration']); - $this->assertNotEmpty($execution['body']['logs']); - $this->assertStringContainsString("total", $execution['body']['logs']); + $this->assertEmpty($execution['body']['logs']); + $this->assertEmpty($execution['body']['errors']); }, 10000, 500); $this->cleanupFunction($functionId); diff --git a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php index f4a70b5a9e..2a8529b580 100644 --- a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php +++ b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php @@ -58,8 +58,8 @@ class FunctionsScheduleTest extends Scope $this->assertEquals('completed', $asyncExecution['status']); $this->assertEquals(200, $asyncExecution['responseStatusCode']); $this->assertEquals('', $asyncExecution['responseBody']); - $this->assertNotEmpty($asyncExecution['logs']); - $this->assertNotEmpty($asyncExecution['errors']); + $this->assertEmpty($asyncExecution['logs']); + $this->assertEmpty($asyncExecution['errors']); $this->assertGreaterThan(0, $asyncExecution['duration']); $this->assertNotEmpty($asyncExecution['$id']); $headers = array_column($asyncExecution['requestHeaders'] ?? [], 'value', 'name'); @@ -132,12 +132,8 @@ class FunctionsScheduleTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals('/custom-path', $execution['body']['requestPath']); $this->assertEquals('PATCH', $execution['body']['requestMethod']); - $this->assertStringContainsString('body-is-custom-body', $execution['body']['logs']); - $this->assertStringContainsString('custom-header-is-custom-value', $execution['body']['logs']); - $this->assertStringContainsString('method-is-patch', $execution['body']['logs']); - $this->assertStringContainsString('path-is-/custom-path', $execution['body']['logs']); - $this->assertStringContainsString('user-is-' . $this->getUser()['$id'], $execution['body']['logs']); - $this->assertStringContainsString('jwt-is-valid', $execution['body']['logs']); + $this->assertEmpty($execution['body']['logs']); + $this->assertEmpty($execution['body']['errors']); $this->assertGreaterThan(0, $execution['body']['duration']); }, 120000, 500); diff --git a/tests/unit/Docker/ComposeTest.php b/tests/unit/Docker/ComposeTest.php index e63d877baf..74779230ac 100644 --- a/tests/unit/Docker/ComposeTest.php +++ b/tests/unit/Docker/ComposeTest.php @@ -23,7 +23,7 @@ class ComposeTest extends TestCase public function testServices(): void { - $this->assertCount(16, $this->object->getServices()); + $this->assertCount(15, $this->object->getServices()); $this->assertEquals('appwrite', $this->object->getService('appwrite')->getContainerName()); $this->assertEquals('', $this->object->getService('appwrite')->getImageVersion()); $this->assertEquals('3.6', $this->object->getService('traefik')->getImageVersion()); From 502fafdc585985c1d2d588adb3595f3ca9ad6081 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 13:04:39 +0530 Subject: [PATCH 03/25] Load scheduled executions from database --- .../Modules/Functions/Http/Executions/Create.php | 4 +--- src/Appwrite/Platform/Tasks/ScheduleBase.php | 9 +-------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index 5d2c6c1d0e..8ce70d5c91 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -301,7 +301,6 @@ class Create extends Base if ($async) { if (is_null($scheduledAt)) { $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); - $publisherForFunctions->enqueue(new FunctionMessage( project: $project, user: $user, @@ -321,8 +320,7 @@ class Create extends Base 'path' => $path, 'method' => $method, 'body' => $body, - 'userId' => $user->getId(), - 'execution' => $execution->getArrayCopy(), + 'userId' => $user->getId() ]; $schedule = $dbForPlatform->createDocument('schedules', new Document([ diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index 2662369cf3..d3e4ad9705 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -270,14 +270,7 @@ abstract class ScheduleBase extends Action // In case the resource is not found (project deleted). try { - $data = \is_array($schedule['data']) ? $schedule['data'] : []; - $resource = static::getSupportedResource() === SCHEDULE_RESOURCE_TYPE_EXECUTION - ? new Document($data['execution'] ?? []) - : new Document(); - - if ($resource->isEmpty()) { - $resource = $getProjectDB($project)->getDocument(static::getCollectionId(), $schedule['resourceId']); - } + $resource = $getProjectDB($project)->getDocument(static::getCollectionId(), $schedule['resourceId']); } catch (\Throwable $th) { Console::error("Failed to load resource: projectId::{$schedule['projectId']} resourceId::{$schedule['resourceId']}"); Console::error($th->getMessage()); From ca603a64eda06b4408ca3cb630a2f816fd42b465 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 13:08:19 +0530 Subject: [PATCH 04/25] Create sync executions after completion --- .../Modules/Functions/Http/Executions/Create.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index 8ce70d5c91..092cb772a5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -362,8 +362,6 @@ class Create extends Base return; } - $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); - $durationStart = \microtime(true); $vars = []; @@ -517,12 +515,7 @@ class Create extends Base ->addMetric(str_replace(['{resourceType}', '{resourceInternalId}'], [RESOURCE_TYPE_FUNCTIONS, $function->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), (int)(($spec['memory'] ?? APP_COMPUTE_MEMORY_DEFAULT) * $execution->getAttribute('duration', 0) * ($spec['cpus'] ?? APP_COMPUTE_CPUS_DEFAULT))) ; - $authorization->skip(fn () => $dbForProject->updateDocument('executions', $execution->getId(), new Document([ - 'status' => $execution->getAttribute('status'), - 'responseStatusCode' => $execution->getAttribute('responseStatusCode'), - 'responseHeaders' => $execution->getAttribute('responseHeaders'), - 'duration' => $execution->getAttribute('duration'), - ]))); + $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); $bus->dispatch(new ExecutionLogged( execution: $execution->getArrayCopy(), From 07bedbd1f50d195f53f33c69322c78a56f261411 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 13:09:21 +0530 Subject: [PATCH 05/25] Remove cached schedule data --- src/Appwrite/Platform/Tasks/ScheduleBase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index d3e4ad9705..1213f78924 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -173,7 +173,6 @@ abstract class ScheduleBase extends Action 'schedule' => $schedule->getAttribute('schedule'), 'active' => $schedule->getAttribute('active'), 'resourceUpdatedAt' => $schedule->getAttribute('resourceUpdatedAt'), - 'data' => $schedule->getAttribute('data', []), ]; } catch (\Throwable $th) { Console::error("Failed to load schedule for project {$schedule->getAttribute('projectId')} {$collectionId} {$schedule->getAttribute('resourceId')}"); From 5955c020e7e40c956b339d59e37a884af87e17f0 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 13:16:07 +0530 Subject: [PATCH 06/25] Fix execution log test analysis --- tests/e2e/Services/Functions/FunctionsCustomClientTest.php | 4 +--- tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 032307a723..617bf57ae9 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -590,9 +590,7 @@ class FunctionsCustomClientTest extends Scope 'data' => ['name' => 'Test Document'], ]); $this->assertEquals(201, $document['headers']['status-code']); - $documentId = $document['body']['$id']; - - $this->assertEventually(function () use ($functionId, $documentId) { + $this->assertEventually(function () use ($functionId) { $executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 8527a90d40..34a3bba500 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -2347,7 +2347,7 @@ class FunctionsCustomServerTest extends Scope $userId = $user['body']['$id'] ?? ''; - $this->assertEventually(function () use ($functionId, $userId) { + $this->assertEventually(function () use ($functionId) { $executions = $this->listExecutions($functionId); $this->assertEquals(200, $executions['headers']['status-code']); From c0e276663a7af56c546e8c22a73f9005f8364a54 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 13:19:22 +0530 Subject: [PATCH 07/25] Fix function worker parser compatibility --- src/Appwrite/Platform/Workers/Functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 75bda7aa18..273847859b 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -320,7 +320,7 @@ class Functions extends Action 'duration' => 0.0, ]); - $executionForEvent = new Document($execution->getArrayCopy()) + $executionForEvent = (new Document($execution->getArrayCopy())) ->setAttribute('errors', $message); Span::add('function.id', $function->getId()); From 3fe1959cde4b2d09a6228b399f1f2c8c0d1c17b3 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 13:33:30 +0530 Subject: [PATCH 08/25] Persist proxy execution documents --- app/controllers/general.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/general.php b/app/controllers/general.php index 219c14774f..5cbd1794f9 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -719,6 +719,8 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S $execution->setAttribute('logs', ''); $execution->setAttribute('errors', ''); + $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); + $headers = []; foreach (($executionResponse['headers'] ?? []) as $key => $value) { $headers[] = ['name' => $key, 'value' => \is_array($value) ? \implode(', ', $value) : $value]; From f8d4b06c10173957d6a88e1d5f7ccf5ce967497c Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 14:02:01 +0530 Subject: [PATCH 09/25] Remove execution log assertions from function tests --- .../e2e/Services/Functions/FunctionsCustomClientTest.php | 2 -- .../e2e/Services/Functions/FunctionsCustomServerTest.php | 8 -------- .../Services/FunctionsSchedule/FunctionsScheduleTest.php | 4 ---- 3 files changed, 14 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 617bf57ae9..18c99e856f 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -603,8 +603,6 @@ class FunctionsCustomClientTest extends Scope $lastExecution = $executions['body']['executions'][0]; $this->assertEquals('completed', $lastExecution['status']); $this->assertEquals(204, $lastExecution['responseStatusCode']); - $this->assertEmpty($lastExecution['logs']); - $this->assertEmpty($lastExecution['errors']); }, 20000, 500); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, [ diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 34a3bba500..0d189e0c69 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -752,8 +752,6 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertEquals('completed', $execution['body']['status']); $this->assertEmpty($execution['body']['responseBody']); - $this->assertEmpty($execution['body']['errors']); - $this->assertEmpty($execution['body']['logs']); }, 10000, 500); $deployment = $this->getDeployment($functionId, $deployment['body']['$id']); @@ -2123,8 +2121,6 @@ class FunctionsCustomServerTest extends Scope $this->assertGreaterThan(2, $execution['body']['duration']); $this->assertLessThan(20, $execution['body']['duration']); $this->assertEquals('', $execution['body']['responseBody']); - $this->assertEquals('', $execution['body']['logs']); - $this->assertEquals('', $execution['body']['errors']); }, 10000, 500); $this->cleanupFunction($functionId); @@ -2357,8 +2353,6 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $lastExecution['status']); $this->assertEquals(204, $lastExecution['responseStatusCode']); - $this->assertEmpty($lastExecution['logs']); - $this->assertEmpty($lastExecution['errors']); $this->assertNotEmpty($lastExecution['$id']); $headers = array_column($lastExecution['requestHeaders'] ?? [], 'value', 'name'); $this->assertEmpty($headers['x-appwrite-client-ip'] ?? ''); @@ -2426,8 +2420,6 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertGreaterThan(0, $execution['body']['duration']); - $this->assertEmpty($execution['body']['logs']); - $this->assertEmpty($execution['body']['errors']); }, 10000, 500); $this->cleanupFunction($functionId); diff --git a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php index 2a8529b580..c1e79b1d68 100644 --- a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php +++ b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php @@ -58,8 +58,6 @@ class FunctionsScheduleTest extends Scope $this->assertEquals('completed', $asyncExecution['status']); $this->assertEquals(200, $asyncExecution['responseStatusCode']); $this->assertEquals('', $asyncExecution['responseBody']); - $this->assertEmpty($asyncExecution['logs']); - $this->assertEmpty($asyncExecution['errors']); $this->assertGreaterThan(0, $asyncExecution['duration']); $this->assertNotEmpty($asyncExecution['$id']); $headers = array_column($asyncExecution['requestHeaders'] ?? [], 'value', 'name'); @@ -132,8 +130,6 @@ class FunctionsScheduleTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals('/custom-path', $execution['body']['requestPath']); $this->assertEquals('PATCH', $execution['body']['requestMethod']); - $this->assertEmpty($execution['body']['logs']); - $this->assertEmpty($execution['body']['errors']); $this->assertGreaterThan(0, $execution['body']['duration']); }, 120000, 500); From 995c8428d369e0d3467a874c784664a9a6e63368 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 14:13:54 +0530 Subject: [PATCH 10/25] Persist proxy execution documents from finally --- app/controllers/general.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 5cbd1794f9..c53e0c29dd 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -714,13 +714,12 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S spec: $spec, resource: $resource->getArrayCopy(), )); + + $execution->setAttribute('logs', ''); + $execution->setAttribute('errors', ''); + $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); } - $execution->setAttribute('logs', ''); - $execution->setAttribute('errors', ''); - - $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); - $headers = []; foreach (($executionResponse['headers'] ?? []) as $key => $value) { $headers[] = ['name' => $key, 'value' => \is_array($value) ? \implode(', ', $value) : $value]; From c51d75a3f200d963bc4c88001693a1b4c14abe7a Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 13:58:00 +0530 Subject: [PATCH 11/25] Wait for benchmark health check --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a7537cf1d..343d22fdf2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -761,11 +761,11 @@ jobs: run: | docker tag ${{ env.IMAGE }}:before ${{ env.IMAGE }} docker compose up -d --wait --no-build - for attempt in $(seq 1 5); do - if curl -fsS http://localhost/v1/health; then + for attempt in $(seq 1 10); do + if curl -fsS http://localhost/v1/health/version; then break fi - if [ "$attempt" -eq 5 ]; then + if [ "$attempt" -eq 10 ]; then exit 1 fi sleep 1 @@ -825,11 +825,11 @@ jobs: run: | docker tag ${{ env.IMAGE }}:after ${{ env.IMAGE }} docker compose up -d --wait --no-build - for attempt in $(seq 1 5); do - if curl -fsS http://localhost/v1/health; then + for attempt in $(seq 1 10); do + if curl -fsS http://localhost/v1/health/version; then break fi - if [ "$attempt" -eq 5 ]; then + if [ "$attempt" -eq 10 ]; then exit 1 fi sleep 1 From 185fcb81e70256d4329eb9cddac46487646dad14 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 15:52:01 +0530 Subject: [PATCH 12/25] site tests --- .../Services/Sites/SitesCustomServerTest.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 9cca689780..e1b55d4dfb 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2770,9 +2770,8 @@ class SitesCustomServerTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertStringContainsString("Inline logs printed.", $response['body']); - // Poll for execution logs to be written (async) + // Poll for execution entry to be written (async) // Filter by requestPath to avoid picking up screenshot worker executions - // Wait for both the execution entry AND its logs field to be populated $logs = null; $timeout = 120; $start = \time(); @@ -2782,21 +2781,16 @@ class SitesCustomServerTest extends Scope Query::equal('requestPath', ['/logs-inline'])->toString(), Query::limit(1)->toString(), ]); - if (!empty($logs['body']['executions']) && !empty($logs['body']['executions'][0]['logs'])) { + if (!empty($logs['body']['executions'])) { break; } \usleep(500000); } $this->assertNotEmpty($logs['body']['executions'], 'Execution logs were not available within timeout'); - $this->assertNotNull($logs['body']['executions'][0]['logs'], 'Execution logs content was not populated within timeout'); $this->assertEquals(200, $logs['headers']['status-code']); $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-inline", $logs['body']['executions'][0]['requestPath']); - $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']); - $this->assertStringContainsString("Log2", $logs['body']['executions'][0]['logs']); - $this->assertStringContainsString("Error1", $logs['body']['executions'][0]['errors']); - $this->assertStringContainsString("Error2", $logs['body']['executions'][0]['errors']); $log1Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log1Id); @@ -2830,21 +2824,16 @@ class SitesCustomServerTest extends Scope Query::equal('requestPath', ['/logs-action'])->toString(), Query::limit(1)->toString(), ]); - if (!empty($logs['body']['executions']) && !empty($logs['body']['executions'][0]['logs'])) { + if (!empty($logs['body']['executions'])) { break; } \usleep(500000); } $this->assertNotEmpty($logs['body']['executions'], 'Action execution logs were not available within timeout'); - $this->assertNotNull($logs['body']['executions'][0]['logs'], 'Action execution logs content was not populated within timeout'); $this->assertEquals(200, $logs['headers']['status-code']); $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-action", $logs['body']['executions'][0]['requestPath']); - $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']); - $this->assertStringContainsString("Log2", $logs['body']['executions'][0]['logs']); - $this->assertStringContainsString("Error1", $logs['body']['executions'][0]['errors']); - $this->assertStringContainsString("Error2", $logs['body']['executions'][0]['errors']); $log2Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log2Id); From 1de158a1465290e6ad9adb98e8c47631497594f8 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 16:06:46 +0530 Subject: [PATCH 13/25] Assert empty execution logs in CE tests --- .../e2e/Services/Functions/FunctionsCustomClientTest.php | 2 ++ .../e2e/Services/Functions/FunctionsCustomServerTest.php | 8 ++++++++ .../Services/FunctionsSchedule/FunctionsScheduleTest.php | 4 ++++ tests/e2e/Services/Sites/SitesCustomServerTest.php | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 18c99e856f..617bf57ae9 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -603,6 +603,8 @@ class FunctionsCustomClientTest extends Scope $lastExecution = $executions['body']['executions'][0]; $this->assertEquals('completed', $lastExecution['status']); $this->assertEquals(204, $lastExecution['responseStatusCode']); + $this->assertEmpty($lastExecution['logs']); + $this->assertEmpty($lastExecution['errors']); }, 20000, 500); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, [ diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 0d189e0c69..34a3bba500 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -752,6 +752,8 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertEquals('completed', $execution['body']['status']); $this->assertEmpty($execution['body']['responseBody']); + $this->assertEmpty($execution['body']['errors']); + $this->assertEmpty($execution['body']['logs']); }, 10000, 500); $deployment = $this->getDeployment($functionId, $deployment['body']['$id']); @@ -2121,6 +2123,8 @@ class FunctionsCustomServerTest extends Scope $this->assertGreaterThan(2, $execution['body']['duration']); $this->assertLessThan(20, $execution['body']['duration']); $this->assertEquals('', $execution['body']['responseBody']); + $this->assertEquals('', $execution['body']['logs']); + $this->assertEquals('', $execution['body']['errors']); }, 10000, 500); $this->cleanupFunction($functionId); @@ -2353,6 +2357,8 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $lastExecution['status']); $this->assertEquals(204, $lastExecution['responseStatusCode']); + $this->assertEmpty($lastExecution['logs']); + $this->assertEmpty($lastExecution['errors']); $this->assertNotEmpty($lastExecution['$id']); $headers = array_column($lastExecution['requestHeaders'] ?? [], 'value', 'name'); $this->assertEmpty($headers['x-appwrite-client-ip'] ?? ''); @@ -2420,6 +2426,8 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertGreaterThan(0, $execution['body']['duration']); + $this->assertEmpty($execution['body']['logs']); + $this->assertEmpty($execution['body']['errors']); }, 10000, 500); $this->cleanupFunction($functionId); diff --git a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php index c1e79b1d68..2a8529b580 100644 --- a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php +++ b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php @@ -58,6 +58,8 @@ class FunctionsScheduleTest extends Scope $this->assertEquals('completed', $asyncExecution['status']); $this->assertEquals(200, $asyncExecution['responseStatusCode']); $this->assertEquals('', $asyncExecution['responseBody']); + $this->assertEmpty($asyncExecution['logs']); + $this->assertEmpty($asyncExecution['errors']); $this->assertGreaterThan(0, $asyncExecution['duration']); $this->assertNotEmpty($asyncExecution['$id']); $headers = array_column($asyncExecution['requestHeaders'] ?? [], 'value', 'name'); @@ -130,6 +132,8 @@ class FunctionsScheduleTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals('/custom-path', $execution['body']['requestPath']); $this->assertEquals('PATCH', $execution['body']['requestMethod']); + $this->assertEmpty($execution['body']['logs']); + $this->assertEmpty($execution['body']['errors']); $this->assertGreaterThan(0, $execution['body']['duration']); }, 120000, 500); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index e1b55d4dfb..2723c62b99 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2791,6 +2791,8 @@ class SitesCustomServerTest extends Scope $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-inline", $logs['body']['executions'][0]['requestPath']); + $this->assertEmpty($logs['body']['executions'][0]['logs']); + $this->assertEmpty($logs['body']['executions'][0]['errors']); $log1Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log1Id); @@ -2834,6 +2836,8 @@ class SitesCustomServerTest extends Scope $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-action", $logs['body']['executions'][0]['requestPath']); + $this->assertEmpty($logs['body']['executions'][0]['logs']); + $this->assertEmpty($logs['body']['executions'][0]['errors']); $log2Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log2Id); From c6eaedc4c9a6eef234f6c97b2876f02b00a7789b Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 16:14:15 +0530 Subject: [PATCH 14/25] Revert "Assert empty execution logs in CE tests" This reverts commit 1de158a1465290e6ad9adb98e8c47631497594f8. --- .../e2e/Services/Functions/FunctionsCustomClientTest.php | 2 -- .../e2e/Services/Functions/FunctionsCustomServerTest.php | 8 -------- .../Services/FunctionsSchedule/FunctionsScheduleTest.php | 4 ---- tests/e2e/Services/Sites/SitesCustomServerTest.php | 4 ---- 4 files changed, 18 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 617bf57ae9..18c99e856f 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -603,8 +603,6 @@ class FunctionsCustomClientTest extends Scope $lastExecution = $executions['body']['executions'][0]; $this->assertEquals('completed', $lastExecution['status']); $this->assertEquals(204, $lastExecution['responseStatusCode']); - $this->assertEmpty($lastExecution['logs']); - $this->assertEmpty($lastExecution['errors']); }, 20000, 500); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, [ diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 34a3bba500..0d189e0c69 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -752,8 +752,6 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertEquals('completed', $execution['body']['status']); $this->assertEmpty($execution['body']['responseBody']); - $this->assertEmpty($execution['body']['errors']); - $this->assertEmpty($execution['body']['logs']); }, 10000, 500); $deployment = $this->getDeployment($functionId, $deployment['body']['$id']); @@ -2123,8 +2121,6 @@ class FunctionsCustomServerTest extends Scope $this->assertGreaterThan(2, $execution['body']['duration']); $this->assertLessThan(20, $execution['body']['duration']); $this->assertEquals('', $execution['body']['responseBody']); - $this->assertEquals('', $execution['body']['logs']); - $this->assertEquals('', $execution['body']['errors']); }, 10000, 500); $this->cleanupFunction($functionId); @@ -2357,8 +2353,6 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $lastExecution['status']); $this->assertEquals(204, $lastExecution['responseStatusCode']); - $this->assertEmpty($lastExecution['logs']); - $this->assertEmpty($lastExecution['errors']); $this->assertNotEmpty($lastExecution['$id']); $headers = array_column($lastExecution['requestHeaders'] ?? [], 'value', 'name'); $this->assertEmpty($headers['x-appwrite-client-ip'] ?? ''); @@ -2426,8 +2420,6 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertGreaterThan(0, $execution['body']['duration']); - $this->assertEmpty($execution['body']['logs']); - $this->assertEmpty($execution['body']['errors']); }, 10000, 500); $this->cleanupFunction($functionId); diff --git a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php index 2a8529b580..c1e79b1d68 100644 --- a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php +++ b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php @@ -58,8 +58,6 @@ class FunctionsScheduleTest extends Scope $this->assertEquals('completed', $asyncExecution['status']); $this->assertEquals(200, $asyncExecution['responseStatusCode']); $this->assertEquals('', $asyncExecution['responseBody']); - $this->assertEmpty($asyncExecution['logs']); - $this->assertEmpty($asyncExecution['errors']); $this->assertGreaterThan(0, $asyncExecution['duration']); $this->assertNotEmpty($asyncExecution['$id']); $headers = array_column($asyncExecution['requestHeaders'] ?? [], 'value', 'name'); @@ -132,8 +130,6 @@ class FunctionsScheduleTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals('/custom-path', $execution['body']['requestPath']); $this->assertEquals('PATCH', $execution['body']['requestMethod']); - $this->assertEmpty($execution['body']['logs']); - $this->assertEmpty($execution['body']['errors']); $this->assertGreaterThan(0, $execution['body']['duration']); }, 120000, 500); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 2723c62b99..e1b55d4dfb 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2791,8 +2791,6 @@ class SitesCustomServerTest extends Scope $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-inline", $logs['body']['executions'][0]['requestPath']); - $this->assertEmpty($logs['body']['executions'][0]['logs']); - $this->assertEmpty($logs['body']['executions'][0]['errors']); $log1Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log1Id); @@ -2836,8 +2834,6 @@ class SitesCustomServerTest extends Scope $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-action", $logs['body']['executions'][0]['requestPath']); - $this->assertEmpty($logs['body']['executions'][0]['logs']); - $this->assertEmpty($logs['body']['executions'][0]['errors']); $log2Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log2Id); From ad108b12d76bb5676d3e5fcd3f563b4aa883b12b Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 16:37:23 +0530 Subject: [PATCH 15/25] Normalize site template root directory in tests --- tests/e2e/Services/Sites/SitesCustomServerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index e1b55d4dfb..01bb0de589 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2274,7 +2274,7 @@ class SitesCustomServerTest extends Scope $deployment = $this->createTemplateDeployment($siteId, [ 'repository' => $template['providerRepositoryId'], 'owner' => $template['providerOwner'], - 'rootDirectory' => $template['frameworks'][0]['providerRootDirectory'], + 'rootDirectory' => \ltrim($template['frameworks'][0]['providerRootDirectory'], './'), 'type' => 'tag', 'reference' => $template['providerVersion'], 'activate' => true @@ -2345,7 +2345,7 @@ class SitesCustomServerTest extends Scope $deployment = $this->createTemplateDeployment($siteId, [ 'repository' => $template['providerRepositoryId'], 'owner' => $template['providerOwner'], - 'rootDirectory' => $template['frameworks'][0]['providerRootDirectory'], + 'rootDirectory' => \ltrim($template['frameworks'][0]['providerRootDirectory'], './'), 'type' => 'branch', 'reference' => 'main', 'activate' => true @@ -2423,7 +2423,7 @@ class SitesCustomServerTest extends Scope $deployment = $this->createTemplateDeployment($siteId, [ 'repository' => $template['providerRepositoryId'], 'owner' => $template['providerOwner'], - 'rootDirectory' => $template['frameworks'][0]['providerRootDirectory'], + 'rootDirectory' => \ltrim($template['frameworks'][0]['providerRootDirectory'], './'), 'type' => 'commit', 'reference' => $latestCommit, 'activate' => true From 8c8f7b7c48fa3118f8de59611580414d80ddeb74 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 16:40:42 +0530 Subject: [PATCH 16/25] Normalize template root directories in builds --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 6 ++++++ tests/e2e/Services/Sites/SitesCustomServerTest.php | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index f04f7c3807..92e00cd4e6 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -298,6 +298,9 @@ class Builds extends Action $templateRootDirectory = $template->getAttribute('rootDirectory', ''); $templateRootDirectory = \trim($templateRootDirectory, '/'); + while (\str_starts_with($templateRootDirectory, './')) { + $templateRootDirectory = \substr($templateRootDirectory, 2); + } if ($templateRootDirectory !== '' && \preg_match('#(^|/)\.\.(/|$)#', $templateRootDirectory)) { throw new \Exception('Invalid template root directory'); } @@ -423,6 +426,9 @@ class Builds extends Action $templateRootDirectory = $template->getAttribute('rootDirectory', ''); $templateRootDirectory = \trim($templateRootDirectory, '/'); + while (\str_starts_with($templateRootDirectory, './')) { + $templateRootDirectory = \substr($templateRootDirectory, 2); + } if ($templateRootDirectory !== '' && \preg_match('#(^|/)\.\.(/|$)#', $templateRootDirectory)) { throw new \Exception('Invalid template root directory'); } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 01bb0de589..e1b55d4dfb 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2274,7 +2274,7 @@ class SitesCustomServerTest extends Scope $deployment = $this->createTemplateDeployment($siteId, [ 'repository' => $template['providerRepositoryId'], 'owner' => $template['providerOwner'], - 'rootDirectory' => \ltrim($template['frameworks'][0]['providerRootDirectory'], './'), + 'rootDirectory' => $template['frameworks'][0]['providerRootDirectory'], 'type' => 'tag', 'reference' => $template['providerVersion'], 'activate' => true @@ -2345,7 +2345,7 @@ class SitesCustomServerTest extends Scope $deployment = $this->createTemplateDeployment($siteId, [ 'repository' => $template['providerRepositoryId'], 'owner' => $template['providerOwner'], - 'rootDirectory' => \ltrim($template['frameworks'][0]['providerRootDirectory'], './'), + 'rootDirectory' => $template['frameworks'][0]['providerRootDirectory'], 'type' => 'branch', 'reference' => 'main', 'activate' => true @@ -2423,7 +2423,7 @@ class SitesCustomServerTest extends Scope $deployment = $this->createTemplateDeployment($siteId, [ 'repository' => $template['providerRepositoryId'], 'owner' => $template['providerOwner'], - 'rootDirectory' => \ltrim($template['frameworks'][0]['providerRootDirectory'], './'), + 'rootDirectory' => $template['frameworks'][0]['providerRootDirectory'], 'type' => 'commit', 'reference' => $latestCommit, 'activate' => true From 277419962be3586ef0e9503a82c74da92168e5b0 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 29 May 2026 17:48:00 +0530 Subject: [PATCH 17/25] fix: correct prefixed SDK enum names introduced in PR #12358 --- .../Platform/Modules/Functions/Http/Functions/Create.php | 2 +- .../Platform/Modules/Functions/Http/Functions/Update.php | 2 +- .../Platform/Modules/Functions/Http/Templates/XList.php | 2 +- .../Modules/Migrations/Http/Migrations/Appwrite/Create.php | 2 +- .../Migrations/Http/Migrations/CSV/Imports/Create.php | 2 +- .../Migrations/Http/Migrations/JSON/Imports/Create.php | 2 +- src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php | 6 +++--- src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php | 6 +++--- .../Platform/Modules/Sites/Http/Templates/XList.php | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php index e37f4120e1..eaafe561df 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php @@ -81,7 +81,7 @@ class Create extends Base )) ->param('functionId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Function ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('name', '', new Text(128), 'Function name. Max length: 128 chars.') - ->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.', enum: new Enum(name: 'FunctionRuntime')) + ->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.', enum: new Enum(name: 'Runtime')) ->param('execute', [], new Roles(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' roles are allowed, each 64 characters long.', true) ->param('events', [], new ArrayList(new FunctionEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true) ->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index 9272c2863c..5fbe010f05 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -73,7 +73,7 @@ class Update extends Base )) ->param('functionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Function ID.', false, ['dbForProject']) ->param('name', '', new Text(128), 'Function name. Max length: 128 chars.') - ->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.', true, enum: new Enum(name: 'FunctionRuntime')) + ->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.', true, enum: new Enum(name: 'Runtime')) ->param('execute', [], new Roles(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of role strings with execution permissions. By default no user is granted with any execute permissions. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' roles are allowed, each 64 characters long.', true) ->param('events', [], new ArrayList(new FunctionEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true) ->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php index d77063e95a..f334351fef 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php @@ -51,7 +51,7 @@ class XList extends Base ) ] )) - ->param('runtimes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('runtimes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of runtimes allowed for filtering function templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' runtimes are allowed.', true, enum: new Enum(name: 'FunctionRuntime')) + ->param('runtimes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('runtimes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of runtimes allowed for filtering function templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' runtimes are allowed.', true, enum: new Enum(name: 'Runtime')) ->param('useCases', [], new ArrayList(new WhiteList(FunctionUseCases::getAll()), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of use cases allowed for filtering function templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' use cases are allowed.', true, enum: new Enum(name: 'FunctionTemplateUseCase')) ->param('limit', 25, new Range(1, 5000), 'Limit the number of templates returned in the response. Default limit is 25, and maximum limit is 5000.', true) ->param('offset', 0, new Range(0, 5000), 'Offset the list of returned templates. Maximum offset is 5000.', true) diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Appwrite/Create.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Appwrite/Create.php index 2633f5f6fb..2e50f7966e 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Appwrite/Create.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/Appwrite/Create.php @@ -59,7 +59,7 @@ class Create extends Action ->param('endpoint', '', new URL(), 'Source Appwrite endpoint') ->param('projectId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Source Project ID', false, ['dbForProject']) ->param('apiKey', '', new Text(512), 'Source API Key') - ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'MigrationOnDuplicate')) + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'OnDuplicate')) ->inject('response') ->inject('dbForProject') ->inject('project') diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Imports/Create.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Imports/Create.php index 7222a05703..66c1b96ae5 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Imports/Create.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/CSV/Imports/Create.php @@ -70,7 +70,7 @@ class Create extends Action ->param('fileId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'File ID.', false, ['dbForProject']) ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) - ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'MigrationOnDuplicate')) + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'OnDuplicate')) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') diff --git a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Imports/Create.php b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Imports/Create.php index cec20fe61e..c1f2e25c8e 100644 --- a/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Imports/Create.php +++ b/src/Appwrite/Platform/Modules/Migrations/Http/Migrations/JSON/Imports/Create.php @@ -69,7 +69,7 @@ class Create extends Action ->param('fileId', '', new UID(), 'File ID.') ->param('resourceId', null, new CompoundUID(), 'Composite ID in the format {databaseId:collectionId}, identifying a collection within a database.') ->param('internalFile', false, new Boolean(), 'Is the file stored in an internal bucket?', true) - ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'MigrationOnDuplicate')) + ->param('onDuplicate', OnDuplicate::Fail->value, new WhiteList(OnDuplicate::values()), 'Behavior when a row with an existing $id is encountered. "fail" (default): abort on first conflict. "skip": silently ignore. "overwrite": replace existing row.', true, enum: new Enum(name: 'OnDuplicate')) ->inject('response') ->inject('dbForProject') ->inject('dbForPlatform') diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php index 064f2e213e..e167c88af2 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php @@ -64,7 +64,7 @@ class Create extends Base )) ->param('siteId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Site ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('name', '', new Text(128), 'Site name. Max length: 128 chars.') - ->param('framework', '', new WhiteList(\array_keys(Config::getParam('frameworks')), true), 'Sites framework.', enum: new Enum(name: 'SiteFramework')) + ->param('framework', '', new WhiteList(\array_keys(Config::getParam('frameworks')), true), 'Sites framework.', enum: new Enum(name: 'Framework')) ->param('enabled', true, new Boolean(), 'Is site enabled? When set to \'disabled\', users cannot access the site but Server SDKs with and API key can still access the site. No data is lost when this is toggled.', true) ->param('logging', true, new Boolean(), 'When disabled, request logs will exclude logs and errors, and site responses will be slightly faster.', true) ->param('timeout', 30, new Range(1, (int) System::getEnv('_APP_SITES_TIMEOUT', 30)), 'Maximum request time in seconds.', true) @@ -72,8 +72,8 @@ class Create extends Base ->param('buildCommand', '', new Text(8192, 0), 'Build Command.', true) ->param('startCommand', '', new Text(8192, 0), 'Custom start command. Leave empty to use default.', true) ->param('outputDirectory', '', new Text(8192, 0), 'Output Directory for site.', true) - ->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', enum: new Enum(name: 'SiteBuildRuntime')) - ->param('adapter', '', new WhiteList(['static', 'ssr']), 'Framework adapter defining rendering strategy. Allowed values are: static, ssr', true, enum: new Enum(name: 'SiteAdapter')) + ->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', enum: new Enum(name: 'BuildRuntime')) + ->param('adapter', '', new WhiteList(['static', 'ssr']), 'Framework adapter defining rendering strategy. Allowed values are: static, ssr', true, enum: new Enum(name: 'Adapter')) ->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Control System) deployment.', true) ->param('fallbackFile', '', new Text(255, 0), 'Fallback file for single page application sites.', true) ->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the site.', true) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 66537edb04..6cb1905550 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -68,7 +68,7 @@ class Update extends Base )) ->param('siteId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Site ID.', false, ['dbForProject']) ->param('name', '', new Text(128), 'Site name. Max length: 128 chars.') - ->param('framework', '', new WhiteList(\array_keys(Config::getParam('frameworks')), true), 'Sites framework.', enum: new Enum(name: 'SiteFramework')) + ->param('framework', '', new WhiteList(\array_keys(Config::getParam('frameworks')), true), 'Sites framework.', enum: new Enum(name: 'Framework')) ->param('enabled', true, new Boolean(), 'Is site enabled? When set to \'disabled\', users cannot access the site but Server SDKs with and API key can still access the site. No data is lost when this is toggled.', true) ->param('logging', true, new Boolean(), 'When disabled, request logs will exclude logs and errors, and site responses will be slightly faster.', true) ->param('timeout', 30, new Range(1, (int) System::getEnv('_APP_SITES_TIMEOUT', 30)), 'Maximum request time in seconds.', true) @@ -76,8 +76,8 @@ class Update extends Base ->param('buildCommand', '', new Text(8192, 0), 'Build Command.', true) ->param('startCommand', '', new Text(8192, 0), 'Custom start command. Leave empty to use default.', true) ->param('outputDirectory', '', new Text(8192, 0), 'Output Directory for site.', true) - ->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', true, enum: new Enum(name: 'SiteBuildRuntime')) - ->param('adapter', '', new WhiteList(['static', 'ssr']), 'Framework adapter defining rendering strategy. Allowed values are: static, ssr', true, enum: new Enum(name: 'SiteAdapter')) + ->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', true, enum: new Enum(name: 'BuildRuntime')) + ->param('adapter', '', new WhiteList(['static', 'ssr']), 'Framework adapter defining rendering strategy. Allowed values are: static, ssr', true, enum: new Enum(name: 'Adapter')) ->param('fallbackFile', '', new Text(255, 0), 'Fallback file for single page application sites.', true) ->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Control System) deployment.', true) ->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the site.', true) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php index a5c6ece560..722cf986f8 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php @@ -50,7 +50,7 @@ class XList extends Base ) ] )) - ->param('frameworks', [], new ArrayList(new WhiteList(\array_keys(Config::getParam('frameworks')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of frameworks allowed for filtering site templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' frameworks are allowed.', true, enum: new Enum(name: 'SiteFramework')) + ->param('frameworks', [], new ArrayList(new WhiteList(\array_keys(Config::getParam('frameworks')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of frameworks allowed for filtering site templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' frameworks are allowed.', true, enum: new Enum(name: 'Framework')) ->param('useCases', [], new ArrayList(new WhiteList(SiteUseCases::getAll()), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of use cases allowed for filtering site templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' use cases are allowed.', true, enum: new Enum(name: 'SiteTemplateUseCase')) ->param('limit', 25, new Range(1, 5000), 'Limit the number of templates returned in the response. Default limit is 25, and maximum limit is 5000.', true) ->param('offset', 0, new Range(0, 5000), 'Offset the list of returned templates. Maximum offset is 5000.', true) From 8630d7511121c48df3b1949920e8c86df38a5ba0 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 29 May 2026 17:57:49 +0530 Subject: [PATCH 18/25] fix: correct RedirectStatusCode enum name to StatusCode --- .../Platform/Modules/Proxy/Http/Rules/Redirect/Create.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php index 8dd15d3f03..24abbf49ba 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -68,7 +68,7 @@ class Create extends Action ->param('domain', null, new ValidatorDomain(), 'Domain name.') ->param('url', null, new URL(), 'Target URL of redirection') ->param('statusCode', null, new WhiteList([301, 302, 307, 308]), 'Status code of redirection', enum: new Enum( - name: 'RedirectStatusCode', + name: 'StatusCode', map: [ '301' => 'MovedPermanently', '302' => 'Found', From 41660819e7ace5d8d25390244b98d39dba50433a Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Sat, 30 May 2026 11:01:37 +0530 Subject: [PATCH 19/25] Fix public hostname DNS resolution in Swoole --- src/Appwrite/Network/Validator/PublicHostname.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Network/Validator/PublicHostname.php b/src/Appwrite/Network/Validator/PublicHostname.php index c16bb92864..e807315521 100644 --- a/src/Appwrite/Network/Validator/PublicHostname.php +++ b/src/Appwrite/Network/Validator/PublicHostname.php @@ -117,19 +117,23 @@ class PublicHostname extends Validator */ public static function resolve(string $hostname): array { - $ipv4 = @\gethostbynamel($hostname) ?: []; - + $ipv4 = []; $ipv6 = []; - $records = @\dns_get_record($hostname, DNS_AAAA); + + $records = @\dns_get_record($hostname, DNS_A | DNS_AAAA); if (\is_array($records)) { foreach ($records as $record) { + if (!empty($record['ip'])) { + $ipv4[] = $record['ip']; + } + if (!empty($record['ipv6'])) { $ipv6[] = $record['ipv6']; } } } - return \array_values(\array_unique(\array_merge($ipv4, $ipv6))); + return \array_values(\array_unique([...$ipv4, ...$ipv6])); } /** From 32c107a239c40f6ec450bb23b422beda140721e4 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Sat, 30 May 2026 16:58:35 +0530 Subject: [PATCH 20/25] Revert execution log removal --- .github/workflows/ci.yml | 12 ++--- Dockerfile | 1 + app/controllers/general.php | 7 ++- app/init/resources.php | 6 +++ app/listeners.php | 2 + app/views/install/compose.phtml | 29 +++++++++++ bin/worker-executions | 3 ++ docker-compose.yml | 31 +++++++++++ src/Appwrite/Bus/Events/ExecutionLogged.php | 18 ------- src/Appwrite/Bus/Listeners/Log.php | 50 ++++++++++++++++++ .../Functions/Http/Executions/Create.php | 14 ----- .../Modules/Functions/Workers/Builds.php | 6 --- src/Appwrite/Platform/Services/Workers.php | 2 + src/Appwrite/Platform/Workers/Executions.php | 51 +++++++++++++++++++ src/Appwrite/Platform/Workers/Functions.php | 26 ++-------- .../Functions/FunctionsCustomClientTest.php | 5 +- .../Functions/FunctionsCustomServerTest.php | 12 ++++- .../FunctionsScheduleTest.php | 8 +++ .../Services/Sites/SitesCustomServerTest.php | 17 +++++-- tests/resources/docker/docker-compose.yml | 21 ++++++++ tests/unit/Docker/ComposeTest.php | 2 +- 21 files changed, 247 insertions(+), 76 deletions(-) create mode 100755 bin/worker-executions delete mode 100644 src/Appwrite/Bus/Events/ExecutionLogged.php create mode 100644 src/Appwrite/Bus/Listeners/Log.php create mode 100644 src/Appwrite/Platform/Workers/Executions.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 343d22fdf2..8a7537cf1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -761,11 +761,11 @@ jobs: run: | docker tag ${{ env.IMAGE }}:before ${{ env.IMAGE }} docker compose up -d --wait --no-build - for attempt in $(seq 1 10); do - if curl -fsS http://localhost/v1/health/version; then + for attempt in $(seq 1 5); do + if curl -fsS http://localhost/v1/health; then break fi - if [ "$attempt" -eq 10 ]; then + if [ "$attempt" -eq 5 ]; then exit 1 fi sleep 1 @@ -825,11 +825,11 @@ jobs: run: | docker tag ${{ env.IMAGE }}:after ${{ env.IMAGE }} docker compose up -d --wait --no-build - for attempt in $(seq 1 10); do - if curl -fsS http://localhost/v1/health/version; then + for attempt in $(seq 1 5); do + if curl -fsS http://localhost/v1/health; then break fi - if [ "$attempt" -eq 10 ]; then + if [ "$attempt" -eq 5 ]; then exit 1 fi sleep 1 diff --git a/Dockerfile b/Dockerfile index 58150321d6..9a61635415 100755 --- a/Dockerfile +++ b/Dockerfile @@ -89,6 +89,7 @@ RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/worker-certificates && \ chmod +x /usr/local/bin/worker-databases && \ chmod +x /usr/local/bin/worker-deletes && \ + chmod +x /usr/local/bin/worker-executions && \ chmod +x /usr/local/bin/worker-functions && \ chmod +x /usr/local/bin/worker-mails && \ chmod +x /usr/local/bin/worker-messaging && \ diff --git a/app/controllers/general.php b/app/controllers/general.php index c53e0c29dd..219c14774f 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -714,12 +714,11 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S spec: $spec, resource: $resource->getArrayCopy(), )); - - $execution->setAttribute('logs', ''); - $execution->setAttribute('errors', ''); - $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); } + $execution->setAttribute('logs', ''); + $execution->setAttribute('errors', ''); + $headers = []; foreach (($executionResponse['headers'] ?? []) as $key => $value) { $headers[] = ['name' => $key, 'value' => \is_array($value) ? \implode(', ', $value) : $value]; diff --git a/app/init/resources.php b/app/init/resources.php index b9f2e90a15..34f66d3de7 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -7,6 +7,7 @@ use Appwrite\Event\Publisher\Build as BuildPublisher; use Appwrite\Event\Publisher\Certificate as CertificatePublisher; use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Event\Publisher\Delete as DeletePublisher; +use Appwrite\Event\Publisher\Execution as ExecutionPublisher; use Appwrite\Event\Publisher\Func as FunctionPublisher; use Appwrite\Event\Publisher\Mail as MailPublisher; use Appwrite\Event\Publisher\Messaging as MessagingPublisher; @@ -104,6 +105,11 @@ $container->set('publisherForUsage', fn (Publisher $publisher) => new UsagePubli new Queue(System::getEnv('_APP_STATS_USAGE_QUEUE_NAME', Event::STATS_USAGE_QUEUE_NAME)) ), ['publisher']); +$container->set('publisherForExecutions', fn (Publisher $publisher) => new ExecutionPublisher( + $publisher, + new Queue(System::getEnv('_APP_EXECUTIONS_QUEUE_NAME', Event::EXECUTIONS_QUEUE_NAME)) +), ['publisher']); + $container->set('publisherForFunctions', fn (Publisher $publisher) => new FunctionPublisher( $publisher, new Queue(System::getEnv('_APP_FUNCTIONS_QUEUE_NAME', Event::FUNCTIONS_QUEUE_NAME), 'utopia-queue', Event::FUNCTIONS_QUEUE_TTL) diff --git a/app/listeners.php b/app/listeners.php index 9f959ac6ab..240225dc45 100644 --- a/app/listeners.php +++ b/app/listeners.php @@ -1,9 +1,11 @@ getParam('hostPath', ''), '/'); - _APP_DB_PASS - _APP_LOGGING_CONFIG + appwrite-worker-executions: + image: /: + entrypoint: worker-executions + <<: *x-logging + container_name: appwrite-worker-executions + restart: unless-stopped + networks: + - appwrite + depends_on: + redis: + condition: service_healthy + : + condition: service_healthy + environment: + - _APP_ENV + - _APP_WORKER_PER_CORE + - _APP_REDIS_HOST + - _APP_REDIS_PORT + - _APP_REDIS_USER + - _APP_REDIS_PASS + - _APP_ENV + - _APP_DB_ADAPTER + - _APP_DB_HOST + - _APP_DB_PORT + - _APP_DB_SCHEMA + - _APP_DB_USER + - _APP_DB_PASS + - _APP_LOGGING_CONFIG + appwrite-worker-functions: image: /: entrypoint: worker-functions diff --git a/bin/worker-executions b/bin/worker-executions new file mode 100755 index 0000000000..6789fb8da8 --- /dev/null +++ b/bin/worker-executions @@ -0,0 +1,3 @@ +#!/bin/sh + +exec php /usr/src/code/app/worker.php executions "$@" diff --git a/docker-compose.yml b/docker-compose.yml index e2a5a7161e..7d3f6bdc5f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -690,6 +690,37 @@ services: - _APP_LOGGING_CONFIG - _APP_DATABASE_SHARED_TABLES + appwrite-worker-executions: + entrypoint: worker-executions + <<: [*x-logging, *x-build] + container_name: appwrite-worker-executions + image: appwrite-dev + networks: + - appwrite + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + depends_on: + - redis + - ${_APP_DB_HOST:-mongodb} + environment: + - _APP_ENV + - _APP_WORKER_PER_CORE + - _APP_POOL_ADAPTER + - _APP_OPENSSL_KEY_V1 + - _APP_REDIS_HOST + - _APP_REDIS_PORT + - _APP_REDIS_USER + - _APP_REDIS_PASS + - _APP_DB_ADAPTER + - _APP_DB_HOST + - _APP_DB_PORT + - _APP_DB_SCHEMA + - _APP_DB_USER + - _APP_DB_PASS + - _APP_LOGGING_CONFIG + - _APP_DATABASE_SHARED_TABLES + appwrite-worker-functions: entrypoint: worker-functions <<: [*x-logging, *x-build] diff --git a/src/Appwrite/Bus/Events/ExecutionLogged.php b/src/Appwrite/Bus/Events/ExecutionLogged.php deleted file mode 100644 index eabdc618e8..0000000000 --- a/src/Appwrite/Bus/Events/ExecutionLogged.php +++ /dev/null @@ -1,18 +0,0 @@ - $execution - * @param array $project - */ - public function __construct( - public readonly array $execution, - public readonly array $project, - ) { - } -} diff --git a/src/Appwrite/Bus/Listeners/Log.php b/src/Appwrite/Bus/Listeners/Log.php new file mode 100644 index 0000000000..e0376a4f81 --- /dev/null +++ b/src/Appwrite/Bus/Listeners/Log.php @@ -0,0 +1,50 @@ +desc('Persists execution logs to database via queue') + ->inject('publisherForExecutions') + ->callback($this->handle(...)); + } + + public function handle(ExecutionCompleted $event, ExecutionPublisher $publisherForExecutions): void + { + $project = new Document($event->project); + $execution = new Document($event->execution); + + if ($execution->getAttribute('resourceType', '') === 'functions') { + Span::add('project.id', $project->getId()); + Span::add('function.id', $execution->getAttribute('resourceId', '')); + Span::add('execution.id', $execution->getId()); + Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); + Span::add('execution.status', $execution->getAttribute('status', '')); + } + + $publisherForExecutions->enqueue(new ExecutionMessage( + project: $project, + execution: $execution, + )); + } +} diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index 092cb772a5..ba36b47884 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Functions\Http\Executions; use Ahc\Jwt\JWT; -use Appwrite\Bus\Events\ExecutionLogged; use Appwrite\Event\Event; use Appwrite\Event\Message\Delete as DeleteMessage; use Appwrite\Event\Message\Func as FunctionMessage; @@ -25,7 +24,6 @@ use Executor\Executor; use MaxMind\Db\Reader; use Utopia\Auth\Proofs\Token; use Utopia\Auth\Store; -use Utopia\Bus\Bus; use Utopia\Config\Config; use Utopia\Console; use Utopia\Database\Database; @@ -109,7 +107,6 @@ class Create extends Base ->inject('authorization') ->inject('publisherForDeletes') ->inject('executionsRetentionCount') - ->inject('bus') ->callback($this->action(...)); } @@ -138,7 +135,6 @@ class Create extends Base Authorization $authorization, DeletePublisher $publisherForDeletes, int $executionsRetentionCount, - Bus $bus, ) { $async = \strval($async) === 'true' || \strval($async) === '1'; @@ -341,11 +337,6 @@ class Create extends Base ->setAttribute('scheduledAt', $scheduledAt); $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); - - $bus->dispatch(new ExecutionLogged( - execution: $execution->getArrayCopy(), - project: $project->getArrayCopy(), - )); } if ($executionsRetentionCount > 0 && ENABLE_EXECUTIONS_LIMIT_ON_ROUTE) { @@ -516,11 +507,6 @@ class Create extends Base ; $execution = $authorization->skip(fn () => $dbForProject->createDocument('executions', $execution)); - - $bus->dispatch(new ExecutionLogged( - execution: $execution->getArrayCopy(), - project: $project->getArrayCopy(), - )); } $executionResponse['headers']['x-appwrite-execution-id'] = $execution->getId(); diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 92e00cd4e6..f04f7c3807 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -298,9 +298,6 @@ class Builds extends Action $templateRootDirectory = $template->getAttribute('rootDirectory', ''); $templateRootDirectory = \trim($templateRootDirectory, '/'); - while (\str_starts_with($templateRootDirectory, './')) { - $templateRootDirectory = \substr($templateRootDirectory, 2); - } if ($templateRootDirectory !== '' && \preg_match('#(^|/)\.\.(/|$)#', $templateRootDirectory)) { throw new \Exception('Invalid template root directory'); } @@ -426,9 +423,6 @@ class Builds extends Action $templateRootDirectory = $template->getAttribute('rootDirectory', ''); $templateRootDirectory = \trim($templateRootDirectory, '/'); - while (\str_starts_with($templateRootDirectory, './')) { - $templateRootDirectory = \substr($templateRootDirectory, 2); - } if ($templateRootDirectory !== '' && \preg_match('#(^|/)\.\.(/|$)#', $templateRootDirectory)) { throw new \Exception('Invalid template root directory'); } diff --git a/src/Appwrite/Platform/Services/Workers.php b/src/Appwrite/Platform/Services/Workers.php index f2cbeb390a..fa77725f7a 100644 --- a/src/Appwrite/Platform/Services/Workers.php +++ b/src/Appwrite/Platform/Services/Workers.php @@ -5,6 +5,7 @@ namespace Appwrite\Platform\Services; use Appwrite\Platform\Workers\Audits; use Appwrite\Platform\Workers\Certificates; use Appwrite\Platform\Workers\Deletes; +use Appwrite\Platform\Workers\Executions; use Appwrite\Platform\Workers\Functions; use Appwrite\Platform\Workers\Mails; use Appwrite\Platform\Workers\Messaging; @@ -23,6 +24,7 @@ class Workers extends Service ->addAction(Audits::getName(), new Audits()) ->addAction(Certificates::getName(), new Certificates()) ->addAction(Deletes::getName(), new Deletes()) + ->addAction(Executions::getName(), new Executions()) ->addAction(Functions::getName(), new Functions()) ->addAction(Mails::getName(), new Mails()) ->addAction(Messaging::getName(), new Messaging()) diff --git a/src/Appwrite/Platform/Workers/Executions.php b/src/Appwrite/Platform/Workers/Executions.php new file mode 100644 index 0000000000..8dbf10cae6 --- /dev/null +++ b/src/Appwrite/Platform/Workers/Executions.php @@ -0,0 +1,51 @@ +desc('Executions worker') + ->groups(['executions']) + ->inject('message') + ->inject('dbForProject') + ->callback($this->action(...)); + } + + public function action( + Message $message, + Database $dbForProject, + ): void { + $executionMessage = Execution::fromArray($message->getPayload()); + $execution = $executionMessage->execution; + + if ($execution->isEmpty()) { + throw new Exception('Missing execution'); + } + + Span::add('project.id', $executionMessage->project->getId()); + Span::add('function.id', $execution->getAttribute('resourceId', '')); + Span::add('execution.id', $execution->getId()); + Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); + Span::add('resource.type', $execution->getAttribute('resourceType', '')); + + $dbForProject->upsertDocument('executions', $execution); + } +} diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 273847859b..73c1db9444 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -263,7 +263,6 @@ class Functions extends Action /** * @param string $message - * @param Database $dbForProject * @param Document $function * @param string $trigger * @param string $path @@ -275,7 +274,6 @@ class Functions extends Action */ private function fail( string $message, - Database $dbForProject, Document $project, Bus $bus, Document $function, @@ -315,24 +313,19 @@ class Functions extends Action 'requestPath' => $path, 'requestMethod' => $method, 'requestHeaders' => $headersFiltered, - 'errors' => '', + 'errors' => $message, 'logs' => '', 'duration' => 0.0, ]); - $executionForEvent = (new Document($execution->getArrayCopy())) - ->setAttribute('errors', $message); - Span::add('function.id', $function->getId()); Span::add('execution.id', $execution->getId()); Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); Span::add('execution.trigger', $trigger); Span::add('execution.status', $execution->getAttribute('status', '')); - $dbForProject->upsertDocument('executions', $execution); - $bus->dispatch(new ExecutionCompleted( - execution: $executionForEvent->getArrayCopy(), + execution: $execution->getArrayCopy(), project: $project->getArrayCopy(), )); } @@ -397,19 +390,19 @@ class Functions extends Action if ($deployment->getAttribute('resourceId') !== $functionId) { $errorMessage = 'The execution could not be completed because a corresponding deployment was not found. A function deployment needs to be created before it can be executed. Please create a deployment for your function and try again.'; - $this->fail($errorMessage, $dbForProject, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); + $this->fail($errorMessage, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); return; } if ($deployment->isEmpty()) { $errorMessage = 'The execution could not be completed because a corresponding deployment was not found. A function deployment needs to be created before it can be executed. Please create a deployment for your function and try again.'; - $this->fail($errorMessage, $dbForProject, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); + $this->fail($errorMessage, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); return; } if ($deployment->getAttribute('status') !== 'ready') { $errorMessage = 'The execution could not be completed because the build is not ready. Please wait for the build to complete and try again.'; - $this->fail($errorMessage, $dbForProject, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); + $this->fail($errorMessage, $project, $bus, $function, $trigger, $path, $method, $user, $jwt, $event); return; } @@ -478,8 +471,6 @@ class Functions extends Action 'duration' => 0.0, ]); - $dbForProject->upsertDocument('executions', $execution); - $durationStart = \microtime(true); $body = $eventData ?? ''; @@ -635,13 +626,6 @@ class Functions extends Action /** Persist final execution status and record usage */ Span::add('execution.status', $execution->getAttribute('status', '')); - $dbForProject->updateDocument('executions', $execution->getId(), new Document([ - 'status' => $execution->getAttribute('status'), - 'responseStatusCode' => $execution->getAttribute('responseStatusCode'), - 'responseHeaders' => $execution->getAttribute('responseHeaders'), - 'duration' => $execution->getAttribute('duration'), - ])); - $bus->dispatch(new ExecutionCompleted( execution: $execution->getArrayCopy(), project: $project->getArrayCopy(), diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 18c99e856f..1208121077 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -590,7 +590,9 @@ class FunctionsCustomClientTest extends Scope 'data' => ['name' => 'Test Document'], ]); $this->assertEquals(201, $document['headers']['status-code']); - $this->assertEventually(function () use ($functionId) { + $documentId = $document['body']['$id']; + + $this->assertEventually(function () use ($functionId, $documentId) { $executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -603,6 +605,7 @@ class FunctionsCustomClientTest extends Scope $lastExecution = $executions['body']['executions'][0]; $this->assertEquals('completed', $lastExecution['status']); $this->assertEquals(204, $lastExecution['responseStatusCode']); + $this->assertStringContainsString($documentId, $lastExecution['logs']); }, 20000, 500); $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId, [ diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 0d189e0c69..44d5d274da 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -745,13 +745,15 @@ class FunctionsCustomServerTest extends Scope $executionId = $execution['body']['$id'] ?? ''; - $this->assertEventually(function () use ($functionId, $executionId) { + $this->assertEventually(function () use ($functionId, $executionId, $totalUsers) { $execution = $this->getExecution($functionId, $executionId); $this->assertEquals(200, $execution['headers']['status-code']); $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertEquals('completed', $execution['body']['status']); $this->assertEmpty($execution['body']['responseBody']); + $this->assertEmpty($execution['body']['errors']); + $this->assertStringContainsString("Total users: " . $totalUsers, $execution['body']['logs']); }, 10000, 500); $deployment = $this->getDeployment($functionId, $deployment['body']['$id']); @@ -2121,6 +2123,8 @@ class FunctionsCustomServerTest extends Scope $this->assertGreaterThan(2, $execution['body']['duration']); $this->assertLessThan(20, $execution['body']['duration']); $this->assertEquals('', $execution['body']['responseBody']); + $this->assertEquals('', $execution['body']['logs']); + $this->assertStringContainsString('timed out', $execution['body']['errors']); }, 10000, 500); $this->cleanupFunction($functionId); @@ -2343,7 +2347,7 @@ class FunctionsCustomServerTest extends Scope $userId = $user['body']['$id'] ?? ''; - $this->assertEventually(function () use ($functionId) { + $this->assertEventually(function () use ($functionId, $userId) { $executions = $this->listExecutions($functionId); $this->assertEquals(200, $executions['headers']['status-code']); @@ -2353,6 +2357,8 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $lastExecution['status']); $this->assertEquals(204, $lastExecution['responseStatusCode']); + $this->assertStringContainsString($userId, $lastExecution['logs']); + $this->assertStringContainsString('Event User', $lastExecution['logs']); $this->assertNotEmpty($lastExecution['$id']); $headers = array_column($lastExecution['requestHeaders'] ?? [], 'value', 'name'); $this->assertEmpty($headers['x-appwrite-client-ip'] ?? ''); @@ -2420,6 +2426,8 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertGreaterThan(0, $execution['body']['duration']); + $this->assertNotEmpty($execution['body']['logs']); + $this->assertStringContainsString("total", $execution['body']['logs']); }, 10000, 500); $this->cleanupFunction($functionId); diff --git a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php index c1e79b1d68..f4a70b5a9e 100644 --- a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php +++ b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php @@ -58,6 +58,8 @@ class FunctionsScheduleTest extends Scope $this->assertEquals('completed', $asyncExecution['status']); $this->assertEquals(200, $asyncExecution['responseStatusCode']); $this->assertEquals('', $asyncExecution['responseBody']); + $this->assertNotEmpty($asyncExecution['logs']); + $this->assertNotEmpty($asyncExecution['errors']); $this->assertGreaterThan(0, $asyncExecution['duration']); $this->assertNotEmpty($asyncExecution['$id']); $headers = array_column($asyncExecution['requestHeaders'] ?? [], 'value', 'name'); @@ -130,6 +132,12 @@ class FunctionsScheduleTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals('/custom-path', $execution['body']['requestPath']); $this->assertEquals('PATCH', $execution['body']['requestMethod']); + $this->assertStringContainsString('body-is-custom-body', $execution['body']['logs']); + $this->assertStringContainsString('custom-header-is-custom-value', $execution['body']['logs']); + $this->assertStringContainsString('method-is-patch', $execution['body']['logs']); + $this->assertStringContainsString('path-is-/custom-path', $execution['body']['logs']); + $this->assertStringContainsString('user-is-' . $this->getUser()['$id'], $execution['body']['logs']); + $this->assertStringContainsString('jwt-is-valid', $execution['body']['logs']); $this->assertGreaterThan(0, $execution['body']['duration']); }, 120000, 500); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index e1b55d4dfb..9cca689780 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2770,8 +2770,9 @@ class SitesCustomServerTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertStringContainsString("Inline logs printed.", $response['body']); - // Poll for execution entry to be written (async) + // Poll for execution logs to be written (async) // Filter by requestPath to avoid picking up screenshot worker executions + // Wait for both the execution entry AND its logs field to be populated $logs = null; $timeout = 120; $start = \time(); @@ -2781,16 +2782,21 @@ class SitesCustomServerTest extends Scope Query::equal('requestPath', ['/logs-inline'])->toString(), Query::limit(1)->toString(), ]); - if (!empty($logs['body']['executions'])) { + if (!empty($logs['body']['executions']) && !empty($logs['body']['executions'][0]['logs'])) { break; } \usleep(500000); } $this->assertNotEmpty($logs['body']['executions'], 'Execution logs were not available within timeout'); + $this->assertNotNull($logs['body']['executions'][0]['logs'], 'Execution logs content was not populated within timeout'); $this->assertEquals(200, $logs['headers']['status-code']); $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-inline", $logs['body']['executions'][0]['requestPath']); + $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Log2", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Error1", $logs['body']['executions'][0]['errors']); + $this->assertStringContainsString("Error2", $logs['body']['executions'][0]['errors']); $log1Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log1Id); @@ -2824,16 +2830,21 @@ class SitesCustomServerTest extends Scope Query::equal('requestPath', ['/logs-action'])->toString(), Query::limit(1)->toString(), ]); - if (!empty($logs['body']['executions'])) { + if (!empty($logs['body']['executions']) && !empty($logs['body']['executions'][0]['logs'])) { break; } \usleep(500000); } $this->assertNotEmpty($logs['body']['executions'], 'Action execution logs were not available within timeout'); + $this->assertNotNull($logs['body']['executions'][0]['logs'], 'Action execution logs content was not populated within timeout'); $this->assertEquals(200, $logs['headers']['status-code']); $this->assertStringContainsString($deploymentId, $logs['body']['executions'][0]['deploymentId']); $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); $this->assertStringContainsString("/logs-action", $logs['body']['executions'][0]['requestPath']); + $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Log2", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Error1", $logs['body']['executions'][0]['errors']); + $this->assertStringContainsString("Error2", $logs['body']['executions'][0]['errors']); $log2Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log2Id); diff --git a/tests/resources/docker/docker-compose.yml b/tests/resources/docker/docker-compose.yml index 735e88525e..47a69f077b 100644 --- a/tests/resources/docker/docker-compose.yml +++ b/tests/resources/docker/docker-compose.yml @@ -216,6 +216,27 @@ services: - _APP_DB_USER - _APP_DB_PASS + appwrite-worker-executions: + entrypoint: worker-executions + container_name: appwrite-worker-executions + build: + context: . + restart: unless-stopped + networks: + - appwrite + depends_on: + - redis + - mariadb + environment: + - _APP_ENV + - _APP_REDIS_HOST + - _APP_REDIS_PORT + - _APP_DB_HOST + - _APP_DB_PORT + - _APP_DB_SCHEMA + - _APP_DB_USER + - _APP_DB_PASS + appwrite-worker-functions: entrypoint: worker-functions container_name: appwrite-worker-functions diff --git a/tests/unit/Docker/ComposeTest.php b/tests/unit/Docker/ComposeTest.php index 74779230ac..e63d877baf 100644 --- a/tests/unit/Docker/ComposeTest.php +++ b/tests/unit/Docker/ComposeTest.php @@ -23,7 +23,7 @@ class ComposeTest extends TestCase public function testServices(): void { - $this->assertCount(15, $this->object->getServices()); + $this->assertCount(16, $this->object->getServices()); $this->assertEquals('appwrite', $this->object->getService('appwrite')->getContainerName()); $this->assertEquals('', $this->object->getService('appwrite')->getImageVersion()); $this->assertEquals('3.6', $this->object->getService('traefik')->getImageVersion()); From 221736694c6bfa699d20714c535f88817ff15f31 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 16:40:42 +0530 Subject: [PATCH 21/25] Normalize template root directories in builds --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index f04f7c3807..92e00cd4e6 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -298,6 +298,9 @@ class Builds extends Action $templateRootDirectory = $template->getAttribute('rootDirectory', ''); $templateRootDirectory = \trim($templateRootDirectory, '/'); + while (\str_starts_with($templateRootDirectory, './')) { + $templateRootDirectory = \substr($templateRootDirectory, 2); + } if ($templateRootDirectory !== '' && \preg_match('#(^|/)\.\.(/|$)#', $templateRootDirectory)) { throw new \Exception('Invalid template root directory'); } @@ -423,6 +426,9 @@ class Builds extends Action $templateRootDirectory = $template->getAttribute('rootDirectory', ''); $templateRootDirectory = \trim($templateRootDirectory, '/'); + while (\str_starts_with($templateRootDirectory, './')) { + $templateRootDirectory = \substr($templateRootDirectory, 2); + } if ($templateRootDirectory !== '' && \preg_match('#(^|/)\.\.(/|$)#', $templateRootDirectory)) { throw new \Exception('Invalid template root directory'); } From a080a184395663524036146fb74131a7d5181929 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Sat, 30 May 2026 18:21:00 +0530 Subject: [PATCH 22/25] Keep benchmark health check fix --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a7537cf1d..343d22fdf2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -761,11 +761,11 @@ jobs: run: | docker tag ${{ env.IMAGE }}:before ${{ env.IMAGE }} docker compose up -d --wait --no-build - for attempt in $(seq 1 5); do - if curl -fsS http://localhost/v1/health; then + for attempt in $(seq 1 10); do + if curl -fsS http://localhost/v1/health/version; then break fi - if [ "$attempt" -eq 5 ]; then + if [ "$attempt" -eq 10 ]; then exit 1 fi sleep 1 @@ -825,11 +825,11 @@ jobs: run: | docker tag ${{ env.IMAGE }}:after ${{ env.IMAGE }} docker compose up -d --wait --no-build - for attempt in $(seq 1 5); do - if curl -fsS http://localhost/v1/health; then + for attempt in $(seq 1 10); do + if curl -fsS http://localhost/v1/health/version; then break fi - if [ "$attempt" -eq 5 ]; then + if [ "$attempt" -eq 10 ]; then exit 1 fi sleep 1 From 8e0891c00d0258091bc7ced7ddd343abfd70ed46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 30 May 2026 20:28:07 +0200 Subject: [PATCH 23/25] Make policies LIST and GET easy to override --- .../Project/Http/Project/Policies/Get.php | 67 ++++++++++++------- .../Project/Http/Project/Policies/XList.php | 36 ++++++---- .../Utopia/Response/Model/PolicyList.php | 30 ++++++--- 3 files changed, 82 insertions(+), 51 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php index 7505cf62c4..c0c247936d 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php @@ -23,6 +23,9 @@ class Get extends Action public function __construct() { + $policies = $this->getPolicies(); + $policyIds = \array_keys($policies); + $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/project/policies/:policyId') @@ -40,31 +43,11 @@ class Get extends Action responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, - model: [ - Response::MODEL_POLICY_PASSWORD_DICTIONARY, - Response::MODEL_POLICY_PASSWORD_HISTORY, - Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA, - Response::MODEL_POLICY_SESSION_ALERT, - Response::MODEL_POLICY_SESSION_DURATION, - Response::MODEL_POLICY_SESSION_INVALIDATION, - Response::MODEL_POLICY_SESSION_LIMIT, - Response::MODEL_POLICY_USER_LIMIT, - Response::MODEL_POLICY_MEMBERSHIP_PRIVACY, - ], + model: \array_values($policies), ) ] )) - ->param('policyId', '', new WhiteList([ - 'password-dictionary', - 'password-history', - 'password-personal-data', - 'session-alert', - 'session-duration', - 'session-invalidation', - 'session-limit', - 'user-limit', - 'membership-privacy', - ], true), 'Policy ID. Can be one of: password-dictionary, password-history, password-personal-data, session-alert, session-duration, session-invalidation, session-limit, user-limit, membership-privacy.', enum: new Enum(name: 'ProjectPolicyId')) + ->param('policyId', '', new WhiteList($policyIds, true), 'Policy ID. Can be one of: ' . \implode(', ', $policyIds) . '.', enum: new Enum(name: 'ProjectPolicyId')) ->inject('response') ->inject('project') ->callback($this->action(...)); @@ -75,9 +58,43 @@ class Get extends Action Response $response, Document $project, ): void { + $resolved = $this->resolvePolicy($policyId, $project); + + if ($resolved === null) { + throw new \LogicException('Unknown policy ID: ' . $policyId); + } + + [$policy, $model] = $resolved; + + $response->dynamic($policy, $model); + } + + /** + * @return array + */ + protected function getPolicies(): array + { + return [ + 'password-dictionary' => Response::MODEL_POLICY_PASSWORD_DICTIONARY, + 'password-history' => Response::MODEL_POLICY_PASSWORD_HISTORY, + 'password-personal-data' => Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA, + 'session-alert' => Response::MODEL_POLICY_SESSION_ALERT, + 'session-duration' => Response::MODEL_POLICY_SESSION_DURATION, + 'session-invalidation' => Response::MODEL_POLICY_SESSION_INVALIDATION, + 'session-limit' => Response::MODEL_POLICY_SESSION_LIMIT, + 'user-limit' => Response::MODEL_POLICY_USER_LIMIT, + 'membership-privacy' => Response::MODEL_POLICY_MEMBERSHIP_PRIVACY, + ]; + } + + /** + * @return ?array + */ + protected function resolvePolicy(string $policyId, Document $project): ?array + { $auths = $project->getAttribute('auths', []); - [$policy, $model] = match ($policyId) { + return match ($policyId) { 'password-dictionary' => [ new Document([ '$id' => 'password-dictionary', @@ -145,9 +162,7 @@ class Get extends Action ]), Response::MODEL_POLICY_MEMBERSHIP_PRIVACY, ], - default => throw new \LogicException('Unknown policy ID: ' . $policyId), + default => null, }; - - $response->dynamic($policy, $model); } } diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php index 3020fa79dd..7057803c8a 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php @@ -71,9 +71,30 @@ class XList extends Action throw new Exception(Exception::GENERAL_QUERY_INVALID, $e->getMessage()); } + $policies = $this->getPolicies($project); + + $total = $includeTotal ? \count($policies) : 0; + + $grouped = Query::groupByType($queries); + $offset = $grouped['offset'] ?? 0; + $limit = $grouped['limit'] ?? null; + + $policies = \array_slice($policies, $offset, $limit); + + $response->dynamic(new Document([ + 'policies' => $policies, + 'total' => $total, + ]), Response::MODEL_POLICY_LIST); + } + + /** + * @return array + */ + protected function getPolicies(Document $project): array + { $auths = $project->getAttribute('auths', []); - $policies = [ + return [ new Document([ '$id' => 'password-dictionary', 'enabled' => $auths['passwordDictionary'] ?? false, @@ -115,18 +136,5 @@ class XList extends Action 'userMFA' => $auths['membershipsMfa'] ?? false, ]), ]; - - $total = $includeTotal ? \count($policies) : 0; - - $grouped = Query::groupByType($queries); - $offset = $grouped['offset'] ?? 0; - $limit = $grouped['limit'] ?? null; - - $policies = \array_slice($policies, $offset, $limit); - - $response->dynamic(new Document([ - 'policies' => $policies, - 'total' => $total, - ]), Response::MODEL_POLICY_LIST); } } diff --git a/src/Appwrite/Utopia/Response/Model/PolicyList.php b/src/Appwrite/Utopia/Response/Model/PolicyList.php index 09548fedcf..11704cdbff 100644 --- a/src/Appwrite/Utopia/Response/Model/PolicyList.php +++ b/src/Appwrite/Utopia/Response/Model/PolicyList.php @@ -17,23 +17,31 @@ class PolicyList extends Model 'example' => 9, ]) ->addRule('policies', [ - 'type' => [ - Response::MODEL_POLICY_PASSWORD_DICTIONARY, - Response::MODEL_POLICY_PASSWORD_HISTORY, - Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA, - Response::MODEL_POLICY_SESSION_ALERT, - Response::MODEL_POLICY_SESSION_DURATION, - Response::MODEL_POLICY_SESSION_INVALIDATION, - Response::MODEL_POLICY_SESSION_LIMIT, - Response::MODEL_POLICY_USER_LIMIT, - Response::MODEL_POLICY_MEMBERSHIP_PRIVACY, - ], + 'type' => $this->getPolicyModels(), 'description' => 'List of policies.', 'default' => [], 'array' => true, ]); } + /** + * @return array + */ + protected function getPolicyModels(): array + { + return [ + Response::MODEL_POLICY_PASSWORD_DICTIONARY, + Response::MODEL_POLICY_PASSWORD_HISTORY, + Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA, + Response::MODEL_POLICY_SESSION_ALERT, + Response::MODEL_POLICY_SESSION_DURATION, + Response::MODEL_POLICY_SESSION_INVALIDATION, + Response::MODEL_POLICY_SESSION_LIMIT, + Response::MODEL_POLICY_USER_LIMIT, + Response::MODEL_POLICY_MEMBERSHIP_PRIVACY, + ]; + } + public function getName(): string { return 'Policies List'; From 61db9a0e2a7674bcc6dfe308089bc3b04d3f7239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 30 May 2026 22:37:16 +0200 Subject: [PATCH 24/25] Improve extensibility of policies tests --- tests/e2e/Services/Project/PoliciesBase.php | 62 ++++++++++----------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index 43c09b55c3..8f9bc1fccb 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -7,13 +7,12 @@ use Utopia\Database\Query; trait PoliciesBase { - // ========================================================================= - // Get Policy - // ========================================================================= - - public function testGetPolicy(): void + /** + * @return array> + */ + protected function getExpectedPolicies(): array { - $expectedFields = [ + return [ 'password-dictionary' => ['enabled'], 'password-history' => ['total'], 'password-personal-data' => ['enabled'], @@ -24,8 +23,15 @@ trait PoliciesBase 'user-limit' => ['total'], 'membership-privacy' => ['userId', 'userEmail', 'userPhone', 'userName', 'userMFA'], ]; + } - foreach ($expectedFields as $policyId => $fields) { + // ========================================================================= + // Get Policy + // ========================================================================= + + public function testGetPolicy(): void + { + foreach ($this->getExpectedPolicies() as $policyId => $fields) { $response = $this->getPolicy($policyId); $this->assertSame(200, $response['headers']['status-code']); @@ -125,25 +131,21 @@ trait PoliciesBase { $response = $this->listPolicies(); + $expected = $this->getExpectedPolicies(); + $this->assertSame(200, $response['headers']['status-code']); $this->assertArrayHasKey('policies', $response['body']); $this->assertArrayHasKey('total', $response['body']); $this->assertIsArray($response['body']['policies']); $this->assertIsInt($response['body']['total']); - $this->assertSame(9, $response['body']['total']); - $this->assertCount(9, $response['body']['policies']); + $this->assertSame(\count($expected), $response['body']['total']); + $this->assertCount(\count($expected), $response['body']['policies']); $policyIds = \array_column($response['body']['policies'], '$id'); - $this->assertContains('password-dictionary', $policyIds); - $this->assertContains('password-history', $policyIds); - $this->assertContains('password-personal-data', $policyIds); - $this->assertContains('session-alert', $policyIds); - $this->assertContains('session-duration', $policyIds); - $this->assertContains('session-invalidation', $policyIds); - $this->assertContains('session-limit', $policyIds); - $this->assertContains('user-limit', $policyIds); - $this->assertContains('membership-privacy', $policyIds); + foreach (\array_keys($expected) as $policyId) { + $this->assertContains($policyId, $policyIds); + } } public function testListPoliciesResponseModel(): void @@ -161,19 +163,13 @@ trait PoliciesBase $byId[$policy['$id']] = $policy; } - $this->assertArrayHasKey('enabled', $byId['password-dictionary']); - $this->assertArrayHasKey('total', $byId['password-history']); - $this->assertArrayHasKey('enabled', $byId['password-personal-data']); - $this->assertArrayHasKey('enabled', $byId['session-alert']); - $this->assertArrayHasKey('duration', $byId['session-duration']); - $this->assertArrayHasKey('enabled', $byId['session-invalidation']); - $this->assertArrayHasKey('total', $byId['session-limit']); - $this->assertArrayHasKey('total', $byId['user-limit']); - $this->assertArrayHasKey('userId', $byId['membership-privacy']); - $this->assertArrayHasKey('userEmail', $byId['membership-privacy']); - $this->assertArrayHasKey('userPhone', $byId['membership-privacy']); - $this->assertArrayHasKey('userName', $byId['membership-privacy']); - $this->assertArrayHasKey('userMFA', $byId['membership-privacy']); + foreach ($this->getExpectedPolicies() as $policyId => $fields) { + $this->assertArrayHasKey($policyId, $byId); + + foreach ($fields as $field) { + $this->assertArrayHasKey($field, $byId[$policyId]); + } + } } public function testListPoliciesReflectsUpdates(): void @@ -226,7 +222,7 @@ trait PoliciesBase $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(0, $response['body']['total']); - $this->assertCount(9, $response['body']['policies']); + $this->assertCount(\count($this->getExpectedPolicies()), $response['body']['policies']); } public function testListPoliciesWithLimit(): void @@ -237,7 +233,7 @@ trait PoliciesBase $this->assertSame(200, $response['headers']['status-code']); $this->assertCount(1, $response['body']['policies']); - $this->assertSame(9, $response['body']['total']); + $this->assertSame(\count($this->getExpectedPolicies()), $response['body']['total']); } public function testListPoliciesWithOffset(): void From 2ae4209a99cad7fe253bb1dc3dd39fdf832e216c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 30 May 2026 22:52:38 +0200 Subject: [PATCH 25/25] Improve downstream tests --- tests/e2e/Services/Project/PoliciesBase.php | 22 +++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index 8f9bc1fccb..71fc85919f 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -138,8 +138,12 @@ trait PoliciesBase $this->assertArrayHasKey('total', $response['body']); $this->assertIsArray($response['body']['policies']); $this->assertIsInt($response['body']['total']); - $this->assertSame(\count($expected), $response['body']['total']); - $this->assertCount(\count($expected), $response['body']['policies']); + + // Unpaginated list: total reflects exactly what was returned. + $this->assertSame($response['body']['total'], \count($response['body']['policies'])); + + // At least the known policies are present; downstream may add more. + $this->assertGreaterThanOrEqual(\count($expected), $response['body']['total']); $policyIds = \array_column($response['body']['policies'], '$id'); @@ -222,7 +226,15 @@ trait PoliciesBase $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(0, $response['body']['total']); - $this->assertCount(\count($this->getExpectedPolicies()), $response['body']['policies']); + + // total=false skips the count but still returns every policy; downstream may add more. + $this->assertGreaterThanOrEqual(\count($this->getExpectedPolicies()), \count($response['body']['policies'])); + + $policyIds = \array_column($response['body']['policies'], '$id'); + + foreach (\array_keys($this->getExpectedPolicies()) as $policyId) { + $this->assertContains($policyId, $policyIds); + } } public function testListPoliciesWithLimit(): void @@ -233,7 +245,9 @@ trait PoliciesBase $this->assertSame(200, $response['headers']['status-code']); $this->assertCount(1, $response['body']['policies']); - $this->assertSame(\count($this->getExpectedPolicies()), $response['body']['total']); + + // limit caps the page, not the total; downstream may add more policies. + $this->assertGreaterThanOrEqual(\count($this->getExpectedPolicies()), $response['body']['total']); } public function testListPoliciesWithOffset(): void