From 545abe046b2037a4e06c2d8133ab1c81662b57b7 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 8 Jul 2026 17:20:51 +0100 Subject: [PATCH] Report sourceSize for remote-source jobs builds via a stat artifact MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Templates and VCS deployments fetch their source in the sidecar (codeload / presigned tarball), so unlike the uploaded-tarball path Appwrite never sees the source and can't size it — leaving sourceSize (and totalSize) at 0, which fails the template E2E size assertions on the orchestrator backend. Add a stat artifact over the downloaded archive (remote-source builds only) and subscribe to the orchestrator.job.artifact callback; the worker records the reported size as the deployment's sourceSize. sourceSize and totalSize are both recomputed on this callback and in finalize so the two agree regardless of callback ordering. Note: reads the size flat or nested under 'stat' and keys the artifact on id 'sourceSize' — the orchestrator's stat-callback payload shape is still settling. Only closes the sourceSize gap (tests using main/commit refs); the version-range tag case (0.3.*) still needs range resolution in utopia-php/vcs. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Appwrite/Compute/Job.php | 12 ++++++- .../Modules/Functions/Workers/Jobs.php | 32 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Compute/Job.php b/src/Appwrite/Compute/Job.php index 1fcc4e5a12..ac8d2ce84e 100644 --- a/src/Appwrite/Compute/Job.php +++ b/src/Appwrite/Compute/Job.php @@ -6,6 +6,7 @@ use Ahc\Jwt\JWT; use Appwrite\Deployment\Token; use OpenRuntimes\Orchestrator\Enum\CallbackEvent; use OpenRuntimes\Orchestrator\Model\Artifact\DownloadArtifact; +use OpenRuntimes\Orchestrator\Model\Artifact\StatArtifact; use OpenRuntimes\Orchestrator\Model\Artifact\UnarchiveArtifact; use OpenRuntimes\Orchestrator\Model\Callback; use OpenRuntimes\Orchestrator\Model\Volume; @@ -73,6 +74,11 @@ final class Job $sourceArtifacts = [ new DownloadArtifact(id: 'source', in: $source['url'], out: 'source.tar.gz'), new UnarchiveArtifact(id: 'extract', in: 'source.tar.gz', out: 'source', subdir: $subdir !== '' ? $subdir : null), + // Appwrite never sees the remote source (the sidecar fetches it), + // so unlike the uploaded-tarball path it can't size it. Stat the + // downloaded archive so the orchestrator reports its byte size in + // an artifact callback, which the worker records as sourceSize. + new StatArtifact(id: 'sourceSize', in: 'source.tar.gz', depends: 'source'), ]; } else { // Presigned source-download URL (GET, no request-body cap), fetched by @@ -128,7 +134,11 @@ final class Job ], 'callback' => new Callback( url: "{$endpoint}/v1/jobs/event?" . \http_build_query(['project' => $projectId]), - events: [CallbackEvent::Log, CallbackEvent::Exit], + // Artifact callbacks only carry the source-size stat, which exists + // only for remote-source builds (templates / VCS). + events: $source !== null + ? [CallbackEvent::Log, CallbackEvent::Artifact, CallbackEvent::Exit] + : [CallbackEvent::Log, CallbackEvent::Exit], key: System::getEnv('_APP_JOBS_SECRET', ''), ), ]; diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php b/src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php index 7615935e1f..61a4e6db60 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php @@ -113,6 +113,7 @@ class Jobs extends Action $deployment = match ($event->event) { 'orchestrator.job.log' => $this->onLog($dbForProject, $deployment, $event->data), + 'orchestrator.job.artifact' => $this->onArtifact($dbForProject, $deployment, $event->data), 'orchestrator.job.exit' => $this->onExit($dbForProject, $dbForPlatform, $project, $deployment, (int) ($event->data['exitCode'] ?? 0), $usage, $publisherForUsage, $deviceForBuilds, $github), default => $deployment, }; @@ -157,6 +158,37 @@ class Jobs extends Action return $dbForProject->updateDocument('deployments', $deployment->getId(), new Document($update)); } + /** + * Record a reported artifact size. Remote-source builds (templates / VCS) + * fetch the source in the sidecar, so Appwrite can't size it the way the + * uploaded-tarball path does — the job stats the downloaded archive and the + * orchestrator reports its size here, which becomes the deployment's + * sourceSize. This arrives before the exit callback, so finalize folds it + * into totalSize. + */ + private function onArtifact(Database $dbForProject, Document $deployment, array $data): Document + { + if (($data['id'] ?? '') !== 'sourceSize') { + return $deployment; + } + + // The stat callback payload shape is still settling upstream; accept the + // size flat or nested under 'stat'. + $stat = \is_array($data['stat'] ?? null) ? $data['stat'] : $data; + $size = (int) ($stat['size'] ?? $stat['bytes'] ?? 0); + if ($size <= 0) { + return $deployment; + } + + // Recompute totalSize too: this callback can land either side of exit + // (they arrive out of order), and finalize likewise derives totalSize + // from the current sourceSize — so whichever runs last, the two agree. + return $dbForProject->updateDocument('deployments', $deployment->getId(), new Document([ + 'sourceSize' => $size, + 'totalSize' => $size + (int) $deployment->getAttribute('buildSize', 0), + ])); + } + /** * Resolve the build-command exit into a terminal outcome. The output is * already on the mounted builds volume, so a zero exit enforces the size