From 3772b3eb6fe84d6d51d940807a32e910b6605db1 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 8 Jul 2026 18:57:28 +0100 Subject: [PATCH] Correct the jobs stat artifact callback contract MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Local testing against the live orchestrator revealed the real artifact-callback payload: {artifactId, artifactType, content, status} — not the id/size I'd guessed. Match on artifactId and read the byte size from content. Also depend the source stat on 'job' (not 'source'): the orchestrator only emits artifact callbacks for post-job artifacts, so a pre-job stat never reports. Known upstream gap: because the stat is post-job, its size callback lands just after the exit callback that marks the deployment ready — so a reader at 'ready' sees sourceSize=0 (flaky). The orchestrator fix is to surface the size by the exit event; the reconciliation here keeps sourceSize/totalSize consistent. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Appwrite/Compute/Job.php | 2 +- src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Compute/Job.php b/src/Appwrite/Compute/Job.php index ac8d2ce84e..0dcd4e3a93 100644 --- a/src/Appwrite/Compute/Job.php +++ b/src/Appwrite/Compute/Job.php @@ -78,7 +78,7 @@ final class Job // 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'), + new StatArtifact(id: 'sourceSize', in: 'source.tar.gz', depends: 'job'), ]; } else { // Presigned source-download URL (GET, no request-body cap), fetched by diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php b/src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php index 61a4e6db60..500998cd93 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php @@ -168,14 +168,12 @@ class Jobs extends Action */ private function onArtifact(Database $dbForProject, Document $deployment, array $data): Document { - if (($data['id'] ?? '') !== 'sourceSize') { + if (($data['artifactId'] ?? '') !== 'sourceSize' || ($data['status'] ?? '') !== 'success') { 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); + // A stat artifact reports the file's byte size as its 'content'. + $size = (int) ($data['content'] ?? 0); if ($size <= 0) { return $deployment; }