Committed-vendor deploys: autoloader skew
Moved verbatim from the drupal-deploy-safety SKILL.md (§8).
Applies to hosts that deploy committed git state and run no composer install
on the server.
What happens. The Composer autoloader class name carries a suffix
(ComposerAutoloaderInit<suffix>, ComposerStaticInit<suffix>) that appears
in three files:
vendor/autoload.php, at the vendor root (it's not insidevendor/composer/)vendor/composer/autoload_real.phpvendor/composer/autoload_static.php
Composer picks the suffix from the config.autoloader-suffix setting if one
is set. Otherwise it reuses the suffix it finds in the existing
vendor/autoload.php. Failing that, it generates one (recent Composer 2.x
uses the lock file's content-hash, else random bytes). If the suffix rotates
and you stage only vendor/composer/, the entry point and the class it loads
disagree. Drupal's autoload.php requires vendor/autoload.php on every
request, so the result is a site-wide fatal:
Class "ComposerAutoloaderInit<old>" not found.
Guards.
Pin the suffix so it never rotates:
"config": { "autoloader-suffix": "my_project" }When you actually add or remove a package, stage
vendor/autoload.php,vendor/composer/, any added or removed package directories, andvendor/drupal/DrupalInstalled.php(generated bydrupal/core-composer-scaffold), all together.Add a pre-commit or pre-push check: extract the suffix from all three files in the staged/committed tree (
git show :vendor/autoload.php, orHEAD:for a push) and fail if they differ.Never commit a dev-dependency autoloader. Build the committed vendor with
composer install --no-dev --optimize-autoloader. You can check it:vendor/composer/installed.phphas'dev' => falseunderrootfor a--no-devbuild. Fail the check if it'strue, or if dev-only packages (phpunit, etc.) show up in the committed classmap.Running
composer install --no-dev -obefore committing vendor is correct. The hazards are committing what comes after it and committing only part of it. If you runcomposer installagain to get your dev tools back, don't commit that result: it's a dev autoloader. And always commit all three suffix files together. A push that doesn't touch packages doesn't need a vendor rebuild at all, becausegit pushships commits, not the working tree.Don't fix a skew by regenerating in a throwaway checkout and copying files back. The optimized classmap comes from scanning files on disk, so a checkout that lacks untracked package files produces a smaller classmap. Reconcile forward: commit the entry point to match the already-committed pair, then diff against a clean
--no-devbuild.