Repository navigation
fix(proxy): bind branch-pinned domains to a deployment - #13795
Merged
Merged
Conversation
Activating a deployment matched only rules whose deploymentVcsProviderBranch was empty, so a branch-pinned rule kept pointing at whatever it already held and a freshly created one kept pointing at nothing. Match the deployment's own branch alongside the empty value, as the build worker already does.
activate() runs only when a deployment is activated, and a push to a branch other than the production one never is. A rule pinned to such a branch was therefore never bound to anything, and its domain answered 404 for as long as it existed. Sites already avoid this through activateBranchPreviewRule. Repoint those rules from finalize() instead, for builds activate() does not handle, so the two paths stay disjoint. Template deployments are excluded: they reuse providerBranch for a resolved ref, tags included.
Creating a branch-pinned rule adopted whatever deployment the resource currently served, so the domain could be born pointing at a build from a different branch and stay there until that branch was next deployed. Look up the branch's newest ready deployment instead, and leave the rule unbound when the branch has none.
Contributor
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
A template deployment stores its resolved ref — branch, tag or commit — in providerBranch and carries no installationId. Every place that matched a branch therefore treated a template whose ref happened to equal a real branch name as a build of that branch, and could bind or repoint that branch's domain to template content. Require a genuine installation wherever providerBranch decides a match: rule creation, both manual activation paths, and the build worker. Cover the rebind end to end in the Gitea suite as well. Every unit test reaches activateBranchRule() directly, so deleting the call site in finalize() left them all green; the new deployment there is never activated, which is the only state that reaches it.
…into fix/rebind-branch-scoped-rules
updateEmptyManualRule() repoints every manual rule for the resource whose deploymentId is empty, with no predicate on the branch. That was near harmless while a rule was born holding whatever the resource served, but a branch-pinned rule created before its branch has built is now born empty by design, so the next template deploy or VCS redeploy would claim it and serve another ref's build from it. Scope it to branch-agnostic rules, as the sibling repoint in this class already scopes itself to one branch. Spell the branch check in activateBranchRule() the same way as the other call sites while here: empty() also rejects the branch named "0", which git allows, and that rule would never have been rebound.
Widening the rule query in the activate-deployment actions had no coverage: the unit tests reach the worker, which carries its own copy of the guard, and every existing caller of the route activates an uploaded deployment, whose branch is empty and whose query is therefore unchanged. Activate the branch's build at the end of the Gitea journey and assert the pinned rule follows it, which the route used to skip. Name the arrange helper after the operation it performs, name the template case after the state it describes rather than the field it reads, and say what the Proxy fixture actually holds: an uploaded deployment with no branch at all, not a build of some other branch.
…into fix/rebind-branch-scoped-rules
Meldiron
approved these changes
Sep 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A proxy rule pinned to a git branch could stay bound to no deployment forever. Its domain then answered
404on every request, while the console showed it as Verified with a working Open URL link, and redeploying never helped.Three separate gaps produced that state. Each commit closes one.
1. Activation ignored branch-pinned rules.
PATCH /v1/functions/:functionId/deploymentand its Sites twin matched only rules whosedeploymentVcsProviderBranchwas empty, so activating a deployment never repointed a branch-pinned rule. The build worker was already fixed this way; these two were not.2. Functions had no branch rebind at all — this is the root cause.
activate()runs only when a deployment is activated, and a push to a branch other than the production one never is. So for functions, a rule pinned to any non-production branch was never bound by anything. Sites do not have this problem:finalize()callsBase::activateBranchPreviewRule()on every successful site build, activated or not, and that call is gated on$collection === 'sites'.3. A rule could be born pointing at the wrong branch.
Proxy/Http/Rules/{Function,Site}/Create.phpadopted whatever deployment the resource currently served, regardless of branch, so a rule pinned todevcould start life on amainbuild.Changes
Functions/Http/Functions/Deployment/Update.php,Sites/Http/Sites/Deployment/Update.php— match the deployment's own branch alongside the empty value, mirroringFunctions/Workers/Jobs.php.Functions/Workers/Jobs.php— newactivateBranchRule()besideactivate(), called fromfinalize()for buildsactivate()does not handle. The guard is$deployment->getAttribute('activate') !== true, so the two paths are exactly disjoint and no rule is written or announced twice. Template deployments are excluded because they reuseproviderBranchfor a resolved ref, tags included — the same exclusionactivateBranchPreviewRule()makes.Proxy/Http/Rules/{Function,Site}/Create.php— a branch-pinned rule looks up that branch's newest ready deployment; ordering copied fromJobs::updateLatestDeployment.findOnereturns an empty document on a miss, so an unbound rule stays unbound rather than adopting a stranger's build.The two
Create.phpedits are duplicated inline rather than extracted, perAGENTS.md.Tests
tests/unit/Platform/Modules/Functions/Workers/ActivateRulesTest.phpgains two methods, using the suite's existingplatformDatabaseCapturing()andqueryFor()helpers and its named fake:['', $branch], which would duplicateactivate()'s work;installationIdis skipped, which is what keeps a template's resolved ref from repointing a branch rule.Both were mutation-checked: widening the query to
['', $branch]fails the first, and dropping theinstallationIdguard fails the second.tests/e2e/Services/Proxy/ProxyBase.phpgains one assertion in each of the two existing branch-rule tests, asserting through the public API that a rule pinned to a branch with no build of its own stays unbound.Locally:
ActivateRulesTest5/5,tests/unit/Platform309 tests with one pre-existingSwoole\Http\Responseenvironment error unrelated to these files. Pint passes on every changed file.Notes
Appwrite Cloud overrides
activate()without callingparent::, so it does not inherit commit 1 — that half is tracked separately. Rules already stuck unbound are not repaired by this PR; they bind on the next successful build of their branch, and anything older needs a backfill.