Skip to content

fix(deployments): redeploy git deployments after a git reconnect - #14666

Merged
HarshMN2345 merged 4 commits into
mainfrom
fix-redeploy-stale-installation
Oct 21, 2026
Merged

HarshMN2345 merged 4 commits into
mainfrom
fix-redeploy-stale-installation

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

What changed

  • Redeploy (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 returns provider_repository_not_found (404) instead of general_unknown (500).
  • Site and function update: when a connected resource's installation differs from the installation on its link for the same repository, the link is moved to the resource's installation. A missing installation or a link for another repository is left alone. Webhook deployments copy their installation from that link, so after a git reconnect every new deployment was stored against the previous installation. Links that are already stale are repaired the next time the resource is updated.

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 returned provider_repository_not_found for both repositories it was linked to.

Testing

  • Pint and PHPStan pass on the four changed files.
  • No new test. Existing Functions, Sites and VCS e2e cover the redeploy and update paths; the reconnect scenario itself is not covered.

…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.
@luxor-code-review

luxor-code-review Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 2 medium

💬 Inline comments (2)

  • 🟡 Stale installation clobbers repository link with empty values — Update.php:284
  • 🟡 Reconnect to a different repository corrupts the old link — Update.php:284

The change wires stale installationId recovery into the deployment duplicate flows and rewrites the repository-link bookkeeping in the function/site update endpoints.

Files Change
Functions/Http/Deployments/Duplicate/Create.php, Sites/Http/Deployments/Duplicate/Create.php Fall back to the function/site installationId when an old deployment's installation fields are stale, remapping installation identifiers before createFromVcs and mapping RepositoryNotFound to PROVIDER_REPOSITORY_NOT_FOUND.
Functions/Http/Functions/Update.php, Sites/Http/Sites/Update.php Add a reconnect path that moves an existing repositories link document to a new installation when installationInternalId differs from the fetched installation's sequence.
both modules' duplicate endpoints On repository-not-found during VCS deployment duplication, return the registered 404 provider error instead of failing the build.

Reviewed commit: b930d57

@ghost

ghost commented Oct 19, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

VCS-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.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 4
File Change
src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php Redeploy VCS function deployments through the current installation when its repository URL matches the source deployment.
src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php Synchronize a connected function’s repository link to its current installation.
src/Appwrite/Platform/Modules/Sites/Http/Deployments/Duplicate/Create.php Apply the same repository-URL match when selecting an installation for site redeploys.
src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php Synchronize a connected site’s repository link to its current installation.
✅ Fixed since the last review · 1
  • Deleted old installations block redeploy after reconnect · src/Appwrite/Platform/Modules/Functions/Http/Deployments/Duplicate/Create.php:163

Reviewed the commits since 55b18c7 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · See the inline comments. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines +284 to +292
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(),
]));
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

Comment on lines +284 to +292
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(),
]));
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-redeploy-stale-installation (after).

Metric Before After Change
🚀 Requests/sec 217.16 222.06 ⚪ +2.3%
⏱️ Latency P50 77.97 ms 77.61 ms ⚪ -0.5%
⏱️ Latency P95 191.64 ms 183.66 ms ⚪ -4.2%
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 77.61 183.66 13,680 222.06 -7.98
Account 152.49 277.41 720 12.46 -8.13
TablesDB 76.28 149.68 7,440 124.14 +11.71
Storage 69.1 161.32 3,600 61.47 -13.37
Functions 106.44 212.97 1,920 33.45 -57.42

Top API waits (after)

API request Max wait (ms)
functions.create 526.95
storage.buckets.create 464.31
account.name.update 403.19
tablesdb.rows.create 367.01
functions.variables.update 356.54

…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.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · See the inline comments. Summary

…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.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@HarshMN2345
HarshMN2345 merged commit ec26529 into main Oct 21, 2026
39 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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.

1 participant