Skip to content

🐛 Bug Report: VCS deployment sourceSize reports the whole cloned repo (.git included), inflating totalSize and deployments-storage metrics #13586

Closed

Description

@AlimFreight

👟 Reproduction steps

  1. Self-hosted Appwrite 2.0.0, PostgreSQL. Any Git-connected function whose providerRootDirectory is a subfolder of a repository (a monorepo makes this obvious, but any repo shows it).
  2. Push a commit and let the VCS build run.
  3. Look at the deployment in the Console, or GET /v1/functions/{id}/deployments.

Observed on a repo with 19 Git-connected functions, each with its own providerRootDirectory:

function                root dir                                   sourceSize  buildSize
contact-email           appwrite-functions/contact-email             4.33 MB     2.49 MB
document-parser         appwrite-functions/document-parser           4.33 MB     2.43 MB
motive-sync             appwrite-functions/motive-sync               4.33 MB     2.94 MB
ifta-report             appwrite-functions/ifta-report               4.33 MB     3.01 MB
arrival-nudger          appwrite-functions/arrival-nudger            4.33 MB     2.89 MB
… all 19 …                                                          4.33 MB     (varies)

sourceSize is byte-identical across every function, regardless of root directory or how much code the function contains. It equals the size of the whole repository: git ls-files -z | xargs -0 tar czf - on the same commit is 4.46 MB.

The same function deployed manually (a tarball of just that folder) reports sourceSize 0.07 MB, and produces a functionally identical build — 2.86 MB vs 2.89 MB.

👍 Expected behavior

sourceSize should describe that deployment's source — the content under providerRootDirectory that was actually built — as it did in 1.9.x, and as the manual-upload path still does.

👎 Actual behavior

For VCS deployments, sourceSize is the size of the temporary clone directory, which is dominated by .git. git fetch --depth=1 downloads every blob of the commit's tree into the object store; core.sparseCheckout only limits which files are written to the working tree. So the number reflects the repository, not the deployment, and is the same for every function built from that repo.

Two consequences:

1. The Console's total is inflated. totalSize = sourceSize + buildSize, so a deployment showing 7.22 MB is really a 2.89 MB artifact plus 4.33 MB of a clone that was deleted seconds later. Users reasonably read this as their function having doubled in size. It also makes the Git and manual paths incomparable, which is what led us here.

2. It is counted as stored bytes when nothing was stored. sourcePath is NULL for every VCS deployment — no source archive is kept. Yet StatsResources.php reports:

['metric' => METRIC_DEPLOYMENTS_STORAGE, 'value' => (int) $dbForProject->sum('deployments', 'sourceSize'), …]

On this instance that is 525 MB of "deployments storage" that does not exist on disk (127 VCS deployments × ~4.2 MB), against 1.9 MB genuinely stored by the 21 manual deployments. On Cloud, this metric would over-report — and if it informs plan limits or billing, over-charge — by roughly the repository size on every Git build.

Builds themselves are correct: sparse checkout works, the right folder is built, and the artifact is right. This is purely the reported size.

🔍 This is a 1.9 → 2.0 regression, with before/after from the same instance

Our previous host still had its pre-upgrade database. Same repository, same functions, same providerRootDirectory values:

period version VCS sourceSize source stored (sourcePath set)
Aug 2026 1.9.x 0.09 MB avg (min 0.01, max 0.52) 19 of 21
Sep 2026 2.0.0-rc.2 4.19 MB 0 of 1

Per-function on 1.9: dashboard_read 0.08 MB, invoice_admin 0.08 MB, ifta_report 0.10 MB — all Git builds, all in the same range as a manual tarball (0.06 MB).

So 1.9 packaged the sparse checkout as a source archive, stored it, and reported that. 2.0 stopped storing a source archive for VCS builds and began reporting the raw clone instead.

🎯 Where it comes from

src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php — sourceSize arrives as a reported artifact and is written straight through:

