From 82df418820da32f070ae23056ec8572435994c2f Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 17 Jun 2026 18:01:16 +0100 Subject: [PATCH 1/3] fix(builds): mask internal errors from user-visible build logs The builds worker wrote the message of any caught throwable straight into the user-visible buildLogs, leaking internal errors (e.g. database or executor failures) to users. Introduce a BuildException (a typed Appwrite\Extend\Exception defaulting to BUILD_FAILED) for every build error we raise intentionally, and only surface its message in the failure handler. Any other throwable is masked behind a generic message; the real error is still recorded on the span. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Functions/Workers/BuildException.php | 23 ++++++++++++++ .../Modules/Functions/Workers/Builds.php | 31 ++++++++++--------- 2 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Functions/Workers/BuildException.php diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/BuildException.php b/src/Appwrite/Platform/Modules/Functions/Workers/BuildException.php new file mode 100644 index 0000000000..1496fd7b72 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Functions/Workers/BuildException.php @@ -0,0 +1,23 @@ +getCollection() === 'functions' ? RESOURCE_TYPE_FUNCTIONS : RESOURCE_TYPE_SITES, $resource->getId())) { - throw new \Exception('Resource is blocked'); + throw new BuildException('Resource is blocked'); } $log->addTag('deploymentId', $deployment->getId()); @@ -226,7 +226,7 @@ class Builds extends Action } if ($resource->getCollection() === 'functions' && empty($deployment->getAttribute('entrypoint', ''))) { - throw new \Exception('Entrypoint for your Appwrite Function is missing. Please specify it when making deployment or update the entrypoint under your function\'s "Settings" > "Configuration" > "Entrypoint".'); + throw new BuildException('Entrypoint for your Appwrite Function is missing. Please specify it when making deployment or update the entrypoint under your function\'s "Settings" > "Configuration" > "Entrypoint".'); } $version = $this->getVersion($resource); @@ -406,7 +406,7 @@ class Builds extends Action $exit = Console::execute($gitCloneCommand, '', $stdout, $stderr); if ($exit !== 0) { - throw new \Exception('Unable to clone code repository: ' . $stderr); + throw new BuildException('Unable to clone code repository: ' . $stderr); } // Local refactoring for function folder with spaces @@ -501,7 +501,7 @@ class Builds extends Action } if ($directorySize > $sizeLimit && $sizeLimit !== 0) { - throw new \Exception('Repository directory size should be less than ' . number_format($sizeLimit / (1000 * 1000), 2) . ' MBs.'); + throw new BuildException('Repository directory size should be less than ' . number_format($sizeLimit / (1000 * 1000), 2) . ' MBs.'); } Console::execute('find ' . \escapeshellarg($tmpDirectory) . ' -type d -name ".git" -exec rm -rf {} +', '', $stdout, $stderr); @@ -739,7 +739,7 @@ class Builds extends Action $span?->set('build.runtime.timed_out', true); $span?->set('build.runtime.error_type', $error::class); $span?->set('build.runtime.error_message', $error->getMessage()); - $err = new AppwriteException(AppwriteException::BUILD_TIMEOUT, previous: $error); + $err = new BuildException(type: AppwriteException::BUILD_TIMEOUT, previous: $error); } catch (\Throwable $error) { $span?->set('build.runtime.error_type', $error::class); $span?->set('build.runtime.error_message', $error->getMessage()); @@ -865,7 +865,7 @@ class Builds extends Action $buildSizeLimit = $plan['buildSize'] * 1000 * 1000; } if ($response['size'] > $buildSizeLimit && $buildSizeLimit !== 0) { - throw new \Exception('Build size should be less than ' . number_format($buildSizeLimit / (1000 * 1000), 2) . ' MBs.'); + throw new BuildException('Build size should be less than ' . number_format($buildSizeLimit / (1000 * 1000), 2) . ' MBs.'); } $deployment->setAttribute('buildPath', $response['path']); @@ -896,7 +896,7 @@ class Builds extends Action Span::add('build.adapter', $deployment->getAttribute('adapter')); Span::add('build.fallback_file', $deployment->getAttribute('fallbackFile')); } elseif ($adapter === 'ssr' && $detection->getName() === 'static') { - throw new \Exception('Adapter mismatch. Detected: ' . $detection->getName() . ' does not match with the set adapter: ' . $adapter); + throw new BuildException('Adapter mismatch. Detected: ' . $detection->getName() . ' does not match with the set adapter: ' . $adapter); } } @@ -1134,14 +1134,12 @@ class Builds extends Action return; } - Span::add('build.error.stage', 'deployment'); - Span::add('build.error.type', $th::class); - Span::add('build.error.message', $th->getMessage()); - Span::add('build.error.file', $th->getFile()); - Span::add('build.error.line', $th->getLine()); + $isUserFacing = $th instanceof BuildException; + $message = $isUserFacing + ? $th->getMessage() + : 'An internal error occurred while building. Please try again, and contact support if the problem persists.'; // Color message red - $message = $th->getMessage(); if (! \str_contains($message, '')) { $message = '' . $message; } @@ -1181,6 +1179,11 @@ class Builds extends Action if ($isVcsEnabled) { $this->runGitAction('failed', $github, $providerCommitHash, $owner, $repositoryName, $project, $resource, $deployment->getId(), $dbForProject, $dbForPlatform, $queueForRealtime, $platform, true); } + + // Let the worker harness record internal errors via the span and logger. + if (! $isUserFacing) { + throw $th; + } } finally { $queueForRealtime ->setPayload($deployment->getArrayCopy()) @@ -1277,7 +1280,7 @@ class Builds extends Action default => null }; if (\is_null($runtime)) { - throw new \Exception('Runtime "' . $resource->getAttribute('runtime', '') . '" is not supported'); + throw new BuildException('Runtime "' . $resource->getAttribute('runtime', '') . '" is not supported'); } return $runtime; From b881a4ed641a175e39b4e836fea85ed96c2dda53 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 23 Jun 2026 14:38:24 +0100 Subject: [PATCH 2/3] feat(builds): record per-phase timings on the build span Emit timings.{setup,source,build,finalize} so each distinct phase of a build (preparation, source packaging, executor build, finalization) can be profiled independently of the overall build.duration. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Platform/Modules/Functions/Workers/Builds.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 392f37bc02..e1e7375cb5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -195,6 +195,7 @@ class Builds extends Action $startTime = DateTime::now(); $durationStart = \microtime(true); + $phaseStart = $durationStart; $resourceKey = match ($resource->getCollection()) { 'functions' => 'functionId', @@ -297,6 +298,9 @@ class Builds extends Action $github->initializeVariables($providerInstallationId, $privateKey, $githubAppId); } + Span::add('timings.setup', \round(\microtime(true) - $phaseStart, 3)); + $phaseStart = \microtime(true); + try { if (! $isVcsEnabled) { // Non-VCS + Template @@ -539,6 +543,9 @@ class Builds extends Action $this->runGitAction('processing', $github, $providerCommitHash, $owner, $repositoryName, $project, $resource, $deployment->getId(), $dbForProject, $dbForPlatform, $queueForRealtime, $platform); } + Span::add('timings.source', \round(\microtime(true) - $phaseStart, 3)); + $phaseStart = \microtime(true); + /** Request the executor to build the code... */ $updated = $dbForProject->updateDocuments('deployments', new Document([ 'status' => 'building', @@ -849,6 +856,9 @@ class Builds extends Action }), ]); + Span::add('timings.build', \round(\microtime(true) - $phaseStart, 3)); + $phaseStart = \microtime(true); + $latestDeployment = $dbForProject->getDocument('deployments', $deploymentId); if ($latestDeployment->getAttribute('status') === 'canceled') { $this->finalizeCanceledDeployment($deployment->getId(), $dbForProject, $queueForRealtime); @@ -1127,6 +1137,8 @@ class Builds extends Action Span::add('build.screenshot_queued', true); } + + Span::add('timings.finalize', \round(\microtime(true) - $phaseStart, 3)); } catch (\Throwable $th) { if ($dbForProject->getDocument('deployments', $deploymentId)->getAttribute('status') === 'canceled') { $this->finalizeCanceledDeployment($deployment->getId(), $dbForProject, $queueForRealtime); From 65b863b44345d09adca5f2971c9590c179d51327 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 23 Jun 2026 14:55:24 +0100 Subject: [PATCH 3/3] fix(builds): record user-facing build failures on the span A swallowed BuildException is never re-raised to the worker harness, so without this its failure reason was absent from the trace. Record build.error.type/message on the span for user-facing failures; internal errors still get full detail via the harness setError on rethrow. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index e1e7375cb5..c2b8837c13 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1151,6 +1151,13 @@ class Builds extends Action ? $th->getMessage() : 'An internal error occurred while building. Please try again, and contact support if the problem persists.'; + // Record user-facing failures on the span here, since they're not + // re-raised to the harness (which records internal errors via setError). + if ($isUserFacing) { + Span::add('build.exception.type', $th->getType()); + Span::add('build.exception.message', $th->getMessage()); + } + // Color message red if (! \str_contains($message, '')) { $message = '' . $message;