Repository navigation
fix(functions): rebind generated branch domain on deployment activation - #13509
Conversation
A Git-connected function's generated "Deployed from <branch>" domain is a manual rule stored under its branch. When it is created before the first successful build — e.g. after an initial build fails — the rule is born with an empty deploymentId, and activate() only rebound rules with an empty deploymentVcsProviderBranch, so the branch rule was skipped and the domain stayed stuck on router_rule_not_found even after a later build activated. Include the activating deployment's own branch in the rule rebind query so the generated branch domain follows activation alongside the branch-agnostic custom and per-deployment domains.
Greptile SummaryThis PR updates function deployment activation so generated branch-scoped domains are rebound to the newly active deployment.
Confidence Score: 5/5The PR appears safe to merge; the branch-scoped rebinding is narrowly constrained and no actionable regressions remain. The activating deployment’s branch is added without removing the existing branch-agnostic match, and branchless deployments retain the prior behavior. Resource identity, resource type, and manual-trigger constraints remain intact, with targeted tests covering the changed behavior. Important Files Changed
Reviews (2): Last reviewed commit: "test(functions): satisfy Rector on activ..." | Re-trigger Greptile |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
What
When a Git-connected function activates a deployment, the worker now also repoints the generated "Deployed from
<branch>" domain (the branch-scoped rule) at that deployment — not only the branch-agnostic custom / per-deployment domains.Problem
Reported from Cloud (region
sfo,*.appwrite.network):The edge router is innocent here: the stuck domain returns
x-edge-rule-cache: miss, so the edge queries Cloud fresh every time and Cloud has no rule bound to a deployment for that host. There is no negative caching at the edge — it faithfully relays Cloud's 404.Root cause
A function's generated branch domain is a
rulesdocument with:trigger = 'manual'deploymentVcsProviderBranch = '<branch>'(e.g.main)deploymentId = ''when it is created before any successful build (the classic trigger being an initial build failure, but also the ordinary first-deploy race)On a successful, auto-activated build,
Functions\Workers\Jobs::activate()walks the resource's manual rules and stamps the newdeploymentIdonto them — but its query filtereddeploymentVcsProviderBranch => [''], i.e. only branch-agnostic rules. The branch-scoped generated domain never matched, so itsdeploymentIdstayed empty and the host kept 404ing.A manually added custom domain works because it is created after a deployment is live (so it is born already bound) and typically carries an empty branch — exactly the rows
activate()already handled.Fix
Include the activating deployment's own
providerBranchin the rebind query:main→ rebinds['', 'main']: branch-agnostic domains and theDeployed from maindomain.branch = '') → unchanged (['']), so a domain for some other branch is never dragged onto it.The rebind stays gated on activation (
activate === true), matching the reported expectation that the branch domain should follow the deployment that becomes Active.Tests
tests/unit/Platform/Modules/Functions/Workers/ActivateRulesTest.php:testActivateRebindsGeneratedBranchDomain— a VCS deployment scopes the rebind to['', 'main']forfunctionrules.testActivateOfNonVcsDeploymentOnlyTouchesBranchAgnosticRules— a branchless deployment stays scoped to[''].testActivateRepointsMatchedRuleAtTheNewDeployment— a matched rule's persisteddeploymentIdis set to the activating deployment and aRuleUpdatedevent is emitted.composer format,composer lint, andcomposer analyzepass on the changed files.Notes / follow-ups
PatchBackfillRuleDeploymentIdstask only matches synthetic<type>:<resourceId>deploymentIds viaQuery::contains('deploymentId', [':']), not these empty-string ones, so it won't catch them as-is.activate()override (src/Appwrite/Cloud/Platform/Workers/Jobs.php) carrying the samedeploymentVcsProviderBranch => ['']filter; it needs the identical change to take effect on Cloud.