// A stat artifact reports the file's byte size as its 'content'.
$size = (int) ($data['content'] ?? 0);
…
'sourceSize' => $size,
'totalSize'  => $size + (int) $deployment->getAttribute('buildSize', 0),

The clone that gets measured is built by generateCloneCommand in utopia-php/vcs (GitHub.php), which sets core.sparseCheckout and then git pull --depth=1 / git fetch --depth=1 — worktree limited, object store not.

Suggested fixes, cheapest first:

  • Exclude .git when measuring (the same rsync -av --exclude '.git' the template path in Builds.php already uses), so the number reflects the checked-out source.
  • Or measure only providerRootDirectory.
  • Or, if nothing is stored for VCS builds, report sourceSize as 0 and keep it out of METRIC_DEPLOYMENTS_STORAGE, so the storage metric counts only bytes that exist.

🧱 Your Environment

  • Appwrite 2.0.0 self-hosted (Docker Compose), PostgreSQL 18.3 (appwrite/postgres:0.1.0)
  • Executor openruntimes/executor:0.29.0, orchestrator ghcr.io/open-runtimes/orchestrator:1.9.2
  • Go functions (go-1.26), monorepo, one providerRootDirectory per function
  • Previous host for the 1.9 comparison: same repo, Appwrite 1.9.x on MariaDB 10.11

📎 Additional information

Happy to supply the full per-deployment table, or to test a patch. Related report from the same instance: #13485.

