Skip to content

fix(deployments): keep the source of template and VCS deployments - #13934

Merged
HarshMN2345 merged 11 commits into
mainfrom
fix/deployment-remote-source-download
Sep 28, 2026
Merged

HarshMN2345 merged 11 commits into
mainfrom
fix/deployment-remote-source-download

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

What

Template, "Deploy to Appwrite" and VCS deployments keep the source they were built from again, so Download source works for them. It has not worked for them since 2.0.0; only manual uploads kept a tarball.

Why

On the jobs-service backend a remote source never reaches Appwrite: createFromRef / createFromVcs hand the sidecar a codeload URL, presigned archive or clone, and nothing wrote sourcePath. The pre-2.0 builds worker tarred the root directory and stored it on the function/site device (a82dc6e386^:src/Appwrite/Platform/Modules/Functions/Workers/Builds.php). Downloads and Appwrite-to-Appwrite migrations of those deployments read that file.

Changes

  • Deployments::payload() — for any remote source, a pre-job ArchiveArtifact packs the extracted root directory into a flat source-root.tar.gz (same shape as an uploaded tarball), and the sourceSize stat now measures it instead of the whole repository archive (362,239 → 3,059 bytes for node/starter; clone-path deployments now report a size too).
    • S3 and other remote devices: a pre-job UploadArtifact puts it on the function/site device at {deploymentId}.gz, before build.sh starts. The Jobs worker records sourcePath when it lands.
    • Local device: the build worker mounts only the builds volume, so the command copies the tarball there before build.sh, and the Jobs worker moves it (below).
  • Jobs worker — the build's own code can write the builds volume, so the local move keeps only the file the sidecar measured: a regular file of the recorded sourceSize, reached without any symlink, whose opened inode is the one checked. It runs once the build has completed and sourceSize is recorded, from whichever callback lands second, since the queue can reorder them. The copy is streamed. A refused file or error is recorded on the span and never holds up readiness. Cleanup unlinks only inside the builds tree.
  • Cancel and Deletes — remove a staged file left by a build canceled or deleted before completing.
  • Download endpoints — 404 when the deployment has no stored file.
  • Duplicate — template and VCS deployments keep re-fetching from their coordinates, so a VCS redeploy still picks up the resource's current root directory; the kept source only serves downloads.
  • docker-compose.yml — appwrite-worker-jobs (separate topology) mounts the functions and sites volumes it now writes to.

Verified

End to end on the local stack (orchestrator 2.1.1, local storage), with the API and worker running this branch in isolated containers:

  • Function template (node/starter): ready, sourcePath set, download?type=source returns a flat tarball byte-identical to the stored file, size equal to sourceSize. Output download and execution unchanged.
  • Site template (other/littlelink): source kept on the sites volume and downloadable.
  • Redeploying keeps working, and the redeployed build keeps its own source.
  • A deployment built before this change: download?type=source returns 404.
  • Build commands that tamper with the staged file were all refused, with the build still reaching ready and nothing stored: a symlink to /proc/self/environ or /etc/hostname, a dangling symlink, a symlinked deployment directory (the file behind it left untouched), a file of a different size, and a 600 MB file (no worker memory error).
  • Canceling a build removes its staged file immediately; deleting a deployment mid-build does too.

Known limits

Remote-source builds hand the sidecar a tarball URL or clone, so Appwrite
never stored their source: sourcePath stayed empty and downloading it
returned deployment_not_found. The sidecar now packs the root directory
it builds into a flat tarball, the same shape as a manual upload. On S3
a post-job upload puts it on the function or site device; on the local
device the worker stages it on the builds volume and the Jobs worker
moves it. sourcePath is set once the file is there, and a failed upload
never fails the build.

sourceSize now measures that tarball instead of the whole repository
archive the source was extracted from.
An empty sourcePath reached the storage device as the root path. The
local device reports it missing, but an S3 device answers a HEAD on the
bucket and lists it on read, so the download returned a bucket listing
named as a tarball.
The build runs its own code with the builds volume mounted read-write,
so the staged source can be swapped for a symlink to anything the Jobs
worker can read, which would then be served as the deployment's source.
The worker now moves only a regular file reached without symlinks,
checks the opened inode against the one it inspected, and skips
deployments that already have a source. A failed move is recorded on the
span and never holds up the build, and a staged file left by a build
that never completed is removed with its build files.

