Skip to content

fix(deployments): scope sourceSize to the extracted tree, not the provider archive - #13614

Closed
breken-ai wants to merge 2 commits into
appwrite:mainfrom
breken-ai:fix-13586-sourcesize-subdir-scope
Closed

breken-ai wants to merge 2 commits into
appwrite:mainfrom
breken-ai:fix-13586-sourcesize-subdir-scope

Conversation

@breken-ai

Copy link
Copy Markdown

Fixes #13586.

Root cause (the reporter's, confirmed at HEAD)

@AlimFreight traced this; verified independently:

  1. Deployments.php (~:398-409): the VCS path downloads the whole-repo provider archive, and StatArtifact(id: 'sourceSize', in: 'source.tar.gz') records the entire archive - while the extracted tree is already scoped to rootDirectory via subdir + strip.
  2. Workers/Jobs.php:308-319: the worker writes that stat into sourceSize/totalSize.
  3. Workers/StatsResources.php:262/290/307: sum(sourceSize) becomes DEPLOYMENTS_STORAGE, with sourcePath NULL on VCS deployments so nothing corrects it - the reporter's ~525MB phantom across 94 functions.

Sharpening (confirmed): deployments reporting sourceSize all went through the archive path (the clone path reports none), and forge archives carry no .git - so this is whole-repo-archive vs subdirectory, not a .git effect. The reporter's numbers back it (4.33MB reported vs ~4.46MB whole-worktree estimate).

Fix (1 file, +11/-4)

Re-pack the extracted, rootDirectory-scoped tree into a plain tar and stat that instead:

  • ArchiveArtifact(id: 'sourceSizeArchive', in: 'source', out: 'source-size.tar', format: Tar, depends: 'extract')
  • StatArtifact(id: 'sourceSize', in: 'source-size.tar', depends: 'sourceSizeArchive')

Only existing orchestrator primitives are used - Stat.Apply rejects directories, Archive.Apply packs them (both verified in the orchestrator Go source), and ArchiveArtifact/ArchiveFormat::Tar exist in open-runtimes/sdk-for-php 0.13.0, which appwrite pins. Zero orchestrator or SDK changes.

Semantic change (disclosed)

sourceSize becomes uncompressed subdir bytes (+512B/file tar overhead) instead of compressed whole-repo bytes; existing rows keep inflated values until the next redeploy. Alternative for maintainers who prefer minimal blast radius: gate the three StatsResources.php sums on sourcePath IS NOT NULL - a one-liner that fixes accounting but leaves per-deployment display wrong, hence the artifact fix instead.

Verification

Every step re-traced in source at main (f31509d) plus the orchestrator (Go) and sdk-for-php 0.13.0 pinned ref. Not run: no PHP runtime or live Appwrite/orchestrator build in the author's environment - the reporter offered to verify storage totals after a redeploy.

Overlap note: this touches src/Appwrite/Deployment/Deployments.php (:395-409), about 200 lines from #13589's change (:182) in the same file; both apply independently against current main, but whichever lands second will need a trivial rebase.

Built by breken, your AI support engineer - breken.ai - this one's on us.

@greptile-apps

greptile-apps Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Changes how deployment source code size is measured.

The accounting change has no established production-code defect, but the test must satisfy the repository’s observable-behavior requirement before merging.

Fix All in Claude CodeFindings

  1. P2 Test checks implementation, not accounting ▶
  2. P2 Scoped accounting lacks coverage ▶
Fix with agent prompt
### Issue 1
tests/unit/Deployment/DeploymentsTest.php:194-211
This test checks artifact IDs, types, and wiring, with `producerOf` walking the artifact graph. It never checks a reported source size or storage total using files inside and outside `rootDirectory`. That violates the repository directive to test observable behavior rather than mirror implementation details. The requirement must be satisfied before merging.

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!

### Issue 2
src/Appwrite/Deployment/Deployments.php:undefined-417
This accounting change has no observable regression test for a VCS deployment with `rootDirectory`. Existing coverage only checks that `sourceSize` is positive and contributes to `totalSize`, so it would still pass if this code reverted to measuring the whole provider archive. Add a deployment-level test showing that large files outside the selected root do not affect the reported source size or deployment-storage total, without asserting the artifact pipeline itself.

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 changes remote deployment source-size accounting to stat a tar of the extracted, root-scoped tree rather than the provider archive.

  • It adds a unit test for the artifact pipeline, but the test does not verify reported size or storage totals.

Reviews (2) · Last reviewed commit: "test(deployments): cover rootDirectory-s..."

// extracted tree instead, already scoped to rootDirectory with
// the forge wrapper stripped. Stat rejects directories, so
// re-pack 'source' into a plain tar first.
new ArchiveArtifact(id: 'sourceSizeArchive', in: 'source', out: 'source-size.tar', format: ArchiveFormat::Tar, depends: '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 Scoped accounting lacks coverage

This accounting change has no observable regression test for a VCS deployment with rootDirectory. Existing coverage only checks that sourceSize is positive and contributes to totalSize, so it would still pass if this code reverted to measuring the whole provider archive. Add a deployment-level test showing that large files outside the selected root do not affect the reported source size or deployment-storage total, without asserting the artifact pipeline itself.

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

Comment:
**Scoped accounting lacks coverage**

This accounting change has no observable regression test for a VCS deployment with `rootDirectory`. Existing coverage only checks that `sourceSize` is positive and contributes to `totalSize`, so it would still pass if this code reverted to measuring the whole provider archive. Add a deployment-level test showing that large files outside the selected root do not affect the reported source size or deployment-storage total, without asserting the artifact pipeline itself.

---

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added in 4fb87ea: DeploymentsTest::testRemoteSourceSizeIsMeasuredOnTheRootDirectoryOnly builds the payload for a remote source with subdir: apps/web. It then walks back from the sourceSize stat through the artifacts that write its input. The test checks that this chain goes through the extract step, which has subdir: apps/web and strip, and never reaches the downloaded provider archive. Files outside the root therefore can't count toward sourceSize or the storage totals built from it.

  • Red: with Deployments.php from main, the test fails (Failed asserting that an array contains 'extract'), because the stat reads source.tar.gz directly.
  • Green: tests/unit/Deployment passes, 15 tests.
  • pint --test and phpstan report no errors on both files.

This is a unit test on the artifact graph. I did not run an e2e deployment against the orchestrator. I also rebased the branch onto current main.

breken-ai and others added 2 commits September 24, 2026 23:40
…vider archive

For git-source deployments the provider archive spans the whole repository,
so recording its byte size as sourceSize inflated every monorepo deployment
(and the storage totals that sum it) with the rest of the repo. Stat the
extracted tree instead - already scoped to rootDirectory with the forge
wrapper stripped. Stat rejects directories, so re-pack 'source' into a
plain tar via ArchiveArtifact first.

Fixes appwrite#13586
@breken-ai
breken-ai force-pushed the fix-13586-sourcesize-subdir-scope branch from 6c47c48 to 4fb87ea Compare September 25, 2026 06:46
@HarshMN2345

Copy link
Copy Markdown
Member

Closing since this is already fixed on main. Thanks for the contribution!

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.

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

3 participants