Activity

  1. added
    product / databases
    product / functions
    product / messaging
    product / self-hosted
    product / storage
    product / vcs
    on Sep 9, 2026
  2. AlimFreight commented on Sep 9, 2026

    @AlimFreight
    Author

    Cross-reference: while investigating this I hit a second, distinct regression from the same 2.0 VCS-source rework — #13587. Redeploy reads providerRootDirectory from the deployment, where nothing in 2.0 ever writes it, so it clones the repo root and every monorepo function fails to redeploy in ~1s.

    They share a root: 2.0 stopped persisting per-deployment source information (sourcePath is NULL here, and providerRootDirectory is NULL on 94 of 128 VCS deployments), but several code paths still read it back from the deployment.

  3. breken-ai commented on Sep 10, 2026

    @breken-ai

    @AlimFreight Confirmed the whole chain at HEAD, with one sharpening:

    1. The VCS path downloads the whole-repo provider archive, and the StatArtifact on source.tar.gz records the entire archive size - the extracted tree is already scoped to rootDirectory (subdir + strip), but the stat never sees it.
    2. The worker (Jobs.php) writes that stat into sourceSize/totalSize.
    3. StatsResources.php sums sourceSize into DEPLOYMENTS_STORAGE (and sourcePath is NULL on VCS deployments, so nothing corrects it) - your ~525MB phantom across 94 functions.

    Sharpening: it is whole-repo-archive vs subdirectory, not .git - forge archives carry no .git, and the clone path records no sourceSize at all. Your numbers back this (4.33MB reported vs ~4.46MB whole-worktree estimate).

    The fix is ready and the PR is being filed: re-pack the extracted, rootDirectory-scoped tree into a plain tar and stat that instead - using only existing orchestrator primitives (Stat rejects directories; Archive packs them), so no orchestrator or SDK changes. That kills the phantom at the source. One semantic change to flag: sourceSize becomes uncompressed subdir bytes instead of compressed whole-repo bytes, and existing rows keep inflated values until the next redeploy. If maintainers prefer a smaller blast radius, gating the three StatsResources sums on sourcePath IS NOT NULL fixes the accounting in one line - but leaves the per-deployment display wrong, so we went with the artifact fix.

    Since you have 94 functions affected: a quick storage-total check after a redeploy once this is available would be the real-world confirmation.

    Built by breken, your AI support engineer - breken.ai finds the bug, proves the fix with unmatched RCA, answers customers in your voice, and keeps your code and support docs clean - this one's on us.

  4. breken-ai commented on Sep 10, 2026

    @breken-ai

    The PR is up: #13614

    The extracted tree is re-packed to a plain tar and stat'd, so sourceSize reflects the rootDirectory-scoped code the deployment actually builds - not the whole provider archive.

    Built by breken, your AI support engineer - breken.ai finds the bug, proves the fix with unmatched RCA, answers customers in your voice, and keeps your code and support docs clean - this one's on us.

  5. AlimFreight commented on Sep 10, 2026

    @AlimFreight
    Author

    Thanks — and the sharpening is correct, my mechanism was wrong. I verified it on our instance: Builds.php → generateCloneCommand (sparse clone) records no sourceSize at all, while Deployments.php → supportsRepositoryArchives() → getRepositoryPresignedUrl(format: 'tarball') is the path we're on, and the Stat artifact on that whole-repo source.tar.gz is what Jobs.php writes through. The presence of a populated sourceSize on our deployments is itself the tell. A forge tarball carries no .git, so "whole-repo archive vs subdirectory" is the right framing — both explanations happen to predict ~4.3 MB, which is why my numbers held up while the reasoning didn't. I've corrected our internal note accordingly.

    Happy to run the storage-total check once #13614 is available. Baseline here, so the delta is measurable:

    VCS deployments 128, sourcePath NULL on every one
    sum(sourceSize) across them 525 MB (phantom)
    genuinely stored source (21 manual deployments) 1.9 MB
    per-function sourceSize 4.33 MB, byte-identical across all 19, regardless of providerRootDirectory

    The functions live in appwrite-functions/<name>, tracked repo ≈ 4.46 MB gzipped, so after the fix I'd expect each function's sourceSize to drop to its own subdirectory's uncompressed size — for our largest that's a few hundred KB, not 4.33 MB. Noted that existing rows keep inflated values until rebuilt; we push often enough that the whole set will turn over quickly, so I can report both the per-deployment number and the storage total.

    One thing worth flagging for whoever reviews the PR: with sourceSize becoming uncompressed subdirectory bytes, totalSize = sourceSize + buildSize stops being an apples-to-apples sum (uncompressed source + compressed build). That's still far better than today, just worth a deliberate decision rather than a surprise.

  6. breken-ai commented on Sep 10, 2026

    @breken-ai

    @AlimFreight The byte-identical 4.33 MB across all 19 functions is the cleanest possible confirmation - that number can only be the whole-repo tarball, independent of providerRootDirectory, exactly the mechanism in #13614. And thank you for correcting the record on the clone path; the presigned-tarball framing is what the patch stats.

    On the units point - fair flag, and worth a deliberate decision as you say. The sum was already mixed-unit before this change (compressed whole-repo archive + compressed build artifact); what changes is that sourceSize becomes the uncompressed size of the tree the deployment actually builds. That is the honest number for "how much source does this deployment represent", and it makes sourceSize comparable across deployments of the same function, which the compressed-tarball number never was (it moved with unrelated repo churn). Making buildSize uncompressed too would be the consistent alternative, but that is a much larger behavioral change for a separate decision. Stated here so it is deliberate, not silent.

    Your baseline table is a great validation setup - the post-fix per-deployment number dropping from 4.33 MB to each subdirectory's real size, plus the storage-total delta, is exactly what the fix should produce.

    Built by breken, your AI support engineer - breken.ai finds the bug, proves the fix with unmatched RCA, answers customers in your voice, and keeps your code and support docs clean - this one's on us.

  7. added a commit that references this issue on Sep 25, 2026
    221f181
  8. HarshMN2345 commented on Sep 29, 2026

    @HarshMN2345
    Member

    Fixed by #13934, VCS deployments now only measure and store the root directory that gets built. It'll be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / databasesproduct / functionsproduct / messagingproduct / self-hostedproduct / storageproduct / vcs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions