Repository navigation
fix(deployments): redeploy git deployments after a git reconnect - #14666
Conversation
…tallation A redeploy fetched the source through the installation stored on the deployment being duplicated. After git is reconnected, older deployments keep pointing at the previous installation, which can no longer read the repository, so GitHub answered 404 and the uncaught RepositoryNotFound surfaced as a 500. A site or function still connected to the deployment's repository now redeploys through its own installation, the new deployment records the installation it was built from, and a repository the installation cannot read returns provider_repository_not_found.
…lation Updating an already connected site or function with a new installation changed only the resource. Its repository link kept the previous installation, and every webhook deployment copies the installation from that link, so they were all saved against an installation that may no longer exist. The update now points the link at the resource's installation whenever they differ, which also repairs links left stale before this change.
|
Review complete. 🟡 2 medium 💬 Inline comments (2)
The change wires stale
Reviewed commit: b930d57 |
🟢 Tier S · Ready to mergeVCS-backed function and site redeployments now use the resource’s current installation when it resolves to the repository recorded on the source deployment, and new deployments record that installation. Updating a connected resource also synchronizes its repository link to the current installation so webhook builds follow a git reconnect. Latest changes: The redeploy checks now compare the current installation’s repository URL with the source deployment URL without requiring the old installation document to still exist, allowing redeploys after uninstalling the previous connection.
📂 Walkthrough · 4
✅ Fixed since the last review · 1
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
There was a problem hiding this comment.
This PR adds installation fallback and reconnection handling for VCS-linked functions and sites in the duplicate-deployment and update endpoints.
Key findings
- 🟡 Stale installation clobbers repository link with empty values — Update.php:284
- 🟡 Reconnect to a different repository corrupts the old link — Update.php:284
| if ($isConnected && !empty($providerRepositoryId) && !empty($repositoryId)) { | ||
| $repository = $dbForPlatform->getDocument('repositories', $repositoryId); | ||
| if (!$repository->isEmpty() && $repository->getAttribute('installationInternalId') !== $installation->getSequence()) { | ||
| $dbForPlatform->updateDocument('repositories', $repository->getId(), new Document([ | ||
| 'installationId' => $installation->getId(), | ||
| 'installationInternalId' => $installation->getSequence(), | ||
| ])); | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Stale installation clobbers repository link with empty values
When a connected function is updated without a providerRepositoryId, the preserve path re-fetches $installation from the stored installationId without an isEmpty() check (src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php:223). If that installation was deleted — possible via the deleteInstallation endpoint, which does not clean up connected resources — getSequence() returns null, the reconnect guard passes, and the repositories document is overwritten with installationId => '' and installationInternalId => null. Webhook-triggered deployments resolve their installation from the repository link, so all git deployments for the resource silently break. The same code appears in src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php at line 290.
📋 Prompt for AI Agents
In src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php lines 284-292 and the identical block in src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php lines 290-298, extend the guard to if (!$repository->isEmpty() && !$installation->isEmpty() && $repository->getAttribute('installationInternalId') !== $installation->getSequence()). Why: when a connected function/site is updated after its installation was deleted via deleteInstallation (which does not clean up resources), the empty installation document makes getSequence() return null, and the block overwrites the repositories document's installationId with '' and installationInternalId with null, breaking webhook-driven deployments that read their installation from the repository link.
| if ($isConnected && !empty($providerRepositoryId) && !empty($repositoryId)) { | ||
| $repository = $dbForPlatform->getDocument('repositories', $repositoryId); | ||
| if (!$repository->isEmpty() && $repository->getAttribute('installationInternalId') !== $installation->getSequence()) { | ||
| $dbForPlatform->updateDocument('repositories', $repository->getId(), new Document([ | ||
| 'installationId' => $installation->getId(), | ||
| 'installationInternalId' => $installation->getSequence(), | ||
| ])); | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Reconnect to a different repository corrupts the old link
Updating an already-connected function to a different providerRepositoryId with a new installationId skips both the disconnect and connect branches, so $repositoryId still points at the old repository's link document (src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php:284). The reconnect block then moves that old document to the new installation without checking that it belongs to the requested repository, and no link or webhook is ever created for the new repository. Deployments for the old repository resolve through an installation that may not have access to it. The same issue appears in src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php at line 290.
📋 Prompt for AI Agents
In src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php lines 284-292 (and identically in src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php lines 290-298), add a guard that the fetched repository document actually refers to the requested repository — require $repository->getAttribute('providerRepositoryId') === $providerRepositoryId before calling $dbForPlatform->updateDocument(...). Why: when a connected function/site is updated with a different providerRepositoryId and a new installationId, the disconnect and connect branches both skip, $repositoryId still points at the previous repository's link document, and the current code silently rewrites that old document's installation while never creating a repository link or webhook for the new repository.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…d repository Repository IDs are only unique within a provider, so a redeploy now switches to the resource's installation only when it is the same provider as the deployment's. The repository link is only moved when the resource's installation exists and the link belongs to the requested repository, so a deleted installation can no longer blank it and switching repositories while connected leaves the old repository's link alone.
…ation's provider Uninstalling and reinstalling the GitHub app deletes the installation older deployments point at, so comparing providers left them unable to redeploy. The resource's installation is now used when it would build the same repository URL the deployment recorded, which needs no stored installation and also tells self-hosted providers apart.
What changed
POST /v1/{functions,sites}/:id/deployments/duplicate): when the site or function is still connected to the deployment's repository, and its installation builds the same repository URL the deployment recorded, the source is fetched through the resource's current installation instead of the one stored on the old deployment. This also covers an old installation that was deleted by uninstalling the app. The new deployment records the installation it was built from. A repository the installation cannot read now returnsprovider_repository_not_found(404) instead ofgeneral_unknown(500).Why
After a git reconnect, the project keeps the old installation document, but that installation can no longer read the repositories. Redeploying any deployment stored against it failed with a 500 and created nothing. Reproduced on Cloud (Toronto) in an affected project: redeploying a deployment from before the reconnect returned
500 general_unknown. A deployment made through the new installation redeployed and built normally, and the old installation returnedprovider_repository_not_foundfor both repositories it was linked to.Testing