On S3 the upload now runs before build.sh instead of after it, so the
build cannot touch the file it uploads and readiness no longer waits on
it. The separate jobs worker mounts the functions and sites volumes it
now writes to.
A build could leave a file at the staged path large enough to exhaust the
worker's memory limit when read whole, killing the worker and leaving the
deployment building. The move now requires the recorded sourceSize and
streams the copy. Cleanup unlinks only inside the builds tree, since the
build can symlink a parent directory elsewhere, and removes dangling
links that exists() does not see. A refused file is recorded on the span.
@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adjusts deployment source handling for templates and VCS.

The PR appears safe to merge based on the reviewed changes, though source retention still lacks automated regression coverage.

Fix All in Claude CodeFindings

  1. P2 Source retention lacks regression coverage ▶
Fix with agent prompt
### Issue 1
src/Appwrite/Deployment/Deployments.php:undefined-443
The new remote-source archive and storage flow has no automated test of a build followed by a source download or duplicate. Local verification will not catch a later regression in this user-visible behavior or the callback-ordering failure. An end-to-end test should check the downloaded bytes and persisted source path, not mirror the artifact configuration.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR retains downloadable source archives for template and VCS deployments, handles local staging and cleanup, and keeps redeployments tied to their remote source coordinates. The latest change adds a timing margin to a TOTP enrollment test.

Reviews (6) · Last reviewed commit: "Merge branch 'main' into fix/deployment-..."

// volume, which the build can write too (see the Jobs worker).
$stage = '';
if ($source !== null) {
$sourceArtifacts[] = new ArchiveArtifact(id: 'sourceArchive', in: 'source', out: 'source-root.tar.gz', compression: ArchiveCompression::Gzip, depends: isset($source['clone']) ? 'source' : 'extract');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Source retention lacks regression coverage

The new remote-source archive and storage flow has no automated test of a build followed by a source download or duplicate. Local verification will not catch a later regression in this user-visible behavior or the callback-ordering failure. An end-to-end test should check the downloaded bytes and persisted source path, not mirror the artifact configuration.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Deployment/Deployments.php
Line: 434

Comment:
**Source retention lacks regression coverage**

The new remote-source archive and storage flow has no automated test of a build followed by a source download or duplicate. Local verification will not catch a later regression in this user-visible behavior or the callback-ordering failure. An end-to-end test should check the downloaded bytes and persisted source path, not mirror the artifact configuration.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

The move required the staged file to match the recorded sourceSize, but
the queue can deliver complete before the sourceSize callback, which
dropped the source of a successful build. It is now bounded by the
deployment size limit manual uploads use instead. Canceling a build also
removes its staged source, since a canceled build never completes.
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/deployment-remote-source-download (after).

Metric Before After Change
🚀 Requests/sec 197.41 203.99 ⚪ +3.3%
⏱️ Latency P50 86.75 ms 85.9 ms ⚪ -1%
⏱️ Latency P95 208.58 ms 195.16 ms 🟢 -6.4%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 85.9 195.16 12,768 203.99 -13.42
Account 158.62 309.98 672 11.23 -21.3
TablesDB 82.97 152.42 6,944 112.93 -8.74
Storage 79.16 173.97 3,360 56.39 +4.59
Functions 117.91 237.55 1,792 30.83 -49.65

Top API waits (after)

API request Max wait (ms)
account.name.update 497.35
functions.variables.create 437.02
functions.variables.update 407.1
account.prefs.update 386.08
functions.create 381.81

Bounding the staged file by the deployment size limit dropped the
sources of unlimited plans and of large repositories, and accepted a
file the build had swapped for another size. The file again has to match
the sourceSize the sidecar measured; the move runs when both that size
and completion are known, from whichever callback arrives second.
HarshMN2345 and others added 4 commits September 28, 2026 12:21
Duplicating a VCS deployment rebuilds from the resource's current root
directory. With a kept source it copied the old root's tarball instead,
so duplicates of template and VCS deployments re-fetch as before; the
kept source only serves downloads.
Duplicates of remote-source deployments re-fetch, so the kept source no
longer serves them. Local::delete already ignores a missing path and
removes a dangling link, so the staged cleanup only needs the builds-tree
guard.
Comment thread docker-compose.yml Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants