Skip to content

fix(functions): persist providerRootDirectory on VCS deployments and refresh it on redeploy - #13589

Closed
breken-ai wants to merge 1 commit into
appwrite:mainfrom
breken-ai:fix-13587-redeploy-rootdir
Closed

breken-ai wants to merge 1 commit into
appwrite:mainfrom
breken-ai:fix-13587-redeploy-rootdir

Conversation

@breken-ai

Copy link
Copy Markdown

Fixes #13587.

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

@AlimFreight traced this end to end; verified independently here:

  1. Deployments/Duplicate/Create.php refreshes entrypoint/buildCommands/startCommand from the function on redeploy but inherits providerRootDirectory from the old deployment.
  2. Nothing in 2.0 writes providerRootDirectory onto VCS deployments - only the template flow (Deployments/Template/Create.php:184) does - so the duplicate gets NULL.
  3. utopia-php/vcs (Adapter/Git/GitHub.php, generateCloneCommand): an empty root directory becomes a * sparse checkout, so the whole repo is checked out, the build runs at the repository root, and monorepo function code is missing - the ~1s build failure in the reporter's log.
  4. The same missing write also empties APPWRITE_VCS_ROOT_DIRECTORY at runtime (Executions/Create.php and the build env in Deployments.php:715 read it from the deployment).

Fix (2 files, +13)

  • Duplicate/Create.php: refresh providerRootDirectory from the function, same treatment as entrypoint/commands above it. A redeploy rebuilds with the function's current root directory - and because it overwrites the inherited NULL, this also heals every existing broken deployment on its next redeploy, no backfill needed (which matches the reporter's finding that backfilling wasn't a path forward).
  • Deployments.php submit(): snapshot $source['subdir'] as providerRootDirectory on new VCS deployments so the value persists going forward. The upload flow (submit(null)) is untouched.

Verification

Every step of the chain re-traced in source at main (f31509d), including the '*' wildcard in the vcs library and all read sites. Not run: no PHP runtime or live Appwrite instance in the author's environment, so no lint or live redeploy test - the reporter offered to test a Redeploy on a subdirectory function, which would be the real-world green proof. (Their POST /deployments/vcs workaround is correct until this lands.)

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

…refresh it on redeploy

Nothing in 2.0 writes providerRootDirectory onto VCS deployments
(only the template flow does), so Duplicate/Create clones a NULL and
the VCS clone turns an empty root directory into a * sparse checkout -
the build runs at the repository root and monorepo functions fail.
The same missing write empties APPWRITE_VCS_ROOT_DIRECTORY at runtime.
Duplicate now refreshes providerRootDirectory from the function like
entrypoint/buildCommands/startCommand (also healing legacy NULL
deployments on the next redeploy), and Deployments::submit snapshots
the source subdir onto new VCS deployments. Upload flow (submit(null))
untouched.
@greptile-apps

greptile-apps Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

This PR is not safe to merge until public-template duplication preserves its deployment-specific source root.

Fix All in Claude CodeFindings

  1. P1 Template root gets overwritten ▶
Fix with agent prompt
### Issue 1
src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php:143
When duplicating a public-template deployment, this replaces the deployment-specific source root with the function's root directory. Template deployments store their own root, which can differ from or be absent on the function. In that case, the duplicate fetches the repository root instead of the template subdirectory, so the build uses the wrong source. Preserve the deployment root for public templates and refresh it from the function only for connected VCS deployments.

---

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

Summary

  • New VCS deployments retain providerRootDirectory for later builds, redeployments, and runtime environment construction.
  • Connected VCS redeployments can recover deployments created before the attribute was persisted.
  • Public-template redeployments regress because their deployment-specific source root is overwritten by independent function configuration.

Reviews (1) · Last reviewed commit: "fix(functions): persist providerRootDire..."

// before this attribute was persisted carry NULL, which the VCS
// clone path turns into a '*' wildcard - the build then runs at
// the repository root and monorepo functions fail.
'providerRootDirectory' => $function->getAttribute('providerRootDirectory', ''),

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.

P1 Template root gets overwritten

When duplicating a public-template deployment, this replaces the deployment-specific source root with the function's root directory. Template deployments store their own root, which can differ from or be absent on the function. In that case, the duplicate fetches the repository root instead of the template subdirectory, so the build uses the wrong source. Preserve the deployment root for public templates and refresh it from the function only for connected VCS deployments.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php
Line: 143

Comment:
**Template root gets overwritten**

When duplicating a public-template deployment, this replaces the deployment-specific source root with the function's root directory. Template deployments store their own root, which can differ from or be absent on the function. In that case, the duplicate fetches the repository root instead of the template subdirectory, so the build uses the wrong source. Preserve the deployment root for public templates and refresh it from the function only for connected VCS deployments.

---

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

Fix in Claude Code Fix in Codex

@breken-ai

Copy link
Copy Markdown
Author

Closing as superseded - fixed upstream in #13622 and utopia-php/monorepo#260. @ChiragAgg5k's change covers this ground, so this branch is no longer needed.

@breken-ai breken-ai closed this Sep 11, 2026
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: Redeploy always fails for monorepo functions — duplicate reads providerRootDirectory from the deployment, where nothing ever sets it

1 participant